mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-26 21:35:35 +00:00
fix random fails
Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
This commit is contained in:
parent
c5b48a6f04
commit
1f7dd8df9b
@ -6,7 +6,7 @@ Time: get seconds
|
|||||||
time_get_seconds:
|
time_get_seconds:
|
||||||
|
|
||||||
Time: delay milliseconds
|
Time: delay milliseconds
|
||||||
time_delay_milliseconds:20
|
time_delay_milliseconds:100
|
||||||
|
|
||||||
Time: delay seconds
|
Time: delay seconds
|
||||||
time_delay_seconds:1
|
time_delay_seconds:1
|
||||||
|
@ -64,23 +64,27 @@ void time_get_seconds()
|
|||||||
void time_delay_milliseconds(int delay_ms)
|
void time_delay_milliseconds(int delay_ms)
|
||||||
{
|
{
|
||||||
mbedtls_ms_time_t current = mbedtls_ms_time();
|
mbedtls_ms_time_t current = mbedtls_ms_time();
|
||||||
|
mbedtls_ms_time_t elapsed_ms;
|
||||||
|
|
||||||
sleep_ms(delay_ms);
|
sleep_ms(delay_ms);
|
||||||
|
|
||||||
current = mbedtls_ms_time() - current;
|
elapsed_ms = mbedtls_ms_time() - current;
|
||||||
TEST_ASSERT(current == delay_ms || current == delay_ms + 1);
|
TEST_ASSERT(elapsed_ms >= delay_ms && elapsed_ms < 500 + delay_ms);
|
||||||
/* 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;
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_HAVE_TIME */
|
/* BEGIN_CASE depends_on:MBEDTLS_HAVE_TIME */
|
||||||
void time_delay_seconds(int delay)
|
void time_delay_seconds(int delay_secs)
|
||||||
{
|
{
|
||||||
mbedtls_time_t current = mbedtls_time(NULL);
|
mbedtls_time_t current = mbedtls_time(NULL);
|
||||||
sleep_ms(delay*1000);
|
mbedtls_time_t elapsed_secs;
|
||||||
current = mbedtls_time(NULL) - current;
|
|
||||||
TEST_ASSERT(current == delay);
|
sleep_ms(delay_secs * 1000);
|
||||||
|
|
||||||
|
elapsed_secs = mbedtls_time(NULL) - current;
|
||||||
|
TEST_ASSERT(elapsed_secs >= delay_secs && 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…
x
Reference in New Issue
Block a user