Commit Graph

2 Commits

Author SHA1 Message Date
Christopher Friedt 0bed5dd459 tests: posix: semaphore: speed up named semaphore test
Reduce N_LOOPS from 999 to 32 by default and use a Kconfig
to encode it as CONFIG_TEST_SEM_N_LOOPS.

Running TESTSUITE semaphore
===============================================================
START - test_named_semaphore
 PASS - test_named_semaphore in 5.685 seconds
===============================================================
START - test_semaphore
 PASS - test_semaphore in 5.010 seconds
===============================================================
TESTSUITE semaphore succeeded

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2024-01-22 09:49:39 +00:00
Christopher Friedt 67a74e4350 tests: posix: test_realtime: improve test reliability
Previously posix_apis.test_realtime was failing (very)
frequently in CI, and in particular, when running on Qemu,
POSIX, or SMP targets.

We are using CLOCK_REALTIME for this test, which incurs an
additional syscall overhead above CLOCK_MONOTONIC. The act
of sleeping itself also incurs a syscall overhead.

The latency from one iteration to the next of the internal
loop is a bit of a random process due to scheduler or clock
noise (although the noise itself is still bounded).

In order to make this test robust against such noise, assert
only on the average time from one iteration to the next,
rather than the instantaneous time.

Rather than calculating a sample mean, use a running average
(aka Cumulative Moving Average) to save some bytes.

Report results, including low and high watermarks before
asserting that the average iteration time within expected
range.

==============================================================
START - test_realtime
I: n: 20, sleep: 100, margin: 10, lo: 110, avg: 110, hi: 110
 PASS - test_realtime in 2.198 seconds
==============================================================

Expect to see the low and high watermarks change more on
Qemu and POSIX platforms when running several jobs in parallel
with twister (such as in CI).

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2024-01-04 08:27:29 +09:00