* [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* Re: [LTP] openposix: timers/twoevtimers: Wait for both timer signals
2026-10-09 6:49 [LTP] [PATCH] openposix: timers/twoevtimers: Wait for both timer signals Jan Stancek via ltp
@ 2026-10-09 10:09 ` linuxtestproject.agent
2026-10-09 10:52 ` [LTP] [PATCH v2] " Jan Stancek via ltp
1 sibling, 0 replies; 12+ messages in thread
From: linuxtestproject.agent @ 2026-10-09 10:09 UTC (permalink / raw)
To: Jan Stancek; +Cc: ltp
Hi Jan,
On 9 Oct 2026, Jan Stancek wrote:
> openposix: timers/twoevtimers: Wait for both timer signals
> + while (left > 0 && !(caughtalarm && caughtabort))
> + left = sleep(left);
On glibc and musl, sleep() discards the fractional remaining time.
If the first signal interrupts sleep(3) after 2.1 seconds, it returns
zero with about 0.9 seconds still in the budget, so this can fail before
the second signal arrives.
Use nanosleep() and retain the full remaining timespec, or wait against
a monotonic deadline.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 12+ messages in thread
* [LTP] [PATCH v2] openposix: timers/twoevtimers: Wait for both timer signals
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 ` Jan Stancek via ltp
2026-10-09 17:26 ` [LTP] " linuxtestproject.agent
2026-10-12 4:56 ` [LTP] [PATCH v3] " Jan Stancek via ltp
1 sibling, 2 replies; 12+ messages in thread
From: Jan Stancek via ltp @ 2026-10-09 10:52 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. Use
nanosleep() rather than sleep() for this, since sleep() returns the
unslept time in whole seconds and the fraction would be lost on every
interruption. Make the counters volatile sig_atomic_t and print from the
handlers with the async-signal-safe PTS_WRITE_MSG() instead of printf().
Arm the timers to expire 50ms from now instead of 3 seconds, so the test
passes in about 50ms, and lower LONGTIME, the upper bound for when a
signal does not arrive, from 5 to 3 seconds. 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 | 51 ++++++++++++++-----
1 file changed, 38 insertions(+), 13 deletions(-)
Changes in v2:
- use nanosleep
- make signals arrive in 50ms instead of 1 second
diff --git a/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c b/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c
index 0e46229777fe..1b2b20a5c399 100644
--- a/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c
+++ b/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c
@@ -5,9 +5,16 @@
* 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 nanosleep() while the second one may still be
+ * on its way. Keep waiting until both have arrived or LONGTIME elapses.
*/
+#include <errno.h>
#include <stdio.h>
#include <time.h>
#include <signal.h>
@@ -16,24 +23,25 @@
#include <sys/wait.h>
#include <unistd.h>
#include "posixtest.h"
+#include "timespec.h"
-#define EXPIREDELTA 3
-#define LONGTIME 5
+#define EXPIREDELTA_NS 50000000
+#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 +53,7 @@ int test_main(int argc, char **argv)
struct timespec ts;
struct itimerspec its;
int flags = 0;
+ struct timespec left = { .tv_sec = LONGTIME };
act1.sa_handler = handler_abrt;
act1.sa_flags = 0;
@@ -77,8 +86,12 @@ int test_main(int argc, char **argv)
return PTS_UNRESOLVED;
}
- its.it_value.tv_sec = ts.tv_sec + EXPIREDELTA;
- its.it_value.tv_nsec = ts.tv_nsec;
+ its.it_value.tv_sec = ts.tv_sec;
+ its.it_value.tv_nsec = ts.tv_nsec + EXPIREDELTA_NS;
+ if (its.it_value.tv_nsec >= NSEC_IN_SEC) {
+ its.it_value.tv_sec++;
+ its.it_value.tv_nsec -= NSEC_IN_SEC;
+ }
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 0;
@@ -93,7 +106,19 @@ int test_main(int argc, char **argv)
return PTS_UNRESOLVED;
}
- sleep(EXPIREDELTA + 1);
+ /*
+ * nanosleep() returns early when the first signal arrives; keep
+ * waiting on the remaining time until the second one has been
+ * delivered as well or we time out.
+ */
+ while (!(caughtalarm && caughtabort)) {
+ if (nanosleep(&left, &left) == 0)
+ break;
+ if (errno != EINTR) {
+ perror("nanosleep() did not return success\n");
+ return PTS_UNRESOLVED;
+ }
+ }
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* Re: [LTP] openposix: timers/twoevtimers: Wait for both timer signals
2026-10-09 10:52 ` [LTP] [PATCH v2] " Jan Stancek via ltp
@ 2026-10-09 17:26 ` linuxtestproject.agent
2026-10-10 9:06 ` Li Wang
2026-10-12 4:56 ` [LTP] [PATCH v3] " Jan Stancek via ltp
1 sibling, 1 reply; 12+ messages in thread
From: linuxtestproject.agent @ 2026-10-09 17:26 UTC (permalink / raw)
To: Jan Stancek; +Cc: ltp
Hi Jan,
On Fri, 9 Oct 2026, Jan Stancek via ltp wrote:
> openposix: timers/twoevtimers: Wait for both timer signals
> + PTS_WRITE_MSG("Caught abort signal\n");
> + PTS_WRITE_MSG("Caught alarm signal\n");
> + if (errno != EINTR) {
> + perror("nanosleep() did not return success\n");
> + return PTS_UNRESOLVED;
> + }
Medium: PTS_WRITE_MSG() calls write() without preserving errno. If the
second signal arrives after nanosleep() sets EINTR but before the new
errno check, a failed handler write (e.g. EAGAIN on a full nonblocking
stdout pipe) causes a spurious unresolved result even when both timers
fired. Save errno on entry and restore it before returning in both
handlers.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [LTP] openposix: timers/twoevtimers: Wait for both timer signals
2026-10-09 17:26 ` [LTP] " linuxtestproject.agent
@ 2026-10-10 9:06 ` Li Wang
2026-10-10 9:42 ` Jan Stancek via ltp
0 siblings, 1 reply; 12+ messages in thread
From: Li Wang @ 2026-10-10 9:06 UTC (permalink / raw)
To: linuxtestproject.agent; +Cc: ltp
Hi Jan,
linuxtestproject.agent@gmail.com wrote:
> Hi Jan,
>
> On Fri, 9 Oct 2026, Jan Stancek via ltp wrote:
> > openposix: timers/twoevtimers: Wait for both timer signals
>
> > + PTS_WRITE_MSG("Caught abort signal\n");
> > + PTS_WRITE_MSG("Caught alarm signal\n");
> > + if (errno != EINTR) {
> > + perror("nanosleep() did not return success\n");
> > + return PTS_UNRESOLVED;
> > + }
>
> Medium: PTS_WRITE_MSG() calls write() without preserving errno. If the
> second signal arrives after nanosleep() sets EINTR but before the new
> errno check, a failed handler write (e.g. EAGAIN on a full nonblocking
> stdout pipe) causes a spurious unresolved result even when both timers
> fired. Save errno on entry and restore it before returning in both
> handlers.
The race condition pointed out by the AI seems plausible. Would it make
sense to save and restore errno in the signal handlers, like this:
static void handler_abrt(int signo PTS_ATTRIBUTE_UNUSED)
{
+ int saved_errno = errno;
+
PTS_WRITE_MSG("Caught abort signal\n");
caughtabort++;
+
+ errno = saved_errno;
+
}
static void handler_alrm(int signo PTS_ATTRIBUTE_UNUSED)
{
+ int saved_errno = errno;
+
PTS_WRITE_MSG("Caught alarm signal\n");
caughtalarm++;
+
+ errno = saved_errno;
}
The rest part looks good to me.
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [LTP] openposix: timers/twoevtimers: Wait for both timer signals
2026-10-10 9:06 ` Li Wang
@ 2026-10-10 9:42 ` Jan Stancek via ltp
2026-10-11 1:07 ` Li Wang
0 siblings, 1 reply; 12+ messages in thread
From: Jan Stancek via ltp @ 2026-10-10 9:42 UTC (permalink / raw)
To: linuxtestproject.agent, Jan Stancek, LTP List
On Sat, Oct 10, 2026, 11:07 Li Wang <li.wang@linux.dev> wrote:
> Hi Jan,
>
> linuxtestproject.agent@gmail.com wrote:
>
> > Hi Jan,
> >
> > On Fri, 9 Oct 2026, Jan Stancek via ltp wrote:
> > > openposix: timers/twoevtimers: Wait for both timer signals
> >
> > > + PTS_WRITE_MSG("Caught abort signal\n");
> > > + PTS_WRITE_MSG("Caught alarm signal\n");
> > > + if (errno != EINTR) {
> > > + perror("nanosleep() did not return success\n");
> > > + return PTS_UNRESOLVED;
> > > + }
> >
> > Medium: PTS_WRITE_MSG() calls write() without preserving errno. If the
> > second signal arrives after nanosleep() sets EINTR but before the new
> > errno check, a failed handler write (e.g. EAGAIN on a full nonblocking
> > stdout pipe) causes a spurious unresolved result even when both timers
> > fired. Save errno on entry and restore it before returning in both
> > handlers.
>
> The race condition pointed out by the AI seems plausible. Would it make
> sense to save and restore errno in the signal handlers, like this:
>
It seems very unlikely. I was thinking to move the print outside of signal
handler if we want to address it.
> static void handler_abrt(int signo PTS_ATTRIBUTE_UNUSED)
> {
> + int saved_errno = errno;
> +
> PTS_WRITE_MSG("Caught abort signal\n");
> caughtabort++;
> +
> + errno = saved_errno;
> +
> }
>
> static void handler_alrm(int signo PTS_ATTRIBUTE_UNUSED)
> {
> + int saved_errno = errno;
> +
> PTS_WRITE_MSG("Caught alarm signal\n");
> caughtalarm++;
> +
> + errno = saved_errno;
> }
>
> The rest part looks good to me.
>
> --
> Regards,
> Li Wang
>
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [LTP] openposix: timers/twoevtimers: Wait for both timer signals
2026-10-10 9:42 ` Jan Stancek via ltp
@ 2026-10-11 1:07 ` Li Wang
0 siblings, 0 replies; 12+ messages in thread
From: Li Wang @ 2026-10-11 1:07 UTC (permalink / raw)
To: Jan Stancek; +Cc: LTP List, linuxtestproject.agent
> > > On Fri, 9 Oct 2026, Jan Stancek via ltp wrote:
> > > > openposix: timers/twoevtimers: Wait for both timer signals
> > >
> > > > + PTS_WRITE_MSG("Caught abort signal\n");
> > > > + PTS_WRITE_MSG("Caught alarm signal\n");
> > > > + if (errno != EINTR) {
> > > > + perror("nanosleep() did not return success\n");
> > > > + return PTS_UNRESOLVED;
> > > > + }
> > >
> > > Medium: PTS_WRITE_MSG() calls write() without preserving errno. If the
> > > second signal arrives after nanosleep() sets EINTR but before the new
> > > errno check, a failed handler write (e.g. EAGAIN on a full nonblocking
> > > stdout pipe) causes a spurious unresolved result even when both timers
> > > fired. Save errno on entry and restore it before returning in both
> > > handlers.
> >
> > The race condition pointed out by the AI seems plausible. Would it make
> > sense to save and restore errno in the signal handlers, like this:
> >
>
> It seems very unlikely. I was thinking to move the print outside of signal
> handler if we want to address it.
Agreed, moving the prints from the handlers is the better fix.
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 12+ messages in thread
* [LTP] [PATCH v3] openposix: timers/twoevtimers: Wait for both timer signals
2026-10-09 10:52 ` [LTP] [PATCH v2] " Jan Stancek via ltp
2026-10-09 17:26 ` [LTP] " linuxtestproject.agent
@ 2026-10-12 4:56 ` Jan Stancek via ltp
2026-10-12 7:19 ` [LTP] " linuxtestproject.agent
2026-10-12 8:03 ` [LTP] [PATCH v4] " Jan Stancek via ltp
1 sibling, 2 replies; 12+ messages in thread
From: Jan Stancek via ltp @ 2026-10-12 4:56 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. Use
nanosleep() rather than sleep() for this, since sleep() returns the
unslept time in whole seconds and the fraction would be lost on every
interruption. Make the counters volatile sig_atomic_t and move the
printf() calls out of the signal handlers, so that they only touch the
counters and cannot clobber errno behind nanosleep()'s back.
Arm the timers to expire 50ms from now instead of 3 seconds, so the test
passes in about 50ms, and lower LONGTIME, the upper bound for when a
signal does not arrive, from 5 to 3 seconds. 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 | 54 ++++++++++++++-----
1 file changed, 41 insertions(+), 13 deletions(-)
Changes in v3:
- move prints out of signal handlers
diff --git a/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c b/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c
index 0e46229777fe..05e53ad4ba48 100644
--- a/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c
+++ b/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c
@@ -5,9 +5,16 @@
* 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 nanosleep() while the second one may still be
+ * on its way. Keep waiting until both have arrived or LONGTIME elapses.
*/
+#include <errno.h>
#include <stdio.h>
#include <time.h>
#include <signal.h>
@@ -16,24 +23,23 @@
#include <sys/wait.h>
#include <unistd.h>
#include "posixtest.h"
+#include "timespec.h"
-#define EXPIREDELTA 3
-#define LONGTIME 5
+#define EXPIREDELTA_NS 50000000
+#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");
caughtabort++;
}
-static void handler_alrm(int signo)
+static void handler_alrm(int signo PTS_ATTRIBUTE_UNUSED)
{
- printf("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;
+ struct timespec left = { .tv_sec = LONGTIME };
act1.sa_handler = handler_abrt;
act1.sa_flags = 0;
@@ -77,8 +84,12 @@ int test_main(int argc, char **argv)
return PTS_UNRESOLVED;
}
- its.it_value.tv_sec = ts.tv_sec + EXPIREDELTA;
- its.it_value.tv_nsec = ts.tv_nsec;
+ its.it_value.tv_sec = ts.tv_sec;
+ its.it_value.tv_nsec = ts.tv_nsec + EXPIREDELTA_NS;
+ if (its.it_value.tv_nsec >= NSEC_IN_SEC) {
+ its.it_value.tv_sec++;
+ its.it_value.tv_nsec -= NSEC_IN_SEC;
+ }
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 0;
@@ -93,7 +104,24 @@ int test_main(int argc, char **argv)
return PTS_UNRESOLVED;
}
- sleep(EXPIREDELTA + 1);
+ /*
+ * nanosleep() returns early when the first signal arrives; keep
+ * waiting on the remaining time until the second one has been
+ * delivered as well or we time out.
+ */
+ while (!(caughtalarm && caughtabort)) {
+ if (nanosleep(&left, &left) == 0)
+ break;
+ if (errno != EINTR) {
+ perror("nanosleep() did not return success\n");
+ return PTS_UNRESOLVED;
+ }
+ }
+
+ if (caughtabort)
+ printf("Caught abort signal\n");
+ if (caughtalarm)
+ printf("Caught alarm signal\n");
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* Re: [LTP] openposix: timers/twoevtimers: Wait for both timer signals
2026-10-12 4:56 ` [LTP] [PATCH v3] " Jan Stancek via ltp
@ 2026-10-12 7:19 ` linuxtestproject.agent
2026-10-12 8:03 ` [LTP] [PATCH v4] " Jan Stancek via ltp
1 sibling, 0 replies; 12+ messages in thread
From: linuxtestproject.agent @ 2026-10-12 7:19 UTC (permalink / raw)
To: Jan Stancek; +Cc: ltp
Hi Jan,
On 12 October 2026, Jan Stancek wrote:
> openposix: timers/twoevtimers: Wait for both timer signals
> + while (!(caughtalarm && caughtabort)) {
> + if (nanosleep(&left, &left) == 0)
> + break;
Low severity, twoevtimers.c:113-114: if the last timer signal is handled
after the condition check but before nanosleep(), the one-shot timers
cannot wake that sleep. The test then waits out the remaining budget
(up to three seconds), even though both signals have arrived, rather than
completing in about 50 ms. Block both signals before arming the timers and
use pselect() with an atomic unblocking mask and a deadline-based timeout,
or consume the blocked signals with sigtimedwait().
Verdict - Needs revision
Compilation and runtime validation could not be completed: the generated
test Makefile is absent, and direct compiler execution was denied.
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 12+ messages in thread* [LTP] [PATCH v4] openposix: timers/twoevtimers: Wait for both timer signals
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 ` Jan Stancek via ltp
2026-10-12 9:33 ` Petr Vorel
2026-10-12 15:47 ` [LTP] " linuxtestproject.agent
1 sibling, 2 replies; 12+ messages in thread
From: Jan Stancek via ltp @ 2026-10-12 8:03 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.
Make the counters volatile sig_atomic_t and move the printf() calls
out of the signal handlers, so that they only touch the counters and
cannot clobber errno behind nanosleep()'s back.
Arm the timers to expire 50ms from now instead of 3 seconds, so the test
passes in about 50ms, and lower LONGTIME, the upper bound for when a
signal does not arrive, from 5 to 3 seconds. 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 | 58 ++++++++++++++-----
1 file changed, 44 insertions(+), 14 deletions(-)
Changes in v4:
- sleep in 50ms chunks
diff --git a/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c b/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c
index 0e46229777fe..2bc819721fd5 100644
--- a/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c
+++ b/testcases/open_posix_testsuite/functional/timers/timers/twoevtimers.c
@@ -5,35 +5,43 @@
* 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 second one may still be on its way when the first one arrives.
+ * Poll for both of them in short sleeps until LONGTIME elapses.
*/
+#include <errno.h>
#include <stdio.h>
#include <time.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include <unistd.h>
#include "posixtest.h"
+#include "timespec.h"
-#define EXPIREDELTA 3
-#define LONGTIME 5
+#define EXPIREDELTA_NS 50000000
+#define LONGTIME 3
+
+#define POLL_MS 50
+#define POLL_COUNT (LONGTIME * 1000 / POLL_MS)
#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");
caughtabort++;
}
-static void handler_alrm(int signo)
+static void handler_alrm(int signo PTS_ATTRIBUTE_UNUSED)
{
- printf("Caught alarm signal\n");
caughtalarm++;
}
@@ -45,6 +53,8 @@ int test_main(int argc, char **argv)
struct timespec ts;
struct itimerspec its;
int flags = 0;
+ struct timespec poll_ts = { .tv_nsec = POLL_MS * 1000000 };
+ int i;
act1.sa_handler = handler_abrt;
act1.sa_flags = 0;
@@ -77,8 +87,12 @@ int test_main(int argc, char **argv)
return PTS_UNRESOLVED;
}
- its.it_value.tv_sec = ts.tv_sec + EXPIREDELTA;
- its.it_value.tv_nsec = ts.tv_nsec;
+ its.it_value.tv_sec = ts.tv_sec;
+ its.it_value.tv_nsec = ts.tv_nsec + EXPIREDELTA_NS;
+ if (its.it_value.tv_nsec >= NSEC_IN_SEC) {
+ its.it_value.tv_sec++;
+ its.it_value.tv_nsec -= NSEC_IN_SEC;
+ }
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 0;
@@ -93,7 +107,23 @@ int test_main(int argc, char **argv)
return PTS_UNRESOLVED;
}
- sleep(EXPIREDELTA + 1);
+ /*
+ * Sleep in short chunks rather than once for LONGTIME: a signal
+ * that lands between the check and nanosleep() has nothing to
+ * interrupt, so a single long sleep would run out the whole budget.
+ * A chunk cut short by a signal only brings the next check forward.
+ */
+ for (i = 0; i < POLL_COUNT && !(caughtalarm && caughtabort); i++) {
+ if (nanosleep(&poll_ts, NULL) != 0 && errno != EINTR) {
+ perror("nanosleep() did not return success");
+ return PTS_UNRESOLVED;
+ }
+ }
+
+ if (caughtabort)
+ printf("Caught abort signal\n");
+ if (caughtalarm)
+ printf("Caught alarm signal\n");
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* Re: [LTP] [PATCH v4] openposix: timers/twoevtimers: Wait for both timer signals
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
1 sibling, 0 replies; 12+ messages in thread
From: Petr Vorel @ 2026-10-12 9:33 UTC (permalink / raw)
To: Jan Stancek; +Cc: ltp
Hi Jan,
thanks, LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
> -#define EXPIREDELTA 3
> -#define LONGTIME 5
> +#define EXPIREDELTA_NS 50000000
very nit: having EXPIREDELTA_MS 50 and then use EXPIREDELTA_MS * 1000000
might be slightly more readable.
> +#define LONGTIME 3
> +
> +#define POLL_MS 50
> +#define POLL_COUNT (LONGTIME * 1000 / POLL_MS)
> #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;
nit: static is 0 already (maybe drop "= 0"?)
> -static void handler_abrt(int signo)
> +static void handler_abrt(int signo PTS_ATTRIBUTE_UNUSED)
Thanks for silence some of the warnings.
> {
> - printf("Caught abort signal\n");
+1
> caughtabort++;
> }
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [LTP] openposix: timers/twoevtimers: Wait for both timer signals
2026-10-12 8:03 ` [LTP] [PATCH v4] " Jan Stancek via ltp
2026-10-12 9:33 ` Petr Vorel
@ 2026-10-12 15:47 ` linuxtestproject.agent
1 sibling, 0 replies; 12+ messages in thread
From: linuxtestproject.agent @ 2026-10-12 15:47 UTC (permalink / raw)
To: Jan Stancek; +Cc: ltp
Hi Jan,
On 12 October 2026, Jan Stancek wrote:
> openposix: timers/twoevtimers: Wait for both timer signals
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [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.