Add sanity test for OSSL_sleep()

Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
(Merged from https://github.com/openssl/openssl/pull/20533)
This commit is contained in:
Tomas Mraz 2023-03-17 14:58:14 +01:00 committed by Dr. David von Oheimb
parent bea92b8c3d
commit 6821acbffd
2 changed files with 22 additions and 2 deletions

View File

@ -92,7 +92,7 @@ IF[{- !$disabled{tests} -}]
SOURCE[sanitytest]=sanitytest.c
INCLUDE[sanitytest]=../include ../apps/include
DEPEND[sanitytest]=../libcrypto libtestutil.a
DEPEND[sanitytest]=../libcrypto.a libtestutil.a
SOURCE[rand_test]=rand_test.c
INCLUDE[rand_test]=../include ../apps/include

View File

@ -11,6 +11,7 @@
#include <openssl/types.h>
#include "testutil.h"
#include "internal/numbers.h"
#include "internal/time.h"
static int test_sanity_null_zero(void)
{
@ -129,6 +130,25 @@ static int test_sanity_memcmp(void)
return CRYPTO_memcmp("ab", "cd", 2);
}
static int test_sanity_sleep(void)
{
OSSL_TIME start = ossl_time_now();
uint64_t seconds;
/*
* On any reasonable system this must sleep at least one second
* but not more than 20.
* Assuming there is no interruption.
*/
OSSL_sleep(1000);
seconds = ossl_time2seconds(ossl_time_subtract(ossl_time_now(), start));
if (!TEST_uint64_t_ge(seconds, 1) || !TEST_uint64_t_le(seconds, 20))
return 0;
return 1;
}
int setup_tests(void)
{
ADD_TEST(test_sanity_null_zero);
@ -138,6 +158,6 @@ int setup_tests(void)
ADD_TEST(test_sanity_unsigned_conversion);
ADD_TEST(test_sanity_range);
ADD_TEST(test_sanity_memcmp);
ADD_TEST(test_sanity_sleep);
return 1;
}