Skip to content

Commit c260915

Browse files
cfriedtkartben
authored andcommitted
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 <cfriedt@tenstorrent.com>
1 parent 0449324 commit c260915

File tree

1 file changed

+6
-4
lines changed
  • tests/posix/semaphores/src

1 file changed

+6
-4
lines changed

tests/posix/semaphores/src/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include <zephyr/sys/util.h>
1414
#include <zephyr/ztest.h>
1515

16+
#define WAIT_TIME_MS 100
17+
BUILD_ASSERT(WAIT_TIME_MS > 0, "WAIT_TIME_MS must be posistive");
18+
1619
static void *child_func(void *p1)
1720
{
1821
sem_t *sem = (sem_t *)p1;
@@ -51,11 +54,10 @@ static void semaphore_test(sem_t *sem)
5154

5255
zassert_equal(clock_gettime(CLOCK_REALTIME, &abstime), 0, "clock_gettime failed");
5356

54-
abstime.tv_sec += 5;
57+
abstime.tv_sec += WAIT_TIME_MS / MSEC_PER_SEC;
58+
abstime.tv_nsec += (WAIT_TIME_MS % MSEC_PER_SEC) * NSEC_PER_MSEC;
5559

56-
/* TESPOINT: Wait for 5 seconds and acquire sema given
57-
* by thread1
58-
*/
60+
/* TESPOINT: Wait to acquire sem given by thread1 */
5961
zassert_equal(sem_timedwait(sem, &abstime), 0);
6062

6163
/* TESTPOINT: Semaphore is already acquired, check if

0 commit comments

Comments
 (0)