Skip to content

Commit e1fef28

Browse files
committed
tests: libc: thrd: use timespec_from_timeout()
Use `timespec_from_timeout(K_MSEC(msec), &ts)` instead of leaning on lazily-crafted timespecs with invalid tv_nsec fields. Signed-off-by: Chris Friedt <[email protected]>
1 parent 49248e4 commit e1fef28

File tree

1 file changed

+2
-1
lines changed
  • tests/lib/c_lib/thrd/src

1 file changed

+2
-1
lines changed

tests/lib/c_lib/thrd/src/thrd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <threads.h>
1111

1212
#include <zephyr/sys_clock.h>
13+
#include <zephyr/sys/timeutil.h>
1314
#include <zephyr/ztest.h>
1415

1516
static thrd_t thr;
@@ -28,7 +29,7 @@ ZTEST(libc_thrd, test_thrd_sleep)
2829
zassert_ok(thrd_sleep(&duration, &duration));
2930

3031
for (int i = 0; i < ARRAY_SIZE(delay_ms); ++i) {
31-
duration = (struct timespec){.tv_nsec = delay_ms[i] * NSEC_PER_MSEC};
32+
timespec_from_timeout(K_MSEC(delay_ms[i]), &duration);
3233
remaining = (struct timespec){.tv_sec = 4242, .tv_nsec = 4242};
3334

3435
printk("sleeping %d ms\n", delay_ms[i]);

0 commit comments

Comments
 (0)