From c2609155b30820af07281f154e5e96c68ff21aca Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Sat, 19 Apr 2025 10:02:22 -0400 Subject: [PATCH] tests: posix: semaphores: reduce execution time by 5s There is no reason to use a 5s wait time in tests. This can add up quite significantly across multiple platforms that execute in real-time under qemu (or even just on real hardware). Speedup observed with qemu_cortex_a53/qemu_cortex_a53/smp Before: ``` START - test_named_semaphore PASS - test_named_semaphore in 5.688 seconds ``` After: ``` START - test_named_semaphore PASS - test_named_semaphore in 0.783 seconds ``` Signed-off-by: Chris Friedt --- tests/posix/semaphores/src/main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/posix/semaphores/src/main.c b/tests/posix/semaphores/src/main.c index 228165fb131..a44571fed86 100644 --- a/tests/posix/semaphores/src/main.c +++ b/tests/posix/semaphores/src/main.c @@ -13,6 +13,9 @@ #include #include +#define WAIT_TIME_MS 100 +BUILD_ASSERT(WAIT_TIME_MS > 0, "WAIT_TIME_MS must be posistive"); + static void *child_func(void *p1) { sem_t *sem = (sem_t *)p1; @@ -51,11 +54,10 @@ static void semaphore_test(sem_t *sem) zassert_equal(clock_gettime(CLOCK_REALTIME, &abstime), 0, "clock_gettime failed"); - abstime.tv_sec += 5; + abstime.tv_sec += WAIT_TIME_MS / MSEC_PER_SEC; + abstime.tv_nsec += (WAIT_TIME_MS % MSEC_PER_SEC) * NSEC_PER_MSEC; - /* TESPOINT: Wait for 5 seconds and acquire sema given - * by thread1 - */ + /* TESPOINT: Wait to acquire sem given by thread1 */ zassert_equal(sem_timedwait(sem, &abstime), 0); /* TESTPOINT: Semaphore is already acquired, check if