2121 import ctypes
2222except ImportError :
2323 ctypes = None
24+ else :
25+ import ctypes .util
2426
2527try :
2628 import threading
@@ -2512,18 +2514,12 @@ def test_communicate_BrokenPipeError_stdin_close_with_timeout(self):
25122514 proc .communicate (timeout = 999 )
25132515 mock_proc_stdin .close .assert_called_once_with ()
25142516
2515- _libc_file_extensions = {
2516- 'Linux' : 'so.6' ,
2517- 'Darwin' : 'dylib' ,
2518- }
25192517 @unittest .skipIf (not ctypes , 'ctypes module required.' )
2520- @unittest .skipIf (platform .uname ()[0 ] not in _libc_file_extensions ,
2521- 'Test requires a libc this code can load with ctypes.' )
25222518 @unittest .skipIf (not sys .executable , 'Test requires sys.executable.' )
25232519 def test_child_terminated_in_stopped_state (self ):
25242520 """Test wait() behavior when waitpid returns WIFSTOPPED; issue29335."""
25252521 PTRACE_TRACEME = 0 # From glibc and MacOS (PT_TRACE_ME).
2526- libc_name = 'libc.' + self . _libc_file_extensions [ platform . uname ()[ 0 ]]
2522+ libc_name = ctypes . util . find_library ( 'c' )
25272523 libc = ctypes .CDLL (libc_name )
25282524 if not hasattr (libc , 'ptrace' ):
25292525 raise unittest .SkipTest ('ptrace() required.' )
@@ -2538,10 +2534,10 @@ def test_child_terminated_in_stopped_state(self):
25382534 raise unittest .SkipTest ('ptrace() failed - unable to test.' )
25392535 child = subprocess .Popen (
25402536 [sys .executable , '-c' , """if True:
2541- import ctypes
2537+ import ctypes, faulthandler
25422538 libc = ctypes.CDLL({libc_name!r})
25432539 libc.ptrace({PTRACE_TRACEME}, 0, 0)
2544- libc.printf(ctypes.c_char_p(0xdeadbeef) ) # Crash the process.
2540+ faulthandler._sigsegv( ) # Crash the process.
25452541 """ .format (libc_name = libc_name , PTRACE_TRACEME = PTRACE_TRACEME )
25462542 ])
25472543 try :
0 commit comments