Skip to content

Commit

Permalink
pythongh-116622: Switch test_stress_delivery_simultaneous from SIGUSR…
Browse files Browse the repository at this point in the history
…1 to SIGUSR2 (pythonGH-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 <smith@chaquo.com>
  • Loading branch information
mhsmith authored and miss-islington committed Sep 12, 2024
1 parent 660baa1 commit d05782c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
22 changes: 19 additions & 3 deletions Android/testbed/app/src/main/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,25 @@
import sys

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

sys.argv[1:] = shlex.split(os.environ["PYTHON_ARGS"])
Expand Down
9 changes: 6 additions & 3 deletions Lib/test/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1325,15 +1325,18 @@ def test_stress_delivery_simultaneous(self):
def handler(signum, frame):
sigs.append(signum)

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

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

expected_sigs += 2
# Wait for handlers to run to avoid signal coalescing
Expand Down

0 comments on commit d05782c

Please sign in to comment.