diff --git a/docs/results.md b/docs/results.md index 4a497c4..9c0ee0c 100644 --- a/docs/results.md +++ b/docs/results.md @@ -201,6 +201,7 @@ kci-dev results builds --giturl 'https://git.kernel.org/pub/scm/linux/kernel/git ## --filter Pass a YAML filter file to customize results. Only supports hardware and test name filtering at the moment. +You can use wildcards (`*`) in both `hardware` and `test`. See filter yaml example below: (available for subcommands `boots` and `tests`) @@ -212,6 +213,7 @@ hardware: test: - kselftest.dt - kselftest.iommu + - kunit.* ``` Example: diff --git a/kcidev/subcommands/results/parser.py b/kcidev/subcommands/results/parser.py index 2c088a0..f1ec9b6 100644 --- a/kcidev/subcommands/results/parser.py +++ b/kcidev/subcommands/results/parser.py @@ -1,5 +1,6 @@ import gzip import json +import re import requests import yaml @@ -224,13 +225,13 @@ def filter_out_by_hardware(test, filter_data): if "hardware" not in filter_data: return False - hardware_list = filter_data["hardware"] - if test["environment_misc"]["platform"] in hardware_list: + hardware_list_re = re.compile(filter_data["hardware"]) + if hardware_list_re.match(test["environment_misc"]["platform"]): return False if test["environment_compatible"]: for compatible in test["environment_compatible"]: - if compatible in hardware_list: + if hardware_list_re.match(compatible): return False return True @@ -238,15 +239,31 @@ def filter_out_by_hardware(test, filter_data): def filter_out_by_test(test, filter_data): # Check if the test name is in the list - test_list = filter_data["test"] - if test["path"] in test_list: + test_list_re = re.compile(filter_data["test"]) + if test_list_re.match(test["path"]): return False return True -def cmd_tests(data, id, download_logs, status_filter, filter, count, use_json): +def filter_array2regex(filter_array): + return f"^({'|'.join(filter_array)})$".replace(".", r"\.").replace("*", ".*") + + +def parse_filter_file(filter): filter_data = yaml.safe_load(filter) if filter else None + if filter_data is None: + return None + parsed_filter = {} + if "hardware" in filter_data: + parsed_filter["hardware"] = filter_array2regex(filter_data["hardware"]) + if "test" in filter_data: + parsed_filter["test"] = filter_array2regex(filter_data["test"]) + return parsed_filter + + +def cmd_tests(data, id, download_logs, status_filter, filter, count, use_json): + filter_data = parse_filter_file(filter) filtered_tests = 0 tests = [] for test in data: