Skip to content

Commit a4498bd

Browse files
cfriedtfabiobaltieri
authored andcommitted
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 <[email protected]>
1 parent 19988ac commit a4498bd

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

tests/posix/common/src/mutex.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <errno.h>
88
#include <pthread.h>
9+
#include <time.h>
910

1011
#include <zephyr/sys/util.h>
1112
#include <zephyr/ztest.h>
@@ -182,7 +183,7 @@ static void *test_mutex_timedlock_fn(void *arg)
182183
struct timespec time_point;
183184
pthread_mutex_t *mtx = (pthread_mutex_t *)arg;
184185

185-
zassume_ok(clock_gettime(CLOCK_MONOTONIC, &time_point));
186+
zassume_ok(clock_gettime(CLOCK_REALTIME, &time_point));
186187
timespec_add_ms(&time_point, TIMEDLOCK_TIMEOUT_MS);
187188

188189
return INT_TO_POINTER(pthread_mutex_timedlock(mtx, &time_point));

tests/posix/common/src/pthread.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <pthread.h>
88
#include <semaphore.h>
9+
#include <time.h>
910

1011
#include <zephyr/sys/util.h>
1112
#include <zephyr/ztest.h>
@@ -409,8 +410,8 @@ ZTEST(pthread, test_pthread_timedjoin)
409410
};
410411

411412
/* setup timespecs when the thread is still running and when it is done */
412-
clock_gettime(CLOCK_MONOTONIC, &not_done);
413-
clock_gettime(CLOCK_MONOTONIC, &done);
413+
clock_gettime(CLOCK_REALTIME, &not_done);
414+
clock_gettime(CLOCK_REALTIME, &done);
414415
not_done.tv_nsec += sleep_duration_ms / 2 * NSEC_PER_MSEC;
415416
done.tv_nsec += sleep_duration_ms * 1.5 * NSEC_PER_MSEC;
416417
while (not_done.tv_nsec >= NSEC_PER_SEC) {

0 commit comments

Comments
 (0)