Skip to content

Commit 7c9bbaa

Browse files
[3.13] gh-116622: Switch test_stress_delivery_simultaneous from SIGUSR1 to SIGUSR2 (GH-123981) (#123988)
gh-116622: Switch test_stress_delivery_simultaneous from SIGUSR1 to SIGUSR2 (GH-123981) Use SIGUSR1 instead of SIGUSR2 to improve reliability of signal stress test on Android. (cherry picked from commit 43303e3) Co-authored-by: Malcolm Smith <[email protected]>
1 parent 87f51a2 commit 7c9bbaa

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

Android/testbed/app/src/main/python/main.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,25 @@
55
import sys
66

77
# Some tests use SIGUSR1, but that's blocked by default in an Android app in
8-
# order to make it available to `sigwait` in the "Signal Catcher" thread. That
9-
# thread's functionality is only relevant to the JVM ("forcing GC (no HPROF) and
10-
# profile save"), so disabling it should not weaken the tests.
8+
# order to make it available to `sigwait` in the Signal Catcher thread.
9+
# (https://cs.android.com/android/platform/superproject/+/android14-qpr3-release:art/runtime/signal_catcher.cc).
10+
# That thread's functionality is only useful for debugging the JVM, so disabling
11+
# it should not weaken the tests.
12+
#
13+
# There's no safe way of stopping the thread completely (#123982), but simply
14+
# unblocking SIGUSR1 is enough to fix most tests.
15+
#
16+
# However, in tests that generate multiple different signals in quick
17+
# succession, it's possible for SIGUSR1 to arrive while the main thread is busy
18+
# running the C-level handler for a different signal. In that case, the SIGUSR1
19+
# may be sent to the Signal Catcher thread instead, which will generate a log
20+
# message containing the text "reacting to signal".
21+
#
22+
# Such tests may need to be changed in one of the following ways:
23+
# * Use a signal other than SIGUSR1 (e.g. test_stress_delivery_simultaneous in
24+
# test_signal.py).
25+
# * Send the signal to a specific thread rather than the whole process (e.g.
26+
# test_signals in test_threadsignals.py.
1127
signal.pthread_sigmask(signal.SIG_UNBLOCK, [signal.SIGUSR1])
1228

1329
sys.argv[1:] = shlex.split(os.environ["PYTHON_ARGS"])

Lib/test/test_signal.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,15 +1327,18 @@ def test_stress_delivery_simultaneous(self):
13271327
def handler(signum, frame):
13281328
sigs.append(signum)
13291329

1330-
self.setsig(signal.SIGUSR1, handler)
1330+
# On Android, SIGUSR1 is unreliable when used in close proximity to
1331+
# another signal – see Android/testbed/app/src/main/python/main.py.
1332+
# So we use a different signal.
1333+
self.setsig(signal.SIGUSR2, handler)
13311334
self.setsig(signal.SIGALRM, handler) # for ITIMER_REAL
13321335

13331336
expected_sigs = 0
13341337
while expected_sigs < N:
13351338
# Hopefully the SIGALRM will be received somewhere during
1336-
# initial processing of SIGUSR1.
1339+
# initial processing of SIGUSR2.
13371340
signal.setitimer(signal.ITIMER_REAL, 1e-6 + random.random() * 1e-5)
1338-
os.kill(os.getpid(), signal.SIGUSR1)
1341+
os.kill(os.getpid(), signal.SIGUSR2)
13391342

13401343
expected_sigs += 2
13411344
# Wait for handlers to run to avoid signal coalescing

0 commit comments

Comments
 (0)