git: 9af3990ba794 - main - sem test: avoid ETIMEDOUT races in the EINTR test cases

From: Olivier Cochard <olivier_at_FreeBSD.org>
Date: Wed, 07 Oct 2026 00:07:21 UTC
The branch main has been updated by olivier:

URL: https://cgit.FreeBSD.org/src/commit/?id=9af3990ba7940e85c31b5fc074e9510ee195465f

commit 9af3990ba7940e85c31b5fc074e9510ee195465f
Author:     Olivier Cochard <olivier@FreeBSD.org>
AuthorDate: 2026-10-07 00:00:58 +0000
Commit:     Olivier Cochard <olivier@FreeBSD.org>
CommitDate: 2026-10-07 00:03:27 +0000

    sem test: avoid ETIMEDOUT races in the EINTR test cases
    
    timedwait and clockwait_absolute_intr_remaining arm a 50ms SIGALRM and then
    wait until an absolute deadline only 100ms in the future.
    On a loaded VM the signal can be delivered more than 50ms late, so the wait
    times out first.
    
    Approved by:    imp
    Sponsored by:   Netflix
    Differential Revision:  https://reviews.freebsd.org/D60347
---
 contrib/netbsd-tests/lib/librt/t_sem.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/contrib/netbsd-tests/lib/librt/t_sem.c b/contrib/netbsd-tests/lib/librt/t_sem.c
index f542c6315528..d24ca81c86de 100644
--- a/contrib/netbsd-tests/lib/librt/t_sem.c
+++ b/contrib/netbsd-tests/lib/librt/t_sem.c
@@ -287,7 +287,11 @@ ATF_TC_BODY(timedwait, tc)
 	    "%s", strerror(errno));
 	ATF_REQUIRE_MSG(clock_gettime(CLOCK_REALTIME, &ts) == 0,
 	    "%s", strerror(errno));
-        timespec_add_ms(&ts, 100);
+	/*
+	 * Only EINTR matters here, not the deadline: keep it far enough
+	 * from the 50ms timer that a loaded host cannot hit ETIMEDOUT.
+	 */
+	ts.tv_sec += 10;
 	ATF_REQUIRE_ERRNO(EINTR, sem_timedwait(&sem, &ts));
 	ATF_REQUIRE_MSG(got_sigalrm, "did not get SIGALRM");
 }
@@ -365,7 +369,11 @@ ATF_TC_BODY(clockwait_absolute_intr_remaining, tc)
 	    "%s", strerror(errno));
 	ATF_REQUIRE_MSG(clock_gettime(CLOCK_MONOTONIC, &ts) == 0,
 	    "%s", strerror(errno));
-        timespec_add_ms(&ts, 100);
+	/*
+	 * Only EINTR matters here, not the deadline: keep it far enough
+	 * from the 50ms timer that a loaded host cannot hit ETIMEDOUT.
+	 */
+	ts.tv_sec += 10;
 	ATF_REQUIRE_EQ(-1, sem_clockwait_np(&sem, CLOCK_MONOTONIC,
 	    TIMER_ABSTIME, &ts, &remain));
 	ATF_REQUIRE_ERRNO(EINTR, 1);