Skip to content

Commit 6592976

Browse files
authored
gh-110367: Enhance regrtest -jN --verbose3 (#110368)
When using worker processes (-jN) with --verbose3 option, regrtest can now display the worker output even if a worker process does crash. Previously, sys.stdout and sys.stderr were replaced and so the worker output was lost on a crash.
1 parent 313aa86 commit 6592976

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

Lib/test/libregrtest/run_workers.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ def create_worker_runtests(self, test_name: TestName, json_file: JsonFile) -> Ru
262262
kwargs = {}
263263
if match_tests:
264264
kwargs['match_tests'] = match_tests
265+
if self.runtests.output_on_failure:
266+
kwargs['verbose'] = True
267+
kwargs['output_on_failure'] = False
265268
return self.runtests.copy(
266269
tests=tests,
267270
json_file=json_file,
@@ -562,8 +565,16 @@ def _process_result(self, item: QueueOutput) -> TestResult:
562565
self.results.accumulate_result(result, self.runtests)
563566
self.display_result(mp_result)
564567

565-
if mp_result.worker_stdout:
566-
print(mp_result.worker_stdout, flush=True)
568+
# Display worker stdout
569+
if not self.runtests.output_on_failure:
570+
show_stdout = True
571+
else:
572+
# --verbose3 ignores stdout on success
573+
show_stdout = (result.state != State.PASSED)
574+
if show_stdout:
575+
stdout = mp_result.worker_stdout
576+
if stdout:
577+
print(stdout, flush=True)
567578

568579
return result
569580

Lib/test/test_faulthandler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def expected_traceback(lineno1, lineno2, header, min_count=1):
3535
return '^' + regex + '$'
3636

3737
def skip_segfault_on_android(test):
38-
# Issue #32138: Raising SIGSEGV on Android may not cause a crash.
38+
# gh-76319: Raising SIGSEGV on Android may not cause a crash.
3939
return unittest.skipIf(is_android,
4040
'raising SIGSEGV on Android is unreliable')(test)
4141

Lib/test/test_regrtest.py

+34
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
EXITCODE_RERUN_FAIL = 5
4343
EXITCODE_INTERRUPTED = 130
4444

45+
MS_WINDOWS = (sys.platform == 'win32')
46+
4547
TEST_INTERRUPTED = textwrap.dedent("""
4648
from signal import SIGINT, raise_signal
4749
try:
@@ -2036,6 +2038,38 @@ def test_add_python_opts(self):
20362038
with self.subTest(opt=opt):
20372039
self.check_add_python_opts(opt)
20382040

2041+
# gh-76319: Raising SIGSEGV on Android may not cause a crash.
2042+
@unittest.skipIf(support.is_android,
2043+
'raising SIGSEGV on Android is unreliable')
2044+
def test_worker_output_on_failure(self):
2045+
try:
2046+
from faulthandler import _sigsegv
2047+
except ImportError:
2048+
self.skipTest("need faulthandler._sigsegv")
2049+
2050+
code = textwrap.dedent(r"""
2051+
import faulthandler
2052+
import unittest
2053+
from test import support
2054+
2055+
class CrashTests(unittest.TestCase):
2056+
def test_crash(self):
2057+
print("just before crash!", flush=True)
2058+
2059+
with support.SuppressCrashReport():
2060+
faulthandler._sigsegv(True)
2061+
""")
2062+
testname = self.create_test(code=code)
2063+
2064+
output = self.run_tests("-j1", testname, exitcode=EXITCODE_BAD_TEST)
2065+
self.check_executed_tests(output, testname,
2066+
failed=[testname],
2067+
stats=0, parallel=True)
2068+
if not MS_WINDOWS:
2069+
exitcode = -int(signal.SIGSEGV)
2070+
self.assertIn(f"Exit code {exitcode} (SIGSEGV)", output)
2071+
self.check_line(output, "just before crash!", full=True, regex=False)
2072+
20392073

20402074
class TestUtils(unittest.TestCase):
20412075
def test_format_duration(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
regrtest: When using worker processes (-jN) with --verbose3 option, regrtest
2+
can now display the worker output even if a worker process does crash.
3+
Previously, sys.stdout and sys.stderr were replaced and so the worker output
4+
was lost on a crash. Patch by Victor Stinner.

0 commit comments

Comments
 (0)