Bug 1463 - ./test.py --example should automatically detect the path
authorMitch Watrous <watrous@u.washington.edu>
Fri, 14 Sep 2012 11:48:14 -0700
changeset 9076 7c9f34fa2dd6
parent 9075 f8fe606acbda
child 9077 16e6f501eeef
Bug 1463 - ./test.py --example should automatically detect the path
RELEASE_NOTES
doc/manual/source/test-framework.rst
test.py
wscript
--- a/RELEASE_NOTES	Wed Sep 12 14:59:21 2012 -0700
+++ b/RELEASE_NOTES	Fri Sep 14 11:48:14 2012 -0700
@@ -24,8 +24,13 @@
 
 Bugs fixed
 ----------
+ - bug 1284 - ./test.py performance tests do not exist
+ - bug 1463 - ./test.py --example should automatically detect the path
  - bug 1485 - Setting global properties in config file (raw text) does
               not have any effect
+ - bug 1493 - test.py --list should show the test type default tip
+ - bug 1494 - test.py --constrain doesn't work
+ - bug 1495 - test.py claims test passed when no test was run
 
 Known issues
 ------------
--- a/doc/manual/source/test-framework.rst	Wed Sep 12 14:59:21 2012 -0700
+++ b/doc/manual/source/test-framework.rst	Fri Sep 14 11:48:14 2012 -0700
@@ -115,7 +115,8 @@
     -c KIND, --constrain=KIND
                           constrain the test-runner by kind of test
     -e EXAMPLE, --example=EXAMPLE
-                          specify a single example to run (with relative path)
+                          specify a single example to run (no relative path is
+                          needed)
     -g, --grind           run the test suites and examples using valgrind
     -k, --kinds           print the kinds of tests available
     -l, --list            print the list of known tests
@@ -285,12 +286,12 @@
 
 Similarly to test suites, one can run a single C++ example program
 using the ``--example`` option.  Note that the relative path for the
-example must be included and that the executables built for C++
-examples do not have extensions.  Entering
+example does not need to be included and that the executables built
+for C++ examples do not have extensions.  Entering
 
 ::
 
-  ./test.py --example=examples/udp/udp-echo
+  ./test.py --example=udp-echo
 
 results in that single example being run.
 
@@ -303,7 +304,7 @@
 
 ::
 
-  ./test.py --buildpath=/home/craigdo/repos/ns-3-allinone-test/ns-3-dev/build/debug --example=examples/wireless/wifi-simple-adhoc
+  ./test.py --buildpath=/home/craigdo/repos/ns-3-allinone-test/ns-3-dev/build/debug --example=wifi-simple-adhoc
 
 One can run a single Python example program using the ``--pyexample``
 option.  Note that the relative path for the example must be included
--- a/test.py	Wed Sep 12 14:59:21 2012 -0700
+++ b/test.py	Fri Sep 14 11:48:14 2012 -0700
@@ -1044,7 +1044,9 @@
     #
     make_paths()
 
+    #
     # Get the information from the build status file.
+    #
     build_status_file = os.path.join (NS3_BUILDDIR, 'build-status.py')
     if os.path.exists(build_status_file):
         ns3_runnable_programs = get_list_from_file(build_status_file, "ns3_runnable_programs")
@@ -1053,6 +1055,15 @@
         print >> sys.stderr, 'The build status file was not found.  You must do waf build before running test.py.'
         sys.exit(2)
 
+    #
+    # Make a dictionary that maps the name of a program to its path.
+    #
+    ns3_runnable_programs_dictionary = {}
+    for program in ns3_runnable_programs:
+        # Remove any directory names from path.
+        program_name = os.path.basename(program)
+        ns3_runnable_programs_dictionary[program_name] = program
+
     # Generate the lists of examples to run as smoke tests in order to
     # ensure that they remain buildable and runnable over time.
     #
@@ -1367,7 +1378,7 @@
                     test_name = os.path.basename(test_name)
 
                     # Don't try to run this example if it isn't runnable.
-                    if test_name in ns3_runnable_programs:
+                    if ns3_runnable_programs_dictionary.has_key(test_name):
                         if eval(do_run):
                             job = Job()
                             job.set_is_example(True)
@@ -1393,22 +1404,21 @@
     elif len(options.example):
         # Add the proper prefix and suffix to the example name to
         # match what is done in the wscript file.
-        (example_path_without_name, example_name) = os.path.split(options.example)
-        example_name = "%s%s-%s-%s" % (APPNAME, VERSION, example_name, BUILD_PROFILE)
-        example_path = os.path.join(example_path_without_name, example_name)
+        example_name = "%s%s-%s-%s" % (APPNAME, VERSION, options.example, BUILD_PROFILE)
 
         # Don't try to run this example if it isn't runnable.
-        if example_name not in ns3_runnable_programs:
+        if not ns3_runnable_programs_dictionary.has_key(example_name):
             print "Example %s is not runnable." % example_name
         else:
             #
             # If you tell me to run an example, I will try and run the example
             # irrespective of any condition.
             #
+            example_path = ns3_runnable_programs_dictionary[example_name]
             job = Job()
             job.set_is_example(True)
             job.set_is_pyexample(False)
-            job.set_display_name(example_name)
+            job.set_display_name(example_path)
             job.set_tmp_file_name("")
             job.set_cwd(testpy_output_dir)
             job.set_basedir(os.getcwd())
@@ -1755,7 +1765,7 @@
 
     parser.add_option("-e", "--example", action="store", type="string", dest="example", default="",
                       metavar="EXAMPLE",
-                      help="specify a single example to run (with relative path)")
+                      help="specify a single example to run (no relative path is needed)")
 
     parser.add_option("-u", "--update-data", action="store_true", dest="update_data", default=False,
                       help="If examples use reference data files, get them to re-generate them")
--- a/wscript	Wed Sep 12 14:59:21 2012 -0700
+++ b/wscript	Fri Sep 14 11:48:14 2012 -0700
@@ -773,7 +773,15 @@
                 if program_built:
                     object_name = "%s%s-%s%s" % (wutils.APPNAME, wutils.VERSION, 
                                                   obj.name, bld.env.BUILD_SUFFIX)
-                    bld.env.append_value('NS3_RUNNABLE_PROGRAMS', object_name)
+
+                    # Get the relative path to the program from the
+                    # launch directory.
+                    launch_dir = os.path.abspath(Context.launch_dir)
+                    object_relative_path = os.path.join(
+                        wutils.relpath(obj.path.abspath(), launch_dir),
+                        object_name)
+
+                    bld.env.append_value('NS3_RUNNABLE_PROGRAMS', object_relative_path)
 
             # disable the modules themselves
             if hasattr(obj, "is_ns3_module") and obj.name not in modules: