All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] openposix: timers/twoevtimers: Wait for both timer signals
@ 2026-10-09  6:49 Jan Stancek via ltp
  2026-10-09 10:09 ` [LTP] " linuxtestproject.agent
  2026-10-09 10:52 ` [LTP] [PATCH v2] " Jan Stancek via ltp
  0 siblings, 2 replies; 12+ messages in thread
From: Jan Stancek via ltp @ 2026-10-09  6:49 UTC (permalink / raw)
  To: ltp

The test arms two timers with the same absolute expiration time and
then does a single sleep() before checking that both signals arrived.
sleep() returns as soon as the first signal interrupts it, and the
kernel delivers the two signals one at a time. This sporadically
leads to failure:

  Caught abort signal
  Test FAILED

even though the second timer fires microseconds later.

Keep sleeping on the remaining time until both signals have been
caught or the LONGTIME budget, which was defined but never used, runs
out. Make the counters volatile sig_atomic_t and print from the handlers
with the async-signal-safe PTS_WRITE_MSG() instead of printf().

Lower the sleep time, and also correct the header comment: the timers
live in the same process, not in different processes, and the test only
checks that both of them expire, not that they expire at the same time.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 .../functional/timers/timers/twoevtimers.c    | 34 +++++++++++++------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c b/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c
index 0e46229777fe..b581678d2b12 100644
--- a/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c
+++ b/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c
@@ -5,8 +5,14 @@
  * of this license, see the COPYING file at the top level of this
  * source tree.
  *
- * Test having two timers in different processes set to expire at the
- * same time, and ensure they both expire at the same time.
+ * Test having two timers in the same process, armed with the same
+ * absolute expiration time but delivering different signals, and ensure
+ * that both of them expire.
+ *
+ * Note that the test does not (and cannot) verify that the two signals
+ * are delivered simultaneously.  Signals are delivered one at a time, so
+ * the first one interrupts sleep() while the second one may still be
+ * on its way.  Keep waiting until both have arrived or LONGTIME elapses.
  */
 #include <stdio.h>
 #include <time.h>
@@ -17,23 +23,23 @@
 #include <unistd.h>
 #include "posixtest.h"
 
-#define EXPIREDELTA 3
-#define LONGTIME 5
+#define EXPIREDELTA 1
+#define LONGTIME 3
 
 #define CHILDPASS 1
 
-static int caughtabort = 0;
-static int caughtalarm = 0;
+static volatile sig_atomic_t caughtabort = 0;
+static volatile sig_atomic_t caughtalarm = 0;
 
-static void handler_abrt(int signo)
+static void handler_abrt(int signo PTS_ATTRIBUTE_UNUSED)
 {
-	printf("Caught abort signal\n");
+	PTS_WRITE_MSG("Caught abort signal\n");
 	caughtabort++;
 }
 
-static void handler_alrm(int signo)
+static void handler_alrm(int signo PTS_ATTRIBUTE_UNUSED)
 {
-	printf("Caught alarm signal\n");
+	PTS_WRITE_MSG("Caught alarm signal\n");
 	caughtalarm++;
 }
 
@@ -45,6 +51,7 @@ int test_main(int argc, char **argv)
 	struct timespec ts;
 	struct itimerspec its;
 	int flags = 0;
+	unsigned int left = LONGTIME;
 
 	act1.sa_handler = handler_abrt;
 	act1.sa_flags = 0;
@@ -93,7 +100,12 @@ int test_main(int argc, char **argv)
 		return PTS_UNRESOLVED;
 	}
 
-	sleep(EXPIREDELTA + 1);
+	/*
+	 * sleep() returns early when the first signal arrives; keep waiting
+	 * until the second one has been delivered as well or we time out.
+	 */
+	while (left > 0 && !(caughtalarm && caughtabort))
+		left = sleep(left);
 
 	if ((caughtalarm == 1) && (caughtabort == 1)) {
 		printf("Test PASSED\n");
-- 
2.56.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-10-12 15:48 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-09  6:49 [LTP] [PATCH] openposix: timers/twoevtimers: Wait for both timer signals Jan Stancek via ltp
2026-10-09 10:09 ` [LTP] " linuxtestproject.agent
2026-10-09 10:52 ` [LTP] [PATCH v2] " Jan Stancek via ltp
2026-10-09 17:26   ` [LTP] " linuxtestproject.agent
2026-10-10  9:06     ` Li Wang
2026-10-10  9:42       ` Jan Stancek via ltp
2026-10-11  1:07         ` Li Wang
2026-10-12  4:56   ` [LTP] [PATCH v3] " Jan Stancek via ltp
2026-10-12  7:19     ` [LTP] " linuxtestproject.agent
2026-10-12  8:03     ` [LTP] [PATCH v4] " Jan Stancek via ltp
2026-10-12  9:33       ` Petr Vorel
2026-10-12 15:47       ` [LTP] " linuxtestproject.agent

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.