aboutsummaryrefslogtreecommitdiffstats
path: root/test/run_tests.py
diff options
context:
space:
mode:
authorKlement Sekera <klement.sekera@gmail.com>2023-04-14 17:44:04 +0200
committerDave Wallace <dwallacelf@gmail.com>2023-04-25 15:44:13 +0000
commit08c50e3b7acb932adb1f62002619a1e52207262a (patch)
treec4c7583aef67c1dde62d2423f99f8fed562d5d11 /test/run_tests.py
parent39d7699c205bb243af12a2d32913e9a9af51b173 (diff)
tests: support multiple filter expressions
Support multiple comma-delimited filter expressions, e.g. to run both bfd and ip4 tests, it's now possible to do: make test TEST=bfd,ip4 Same goes for wildcards, e.g.: make test TEST=bfd,..test_longest_prefix_match,..test_icmp_error Type: improvement Change-Id: I0cceaa443cb612dca955f301c7407959f9a71a6e Signed-off-by: Klement Sekera <klement.sekera@gmail.com>
Diffstat (limited to 'test/run_tests.py')
-rw-r--r--test/run_tests.py56
1 files changed, 39 insertions, 17 deletions
diff --git a/test/run_tests.py b/test/run_tests.py
index 85344ca15e2..3bbf1bc3153 100644
--- a/test/run_tests.py
+++ b/test/run_tests.py
@@ -631,7 +631,7 @@ def parse_test_filter(test_filter):
if "." in f:
parts = f.split(".")
if len(parts) > 3:
- raise Exception("Unrecognized %s option: %s" % (test_option, f))
+ raise Exception(f"Invalid test filter: {test_filter}")
if len(parts) > 2:
if parts[2] not in ("*", ""):
filter_func_name = parts[2]
@@ -677,21 +677,40 @@ def filter_tests(tests, filter_cb):
class FilterByTestOption:
- def __init__(self, filter_file_name, filter_class_name, filter_func_name):
- self.filter_file_name = filter_file_name
- self.filter_class_name = filter_class_name
- self.filter_func_name = filter_func_name
+ def __init__(self, filters):
+ self.filters = filters
def __call__(self, file_name, class_name, func_name):
- if self.filter_file_name:
- fn_match = fnmatch.fnmatch(file_name, self.filter_file_name)
- if not fn_match:
+ def test_one(
+ filter_file_name,
+ filter_class_name,
+ filter_func_name,
+ file_name,
+ class_name,
+ func_name,
+ ):
+ if filter_file_name:
+ fn_match = fnmatch.fnmatch(file_name, filter_file_name)
+ if not fn_match:
+ return False
+ if filter_class_name and class_name != filter_class_name:
return False
- if self.filter_class_name and class_name != self.filter_class_name:
- return False
- if self.filter_func_name and func_name != self.filter_func_name:
- return False
- return True
+ if filter_func_name and func_name != filter_func_name:
+ return False
+ return True
+
+ for filter_file_name, filter_class_name, filter_func_name in self.filters:
+ if test_one(
+ filter_file_name,
+ filter_class_name,
+ filter_func_name,
+ file_name,
+ class_name,
+ func_name,
+ ):
+ return True
+
+ return False
class FilterByClassList:
@@ -938,14 +957,17 @@ if __name__ == "__main__":
descriptions = True
print("Running tests using custom test runner.")
- filter_file, filter_class, filter_func = parse_test_filter(config.filter)
+ filters = [(parse_test_filter(f)) for f in config.filter.split(",")]
print(
- "Selected filters: file=%s, class=%s, function=%s"
- % (filter_file, filter_class, filter_func)
+ "Selected filters: ",
+ "|".join(
+ f"file={filter_file}, class={filter_class}, function={filter_func}"
+ for filter_file, filter_class, filter_func in filters
+ ),
)
- filter_cb = FilterByTestOption(filter_file, filter_class, filter_func)
+ filter_cb = FilterByTestOption(filters)
cb = SplitToSuitesCallback(filter_cb)
for d in config.test_src_dir: