tests/posix/common: Adjust miscalibrated timing test

This test seems a little confused.  It does a POSIX usleep() for 90ms,
then checks the time taken, and verifies that it was no less
than... 91ms!

On existing platforms, tick alignment makes sure that we always take a
little longer, so this passes. But on high tick rate configurations we
get it exactly right.  And fail.

Adjust the calibration to allow (exactly) 90ms sleeps.  Also fixed a
comment that described the wrong units.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2019-06-15 22:19:49 -07:00 committed by Anas Nashif
parent 03164a7802
commit ffb9e0977d

View file

@ -84,10 +84,10 @@ void test_posix_realtime(void)
zassert_equal(ret, 0, "Fail to set realtime clock");
/*
* Loop for 20 10ths of a second, sleeping a little bit for
* each, making sure that the arithmetic roughly makes sense.
* This tries to catch all of the boundary conditions of the
* clock to make sure there are no errors in the arithmetic.
* Loop 20 times, sleeping a little bit for each, making sure
* that the arithmetic roughly makes sense. This tries to
* catch all of the boundary conditions of the clock to make
* sure there are no errors in the arithmetic.
*/
s64_t last_delta = 0;
for (int i = 1; i <= 20; i++) {
@ -100,7 +100,7 @@ void test_posix_realtime(void)
(s64_t)nts.tv_sec * NSEC_PER_SEC) +
((s64_t)rts.tv_nsec - (s64_t)nts.tv_nsec);
/* Make the delta 10ths of a second. */
/* Make the delta milliseconds. */
delta /= (NSEC_PER_SEC / 1000U);
zassert_true(delta > last_delta, "Clock moved backward");
@ -108,9 +108,11 @@ void test_posix_realtime(void)
/* printk("Delta %d: %lld\n", i, delta); */
/* Allow for a little drift */
zassert_true(error > 90, "Clock inaccurate");
zassert_true(error < 110, "Clock inaccurate");
/* Allow for a little drift upward, but not
* downward
*/
zassert_true(error >= 90, "Clock inaccurate %d", error);
zassert_true(error < 110, "Clock inaccurate %d", error);
last_delta = delta;
}