8 def positive_int_or_default(default):
9 def positive_integer(v):
10 if v is None or v == "":
13 raise ValueError("value must be positive")
16 return positive_integer
19 def positive_float_or_default(default):
20 def positive_float(v):
21 if v is None or v == "":
24 raise ValueError("value must be positive")
30 def positive_int_or_auto(v):
31 if v is None or v in ("", "auto"):
34 raise ValueError("value must be positive or auto")
39 if v is None or v in ("", "auto"):
42 raise ValueError("value must be positive or auto")
46 def int_choice_or_default(options, default):
47 assert default in options
50 if v is None or v == "":
54 raise ValueError("invalid choice")
60 if v is None or v == "":
62 if v.startswith("workers "):
63 return int(v.split(" ")[1])
68 if not os.path.isdir(v):
69 raise ValueError(f"provided path '{v}' doesn't exist or is not a directory")
73 def directory_verify_or_create(v):
74 if not os.path.isdir(v):
79 parser = argparse.ArgumentParser(
80 description="VPP unit tests", formatter_class=argparse.RawTextHelpFormatter
84 "--failfast", action="store_true", help="stop running tests on first failure"
91 help="directory containing test files "
92 "(may be specified multiple times) "
93 "(VPP_WS_DIR/test is added automatically to the set)",
101 default=default_verbose,
102 type=int_choice_or_default((0, 1, 2), default_verbose),
103 help="verbosity setting - 0 - least verbose, 2 - most verbose (default: 0)",
106 default_test_run_timeout = 600
111 type=positive_int_or_default(default_test_run_timeout),
112 default=default_test_run_timeout,
113 metavar="TEST_RUN_TIMEOUT",
114 help="test run timeout in seconds - per test "
115 f"(default: {default_test_run_timeout})",
122 help="directory containing failed tests",
125 filter_help_string = """\
126 expression consists of 3 string selectors separated by '.' separators:
128 <file>.<class>.<function>
130 - selectors restrict which files/classes/functions are run
131 - selector can be replaced with '*' or omitted entirely if not needed
132 - <file> selector is automatically prepended with 'test_' if required
133 - '.' separators are required only if selector(s) follow(s)
137 1. all of the following expressions are equivalent and will select
138 all test classes and functions from test_bfd.py:
139 'test_bfd' 'bfd' 'test_bfd..' 'bfd.' 'bfd.*.*' 'test_bfd.*.*'
140 2. 'bfd.BFDAPITestCase' selects all tests from test_bfd.py,
141 which are part of BFDAPITestCase class
142 3. 'bfd.BFDAPITestCase.test_add_bfd' selects a single test named
143 test_add_bfd from test_bfd.py/BFDAPITestCase
144 4. '.*.test_add_bfd' selects all test functions named test_add_bfd
145 from all files/classes
148 "--filter", action="store", metavar="FILTER_EXPRESSION", help=filter_help_string
156 default=default_retries,
157 type=positive_int_or_default(default_retries),
158 help="retry failed tests RETRIES times",
162 "--step", action="store_true", default=False, help="enable stepping through tests"
165 debug_help_string = """\
166 attach - attach to already running vpp
167 core - detect coredump and load core in gdb on crash
168 gdb - print VPP PID and pause allowing attaching gdb
169 gdbserver - same as above, but run gdb in gdbserver
175 choices=["attach", "core", "gdb", "gdbserver"],
176 help=debug_help_string,
182 help="enable internal test framework debugging",
188 help="compress core files if not debugging them",
191 parser.add_argument("--extended", action="store_true", help="run extended tests")
194 "--sanity", action="store_true", help="perform sanity vpp run before running tests"
198 "--force-foreground",
200 help="force running in foreground - don't fork",
206 type=positive_int_or_auto,
208 help="maximum concurrent test jobs",
212 "--venv-dir", action="store", type=directory, help="path to virtual environment"
215 default_rnd_seed = time.time()
219 default=default_rnd_seed,
220 type=positive_float_or_default(default_rnd_seed),
221 help="random generator seed (default: current time)",
225 "--vpp-worker-count",
229 help="number of vpp workers",
233 "--gcov", action="store_true", default=False, help="running gcov tests"
237 "--cache-vpp-output",
240 help="cache VPP stdout/stderr and log as one block after test finishes",
248 help="vpp workspace directory",
257 help="vpp tag (e.g. vpp, vpp_debug, vpp_gcov)",
263 help="path to vpp binary (default: derive from VPP_WS_DIR and VPP_TAG)",
270 help="path to vpp install directory"
271 "(default: derive from VPP_WS_DIR and VPP_TAG)",
278 help="vpp build directory (default: derive from VPP_WS_DIR and VPP_TAG)",
285 help="directory containing vpp plugins"
286 "(default: derive from VPP_WS_DIR and VPP_TAG)",
290 "--vpp-test-plugin-dir",
293 help="directory containing vpp api test plugins"
294 "(default: derive from VPP_WS_DIR and VPP_TAG)",
298 "--extern-plugin-dir",
302 help="directory containing external plugins",
309 help="specify vpp coredump size",
317 help="max cpus used by vpp",
320 variant_help_string = """\
321 specify which march node variant to unit test
322 e.g. --variant=skx - test the skx march variants
323 e.g. --variant=icl - test the icl march variants
326 parser.add_argument("--variant", action="store", help=variant_help_string)
329 "--api-fuzz", action="store", default=None, help="specify api fuzzing parameters"
336 help="remove test tmp directory before running test",
343 type=directory_verify_or_create,
344 help="directory where to store test temporary directories",
350 type=directory_verify_or_create,
351 help="directory where to store directories "
352 "containing log files (default: --tmp-dir)",
355 default_keep_pcaps = False
359 default=default_keep_pcaps,
360 help="if set, keep all pcap files from a test run"
361 f" (default: {default_keep_pcaps})",
364 config = parser.parse_args()
366 ws = config.vpp_ws_dir
367 br = f"{ws}/build-root"
370 if config.vpp_install_dir is None:
371 config.vpp_install_dir = f"{br}/install-{tag}-native"
373 if config.vpp is None:
374 config.vpp = f"{config.vpp_install_dir}/vpp/bin/vpp"
376 if config.vpp_build_dir is None:
377 config.vpp_build_dir = f"{br}/build-{tag}-native"
379 libs = ["lib", "lib64"]
381 if config.vpp_plugin_dir is None:
382 config.vpp_plugin_dir = [
383 f"{config.vpp_install_dir}/vpp/{lib}/vpp_plugins" for lib in libs
386 if config.vpp_test_plugin_dir is None:
387 config.vpp_test_plugin_dir = [
388 f"{config.vpp_install_dir}/vpp/{lib}/vpp_api_test_plugins" for lib in libs
391 test_dirs = [f"{ws}/test"]
393 if config.test_src_dir is not None:
394 test_dirs.extend(config.test_src_dir)
396 config.test_src_dir = test_dirs
399 if config.venv_dir is None:
400 config.venv_dir = f"{ws}/test/venv"
402 available_cpus = psutil.Process().cpu_affinity()
403 num_cpus = len(available_cpus)
405 if config.max_vpp_cpus == "auto":
406 max_vpp_cpus = num_cpus
407 elif config.max_vpp_cpus > 0:
408 max_vpp_cpus = min(config.max_vpp_cpus, num_cpus)
410 max_vpp_cpus = num_cpus
412 if __name__ == "__main__":
413 print("Provided arguments:")
414 for i in config.__dict__:
415 print(f" {i} is {config.__dict__[i]}")