Skip to content

Commit cdee3f1

Browse files
authored
bpo-30764: test_subprocess uses SuppressCrashReport (#2405)
bpo-30764, bpo-29335: test_child_terminated_in_stopped_state() of test_subprocess now uses support.SuppressCrashReport() to prevent the creation of a core dump on FreeBSD.
1 parent ace56d5 commit cdee3f1

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

Lib/test/test_subprocess.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,37 +2563,40 @@ def test_communicate_BrokenPipeError_stdin_close_with_timeout(self):
25632563
proc.communicate(timeout=999)
25642564
mock_proc_stdin.close.assert_called_once_with()
25652565

2566-
@unittest.skipIf(not ctypes, 'ctypes module required.')
2567-
@unittest.skipIf(not sys.executable, 'Test requires sys.executable.')
2566+
@unittest.skipIf(not ctypes, 'ctypes module required')
2567+
@unittest.skipIf(not sys.executable, 'Test requires sys.executable')
25682568
def test_child_terminated_in_stopped_state(self):
25692569
"""Test wait() behavior when waitpid returns WIFSTOPPED; issue29335."""
25702570
PTRACE_TRACEME = 0 # From glibc and MacOS (PT_TRACE_ME).
25712571
libc_name = ctypes.util.find_library('c')
25722572
libc = ctypes.CDLL(libc_name)
25732573
if not hasattr(libc, 'ptrace'):
2574-
raise unittest.SkipTest('ptrace() required.')
2575-
test_ptrace = subprocess.Popen(
2576-
[sys.executable, '-c', """if True:
2574+
raise unittest.SkipTest('ptrace() required')
2575+
2576+
code = textwrap.dedent(f"""
25772577
import ctypes
2578+
import faulthandler
2579+
from test.support import SuppressCrashReport
2580+
25782581
libc = ctypes.CDLL({libc_name!r})
25792582
libc.ptrace({PTRACE_TRACEME}, 0, 0)
2580-
""".format(libc_name=libc_name, PTRACE_TRACEME=PTRACE_TRACEME)
2581-
])
2582-
if test_ptrace.wait() != 0:
2583-
raise unittest.SkipTest('ptrace() failed - unable to test.')
2584-
child = subprocess.Popen(
2585-
[sys.executable, '-c', """if True:
2586-
import ctypes, faulthandler
2587-
libc = ctypes.CDLL({libc_name!r})
2588-
libc.ptrace({PTRACE_TRACEME}, 0, 0)
2589-
faulthandler._sigsegv() # Crash the process.
2590-
""".format(libc_name=libc_name, PTRACE_TRACEME=PTRACE_TRACEME)
2591-
])
2583+
""")
2584+
2585+
child = subprocess.Popen([sys.executable, '-c', code])
2586+
if child.wait() != 0:
2587+
raise unittest.SkipTest('ptrace() failed - unable to test')
2588+
2589+
code += textwrap.dedent(f"""
2590+
with SuppressCrashReport():
2591+
# Crash the process
2592+
faulthandler._sigsegv()
2593+
""")
2594+
child = subprocess.Popen([sys.executable, '-c', code])
25922595
try:
25932596
returncode = child.wait()
2594-
except Exception as e:
2597+
except:
25952598
child.kill() # Clean up the hung stopped process.
2596-
raise e
2599+
raise
25972600
self.assertNotEqual(0, returncode)
25982601
self.assertLess(returncode, 0) # signal death, likely SIGSEGV.
25992602

0 commit comments

Comments
 (0)