Skip to content

Commit 4d92982

Browse files
Chris Friedtcfriedt
authored andcommitted
tests: posix: clock: do not use usleep in a broken way
Using `usleep()` for >= 10000000 microseconds results in an error, so this test was kind of defective, having explicitly called `usleep()` for seconds. Also, check the return values of `clock_gettime()`. Signed-off-by: Chris Friedt <[email protected]> (cherry picked from commit 23a1f0a)
1 parent 37b3641 commit 4d92982

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

tests/posix/common/src/clock.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ void test_posix_clock(void)
2323
NULL);
2424
zassert_equal(errno, EINVAL, NULL);
2525

26-
clock_gettime(CLOCK_MONOTONIC, &ts);
27-
/* 2 Sec Delay */
28-
sleep(SLEEP_SECONDS);
29-
usleep(SLEEP_SECONDS * USEC_PER_SEC);
30-
clock_gettime(CLOCK_MONOTONIC, &te);
26+
zassert_ok(clock_gettime(CLOCK_MONOTONIC, &ts));
27+
zassert_ok(k_sleep(K_SECONDS(SLEEP_SECONDS)));
28+
zassert_ok(clock_gettime(CLOCK_MONOTONIC, &te));
3129

3230
if (te.tv_nsec >= ts.tv_nsec) {
3331
secs_elapsed = te.tv_sec - ts.tv_sec;
@@ -38,7 +36,7 @@ void test_posix_clock(void)
3836
}
3937

4038
/*TESTPOINT: Check if POSIX clock API test passes*/
41-
zassert_equal(secs_elapsed, (2 * SLEEP_SECONDS),
39+
zassert_equal(secs_elapsed, SLEEP_SECONDS,
4240
"POSIX clock API test failed");
4341

4442
printk("POSIX clock APIs test done\n");

0 commit comments

Comments
 (0)