From 9aae14a14a663a67da8f383d6fc5099f3d7c5f93 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Mon, 12 May 2025 05:24:05 +1000 Subject: [PATCH] test-runner: rework output dir construction The old code would compare all the test group names to work out some sort of common path, but it didn't appear to work consistently, sometimes placing output in a top-level dir, other times in one or more subdirs. (I confess, I do not quite understand what it's supposed to do). This is a very simple rework that simply looks at all the test group paths, removes common leading components, and uses the remainder as the output directory. This should work because groups paths are unique, and means we get a output dir tree of roughly the same shape as the test groups in the runfiles and the test source dirs themselves. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Reviewed-by: Tony Hutter Reviewed-by: Alexander Motin Reviewed-by: @ImAwsumm Signed-off-by: Rob Norris Closes #17167 --- tests/test-runner/bin/test-runner.py.in | 47 ++++++++++++++----------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/tests/test-runner/bin/test-runner.py.in b/tests/test-runner/bin/test-runner.py.in index 12c03f7bb..5bf13f5c0 100755 --- a/tests/test-runner/bin/test-runner.py.in +++ b/tests/test-runner/bin/test-runner.py.in @@ -858,9 +858,10 @@ class TestRun(object): def complete_outputdirs(self): """ - Collect all the pathnames for Tests, and TestGroups. Work - backwards one pathname component at a time, to create a unique - directory name in which to deposit test output. Tests will be able + Collect all the pathnames for Tests, and TestGroups. Strip off all + common leading path components, and append what remains to the top + "output" dir, to create a tree of output directories that match + the test and group names in structure. Tests will be able to write output files directly in the newly modified outputdir. TestGroups will be able to create one subdirectory per test in the outputdir, and are guaranteed uniqueness because a group can only @@ -869,24 +870,30 @@ class TestRun(object): question for their output. Failsafe scripts will create a directory rooted at the outputdir of each Test for their output. """ - done = False - components = 0 - tmp_dict = dict(list(self.tests.items()) + - list(self.testgroups.items())) - total = len(tmp_dict) - base = self.outputdir - while not done: - paths = [] - components -= 1 - for testfile in list(tmp_dict.keys()): - uniq = '/'.join(testfile.split('/')[components:]).lstrip('/') - if uniq not in paths: - paths.append(uniq) - tmp_dict[testfile].outputdir = os.path.join(base, uniq) - else: - break - done = total == len(paths) + alltests = dict(list(self.tests.items()) + + list(self.testgroups.items())) + base = os.path.join(self.outputdir, 'output') + + seen = [] + + for path in list(alltests.keys()): + frag = path.split('/') + for i in range(0, len(frag)): + if len(seen) == i: + seen.append({}) + seen[i][frag[i]] = 1 + + cut = 0 + for i in range(0, len(seen)): + if len(list(seen[i].keys())) == 1: + cut += 1 + else: + break + + for path in list(alltests.keys()): + uniq = path.split('/', cut)[-1] + alltests[path].outputdir = os.path.join(base, uniq) def setup_logging(self, options): """