resource.setrlimit(resource.RLIMIT_CORE, self.old_value)
except (ValueError, OSError):
pass
+
+
+def _crash_python():
+ """Deliberate crash of Python.
+
+ Python can be killed by a segmentation fault (SIGSEGV), a bus error
+ (SIGBUS), or a different error depending on the platform.
+
+ Use SuppressCrashReport() to prevent a crash report from popping up.
+ """
+
+ import ctypes
+ with SuppressCrashReport():
+ ctypes.string_at(0)
def test_crashed(self):
# Any code which causes a crash
- code = 'import ctypes; ctypes.string_at(0)'
+ code = 'import test.support; test.support._crash_python()'
crash_test = self.create_test(name="crash", code=code)
ok_test = self.create_test(name="ok")
code = textwrap.dedent("""
import ctypes
- from test.support import SuppressCrashReport
+ from test.support import _crash_python
libc = ctypes.CDLL({libc_name!r})
libc.ptrace({PTRACE_TRACEME}, 0, 0)
raise unittest.SkipTest('ptrace() failed - unable to test')
code += textwrap.dedent("""
- with SuppressCrashReport():
- # Crash the process
- libc.printf(ctypes.c_char_p(0xdeadbeef)) # Crash the process.
+ # Crash the process
+ _crash_python()
""")
child = subprocess.Popen([sys.executable, '-c', code])
try: