From 74628976f0a7232d477d7a2b4f1080c515af255f Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Fri, 22 Aug 2025 10:32:08 -0400 Subject: [PATCH] tests: posix: common: use realtime clock instead of monotonic Use the realtime clock, since that is always guaranteed to be available with _POSIX_TIMERS. Signed-off-by: Chris Friedt --- tests/posix/common/src/mutex.c | 3 ++- tests/posix/common/src/pthread.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/posix/common/src/mutex.c b/tests/posix/common/src/mutex.c index 40987d50297a0..20b992620eb8a 100644 --- a/tests/posix/common/src/mutex.c +++ b/tests/posix/common/src/mutex.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -182,7 +183,7 @@ static void *test_mutex_timedlock_fn(void *arg) struct timespec time_point; pthread_mutex_t *mtx = (pthread_mutex_t *)arg; - zassume_ok(clock_gettime(CLOCK_MONOTONIC, &time_point)); + zassume_ok(clock_gettime(CLOCK_REALTIME, &time_point)); timespec_add_ms(&time_point, TIMEDLOCK_TIMEOUT_MS); return INT_TO_POINTER(pthread_mutex_timedlock(mtx, &time_point)); diff --git a/tests/posix/common/src/pthread.c b/tests/posix/common/src/pthread.c index 035730ee4dc73..96a16f7ddb33b 100644 --- a/tests/posix/common/src/pthread.c +++ b/tests/posix/common/src/pthread.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -409,8 +410,8 @@ ZTEST(pthread, test_pthread_timedjoin) }; /* setup timespecs when the thread is still running and when it is done */ - clock_gettime(CLOCK_MONOTONIC, ¬_done); - clock_gettime(CLOCK_MONOTONIC, &done); + clock_gettime(CLOCK_REALTIME, ¬_done); + clock_gettime(CLOCK_REALTIME, &done); not_done.tv_nsec += sleep_duration_ms / 2 * NSEC_PER_MSEC; done.tv_nsec += sleep_duration_ms * 1.5 * NSEC_PER_MSEC; while (not_done.tv_nsec >= NSEC_PER_SEC) {