From ec6263095013a2ef2315a9108655f8f6efa0b7a5 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Sun, 18 May 2025 10:55:18 -0400 Subject: [PATCH] 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 --- tests/lib/c_lib/thrd/src/thrd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/lib/c_lib/thrd/src/thrd.c b/tests/lib/c_lib/thrd/src/thrd.c index 0a4c1697c54..6a9f0b5de17 100644 --- a/tests/lib/c_lib/thrd/src/thrd.c +++ b/tests/lib/c_lib/thrd/src/thrd.c @@ -10,6 +10,7 @@ #include #include +#include #include static thrd_t thr; @@ -32,7 +33,7 @@ ZTEST(libc_thrd, test_thrd_sleep) zassert_equal(thrd_success, thrd_sleep(&duration, &duration)); for (int i = 0; i < ARRAY_SIZE(delay_ms); ++i) { - duration = (struct timespec){.tv_nsec = delay_ms[i] * NSEC_PER_MSEC}; + timespec_from_timeout(K_MSEC(delay_ms[i]), &duration); remaining = (struct timespec){.tv_sec = 4242, .tv_nsec = 4242}; printk("sleeping %d ms\n", delay_ms[i]);