Skip to content
Permalink
Browse files

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>
  • Loading branch information...
andyross authored and nashif committed Jun 16, 2019
1 parent 03164a7 commit ffb9e0977da03bdb4563ca73b01a65588687c2c8
Showing with 10 additions and 8 deletions.
  1. +10 −8 tests/posix/common/src/clock.c
@@ -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,17 +100,19 @@ 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");
s64_t error = delta - last_delta;

/* 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;
}

0 comments on commit ffb9e09

Please sign in to comment.
You can’t perform that action at this time.