mirror of
https://github.com/cuberite/polarssl.git
synced 2025-12-11 08:18:49 -05:00
Merge pull request #7419 from yuhaoth/test/random-time-test-fail
Workaround random `test_suite_platform` fail in time test
This commit is contained in:
commit
14d6b1124b
@ -7,6 +7,3 @@ time_get_seconds:
|
|||||||
|
|
||||||
Time: delay milliseconds
|
Time: delay milliseconds
|
||||||
time_delay_milliseconds:1000
|
time_delay_milliseconds:1000
|
||||||
|
|
||||||
Time: delay seconds
|
|
||||||
time_delay_seconds:1
|
|
||||||
|
|||||||
@ -38,8 +38,6 @@ void sleep_ms(int milliseconds)
|
|||||||
|
|
||||||
/* END_DEPENDENCIES */
|
/* END_DEPENDENCIES */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_HAVE_TIME */
|
/* BEGIN_CASE depends_on:MBEDTLS_HAVE_TIME */
|
||||||
void time_get_milliseconds()
|
void time_get_milliseconds()
|
||||||
{
|
{
|
||||||
@ -76,6 +74,14 @@ void time_delay_milliseconds(int delay_ms)
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_HAVE_TIME */
|
/* BEGIN_CASE depends_on:MBEDTLS_HAVE_TIME */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING: DO NOT ENABLE THIS TEST. We keep the code here to document the
|
||||||
|
* reason.
|
||||||
|
*
|
||||||
|
* The test often failed on the CI. See #1517. CI failures cannot be
|
||||||
|
* completely avoided due to out-of-sync clock sources.
|
||||||
|
*/
|
||||||
void time_delay_seconds(int delay_secs)
|
void time_delay_seconds(int delay_secs)
|
||||||
{
|
{
|
||||||
mbedtls_time_t current = mbedtls_time(NULL);
|
mbedtls_time_t current = mbedtls_time(NULL);
|
||||||
@ -84,7 +90,23 @@ void time_delay_seconds(int delay_secs)
|
|||||||
sleep_ms(delay_secs * 1000);
|
sleep_ms(delay_secs * 1000);
|
||||||
|
|
||||||
elapsed_secs = mbedtls_time(NULL) - current;
|
elapsed_secs = mbedtls_time(NULL) - current;
|
||||||
TEST_ASSERT(elapsed_secs >= delay_secs && elapsed_secs < 4 + delay_secs);
|
|
||||||
|
/*
|
||||||
|
* `mbedtls_time()` was defined as c99 function `time()`, returns the number
|
||||||
|
* of seconds since the Epoch. And it is affected by discontinuous changes
|
||||||
|
* 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 discontinuous changes occur during `nanosleep()`, we will get
|
||||||
|
* `elapsed_secs < delay_secs` for backward or `elapsed_secs > delay_secs`
|
||||||
|
* for forward.
|
||||||
|
*
|
||||||
|
* The following tolerance windows cannot be guaranteed.
|
||||||
|
* PLEASE DO NOT ENABLE IT IN CI TEST.
|
||||||
|
*/
|
||||||
|
TEST_ASSERT(elapsed_secs - delay_secs >= -1 &&
|
||||||
|
elapsed_secs - delay_secs < 4);
|
||||||
/* 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…
x
Reference in New Issue
Block a user