Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround random test_suite_platform fail in time test #7419

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve comments about the time_delay test.
Signed-off-by: Jerry Yu <[email protected]>
yuhaoth committed Apr 19, 2023
commit d3c7d538f1aa41518924f2dc138942970aaf11d0
23 changes: 12 additions & 11 deletions tests/suites/test_suite_platform.function
Original file line number Diff line number Diff line change
@@ -91,20 +91,21 @@ void time_delay_seconds(int delay_secs)
elapsed_secs = mbedtls_time(NULL) - current;

/*
* `mbedtls_time` was defined as c99 function `time`, it uses
* CLOCK_REALTIME and returns the number of seconds since the Epoch. And
* `nanosleep` uses CLOCK_MONOTONIC. The time sources are out of sync.
* `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 CLOCK_MONOTONIC is faster than CLOCK_REALTIME and `nanosleep` exits at
* the end of a second, `elapsed_secs` will be less than `delay_secs`.
* If discontinuous changes occur during `nanosleep()`, we will get
* `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);
/* If CLOCK_MONOTONIC is slower than CLOCK_REALTIME or nanosleep does not
* exit on time.
*/
TEST_ASSERT(elapsed_secs < 4 + delay_secs);
TEST_ASSERT(elapsed_secs - delay_secs >= -1 &&
elapsed_secs - delay_secs < 4);
/* This goto is added to avoid warnings from the generated code. */
goto exit;
}