21
21
import ctypes
22
22
except ImportError :
23
23
ctypes = None
24
+ else :
25
+ import ctypes .util
24
26
25
27
try :
26
28
import threading
@@ -2512,18 +2514,12 @@ def test_communicate_BrokenPipeError_stdin_close_with_timeout(self):
2512
2514
proc .communicate (timeout = 999 )
2513
2515
mock_proc_stdin .close .assert_called_once_with ()
2514
2516
2515
- _libc_file_extensions = {
2516
- 'Linux' : 'so.6' ,
2517
- 'Darwin' : 'dylib' ,
2518
- }
2519
2517
@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.' )
2522
2518
@unittest .skipIf (not sys .executable , 'Test requires sys.executable.' )
2523
2519
def test_child_terminated_in_stopped_state (self ):
2524
2520
"""Test wait() behavior when waitpid returns WIFSTOPPED; issue29335."""
2525
2521
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' )
2527
2523
libc = ctypes .CDLL (libc_name )
2528
2524
if not hasattr (libc , 'ptrace' ):
2529
2525
raise unittest .SkipTest ('ptrace() required.' )
@@ -2538,10 +2534,10 @@ def test_child_terminated_in_stopped_state(self):
2538
2534
raise unittest .SkipTest ('ptrace() failed - unable to test.' )
2539
2535
child = subprocess .Popen (
2540
2536
[sys .executable , '-c' , """if True:
2541
- import ctypes
2537
+ import ctypes, faulthandler
2542
2538
libc = ctypes.CDLL({libc_name!r})
2543
2539
libc.ptrace({PTRACE_TRACEME}, 0, 0)
2544
- libc.printf(ctypes.c_char_p(0xdeadbeef) ) # Crash the process.
2540
+ faulthandler._sigsegv( ) # Crash the process.
2545
2541
""" .format (libc_name = libc_name , PTRACE_TRACEME = PTRACE_TRACEME )
2546
2542
])
2547
2543
try :
0 commit comments