From 26249f6c06591ba87d45e2a0f7322082a157fa06 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 6 Dec 2022 17:16:00 +1300 Subject: [PATCH] selftest: make filter-subunit much more efficient for large knownfail lists By compiling the knownfail lists ahead of time we change a 20min test into a 90sec test. This could be improved further by combining this into a single regular expression, but this is enough for now. The 'reason' is thankfully not used. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15258 Pair-programmed-with: Joseph Sutton Signed-off-by: Andrew Bartlett Signed-off-by: Joseph Sutton Reviewed-by: Stefan Metzmacher Reviewed-by: Ralph Boehme (cherry picked from commit 22128c718cadd34af892df102bd52df6a6b03303) --- selftest/subunithelper.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/selftest/subunithelper.py b/selftest/subunithelper.py index 2b78d16eb3ae..801149f8910d 100644 --- a/selftest/subunithelper.py +++ b/selftest/subunithelper.py @@ -236,7 +236,7 @@ class SubunitOps(TestProtocolClient, TestsuiteEnabledTestResult): def read_test_regexes(*names): - ret = {} + ret = [] files = [] for name in names: # if we are given a directory, we read all the files it contains @@ -256,20 +256,18 @@ def read_test_regexes(*names): continue if "#" in l: (regex, reason) = l.split("#", 1) - ret[regex.strip()] = reason.strip() + ret.append(re.compile(regex.strip())) else: - ret[l] = None + ret.append(re.compile(l)) return ret def find_in_list(regexes, fullname): - for regex, reason in regexes.items(): - if re.match(regex, fullname): - if reason is None: - return "" - return reason - return None + for regex in regexes: + if regex.match(fullname): + return True + return False class ImmediateFail(Exception): @@ -344,10 +342,10 @@ class FilterOps(unittest.TestResult): def addFailure(self, test, err=None): test = self._add_prefix(test) - xfail_reason = find_in_list(self.expected_failures, test.id()) - if xfail_reason is None: - xfail_reason = find_in_list(self.flapping, test.id()) - if xfail_reason is not None: + xfail = find_in_list(self.expected_failures, test.id()) + if not xfail: + xfail = find_in_list(self.flapping, test.id()) + if xfail: self.xfail_added += 1 self.total_xfail += 1 self._ops.addExpectedFailure(test, err) @@ -365,8 +363,8 @@ class FilterOps(unittest.TestResult): def addSuccess(self, test): test = self._add_prefix(test) - xfail_reason = find_in_list(self.expected_failures, test.id()) - if xfail_reason is not None: + xfail = find_in_list(self.expected_failures, test.id()) + if xfail: self.uxsuccess_added += 1 self.total_uxsuccess += 1 self._ops.addUnexpectedSuccess(test) @@ -438,11 +436,11 @@ class FilterOps(unittest.TestResult): if expected_failures is not None: self.expected_failures = expected_failures else: - self.expected_failures = {} + self.expected_failures = [] if flapping is not None: self.flapping = flapping else: - self.flapping = {} + self.flapping = [] self.strip_ok_output = strip_ok_output self.xfail_added = 0 self.fail_added = 0 -- 2.34.1