diff --git a/test.py b/test.py index 941987840..8f271f206 100755 --- a/test.py +++ b/test.py @@ -8,6 +8,7 @@ import argparse import fnmatch import os import queue +import re import shutil import signal import subprocess @@ -1248,7 +1249,7 @@ def run_tests(): # user wants to run everything. # if len(args.example): - build_cmd = "./ns3 build %s" % os.path.basename(args.example) + build_cmd = "./ns3 build %s" % os.path.basename(args.example.replace("*", "")) else: build_cmd = "./ns3" @@ -1710,14 +1711,51 @@ def run_tests(): # ./test.py: run all of the examples # ./test.py --constrain=unit run no examples # ./test.py --constrain=example run all of the examples - # ./test.py --suite=some-test-suite: run no examples - # ./test.py --example=some-example: run the single example - # ./test.py --suite=some-suite --example=some-example: run the single example + # ./test.py --suite=some-test-suite run no examples + # ./test.py --example=some-example run the single example with no parameters + # ./test.py --example="some-example --args=2" run the single example with custom parameters + # ./test.py --example=some-example* run the all examples-to-run.py instances with said example + # ./test.py --suite=some-suite --example=some-example run the single example # # - if len(args.suite) == 0 and len(args.example) == 0 and len(args.pyexample) == 0: + if len(args.suite) == 0 and len(args.pyexample) == 0: if len(args.constrain) == 0 or args.constrain == "example": if ENABLE_EXAMPLES: + if args.example: + if args.example.endswith("*"): + # If an example name is passed without arguments, we filter all examples containing said program + example_tests = list( + filter(lambda x: args.example[:-1] in x[0], example_tests) + ) + args.example_args = [] + else: + example_tests = list( + filter( + lambda x: " ".join([args.example, *args.example_args]) + == x[0].split("/")[-1], + example_tests, + ) + ) + args.example_args = [] + + if not example_tests or args.example_args: + # If an example name is passed with arguments, we create an example entry for said example + example_name = " ".join([args.example, *args.example_args]) + example_path = "%s%s-%s%s" % ( + APPNAME, + VERSION, + args.example, + BUILD_PROFILE_SUFFIX, + ) + if example_path in ns3_runnable_programs_dictionary: + example_path = ns3_runnable_programs_dictionary[example_path] + example_path += ".exe" if sys.platform == "win32" else "" + example_path = " ".join([example_path, *args.example_args]) + example_tests = [(example_name, example_path, "True", "True", "QUICK")] + else: + print("No example matching the name %s" % example_name) + example_tests = [] + for name, test, do_run, do_valgrind_run, fullness in example_tests: # Remove any arguments and directory names from test. test_name = test.split(" ", 1)[0] @@ -1772,44 +1810,6 @@ def run_tests(): jobs = jobs + 1 total_tests = total_tests + 1 - elif len(args.example): - # Add the proper prefix and suffix to the example name to - # match what is done in the CMakeLists.txt file. - example_name = "%s%s-%s%s" % (APPNAME, VERSION, args.example, BUILD_PROFILE_SUFFIX) - - key_list = [] - for key in ns3_runnable_programs_dictionary: - key_list.append(key) - example_name_key_list = fnmatch.filter(key_list, example_name) - - if len(example_name_key_list) == 0: - print("No example matching the name %s" % args.example) - else: - # - # If you tell me to run an example, I will try and run the example - # irrespective of any condition. - # - for example_name_iter in example_name_key_list: - example_path = ns3_runnable_programs_dictionary[example_name_iter] - example_path = os.path.abspath(example_path) - job = Job() - job.set_is_example(True) - job.set_is_pyexample(False) - job.set_display_name(example_path) - job.set_tmp_file_name("") - job.set_cwd(testpy_output_dir) - job.set_basedir(os.getcwd()) - job.set_tempdir(testpy_output_dir) - job.set_shell_command(example_path) - job.set_build_path(args.buildpath) - - if args.verbose: - print("Queue %s" % example_name_iter) - - input_queue.put(job) - jobs = jobs + 1 - total_tests = total_tests + 1 - # # Run some Python examples as smoke tests. We have a list of all of # the example programs it makes sense to try and run. Each example will @@ -2237,6 +2237,17 @@ def run_tests(): return 1 # catchall for general errors +def split_program_and_arguments(argv): + split_argv = re.findall(r'(?:".*[|*]?"|\S)+', argv) + program = "" + program_args = [] + if split_argv: + program = split_argv[0] + if len(split_argv) > 1: + program_args = split_argv[1:] + return program, program_args + + def main(argv): parser = argparse.ArgumentParser() parser.add_argument( @@ -2428,6 +2439,8 @@ def main(argv): global args args = parser.parse_args() + args.example, exargs = split_program_and_arguments(args.example) + setattr(args, "example_args", exargs) signal.signal(signal.SIGINT, sigint_hook) # From waf/waflib/Options.py diff --git a/utils/tests/test-test.py b/utils/tests/test-test.py index 98c676569..8d79da382 100644 --- a/utils/tests/test-test.py +++ b/utils/tests/test-test.py @@ -100,6 +100,9 @@ def main(argv): "--html=t_opt.html && rm t_opt.html", "-x t_opt.xml && rm t_opt.xml", "--xml=t_opt.xml && rm t_opt.xml", + "--example=wifi-phy-configuration", + "--example=wifi-phy-configuration*", + '--example="wifi-phy-configuration --testCase=0"', ] configure_string = sys.executable + " ns3 configure --enable-tests --enable-examples"