Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 1 | import argparse |
| 2 | import os |
| 3 | import psutil |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 4 | import time |
Andrew Yourtchenko | 9ba6dcf | 2023-06-20 14:52:08 +0000 | [diff] [blame] | 5 | from vpp_qemu_utils import can_create_namespaces |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 6 | |
| 7 | |
| 8 | def positive_int_or_default(default): |
| 9 | def positive_integer(v): |
Dmitry Valter | 236fae4 | 2023-10-11 20:37:04 +0000 | [diff] [blame] | 10 | if v is None or v == "" or int(v) == default: |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 11 | return default |
Andrew Yourtchenko | f56b007 | 2022-03-18 17:05:53 +0000 | [diff] [blame] | 12 | if int(v) <= 0: |
| 13 | raise ValueError("value must be positive") |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 14 | return int(v) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 15 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 16 | return positive_integer |
| 17 | |
| 18 | |
Andrew Yourtchenko | f56b007 | 2022-03-18 17:05:53 +0000 | [diff] [blame] | 19 | def positive_float_or_default(default): |
| 20 | def positive_float(v): |
Dmitry Valter | 236fae4 | 2023-10-11 20:37:04 +0000 | [diff] [blame] | 21 | if v is None or v == "" or float(v) == default: |
Andrew Yourtchenko | f56b007 | 2022-03-18 17:05:53 +0000 | [diff] [blame] | 22 | return default |
| 23 | if float(v) <= 0: |
| 24 | raise ValueError("value must be positive") |
| 25 | return float(v) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 26 | |
Andrew Yourtchenko | f56b007 | 2022-03-18 17:05:53 +0000 | [diff] [blame] | 27 | return positive_float |
| 28 | |
| 29 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 30 | def positive_int_or_auto(v): |
| 31 | if v is None or v in ("", "auto"): |
| 32 | return "auto" |
| 33 | if int(v) <= 0: |
| 34 | raise ValueError("value must be positive or auto") |
| 35 | return int(v) |
| 36 | |
| 37 | |
| 38 | def int_or_auto(v): |
| 39 | if v is None or v in ("", "auto"): |
| 40 | return "auto" |
| 41 | if int(v) < 0: |
| 42 | raise ValueError("value must be positive or auto") |
| 43 | return int(v) |
| 44 | |
| 45 | |
| 46 | def int_choice_or_default(options, default): |
| 47 | assert default in options |
| 48 | |
| 49 | def choice(v): |
| 50 | if v is None or v == "": |
| 51 | return default |
| 52 | if int(v) in options: |
| 53 | return int(v) |
| 54 | raise ValueError("invalid choice") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 55 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 56 | return choice |
| 57 | |
| 58 | |
| 59 | def worker_config(v): |
| 60 | if v is None or v == "": |
| 61 | return 0 |
| 62 | if v.startswith("workers "): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 63 | return int(v.split(" ")[1]) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 64 | return int(v) |
| 65 | |
| 66 | |
| 67 | def directory(v): |
| 68 | if not os.path.isdir(v): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 69 | raise ValueError(f"provided path '{v}' doesn't exist or is not a directory") |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 70 | return v |
| 71 | |
| 72 | |
| 73 | def directory_verify_or_create(v): |
| 74 | if not os.path.isdir(v): |
| 75 | os.mkdir(v) |
| 76 | return v |
| 77 | |
| 78 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 79 | parser = argparse.ArgumentParser( |
| 80 | description="VPP unit tests", formatter_class=argparse.RawTextHelpFormatter |
| 81 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 82 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 83 | parser.add_argument( |
| 84 | "--failfast", action="store_true", help="stop running tests on first failure" |
| 85 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 86 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 87 | parser.add_argument( |
| 88 | "--test-src-dir", |
| 89 | action="append", |
| 90 | type=directory, |
| 91 | help="directory containing test files " |
| 92 | "(may be specified multiple times) " |
| 93 | "(VPP_WS_DIR/test is added automatically to the set)", |
| 94 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 95 | |
| 96 | default_verbose = 0 |
| 97 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 98 | parser.add_argument( |
| 99 | "--verbose", |
| 100 | action="store", |
| 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)", |
| 104 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 105 | |
| 106 | default_test_run_timeout = 600 |
| 107 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 108 | parser.add_argument( |
| 109 | "--timeout", |
| 110 | action="store", |
| 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})", |
| 116 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 117 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 118 | parser.add_argument( |
| 119 | "--failed-dir", |
| 120 | action="store", |
| 121 | type=directory, |
Klement Sekera | 152a9b6 | 2022-05-13 18:01:36 +0200 | [diff] [blame] | 122 | help="directory containing failed tests (default: --tmp-dir)", |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 123 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 124 | |
| 125 | filter_help_string = """\ |
Klement Sekera | 08c50e3 | 2023-04-14 17:44:04 +0200 | [diff] [blame] | 126 | expression consists of one or more filters separated by commas (',') |
| 127 | filter consists of 3 string selectors separated by dots ('.') |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 128 | |
| 129 | <file>.<class>.<function> |
| 130 | |
| 131 | - selectors restrict which files/classes/functions are run |
| 132 | - selector can be replaced with '*' or omitted entirely if not needed |
| 133 | - <file> selector is automatically prepended with 'test_' if required |
| 134 | - '.' separators are required only if selector(s) follow(s) |
| 135 | |
| 136 | examples: |
| 137 | |
| 138 | 1. all of the following expressions are equivalent and will select |
| 139 | all test classes and functions from test_bfd.py: |
| 140 | 'test_bfd' 'bfd' 'test_bfd..' 'bfd.' 'bfd.*.*' 'test_bfd.*.*' |
| 141 | 2. 'bfd.BFDAPITestCase' selects all tests from test_bfd.py, |
| 142 | which are part of BFDAPITestCase class |
| 143 | 3. 'bfd.BFDAPITestCase.test_add_bfd' selects a single test named |
| 144 | test_add_bfd from test_bfd.py/BFDAPITestCase |
| 145 | 4. '.*.test_add_bfd' selects all test functions named test_add_bfd |
| 146 | from all files/classes |
Klement Sekera | 08c50e3 | 2023-04-14 17:44:04 +0200 | [diff] [blame] | 147 | 5. 'bfd,ip4,..test_icmp_error' selects all test functions in test_bfd.py, |
| 148 | test_ip4.py and all test functions named 'test_icmp_error' in all files |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 149 | """ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 150 | parser.add_argument( |
| 151 | "--filter", action="store", metavar="FILTER_EXPRESSION", help=filter_help_string |
| 152 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 153 | |
| 154 | default_retries = 0 |
| 155 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 156 | parser.add_argument( |
| 157 | "--retries", |
| 158 | action="store", |
| 159 | default=default_retries, |
| 160 | type=positive_int_or_default(default_retries), |
| 161 | help="retry failed tests RETRIES times", |
| 162 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 163 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 164 | parser.add_argument( |
| 165 | "--step", action="store_true", default=False, help="enable stepping through tests" |
| 166 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 167 | |
| 168 | debug_help_string = """\ |
| 169 | attach - attach to already running vpp |
| 170 | core - detect coredump and load core in gdb on crash |
| 171 | gdb - print VPP PID and pause allowing attaching gdb |
| 172 | gdbserver - same as above, but run gdb in gdbserver |
| 173 | """ |
| 174 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 175 | parser.add_argument( |
| 176 | "--debug", |
| 177 | action="store", |
| 178 | choices=["attach", "core", "gdb", "gdbserver"], |
| 179 | help=debug_help_string, |
| 180 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 181 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 182 | parser.add_argument( |
| 183 | "--debug-framework", |
| 184 | action="store_true", |
| 185 | help="enable internal test framework debugging", |
| 186 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 187 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 188 | parser.add_argument( |
| 189 | "--compress-core", |
| 190 | action="store_true", |
| 191 | help="compress core files if not debugging them", |
| 192 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 193 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 194 | parser.add_argument("--extended", action="store_true", help="run extended tests") |
Andrew Yourtchenko | 9ba6dcf | 2023-06-20 14:52:08 +0000 | [diff] [blame] | 195 | parser.add_argument( |
| 196 | "--skip-netns-tests", |
| 197 | action="store_true", |
| 198 | help="skip tests involving netns operations", |
| 199 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 200 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 201 | parser.add_argument( |
| 202 | "--sanity", action="store_true", help="perform sanity vpp run before running tests" |
| 203 | ) |
Maxime Peim | 77caeb1 | 2023-11-14 15:26:41 +0100 | [diff] [blame] | 204 | parser.add_argument("--api-preload", action="store_true", help="preload API files") |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 205 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 206 | parser.add_argument( |
| 207 | "--force-foreground", |
| 208 | action="store_true", |
| 209 | help="force running in foreground - don't fork", |
| 210 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 211 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 212 | parser.add_argument( |
| 213 | "--jobs", |
| 214 | action="store", |
| 215 | type=positive_int_or_auto, |
| 216 | default="auto", |
| 217 | help="maximum concurrent test jobs", |
| 218 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 219 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 220 | parser.add_argument( |
| 221 | "--venv-dir", action="store", type=directory, help="path to virtual environment" |
| 222 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 223 | |
| 224 | default_rnd_seed = time.time() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 225 | parser.add_argument( |
| 226 | "--rnd-seed", |
| 227 | action="store", |
| 228 | default=default_rnd_seed, |
| 229 | type=positive_float_or_default(default_rnd_seed), |
| 230 | help="random generator seed (default: current time)", |
| 231 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 232 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 233 | parser.add_argument( |
| 234 | "--vpp-worker-count", |
| 235 | action="store", |
| 236 | type=worker_config, |
| 237 | default=0, |
| 238 | help="number of vpp workers", |
| 239 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 240 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 241 | parser.add_argument( |
| 242 | "--gcov", action="store_true", default=False, help="running gcov tests" |
| 243 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 244 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 245 | parser.add_argument( |
| 246 | "--cache-vpp-output", |
| 247 | action="store_true", |
| 248 | default=False, |
| 249 | help="cache VPP stdout/stderr and log as one block after test finishes", |
| 250 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 251 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 252 | parser.add_argument( |
| 253 | "--vpp-ws-dir", |
| 254 | action="store", |
| 255 | required=True, |
| 256 | type=directory, |
| 257 | help="vpp workspace directory", |
| 258 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 259 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 260 | parser.add_argument( |
| 261 | "--vpp-tag", |
| 262 | action="store", |
| 263 | default="vpp_debug", |
| 264 | metavar="VPP_TAG", |
| 265 | required=True, |
| 266 | help="vpp tag (e.g. vpp, vpp_debug, vpp_gcov)", |
| 267 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 268 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 269 | parser.add_argument( |
| 270 | "--vpp", |
| 271 | action="store", |
| 272 | help="path to vpp binary (default: derive from VPP_WS_DIR and VPP_TAG)", |
| 273 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 274 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 275 | parser.add_argument( |
| 276 | "--vpp-install-dir", |
| 277 | type=directory, |
| 278 | action="store", |
| 279 | help="path to vpp install directory" |
| 280 | "(default: derive from VPP_WS_DIR and VPP_TAG)", |
| 281 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 282 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 283 | parser.add_argument( |
| 284 | "--vpp-build-dir", |
| 285 | action="store", |
| 286 | type=directory, |
| 287 | help="vpp build directory (default: derive from VPP_WS_DIR and VPP_TAG)", |
| 288 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 289 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 290 | parser.add_argument( |
| 291 | "--vpp-plugin-dir", |
| 292 | action="append", |
| 293 | type=directory, |
| 294 | help="directory containing vpp plugins" |
| 295 | "(default: derive from VPP_WS_DIR and VPP_TAG)", |
| 296 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 297 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 298 | parser.add_argument( |
| 299 | "--vpp-test-plugin-dir", |
| 300 | action="append", |
| 301 | type=directory, |
| 302 | help="directory containing vpp api test plugins" |
| 303 | "(default: derive from VPP_WS_DIR and VPP_TAG)", |
| 304 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 305 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 306 | parser.add_argument( |
| 307 | "--extern-plugin-dir", |
| 308 | action="append", |
| 309 | type=directory, |
| 310 | default=[], |
| 311 | help="directory containing external plugins", |
| 312 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 313 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 314 | parser.add_argument( |
Ole Troan | 37157da | 2022-12-01 11:22:06 +0100 | [diff] [blame] | 315 | "--extern-apidir", |
| 316 | action="append", |
| 317 | type=directory, |
| 318 | default=[], |
| 319 | help="directory to look for API JSON files", |
| 320 | ) |
| 321 | |
| 322 | parser.add_argument( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 323 | "--coredump-size", |
| 324 | action="store", |
| 325 | default="unlimited", |
| 326 | help="specify vpp coredump size", |
| 327 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 328 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 329 | parser.add_argument( |
| 330 | "--max-vpp-cpus", |
| 331 | action="store", |
| 332 | type=int_or_auto, |
| 333 | default=0, |
| 334 | help="max cpus used by vpp", |
| 335 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 336 | |
| 337 | variant_help_string = """\ |
| 338 | specify which march node variant to unit test |
| 339 | e.g. --variant=skx - test the skx march variants |
| 340 | e.g. --variant=icl - test the icl march variants |
| 341 | """ |
| 342 | |
| 343 | parser.add_argument("--variant", action="store", help=variant_help_string) |
| 344 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 345 | parser.add_argument( |
| 346 | "--api-fuzz", action="store", default=None, help="specify api fuzzing parameters" |
| 347 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 348 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 349 | parser.add_argument( |
| 350 | "--wipe-tmp-dir", |
| 351 | action="store_true", |
| 352 | default=True, |
| 353 | help="remove test tmp directory before running test", |
| 354 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 355 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 356 | parser.add_argument( |
| 357 | "--tmp-dir", |
| 358 | action="store", |
| 359 | default="/tmp", |
| 360 | type=directory_verify_or_create, |
| 361 | help="directory where to store test temporary directories", |
| 362 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 363 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 364 | parser.add_argument( |
| 365 | "--log-dir", |
| 366 | action="store", |
| 367 | type=directory_verify_or_create, |
| 368 | help="directory where to store directories " |
| 369 | "containing log files (default: --tmp-dir)", |
| 370 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 371 | |
| 372 | default_keep_pcaps = False |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 373 | parser.add_argument( |
| 374 | "--keep-pcaps", |
| 375 | action="store_true", |
| 376 | default=default_keep_pcaps, |
Klement Sekera | 152a9b6 | 2022-05-13 18:01:36 +0200 | [diff] [blame] | 377 | help=f"if set, keep all pcap files from a test run (default: {default_keep_pcaps})", |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 378 | ) |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 379 | |
Naveen Joy | c872cec | 2022-08-30 13:59:03 -0700 | [diff] [blame] | 380 | parser.add_argument( |
| 381 | "-r", |
| 382 | "--use-running-vpp", |
| 383 | dest="running_vpp", |
| 384 | required=False, |
| 385 | action="store_true", |
| 386 | default=False, |
| 387 | help="Runs tests against a running VPP.", |
| 388 | ) |
| 389 | |
| 390 | parser.add_argument( |
Andrew Yourtchenko | bc37878 | 2023-09-26 16:01:21 +0200 | [diff] [blame] | 391 | "--excluded-plugin", |
| 392 | dest="excluded_plugins", |
| 393 | required=False, |
| 394 | action="append", |
| 395 | default=[], |
| 396 | help="Exclude the tests that indicate they require this plugin(s)", |
| 397 | ) |
| 398 | |
| 399 | parser.add_argument( |
Naveen Joy | c872cec | 2022-08-30 13:59:03 -0700 | [diff] [blame] | 400 | "-d", |
| 401 | "--socket-dir", |
| 402 | dest="socket_dir", |
| 403 | required=False, |
| 404 | action="store", |
| 405 | default="", |
| 406 | help="Relative or absolute path to running VPP's socket directory.\n" |
| 407 | "The directory must contain VPP's socket files:api.sock & stats.sock.\n" |
| 408 | "Default: /var/run/vpp if VPP is started as the root user, else " |
| 409 | "/var/run/user/${uid}/vpp.", |
| 410 | ) |
| 411 | |
Klement Sekera | ca2f2e1 | 2024-05-23 11:19:51 +0200 | [diff] [blame] | 412 | default_decode_pcaps = "failed" |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 413 | parser.add_argument( |
| 414 | "--decode-pcaps", |
Klement Sekera | ca2f2e1 | 2024-05-23 11:19:51 +0200 | [diff] [blame] | 415 | action="store", |
| 416 | choices=["none", "failed", "all"], |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 417 | default=default_decode_pcaps, |
| 418 | help=f"if set, decode all pcap files from a test run (default: {default_decode_pcaps})", |
| 419 | ) |
| 420 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 421 | config = parser.parse_args() |
| 422 | |
| 423 | ws = config.vpp_ws_dir |
| 424 | br = f"{ws}/build-root" |
| 425 | tag = config.vpp_tag |
| 426 | |
| 427 | if config.vpp_install_dir is None: |
| 428 | config.vpp_install_dir = f"{br}/install-{tag}-native" |
| 429 | |
| 430 | if config.vpp is None: |
| 431 | config.vpp = f"{config.vpp_install_dir}/vpp/bin/vpp" |
| 432 | |
| 433 | if config.vpp_build_dir is None: |
| 434 | config.vpp_build_dir = f"{br}/build-{tag}-native" |
| 435 | |
| 436 | libs = ["lib", "lib64"] |
| 437 | |
| 438 | if config.vpp_plugin_dir is None: |
| 439 | config.vpp_plugin_dir = [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 440 | f"{config.vpp_install_dir}/vpp/{lib}/vpp_plugins" for lib in libs |
| 441 | ] |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 442 | |
| 443 | if config.vpp_test_plugin_dir is None: |
| 444 | config.vpp_test_plugin_dir = [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 445 | f"{config.vpp_install_dir}/vpp/{lib}/vpp_api_test_plugins" for lib in libs |
| 446 | ] |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 447 | |
| 448 | test_dirs = [f"{ws}/test"] |
| 449 | |
| 450 | if config.test_src_dir is not None: |
| 451 | test_dirs.extend(config.test_src_dir) |
| 452 | |
| 453 | config.test_src_dir = test_dirs |
| 454 | |
| 455 | |
| 456 | if config.venv_dir is None: |
Saima Yunus | c7f93b3 | 2022-08-10 03:25:31 -0400 | [diff] [blame] | 457 | config.venv_dir = f"{ws}/build-root/test/venv" |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 458 | |
Klement Sekera | 152a9b6 | 2022-05-13 18:01:36 +0200 | [diff] [blame] | 459 | if config.failed_dir is None: |
| 460 | config.failed_dir = f"{config.tmp_dir}" |
| 461 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 462 | available_cpus = psutil.Process().cpu_affinity() |
| 463 | num_cpus = len(available_cpus) |
| 464 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 465 | if config.max_vpp_cpus == "auto": |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 466 | max_vpp_cpus = num_cpus |
| 467 | elif config.max_vpp_cpus > 0: |
| 468 | max_vpp_cpus = min(config.max_vpp_cpus, num_cpus) |
| 469 | else: |
| 470 | max_vpp_cpus = num_cpus |
| 471 | |
Andrew Yourtchenko | 9ba6dcf | 2023-06-20 14:52:08 +0000 | [diff] [blame] | 472 | if not config.skip_netns_tests: |
| 473 | if not can_create_namespaces(): |
| 474 | config.skip_netns_tests = True |
| 475 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 476 | if __name__ == "__main__": |
| 477 | print("Provided arguments:") |
| 478 | for i in config.__dict__: |
| 479 | print(f" {i} is {config.__dict__[i]}") |