selftests/timers/posix_timers: Add SIG_IGN test
authorThomas Gleixner <tglx@linutronix.de>
Mon, 10 Jun 2024 16:42:07 +0000 (18:42 +0200)
committerFrederic Weisbecker <frederic@kernel.org>
Mon, 29 Jul 2024 19:57:34 +0000 (21:57 +0200)
commit45c4225c3dcc7db2c0cdbf889cc7a9c72a53f742
tree4a832a2a29ec878490284e078407e53c5cdd1a50
parent0af02a8e356fc6d3b1eebb32fae7d35625127835
selftests/timers/posix_timers: Add SIG_IGN test

Add a test case to validate correct behaviour vs. SIG_IGN.

The posix specification states:

  "Setting a signal action to SIG_IGN for a signal that is pending shall
   cause the pending signal to be discarded, whether or not it is blocked."

The kernel implements this in the signal handling code, but due to the way
how posix timers are handling SIG_IGN for periodic timers, the behaviour
after installing a real handler again is inconsistent and suprising.

The following sequence is expected to deliver a signal:

  install_handler(SIG);
  block_signal(SIG);
  timer_create(...);  <- Should send SIG
  timer_settime(value=100ms, interval=100ms);
  sleep(1);  <- Timer expires and queues signal, timer is not rearmed
       as that should happen in the signal delivery path
  ignore_signal(SIG);  <- Discards queued signal
  install_handler(SIG);  <- Restore handler, should rearm but does not
  sleep(1);
  unblock_signal(SIG);  <- Should deliver one signal with overrun count
       set in siginfo

This fails because nothing rearms the timer when the signal handler is
restored. Add a test for this case which fails until the signal and posix
timer code is fixed.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
tools/testing/selftests/timers/posix_timers.c