Configure: move the processing of predefined macros to a function
[openssl.git] / test / siphash_internal_test.c
index 0114af18d08e87b3dbe48acee0d2c7ee04f3f65b..fe207620c700d32173f42c1f9ab7c7b114a812b1 100644 (file)
@@ -16,7 +16,8 @@
 #include "testutil.h"
 #include "internal/siphash.h"
 #include "../crypto/siphash/siphash_local.h"
-#include "e_os.h"
+#include "internal/nelem.h"
+#include "internal/cryptlib.h"
 
 static BIO* b_stderr = NULL;
 static BIO* b_stdout = NULL;
@@ -43,8 +44,7 @@ static int benchmark_siphash(void)
     SIPHASH siphash;
     unsigned char key[SIPHASH_KEY_SIZE];
     unsigned char buf[8192];
-    unsigned long long stopwatch;
-    unsigned long long OPENSSL_rdtsc();
+    uint32_t stopwatch;
     unsigned int i;
 
     memset (buf,0x55,sizeof(buf));
@@ -235,10 +235,10 @@ static int test_siphash(int idx)
 
     /* key and in data are 00 01 02 ... */
     for (i = 0; i < sizeof(key); i++)
-        key[i] = i;
+        key[i] = (unsigned char)i;
 
     for (i = 0; i < inlen; i++)
-        in[i] = i;
+        in[i] = (unsigned char)i;
 
     if (!TEST_true(SipHash_Init(&siphash, key, expectedlen, 0, 0)))
         return 0;
@@ -319,11 +319,13 @@ static int test_siphash_basic(void)
            && TEST_true(SipHash_Final(&siphash, output, 16));
 }
 
-int test_main(int argc, char **argv)
+int setup_tests(void)
 {
-    int result = 0;
-    int iter_argv;
-    int benchmark = 0;
+    if (test_has_option("-h")) {
+        BIO_printf(bio_out, "-h\tThis help\n");
+        BIO_printf(bio_out, "-b\tBenchmark in addition to the tests\n");
+        return 1;
+    }
 
     b_stderr = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
     b_stdout = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);
@@ -332,28 +334,15 @@ int test_main(int argc, char **argv)
     b_stdout = BIO_push(BIO_new(BIO_f_linebuffer()), b_stdout);
 #endif
 
-    for (iter_argv = 1; iter_argv < argc; iter_argv++) {
-        if (strcmp(argv[iter_argv], "-b") == 0)
-            benchmark = 1;
-        else if (strcmp(argv[iter_argv], "-h") == 0)
-            goto help;
-    }
-
     ADD_TEST(test_siphash_basic);
     ADD_ALL_TESTS(test_siphash, OSSL_NELEM(tests));
-    if (benchmark)
+    if (test_has_option("-b"))
         ADD_TEST(benchmark_siphash);
+    return 1;
+}
 
-    result = run_tests(argv[0]);
-    goto out;
-
- help:
-    BIO_printf(b_stdout, "-h\tThis help\n");
-    BIO_printf(b_stdout, "-b\tBenchmark in addition to the tests\n");
-
- out:
+void cleanup_tests(void)
+{
     BIO_free(b_stdout);
     BIO_free(b_stderr);
-
-    return result;
 }