summaryrefslogtreecommitdiffstats
path: root/test/bntest.c
diff options
context:
space:
mode:
authorPauli <paul.dale@oracle.com>2017-07-18 11:48:27 +1000
committerPauli <paul.dale@oracle.com>2017-07-27 07:53:08 +1000
commitad887416f1e59c3294a7d8f83a0ca77120523b4a (patch)
tree99971c4acaaa7a43efa38a0d52e230c0e68a1c6c /test/bntest.c
parentd445302418b41b76c15e103954b1311d98077480 (diff)
Update the test framework so that the need for test_main is removed. Everything
that needed test_main now works using the same infrastructure as tests that used register_tests. This meant: * renaming register_tests to setup_tests and giving it a success/failure return. * renaming the init_test function to setup_test_framework. * renaming the finish_test function to pulldown_test_framework. * adding a user provided global_init function that runs before the test frame work is initialised. It returns a failure indication that stops the stest. * adding helper functions that permit tests to access their command line args. * spliting the BIO initialisation and finalisation out from the test setup and teardown. * hiding some of the now test internal functions. * fix the comments in testutil.h Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3953)
Diffstat (limited to 'test/bntest.c')
-rw-r--r--test/bntest.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/test/bntest.c b/test/bntest.c
index 59148b0366..a570d0099b 100644
--- a/test/bntest.c
+++ b/test/bntest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -2003,16 +2003,15 @@ static int file_test_run(STANZA *s)
return 0;
}
-static char * const *testfiles;
-
static int run_file_tests(int i)
{
STANZA *s = NULL;
+ char *testfile = test_get_argument(i);
int c;
if (!TEST_ptr(s = OPENSSL_zalloc(sizeof(*s))))
return 0;
- if (!test_start_file(s, testfiles[i])) {
+ if (!test_start_file(s, testfile)) {
OPENSSL_free(s);
return 0;
}
@@ -2034,18 +2033,17 @@ static int run_file_tests(int i)
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
static const char rnd_seed[] =
"If not seeded, BN_generate_prime might fail";
- int result = EXIT_FAILURE;
-
+ int n = test_get_argument_count();
- RAND_seed(rnd_seed, sizeof rnd_seed);
+ RAND_seed(rnd_seed, sizeof(rnd_seed));
if (!TEST_ptr(ctx = BN_CTX_new()))
- goto end;
+ return 0;
- if (argc < 2) {
+ if (n == 0) {
ADD_TEST(test_sub);
ADD_TEST(test_div_recip);
ADD_TEST(test_mod);
@@ -2074,13 +2072,12 @@ int test_main(int argc, char *argv[])
#endif
ADD_TEST(test_3_is_prime);
} else {
- testfiles = &argv[1];
- ADD_ALL_TESTS(run_file_tests, argc - 1);
+ ADD_ALL_TESTS(run_file_tests, n);
}
+ return 1;
+}
- result = run_tests(argv[0]);
-
-end:
+void cleanup_tests(void)
+{
BN_CTX_free(ctx);
- return result;
}