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.
This commit is contained in:
Victor Stinner 2017-06-26 17:23:03 +02:00 committed by GitHub
parent ace56d5836
commit cdee3f14f7

View file

@ -2563,37 +2563,40 @@ class POSIXProcessTestCase(BaseTestCase):
proc.communicate(timeout=999) proc.communicate(timeout=999)
mock_proc_stdin.close.assert_called_once_with() mock_proc_stdin.close.assert_called_once_with()
@unittest.skipIf(not ctypes, 'ctypes module required.') @unittest.skipIf(not ctypes, 'ctypes module required')
@unittest.skipIf(not sys.executable, 'Test requires sys.executable.') @unittest.skipIf(not sys.executable, 'Test requires sys.executable')
def test_child_terminated_in_stopped_state(self): def test_child_terminated_in_stopped_state(self):
"""Test wait() behavior when waitpid returns WIFSTOPPED; issue29335.""" """Test wait() behavior when waitpid returns WIFSTOPPED; issue29335."""
PTRACE_TRACEME = 0 # From glibc and MacOS (PT_TRACE_ME). PTRACE_TRACEME = 0 # From glibc and MacOS (PT_TRACE_ME).
libc_name = ctypes.util.find_library('c') libc_name = ctypes.util.find_library('c')
libc = ctypes.CDLL(libc_name) libc = ctypes.CDLL(libc_name)
if not hasattr(libc, 'ptrace'): if not hasattr(libc, 'ptrace'):
raise unittest.SkipTest('ptrace() required.') raise unittest.SkipTest('ptrace() required')
test_ptrace = subprocess.Popen(
[sys.executable, '-c', """if True: code = textwrap.dedent(f"""
import ctypes import ctypes
import faulthandler
from test.support import SuppressCrashReport
libc = ctypes.CDLL({libc_name!r}) libc = ctypes.CDLL({libc_name!r})
libc.ptrace({PTRACE_TRACEME}, 0, 0) libc.ptrace({PTRACE_TRACEME}, 0, 0)
""".format(libc_name=libc_name, PTRACE_TRACEME=PTRACE_TRACEME) """)
])
if test_ptrace.wait() != 0: child = subprocess.Popen([sys.executable, '-c', code])
raise unittest.SkipTest('ptrace() failed - unable to test.') if child.wait() != 0:
child = subprocess.Popen( raise unittest.SkipTest('ptrace() failed - unable to test')
[sys.executable, '-c', """if True:
import ctypes, faulthandler code += textwrap.dedent(f"""
libc = ctypes.CDLL({libc_name!r}) with SuppressCrashReport():
libc.ptrace({PTRACE_TRACEME}, 0, 0) # Crash the process
faulthandler._sigsegv() # Crash the process. faulthandler._sigsegv()
""".format(libc_name=libc_name, PTRACE_TRACEME=PTRACE_TRACEME) """)
]) child = subprocess.Popen([sys.executable, '-c', code])
try: try:
returncode = child.wait() returncode = child.wait()
except Exception as e: except:
child.kill() # Clean up the hung stopped process. child.kill() # Clean up the hung stopped process.
raise e raise
self.assertNotEqual(0, returncode) self.assertNotEqual(0, returncode)
self.assertLess(returncode, 0) # signal death, likely SIGSEGV. self.assertLess(returncode, 0) # signal death, likely SIGSEGV.