mirror of
https://github.com/openssl/openssl.git
synced 2025-01-12 13:36:28 +08:00
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:
parent
bea92b8c3d
commit
6821acbffd
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user