Skip to content

Commit

Permalink
pythongh-110367: Enhance regrtest -jN --verbose3 (python#110368)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vstinner authored Oct 5, 2023
1 parent 313aa86 commit 6592976
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
15 changes: 13 additions & 2 deletions Lib/test/libregrtest/run_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ def create_worker_runtests(self, test_name: TestName, json_file: JsonFile) -> Ru
kwargs = {}
if match_tests:
kwargs['match_tests'] = match_tests
if self.runtests.output_on_failure:
kwargs['verbose'] = True
kwargs['output_on_failure'] = False
return self.runtests.copy(
tests=tests,
json_file=json_file,
Expand Down Expand Up @@ -562,8 +565,16 @@ def _process_result(self, item: QueueOutput) -> TestResult:
self.results.accumulate_result(result, self.runtests)
self.display_result(mp_result)

if mp_result.worker_stdout:
print(mp_result.worker_stdout, flush=True)
# Display worker stdout
if not self.runtests.output_on_failure:
show_stdout = True
else:
# --verbose3 ignores stdout on success
show_stdout = (result.state != State.PASSED)
if show_stdout:
stdout = mp_result.worker_stdout
if stdout:
print(stdout, flush=True)

return result

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_faulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def expected_traceback(lineno1, lineno2, header, min_count=1):
return '^' + regex + '$'

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

Expand Down
34 changes: 34 additions & 0 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
EXITCODE_RERUN_FAIL = 5
EXITCODE_INTERRUPTED = 130

MS_WINDOWS = (sys.platform == 'win32')

TEST_INTERRUPTED = textwrap.dedent("""
from signal import SIGINT, raise_signal
try:
Expand Down Expand Up @@ -2036,6 +2038,38 @@ def test_add_python_opts(self):
with self.subTest(opt=opt):
self.check_add_python_opts(opt)

# gh-76319: Raising SIGSEGV on Android may not cause a crash.
@unittest.skipIf(support.is_android,
'raising SIGSEGV on Android is unreliable')
def test_worker_output_on_failure(self):
try:
from faulthandler import _sigsegv
except ImportError:
self.skipTest("need faulthandler._sigsegv")

code = textwrap.dedent(r"""
import faulthandler
import unittest
from test import support
class CrashTests(unittest.TestCase):
def test_crash(self):
print("just before crash!", flush=True)
with support.SuppressCrashReport():
faulthandler._sigsegv(True)
""")
testname = self.create_test(code=code)

output = self.run_tests("-j1", testname, exitcode=EXITCODE_BAD_TEST)
self.check_executed_tests(output, testname,
failed=[testname],
stats=0, parallel=True)
if not MS_WINDOWS:
exitcode = -int(signal.SIGSEGV)
self.assertIn(f"Exit code {exitcode} (SIGSEGV)", output)
self.check_line(output, "just before crash!", full=True, regex=False)


class TestUtils(unittest.TestCase):
def test_format_duration(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
regrtest: 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. Patch by Victor Stinner.

0 comments on commit 6592976

Please sign in to comment.