1313import time
1414import unittest
1515from test import support
16- from test .support import os_helper
16+ from test .support import (
17+ is_apple , is_apple_mobile , os_helper , threading_helper
18+ )
1719from test .support .script_helper import assert_python_ok , spawn_python
18- from test .support import threading_helper
1920try :
2021 import _testcapi
2122except ImportError :
@@ -122,6 +123,8 @@ def __repr__(self):
122123 self .assertEqual (signal .getsignal (signal .SIGHUP ), hup )
123124 self .assertEqual (0 , argument .repr_count )
124125
126+ @unittest .skipIf (sys .platform .startswith ("netbsd" ),
127+ "gh-124083: strsignal is not supported on NetBSD" )
125128 def test_strsignal (self ):
126129 self .assertIn ("Interrupt" , signal .strsignal (signal .SIGINT ))
127130 self .assertIn ("Terminated" , signal .strsignal (signal .SIGTERM ))
@@ -189,8 +192,7 @@ def test_valid_signals(self):
189192 self .assertNotIn (signal .NSIG , s )
190193 self .assertLess (len (s ), signal .NSIG )
191194
192- # TODO: RUSTPYTHON
193- @unittest .expectedFailure
195+ @unittest .expectedFailure # TODO: RUSTPYTHON
194196 def test_issue9324 (self ):
195197 # Updated for issue #10003, adding SIGBREAK
196198 handler = lambda x , y : None
@@ -699,7 +701,7 @@ def handler(signum, frame):
699701@unittest .skipUnless (hasattr (os , "pipe" ), "requires os.pipe()" )
700702class SiginterruptTest (unittest .TestCase ):
701703
702- def readpipe_interrupted (self , interrupt ):
704+ def readpipe_interrupted (self , interrupt , timeout = support . SHORT_TIMEOUT ):
703705 """Perform a read during which a signal will arrive. Return True if the
704706 read is interrupted by the signal and raises an exception. Return False
705707 if it returns normally.
@@ -747,7 +749,7 @@ def handler(signum, frame):
747749 # wait until the child process is loaded and has started
748750 first_line = process .stdout .readline ()
749751
750- stdout , stderr = process .communicate (timeout = support . SHORT_TIMEOUT )
752+ stdout , stderr = process .communicate (timeout = timeout )
751753 except subprocess .TimeoutExpired :
752754 process .kill ()
753755 return False
@@ -778,7 +780,7 @@ def test_siginterrupt_off(self):
778780 # If a signal handler is installed and siginterrupt is called with
779781 # a false value for the second argument, when that signal arrives, it
780782 # does not interrupt a syscall that's in progress.
781- interrupted = self .readpipe_interrupted (False )
783+ interrupted = self .readpipe_interrupted (False , timeout = 2 )
782784 self .assertFalse (interrupted )
783785
784786
@@ -834,16 +836,16 @@ def test_itimer_real(self):
834836 self .assertEqual (self .hndl_called , True )
835837
836838 # Issue 3864, unknown if this affects earlier versions of freebsd also
837- @unittest .skipIf (sys .platform in ('netbsd5' ,),
839+ @unittest .skipIf (sys .platform in ('netbsd5' ,) or is_apple_mobile ,
838840 'itimer not reliable (does not mix well with threading) on some BSDs.' )
839841 def test_itimer_virtual (self ):
840842 self .itimer = signal .ITIMER_VIRTUAL
841843 signal .signal (signal .SIGVTALRM , self .sig_vtalrm )
842- signal .setitimer (self .itimer , 0.3 , 0.2 )
844+ signal .setitimer (self .itimer , 0.001 , 0.001 )
843845
844846 for _ in support .busy_retry (support .LONG_TIMEOUT ):
845847 # use up some virtual time by doing real work
846- _ = pow ( 12345 , 67890 , 10000019 )
848+ _ = sum ( i * i for i in range ( 10 ** 5 ) )
847849 if signal .getitimer (self .itimer ) == (0.0 , 0.0 ):
848850 # sig_vtalrm handler stopped this itimer
849851 break
@@ -860,7 +862,7 @@ def test_itimer_prof(self):
860862
861863 for _ in support .busy_retry (support .LONG_TIMEOUT ):
862864 # do some work
863- _ = pow ( 12345 , 67890 , 10000019 )
865+ _ = sum ( i * i for i in range ( 10 ** 5 ) )
864866 if signal .getitimer (self .itimer ) == (0.0 , 0.0 ):
865867 # sig_prof handler stopped this itimer
866868 break
@@ -1326,15 +1328,18 @@ def test_stress_delivery_simultaneous(self):
13261328 def handler (signum , frame ):
13271329 sigs .append (signum )
13281330
1329- self .setsig (signal .SIGUSR1 , handler )
1331+ # On Android, SIGUSR1 is unreliable when used in close proximity to
1332+ # another signal – see Android/testbed/app/src/main/python/main.py.
1333+ # So we use a different signal.
1334+ self .setsig (signal .SIGUSR2 , handler )
13301335 self .setsig (signal .SIGALRM , handler ) # for ITIMER_REAL
13311336
13321337 expected_sigs = 0
13331338 while expected_sigs < N :
13341339 # Hopefully the SIGALRM will be received somewhere during
1335- # initial processing of SIGUSR1 .
1340+ # initial processing of SIGUSR2 .
13361341 signal .setitimer (signal .ITIMER_REAL , 1e-6 + random .random () * 1e-5 )
1337- os .kill (os .getpid (), signal .SIGUSR1 )
1342+ os .kill (os .getpid (), signal .SIGUSR2 )
13381343
13391344 expected_sigs += 2
13401345 # Wait for handlers to run to avoid signal coalescing
@@ -1346,8 +1351,8 @@ def handler(signum, frame):
13461351 # Python handler
13471352 self .assertEqual (len (sigs ), N , "Some signals were lost" )
13481353
1349- @unittest .skip (" TODO: RUSTPYTHON; hang" )
1350- @unittest .skipIf (sys . platform == "darwin" , "crashes due to system bug (FB13453490)" )
1354+ @unittest .skip (' TODO: RUSTPYTHON; hang' )
1355+ @unittest .skipIf (is_apple , "crashes due to system bug (FB13453490)" )
13511356 @unittest .skipUnless (hasattr (signal , "SIGUSR1" ),
13521357 "test needs SIGUSR1" )
13531358 @threading_helper .requires_working_threading ()
@@ -1414,8 +1419,7 @@ def test_sigint(self):
14141419 with self .assertRaises (KeyboardInterrupt ):
14151420 signal .raise_signal (signal .SIGINT )
14161421
1417- # TODO: RUSTPYTHON
1418- @unittest .expectedFailure
1422+ @unittest .expectedFailure # TODO: RUSTPYTHON
14191423 @unittest .skipIf (sys .platform != "win32" , "Windows specific test" )
14201424 def test_invalid_argument (self ):
14211425 try :
@@ -1439,8 +1443,7 @@ def handler(a, b):
14391443 signal .raise_signal (signal .SIGINT )
14401444 self .assertTrue (is_ok )
14411445
1442- # TODO: RUSTPYTHON
1443- @unittest .expectedFailure
1446+ @unittest .expectedFailure # TODO: RUSTPYTHON
14441447 def test__thread_interrupt_main (self ):
14451448 # See https://github.com/python/cpython/issues/102397
14461449 code = """if 1:
0 commit comments