Improve comments about the time_delay test.
Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
This commit is contained in:
parent
ed9b9a7579
commit
d3c7d538f1
1 changed files with 12 additions and 11 deletions
|
@ -91,20 +91,21 @@ void time_delay_seconds(int delay_secs)
|
||||||
elapsed_secs = mbedtls_time(NULL) - current;
|
elapsed_secs = mbedtls_time(NULL) - current;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* `mbedtls_time` was defined as c99 function `time`, it uses
|
* `mbedtls_time()` was defined as c99 function `time()`, returns the number
|
||||||
* CLOCK_REALTIME and returns the number of seconds since the Epoch. And
|
* of seconds since the Epoch. And it is affected by discontinuous changes
|
||||||
* `nanosleep` uses CLOCK_MONOTONIC. The time sources are out of sync.
|
* from automatic drift adjustment or time setting system call. The POSIX.1
|
||||||
|
* specification for clock_settime says that discontinuous changes in
|
||||||
|
* CLOCK_REALTIME should not affect `nanosleep()`.
|
||||||
*
|
*
|
||||||
* If CLOCK_MONOTONIC is faster than CLOCK_REALTIME and `nanosleep` exits at
|
* If discontinuous changes occur during `nanosleep()`, we will get
|
||||||
* the end of a second, `elapsed_secs` will be less than `delay_secs`.
|
* `elapsed_secs < delay_secs` for backward and `elapsed_secs > delay_secs`
|
||||||
|
* for forward.
|
||||||
*
|
*
|
||||||
* Workaround it with 1 second tolerance.
|
* The following tolerance windows cannot be guaranteed.
|
||||||
|
* PLEASE DO NOT ENABLE IT IN CI TEST.
|
||||||
*/
|
*/
|
||||||
TEST_ASSERT(elapsed_secs >= delay_secs - 1);
|
TEST_ASSERT(elapsed_secs - delay_secs >= -1 &&
|
||||||
/* If CLOCK_MONOTONIC is slower than CLOCK_REALTIME or nanosleep does not
|
elapsed_secs - delay_secs < 4);
|
||||||
* exit on time.
|
|
||||||
*/
|
|
||||||
TEST_ASSERT(elapsed_secs < 4 + delay_secs);
|
|
||||||
/* This goto is added to avoid warnings from the generated code. */
|
/* This goto is added to avoid warnings from the generated code. */
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue