7 def positive_int_or_default(default):
8 def positive_integer(v):
9 if v is None or v == "":
12 raise ValueError("value must be positive")
15 return positive_integer
18 def positive_float_or_default(default):
19 def positive_float(v):
20 if v is None or v == "":
23 raise ValueError("value must be positive")
29 def positive_int_or_auto(v):
30 if v is None or v in ("", "auto"):
33 raise ValueError("value must be positive or auto")
38 if v is None or v in ("", "auto"):
41 raise ValueError("value must be positive or auto")
45 def int_choice_or_default(options, default):
46 assert default in options
49 if v is None or v == "":
53 raise ValueError("invalid choice")
59 if v is None or v == "":
61 if v.startswith("workers "):
62 return int(v.split(" ")[1])
67 if not os.path.isdir(v):
68 raise ValueError(f"provided path '{v}' doesn't exist or is not a directory")
72 def directory_verify_or_create(v):
73 if not os.path.isdir(v):
78 parser = argparse.ArgumentParser(
79 description="VPP unit tests", formatter_class=argparse.RawTextHelpFormatter
83 "--failfast", action="store_true", help="stop running tests on first failure"
90 help="directory containing test files "
91 "(may be specified multiple times) "
92 "(VPP_WS_DIR/test is added automatically to the set)",
100 default=default_verbose,
101 type=int_choice_or_default((0, 1, 2), default_verbose),
102 help="verbosity setting - 0 - least verbose, 2 - most verbose (default: 0)",
105 default_test_run_timeout = 600
110 type=positive_int_or_default(default_test_run_timeout),
111 default=default_test_run_timeout,
112 metavar="TEST_RUN_TIMEOUT",
113 help="test run timeout in seconds - per test "
114 f"(default: {default_test_run_timeout})",
121 help="directory containing failed tests (default: --tmp-dir)",
124 filter_help_string = """\
125 expression consists of one or more filters separated by commas (',')
126 filter consists of 3 string selectors separated by dots ('.')
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
146 5. 'bfd,ip4,..test_icmp_error' selects all test functions in test_bfd.py,
147 test_ip4.py and all test functions named 'test_icmp_error' in all files
150 "--filter", action="store", metavar="FILTER_EXPRESSION", help=filter_help_string
158 default=default_retries,
159 type=positive_int_or_default(default_retries),
160 help="retry failed tests RETRIES times",
164 "--step", action="store_true", default=False, help="enable stepping through tests"
167 debug_help_string = """\
168 attach - attach to already running vpp
169 core - detect coredump and load core in gdb on crash
170 gdb - print VPP PID and pause allowing attaching gdb
171 gdbserver - same as above, but run gdb in gdbserver
177 choices=["attach", "core", "gdb", "gdbserver"],
178 help=debug_help_string,
184 help="enable internal test framework debugging",
190 help="compress core files if not debugging them",
193 parser.add_argument("--extended", action="store_true", help="run extended tests")
196 "--sanity", action="store_true", help="perform sanity vpp run before running tests"
200 "--force-foreground",
202 help="force running in foreground - don't fork",
208 type=positive_int_or_auto,
210 help="maximum concurrent test jobs",
214 "--venv-dir", action="store", type=directory, help="path to virtual environment"
217 default_rnd_seed = time.time()
221 default=default_rnd_seed,
222 type=positive_float_or_default(default_rnd_seed),
223 help="random generator seed (default: current time)",
227 "--vpp-worker-count",
231 help="number of vpp workers",
235 "--gcov", action="store_true", default=False, help="running gcov tests"
239 "--cache-vpp-output",
242 help="cache VPP stdout/stderr and log as one block after test finishes",
250 help="vpp workspace directory",
259 help="vpp tag (e.g. vpp, vpp_debug, vpp_gcov)",
265 help="path to vpp binary (default: derive from VPP_WS_DIR and VPP_TAG)",
272 help="path to vpp install directory"
273 "(default: derive from VPP_WS_DIR and VPP_TAG)",
280 help="vpp build directory (default: derive from VPP_WS_DIR and VPP_TAG)",
287 help="directory containing vpp plugins"
288 "(default: derive from VPP_WS_DIR and VPP_TAG)",
292 "--vpp-test-plugin-dir",
295 help="directory containing vpp api test plugins"
296 "(default: derive from VPP_WS_DIR and VPP_TAG)",
300 "--extern-plugin-dir",
304 help="directory containing external plugins",
312 help="directory to look for API JSON files",
319 help="specify vpp coredump size",
327 help="max cpus used by vpp",
330 variant_help_string = """\
331 specify which march node variant to unit test
332 e.g. --variant=skx - test the skx march variants
333 e.g. --variant=icl - test the icl march variants
336 parser.add_argument("--variant", action="store", help=variant_help_string)
339 "--api-fuzz", action="store", default=None, help="specify api fuzzing parameters"
346 help="remove test tmp directory before running test",
353 type=directory_verify_or_create,
354 help="directory where to store test temporary directories",
360 type=directory_verify_or_create,
361 help="directory where to store directories "
362 "containing log files (default: --tmp-dir)",
365 default_keep_pcaps = False
369 default=default_keep_pcaps,
370 help=f"if set, keep all pcap files from a test run (default: {default_keep_pcaps})",
380 help="Runs tests against a running VPP.",
390 help="Relative or absolute path to running VPP's socket directory.\n"
391 "The directory must contain VPP's socket files:api.sock & stats.sock.\n"
392 "Default: /var/run/vpp if VPP is started as the root user, else "
393 "/var/run/user/${uid}/vpp.",
396 config = parser.parse_args()
398 ws = config.vpp_ws_dir
399 br = f"{ws}/build-root"
402 if config.vpp_install_dir is None:
403 config.vpp_install_dir = f"{br}/install-{tag}-native"
405 if config.vpp is None:
406 config.vpp = f"{config.vpp_install_dir}/vpp/bin/vpp"
408 if config.vpp_build_dir is None:
409 config.vpp_build_dir = f"{br}/build-{tag}-native"
411 libs = ["lib", "lib64"]
413 if config.vpp_plugin_dir is None:
414 config.vpp_plugin_dir = [
415 f"{config.vpp_install_dir}/vpp/{lib}/vpp_plugins" for lib in libs
418 if config.vpp_test_plugin_dir is None:
419 config.vpp_test_plugin_dir = [
420 f"{config.vpp_install_dir}/vpp/{lib}/vpp_api_test_plugins" for lib in libs
423 test_dirs = [f"{ws}/test"]
425 if config.test_src_dir is not None:
426 test_dirs.extend(config.test_src_dir)
428 config.test_src_dir = test_dirs
431 if config.venv_dir is None:
432 config.venv_dir = f"{ws}/build-root/test/venv"
434 if config.failed_dir is None:
435 config.failed_dir = f"{config.tmp_dir}"
437 available_cpus = psutil.Process().cpu_affinity()
438 num_cpus = len(available_cpus)
440 if config.max_vpp_cpus == "auto":
441 max_vpp_cpus = num_cpus
442 elif config.max_vpp_cpus > 0:
443 max_vpp_cpus = min(config.max_vpp_cpus, num_cpus)
445 max_vpp_cpus = num_cpus
447 if __name__ == "__main__":
448 print("Provided arguments:")
449 for i in config.__dict__:
450 print(f" {i} is {config.__dict__[i]}")