gh-119727: Add --single-process option to regrtest (#119728)

This commit is contained in:
Victor Stinner 2024-06-03 18:34:36 +02:00 committed by GitHub
parent 1d4c2e4a87
commit 4e8aa32245
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 46 additions and 12 deletions

View file

@ -89,12 +89,13 @@ class Regrtest:
self.cmdline_args: TestList = ns.args
# Workers
if ns.use_mp is None:
num_workers = 0 # run sequentially
self.single_process: bool = ns.single_process
if self.single_process or ns.use_mp is None:
num_workers = 0 # run sequentially in a single process
elif ns.use_mp <= 0:
num_workers = -1 # use the number of CPUs
num_workers = -1 # run in parallel, use the number of CPUs
else:
num_workers = ns.use_mp
num_workers = ns.use_mp # run in parallel
self.num_workers: int = num_workers
self.worker_json: StrJSON | None = ns.worker_json
@ -236,7 +237,7 @@ class Regrtest:
def _rerun_failed_tests(self, runtests: RunTests):
# Configure the runner to re-run tests
if self.num_workers == 0:
if self.num_workers == 0 and not self.single_process:
# Always run tests in fresh processes to have more deterministic
# initial state. Don't re-run tests in parallel but limit to a
# single worker process to have side effects (on the system load
@ -246,7 +247,6 @@ class Regrtest:
tests, match_tests_dict = self.results.prepare_rerun()
# Re-run failed tests
self.log(f"Re-running {len(tests)} failed tests in verbose mode in subprocesses")
runtests = runtests.copy(
tests=tests,
rerun=True,
@ -256,7 +256,15 @@ class Regrtest:
match_tests_dict=match_tests_dict,
output_on_failure=False)
self.logger.set_tests(runtests)
self._run_tests_mp(runtests, self.num_workers)
msg = f"Re-running {len(tests)} failed tests in verbose mode"
if not self.single_process:
msg = f"{msg} in subprocesses"
self.log(msg)
self._run_tests_mp(runtests, self.num_workers)
else:
self.log(msg)
self.run_tests_sequentially(runtests)
return runtests
def rerun_failed_tests(self, runtests: RunTests):
@ -371,7 +379,7 @@ class Regrtest:
tests = count(jobs, 'test')
else:
tests = 'tests'
msg = f"Run {tests} sequentially"
msg = f"Run {tests} sequentially in a single process"
if runtests.timeout:
msg += " (timeout: %s)" % format_duration(runtests.timeout)
self.log(msg)
@ -599,7 +607,7 @@ class Regrtest:
keep_environ = True
if cross_compile and hostrunner:
if self.num_workers == 0:
if self.num_workers == 0 and not self.single_process:
# For now use only two cores for cross-compiled builds;
# hostrunner can be expensive.
regrtest_opts.extend(['-j', '2'])