Skip to content

Commit

Permalink
test.py: make case cache global
Browse files Browse the repository at this point in the history
test.py runs each unit test's test case in a separate process.
The list of test cases is built at start, by running --list-cases
for each unit test. The output is cached, so that if one uses --repeat
option, we don't list the cases again and again.

The cache, however, was only useful for --repeat, because it was only
caching the last tests' output, not all tests output, so if I, for example,
run tests like:

./test.py foo bar foo

.. the cache was unused. Make the cache global which simplifies its
logic and makes it work in more cases.
  • Loading branch information
kostja committed Feb 4, 2022
1 parent 445f90d commit 45270f5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,18 @@ def pattern(self):
class BoostTestSuite(UnitTestSuite):
"""TestSuite for boost unit tests"""

# A cache of individual test cases, for which we have called
# --list_content. Static to share across all modes.
_case_cache = dict()

def __init__(self, path, cfg, options, mode):
super().__init__(path, cfg, options, mode)
self._cases_cache = {'name': None, 'cases': []}

def create_test(self, shortname, suite, args):
options = suite.options
if options.parallel_cases and (shortname not in self.no_parallel_cases):
if self._cases_cache['name'] != shortname:
fqname = os.path.join(self.mode, self.name, shortname)
if fqname not in self._case_cache:
exe = os.path.join("build", suite.mode, "test", suite.name, shortname)
cases = subprocess.run([exe, '--list_content'],
stdout=subprocess.PIPE,
Expand All @@ -226,10 +230,9 @@ def create_test(self, shortname, suite, args):
**{"ASAN_OPTIONS": "halt_on_error=0"}),
check=True, universal_newlines=True).stderr
case_list = [case[:-1] for case in cases.splitlines() if case.endswith('*')]
self._cases_cache['name'] = shortname
self._cases_cache['cases'] = case_list
self._case_cache[fqname] = case_list

case_list = self._cases_cache['cases']
case_list = self._case_cache[fqname]
if len(case_list) == 1:
test = BoostTest(self.next_id, shortname, suite, args, None)
self.tests.append(test)
Expand Down Expand Up @@ -737,6 +740,7 @@ def find_tests(options):

logging.info("Found %d tests, repeat count is %d, starting %d concurrent jobs",
TestSuite.test_count(), options.repeat, options.jobs)
print("Found {} tests.".format(TestSuite.test_count()))


async def run_all_tests(signaled, options):
Expand Down

0 comments on commit 45270f5

Please sign in to comment.