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 3 string selectors separated by '.' separators:
127 <file>.<class>.<function>
129 - selectors restrict which files/classes/functions are run
130 - selector can be replaced with '*' or omitted entirely if not needed
131 - <file> selector is automatically prepended with 'test_' if required
132 - '.' separators are required only if selector(s) follow(s)
136 1. all of the following expressions are equivalent and will select
137 all test classes and functions from test_bfd.py:
138 'test_bfd' 'bfd' 'test_bfd..' 'bfd.' 'bfd.*.*' 'test_bfd.*.*'
139 2. 'bfd.BFDAPITestCase' selects all tests from test_bfd.py,
140 which are part of BFDAPITestCase class
141 3. 'bfd.BFDAPITestCase.test_add_bfd' selects a single test named
142 test_add_bfd from test_bfd.py/BFDAPITestCase
143 4. '.*.test_add_bfd' selects all test functions named test_add_bfd
144 from all files/classes
147 "--filter", action="store", metavar="FILTER_EXPRESSION", help=filter_help_string
155 default=default_retries,
156 type=positive_int_or_default(default_retries),
157 help="retry failed tests RETRIES times",
161 "--step", action="store_true", default=False, help="enable stepping through tests"
164 debug_help_string = """\
165 attach - attach to already running vpp
166 core - detect coredump and load core in gdb on crash
167 gdb - print VPP PID and pause allowing attaching gdb
168 gdbserver - same as above, but run gdb in gdbserver
174 choices=["attach", "core", "gdb", "gdbserver"],
175 help=debug_help_string,
181 help="enable internal test framework debugging",
187 help="compress core files if not debugging them",
190 parser.add_argument("--extended", action="store_true", help="run extended tests")
193 "--sanity", action="store_true", help="perform sanity vpp run before running tests"
197 "--force-foreground",
199 help="force running in foreground - don't fork",
205 type=positive_int_or_auto,
207 help="maximum concurrent test jobs",
211 "--venv-dir", action="store", type=directory, help="path to virtual environment"
214 default_rnd_seed = time.time()
218 default=default_rnd_seed,
219 type=positive_float_or_default(default_rnd_seed),
220 help="random generator seed (default: current time)",
224 "--vpp-worker-count",
228 help="number of vpp workers",
232 "--gcov", action="store_true", default=False, help="running gcov tests"
236 "--cache-vpp-output",
239 help="cache VPP stdout/stderr and log as one block after test finishes",
247 help="vpp workspace directory",
256 help="vpp tag (e.g. vpp, vpp_debug, vpp_gcov)",
262 help="path to vpp binary (default: derive from VPP_WS_DIR and VPP_TAG)",
269 help="path to vpp install directory"
270 "(default: derive from VPP_WS_DIR and VPP_TAG)",
277 help="vpp build directory (default: derive from VPP_WS_DIR and VPP_TAG)",
284 help="directory containing vpp plugins"
285 "(default: derive from VPP_WS_DIR and VPP_TAG)",
289 "--vpp-test-plugin-dir",
292 help="directory containing vpp api test plugins"
293 "(default: derive from VPP_WS_DIR and VPP_TAG)",
297 "--extern-plugin-dir",
301 help="directory containing external plugins",
308 help="specify vpp coredump size",
316 help="max cpus used by vpp",
319 variant_help_string = """\
320 specify which march node variant to unit test
321 e.g. --variant=skx - test the skx march variants
322 e.g. --variant=icl - test the icl march variants
325 parser.add_argument("--variant", action="store", help=variant_help_string)
328 "--api-fuzz", action="store", default=None, help="specify api fuzzing parameters"
335 help="remove test tmp directory before running test",
342 type=directory_verify_or_create,
343 help="directory where to store test temporary directories",
349 type=directory_verify_or_create,
350 help="directory where to store directories "
351 "containing log files (default: --tmp-dir)",
354 default_keep_pcaps = False
358 default=default_keep_pcaps,
359 help=f"if set, keep all pcap files from a test run (default: {default_keep_pcaps})",
369 help="Runs tests against a running VPP.",
379 help="Relative or absolute path to running VPP's socket directory.\n"
380 "The directory must contain VPP's socket files:api.sock & stats.sock.\n"
381 "Default: /var/run/vpp if VPP is started as the root user, else "
382 "/var/run/user/${uid}/vpp.",
385 config = parser.parse_args()
387 ws = config.vpp_ws_dir
388 br = f"{ws}/build-root"
391 if config.vpp_install_dir is None:
392 config.vpp_install_dir = f"{br}/install-{tag}-native"
394 if config.vpp is None:
395 config.vpp = f"{config.vpp_install_dir}/vpp/bin/vpp"
397 if config.vpp_build_dir is None:
398 config.vpp_build_dir = f"{br}/build-{tag}-native"
400 libs = ["lib", "lib64"]
402 if config.vpp_plugin_dir is None:
403 config.vpp_plugin_dir = [
404 f"{config.vpp_install_dir}/vpp/{lib}/vpp_plugins" for lib in libs
407 if config.vpp_test_plugin_dir is None:
408 config.vpp_test_plugin_dir = [
409 f"{config.vpp_install_dir}/vpp/{lib}/vpp_api_test_plugins" for lib in libs
412 test_dirs = [f"{ws}/test"]
414 if config.test_src_dir is not None:
415 test_dirs.extend(config.test_src_dir)
417 config.test_src_dir = test_dirs
420 if config.venv_dir is None:
421 config.venv_dir = f"{ws}/build-root/test/venv"
423 if config.failed_dir is None:
424 config.failed_dir = f"{config.tmp_dir}"
426 available_cpus = psutil.Process().cpu_affinity()
427 num_cpus = len(available_cpus)
429 if config.max_vpp_cpus == "auto":
430 max_vpp_cpus = num_cpus
431 elif config.max_vpp_cpus > 0:
432 max_vpp_cpus = min(config.max_vpp_cpus, num_cpus)
434 max_vpp_cpus = num_cpus
436 if __name__ == "__main__":
437 print("Provided arguments:")
438 for i in config.__dict__:
439 print(f" {i} is {config.__dict__[i]}")