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.
This commit is contained in:
Victor Stinner 2023-10-05 08:24:43 +02:00 committed by GitHub
parent 313aa861ce
commit 6592976061
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 3 deletions

View file

@ -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,
@ -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

View file

@ -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)

View file

@ -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:
@ -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):

View file

@ -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.