From: Tomas Mraz Date: Fri, 17 Mar 2023 13:58:14 +0000 (+0100) Subject: Add sanity test for OSSL_sleep() X-Git-Tag: openssl-3.2.0-alpha1~1141 X-Git-Url: https://git.openssl.org/?p=openssl.git;a=commitdiff_plain;h=6821acbffda908ec69769ed7f110cfde57d8ca58 Add sanity test for OSSL_sleep() Reviewed-by: David von Oheimb Reviewed-by: Richard Levitte Reviewed-by: Tom Cosgrove (Merged from https://github.com/openssl/openssl/pull/20533) --- diff --git a/test/build.info b/test/build.info index 99f27e12b5..255aef27c0 100644 --- a/test/build.info +++ b/test/build.info @@ -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 diff --git a/test/sanitytest.c b/test/sanitytest.c index aba9149231..9628fdb4bf 100644 --- a/test/sanitytest.c +++ b/test/sanitytest.c @@ -11,6 +11,7 @@ #include #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; } -