handle include and exclude, fix reporting

This commit is contained in:
Markus Pilman 2022-08-16 13:21:58 -06:00
parent 0971ee5f7a
commit 2704891c1a
2 changed files with 20 additions and 6 deletions

View File

@ -109,6 +109,10 @@ class Config:
self.binary_args = {'help': 'Path to executable'} self.binary_args = {'help': 'Path to executable'}
self.output_format: str = 'xml' self.output_format: str = 'xml'
self.output_format_args = {'short_name': 'O', 'choices': ['json', 'xml']} self.output_format_args = {'short_name': 'O', 'choices': ['json', 'xml']}
self.include_test_files: str = r'.*'
self.exclude_test_files: str = r'.^'
self.include_test_names: str = r'.*'
self.exclude_test_names: str = r'.^'
self.config_map = self._build_map() self.config_map = self._build_map()
def _build_map(self): def _build_map(self):

View File

@ -75,6 +75,10 @@ class TestPicker:
def __init__(self, test_dir: Path, fetcher: StatFetcherCreator): def __init__(self, test_dir: Path, fetcher: StatFetcherCreator):
if not test_dir.exists(): if not test_dir.exists():
raise RuntimeError('{} is neither a directory nor a file'.format(test_dir)) raise RuntimeError('{} is neither a directory nor a file'.format(test_dir))
self.include_files_regex = re.compile(config.include_test_files)
self.exclude_files_regex = re.compile(config.exclude_test_files)
self.include_tests_regex = re.compile(config.include_test_names)
self.exclude_tests_regex = re.compile(config.exclude_test_names)
self.test_dir: Path = test_dir self.test_dir: Path = test_dir
self.tests: OrderedDict[str, TestDescription] = collections.OrderedDict() self.tests: OrderedDict[str, TestDescription] = collections.OrderedDict()
self.restart_test: Pattern = re.compile(r".*-\d+\.(txt|toml)") self.restart_test: Pattern = re.compile(r".*-\d+\.(txt|toml)")
@ -117,6 +121,8 @@ class TestPicker:
idx += 1 idx += 1
def parse_txt(self, path: Path): def parse_txt(self, path: Path):
if self.include_files_regex.match(str(path)) is None or self.exclude_files_regex.match(str(path)) is not None:
return
with path.open('r') as f: with path.open('r') as f:
test_name: str | None = None test_name: str | None = None
test_class: str | None = None test_class: str | None = None
@ -145,6 +151,9 @@ class TestPicker:
test_class = test_name test_class = test_name
if priority is None: if priority is None:
priority = 1.0 priority = 1.0
if self.include_tests_regex.match(test_class) is None \
or self.exclude_tests_regex.match(test_class) is not None:
return
if test_class not in self.tests: if test_class not in self.tests:
self.tests[test_class] = TestDescription(path, test_class, priority) self.tests[test_class] = TestDescription(path, test_class, priority)
else: else:
@ -293,6 +302,7 @@ class TestRun:
self.buggify_enabled: bool = random.random() < config.buggify_on_ratio self.buggify_enabled: bool = random.random() < config.buggify_on_ratio
self.fault_injection_enabled: bool = True self.fault_injection_enabled: bool = True
self.trace_format = config.trace_format self.trace_format = config.trace_format
self.temp_path = config.run_dir / str(self.uid)
# state for the run # state for the run
self.retryable_error: bool = False self.retryable_error: bool = False
self.summary: Summary = Summary(binary) self.summary: Summary = Summary(binary)
@ -331,13 +341,13 @@ class TestRun:
command += ['-b', 'on'] command += ['-b', 'on']
if config.crash_on_error: if config.crash_on_error:
command.append('--crash') command.append('--crash')
temp_path = config.run_dir / str(self.uid)
temp_path.mkdir(parents=True, exist_ok=True) self.temp_path.mkdir(parents=True, exist_ok=True)
# self.log_test_plan(out) # self.log_test_plan(out)
resources = ResourceMonitor() resources = ResourceMonitor()
resources.start() resources.start()
process = subprocess.Popen(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=temp_path) process = subprocess.Popen(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=self.temp_path)
did_kill = False did_kill = False
try: try:
process.wait(20 * config.kill_seconds if self.use_valgrind else config.kill_seconds) process.wait(20 * config.kill_seconds if self.use_valgrind else config.kill_seconds)
@ -350,9 +360,11 @@ class TestRun:
self.summary.runtime = resources.time() self.summary.runtime = resources.time()
self.summary.max_rss = resources.max_rss self.summary.max_rss = resources.max_rss
self.summary.was_killed = did_kill self.summary.was_killed = did_kill
self.summary = Summary(self.binary, temp_path, runtime=resources.time(), max_rss=resources.max_rss, self.summary = Summary(self.binary, runtime=resources.time(), max_rss=resources.max_rss,
was_killed=did_kill, uid=self.uid, stats=self.stats, valgrind_out_file=valgrind_file, was_killed=did_kill, uid=self.uid, stats=self.stats, valgrind_out_file=valgrind_file,
expected_unseed=self.expected_unseed) expected_unseed=self.expected_unseed)
self.summary.summarize(self.temp_path)
self.summary.out.dump(sys.stdout)
return self.summary.ok() return self.summary.ok()
@ -400,7 +412,6 @@ class TestRunner:
self.backup_sim_dir(seed + count - 1) self.backup_sim_dir(seed + count - 1)
run = TestRun(binary, file.absolute(), seed + count, self.uid, restarting=count != 0, run = TestRun(binary, file.absolute(), seed + count, self.uid, restarting=count != 0,
stats=test_picker.dump_stats()) stats=test_picker.dump_stats())
run.summary.out.dump(sys.stdout)
result = result and run.success result = result and run.success
test_picker.add_time(file, run.run_time) test_picker.add_time(file, run.run_time)
if run.success and unseed_check and run.summary.unseed is not None: if run.success and unseed_check and run.summary.unseed is not None:
@ -408,7 +419,6 @@ class TestRunner:
run2 = TestRun(binary, file.absolute(), seed + count, self.uid, restarting=count != 0, run2 = TestRun(binary, file.absolute(), seed + count, self.uid, restarting=count != 0,
stats=test_picker.dump_stats(), expected_unseed=run.summary.unseed) stats=test_picker.dump_stats(), expected_unseed=run.summary.unseed)
test_picker.add_time(file, run2.run_time) test_picker.add_time(file, run2.run_time)
run2.summary.out.dump(sys.stdout)
if not result: if not result:
return False return False
count += 1 count += 1