start of regression tests
authorCraig Dowell <craigdo@ee.washington.edu>
Tue, 25 Mar 2008 23:17:24 -0700
changeset 2846 7689461231ac
parent 2740 45f6c609e22c
child 2847 f0aedbbb037b
start of regression tests
regression/regression.py
regression/tests/test_csma_one_subnet.py
regression/waf
wscript
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regression/regression.py	Tue Mar 25 23:17:24 2008 -0700
@@ -0,0 +1,123 @@
+#! /usr/bin/env python
+# regression.py adapted from python language regression scripts.
+
+"""Regression test.
+
+This will find all modules whose name is "test_*" in the tests
+directory, and run them.
+
+Command line options:
+
+-v: verbose   -- run tests in verbose mode with output to stdout
+-g: generate  -- write the output file for a test instead of comparing it
+
+If non-option arguments are present, they are names for tests to run.
+If no test names are given, all tests are run.
+
+"""
+
+import sys
+import os
+import getopt
+
+verbose = 0
+generate = 0
+
+def main(tests = None, testdir = None):
+    """Execute regression tests.
+
+    Arguments:
+    tests -- a list of strings containing test names (optional)
+    testdir -- the directory in which to look for tests (optional)
+    """
+
+    global verbose
+    global generate
+    
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], 'vg')
+    except getopt.error, msg:
+        print msg
+        print __doc__
+        return 2
+
+    for o, a in opts:
+        if o == '-v': verbose = 1
+        if o == '-g': generate = 1
+
+    if not os.path.exists('./traces'):
+        os.mkdir('./traces')
+    
+    bad = []
+
+    if not testdir:
+        testdir = os.path.join(os.curdir, "tests")
+
+    if not os.path.exists(testdir):
+        print "Tests directory does not exist"
+        return 3
+    
+    if verbose:
+        print "tests directory: ", testdir
+
+    sys.path.append(testdir)
+        
+    for i in range(len(args)):
+        if args[i][-3:] == '.py':
+            args[i] = args[i][:-3]
+
+    if not tests:
+        tests = args
+
+    if not tests:
+        tests = findtests(testdir)
+
+    for test in tests:
+        if verbose:
+            print "main(): running test", test
+        result = runtest(test)
+        if result == 0:
+            print "PASS ", test
+        else:
+            bad.append(test)
+            print "FAIL ", test
+
+    return len(bad) > 0
+
+def findtests(testdir):
+    """Return a list of test modules in the test directory
+
+    Arguments:
+    testdir -- the directory to look in for tests
+    """
+    if verbose:
+        print "findtests(", testdir, ")"
+    if verbose:
+        print "findtests(): look in ", testdir
+
+    names = os.listdir(testdir)
+    if verbose:
+        print "findtests(): found ", names
+    tests = []
+    for name in names:
+        if name[:5] == "test_" and name[-3:] == ".py":
+            testname = name[:-3]
+            tests.append(testname)
+    tests.sort()
+    if verbose:
+        print "findtests(): found tests ", tests
+    return tests
+
+def runtest(test):
+    """Run a single test.
+
+    Arguments:
+    test -- the name of the test
+    """
+    if verbose:
+        print "runtest(): run ", test
+    mod = __import__(test, globals(), locals(), [])
+    return mod.run(verbose, generate)
+
+if __name__ == '__main__':
+    sys.exit(main())
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regression/tests/test_csma_one_subnet.py	Tue Mar 25 23:17:24 2008 -0700
@@ -0,0 +1,10 @@
+#! /usr/bin/env python
+
+"""Regression test csma-one-subnet."""
+
+import os
+
+def run(verbose, generate):
+    """Execute a test."""
+    os.system("./waf --cwd regression/traces --run csma-one-subnet")
+    return 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regression/waf	Tue Mar 25 23:17:24 2008 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../waf "$@"
\ No newline at end of file
--- a/wscript	Tue Mar 25 14:17:35 2008 -0700
+++ b/wscript	Tue Mar 25 23:17:24 2008 -0700
@@ -20,7 +20,6 @@
 srcdir = '.'
 blddir = 'build'
 
-
 def dist_hook():
     shutil.rmtree("doc/html", True)
     shutil.rmtree("doc/latex", True)
@@ -48,6 +47,11 @@
     # options provided by the modules
     opt.tool_options('compiler_cxx')
 
+    opt.add_option('--cwd',
+                   help=('Set the working directory for a program.'),
+                   action="store", type="string", default=None,
+                   dest='cwd_launch')
+
     opt.add_option('--enable-gcov',
                    help=('Enable code coverage analysis.'
                          ' WARNING: this option only has effect '
@@ -164,7 +168,7 @@
 
 def build(bld):
     Params.g_cwd_launch = Params.g_build.m_curdirnode.abspath()
-
+        
     bld.create_ns3_program = types.MethodType(create_ns3_program, bld)
 
     variant_name = bld.env_of_name('default')['NS3_ACTIVE_VARIANT']
@@ -378,9 +382,11 @@
 
         execvec = shlex.split(command_template % (program_node.abspath(env),))
 
-
     former_cwd = os.getcwd()
-    os.chdir(Params.g_cwd_launch)
+    if (Params.g_options.cwd_launch):
+        os.chdir(Params.g_options.cwd_launch)
+    else:
+        os.chdir(Params.g_cwd_launch)
     try:
         retval = _run_argv(execvec)
     finally:
@@ -416,7 +422,6 @@
     env = Params.g_build.env_of_name('default')
     _run_argv([shell], {'NS3_MODULE_PATH': os.pathsep.join(env['NS3_MODULE_PATH'])})
 
-
 def doxygen():
     if not os.path.exists('doc/introspected-doxygen.h'):
         Params.warning("doc/introspected-doxygen.h does not exist; run waf check to generate it.")