Add sanity test for OSSL_sleep()
authorTomas Mraz <tomas@openssl.org>
Fri, 17 Mar 2023 13:58:14 +0000 (14:58 +0100)
committerDr. David von Oheimb <dev@ddvo.net>
Sat, 18 Mar 2023 19:00:57 +0000 (20:00 +0100)
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)

test/build.info
test/sanitytest.c

index 99f27e12b5c56f7c0601529b2735fc0df82254bb..255aef27c0ee0a5b04abf13ba2a4e9de9433492d 100644 (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
index aba9149231f3a465b9bd9c48c9c52288d7f2737d..9628fdb4bf8142ac6dc447ec23e48ed25fa2e2f6 100644 (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;
 }
-