[openssl-commits] [openssl] master update
paul.dale at oracle.com
paul.dale at oracle.com
Wed Jul 26 23:04:29 UTC 2017
The branch master has been updated
via 43405889f47648ee70c1b412b8b71570e8aaa24a (commit)
via ad887416f1e59c3294a7d8f83a0ca77120523b4a (commit)
from d445302418b41b76c15e103954b1311d98077480 (commit)
- Log -----------------------------------------------------------------
commit 43405889f47648ee70c1b412b8b71570e8aaa24a
Author: Pauli <paul.dale at oracle.com>
Date: Thu Jul 27 08:08:36 2017 +1000
Fix the two new tests since approval.
Reviewed-by: Richard Levitte <levitte at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3953)
commit ad887416f1e59c3294a7d8f83a0ca77120523b4a
Author: Pauli <paul.dale at oracle.com>
Date: Tue Jul 18 11:48:27 2017 +1000
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 at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3953)
-----------------------------------------------------------------------
Summary of changes:
test/README | 3 +-
test/afalgtest.c | 30 +++++----
test/asn1_encode_test.c | 3 +-
test/asn1_internal_test.c | 3 +-
test/asn1_string_table_test.c | 3 +-
test/asynciotest.c | 23 +++----
test/bad_dtls_test.c | 3 +-
test/bftest.c | 23 +++----
test/bio_enc_test.c | 5 +-
test/bioprinttest.c | 8 +--
test/bntest.c | 29 ++++-----
test/build.info | 4 +-
test/casttest.c | 5 +-
test/chacha_internal_test.c | 3 +-
test/cipher_overhead_test.c | 5 +-
test/cipherbytes_test.c | 13 ++--
test/cipherlist_test.c | 3 +-
test/ciphername_test.c | 3 +-
test/clienthellotest.c | 13 ++--
test/constant_time_test.c | 5 +-
test/crltest.c | 13 ++--
test/ct_test.c | 6 +-
test/d2i_test.c | 23 +++----
test/danetest.c | 17 ++---
test/destest.c | 3 +-
test/dhtest.c | 17 +++--
test/drbgtest.c | 8 +--
test/dsatest.c | 5 +-
test/dtls_mtu_test.c | 5 +-
test/dtlstest.c | 20 +++---
test/dtlsv1listentest.c | 3 +-
test/ecdsatest.c | 5 +-
test/ecstresstest.c | 31 +++------
test/ectest.c | 14 ++---
test/enginetest.c | 17 +++--
test/evp_extra_test.c | 9 +--
test/evp_test.c | 19 +++---
test/exdatatest.c | 3 +-
test/exptest.c | 3 +-
test/gmdifftest.c | 3 +-
test/hmactest.c | 3 +-
test/ideatest.c | 3 +-
test/igetest.c | 5 +-
test/lhash_test.c | 3 +-
test/md2test.c | 3 +-
test/mdc2_internal_test.c | 5 +-
test/mdc2test.c | 3 +-
test/modes_internal_test.c | 33 ++++------
test/packettest.c | 5 +-
test/pbelutest.c | 5 +-
test/pemtest.c | 3 +-
test/pkey_meth_test.c | 3 +-
test/poly1305_internal_test.c | 33 ++++------
test/randtest.c | 5 +-
test/rc2test.c | 3 +-
test/rc4test.c | 3 +-
test/rc5test.c | 3 +-
test/recordlentest.c | 21 +++----
test/rsa_test.c | 5 +-
test/sanitytest.c | 3 +-
test/secmemtest.c | 3 +-
test/shlibloadtest.c | 22 +++----
test/siphash_internal_test.c | 33 ++++------
test/srptest.c | 5 +-
test/ssl_cert_table_internal_test.c | 3 +-
test/ssl_test.c | 19 +++---
test/ssl_test_ctx_test.c | 24 ++++---
test/sslapitest.c | 22 +++----
test/sslbuffertest.c | 30 ++++-----
test/sslcorrupttest.c | 24 +++----
test/stack_test.c | 3 +-
test/test_test.c | 3 +-
test/testutil.h | 63 ++++++++++---------
test/testutil/driver.c | 64 ++++++++++---------
test/{evp_test.h => testutil/init.c} | 8 ++-
test/testutil/main.c | 94 ++++++++++++++++++++++++++--
test/testutil/stanza.c | 1 +
test/{evp_test.h => testutil/test_cleanup.c} | 7 ++-
test/testutil/test_main.c | 22 -------
test/testutil/tu_local.h | 6 ++
test/threadstest.c | 3 +-
test/time_offset_test.c | 3 +-
test/tls13encryptiontest.c | 3 +-
test/tls13secretstest.c | 5 +-
test/uitest.c | 5 +-
test/v3ext.c | 14 ++---
test/v3nametest.c | 7 ++-
test/verify_extra_test.c | 23 ++++---
test/wpackettest.c | 12 ++--
test/x509_check_cert_pkey_test.c | 22 ++++---
test/x509_dup_cert_test.c | 16 +++--
test/x509_internal_test.c | 3 +-
test/x509_time_test.c | 3 +-
test/x509aux.c | 19 +++---
94 files changed, 604 insertions(+), 551 deletions(-)
copy test/{evp_test.h => testutil/init.c} (79%)
copy test/{evp_test.h => testutil/test_cleanup.c} (79%)
delete mode 100644 test/testutil/test_main.c
diff --git a/test/README b/test/README
index bc96ff2..d852680 100644
--- a/test/README
+++ b/test/README
@@ -123,9 +123,10 @@ Generic form of C test executables
return testresult;
}
- void register_tests(void)
+ int setup_tests(void)
{
ADD_TEST(my_test); /* Add each test separately */
+ return 1; /* Indicate success */
}
You should use the TEST_xxx macros provided by testutil.h to test all failure
diff --git a/test/afalgtest.c b/test/afalgtest.c
index 40ea025..62dcdb2 100644
--- a/test/afalgtest.c
+++ b/test/afalgtest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-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
@@ -85,21 +85,20 @@ static int test_afalg_aes_128_cbc(void)
}
#endif
-int main(int argc, char **argv)
+#ifndef OPENSSL_NO_ENGINE
+int global_init(void)
{
- int ret = 0;
-
-#ifdef OPENSSL_NO_ENGINE
- setup_test();
- ret = run_tests(argv[0]);
-#else
ENGINE_load_builtin_engines();
# ifndef OPENSSL_NO_STATIC_ENGINE
OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_AFALG, NULL);
# endif
+ return 1;
+}
+#endif
- setup_test();
-
+int setup_tests(void)
+{
+#ifndef OPENSSL_NO_ENGINE
if ((e = ENGINE_by_id("afalg")) == NULL) {
/* Probably a platform env issue, not a test failure. */
TEST_info("Can't load AFALG engine");
@@ -108,9 +107,14 @@ int main(int argc, char **argv)
ADD_TEST(test_afalg_aes_128_cbc);
# endif
}
- ret = run_tests(argv[0]);
- ENGINE_free(e);
#endif
- return finish_test(ret);
+ return 1;
}
+
+#ifndef OPENSSL_NO_ENGINE
+void cleanup_tests(void)
+{
+ ENGINE_free(e);
+}
+#endif
diff --git a/test/asn1_encode_test.c b/test/asn1_encode_test.c
index 9b8cdca..b8ec168 100644
--- a/test/asn1_encode_test.c
+++ b/test/asn1_encode_test.c
@@ -853,7 +853,7 @@ static int test_uint64(void)
return test_intern(&uint64_test_package);
}
-void register_tests(void)
+int setup_tests(void)
{
#if OPENSSL_API_COMPAT < 0x10200000L
ADD_TEST(test_long_32bit);
@@ -863,4 +863,5 @@ void register_tests(void)
ADD_TEST(test_uint32);
ADD_TEST(test_int64);
ADD_TEST(test_uint64);
+ return 1;
}
diff --git a/test/asn1_internal_test.c b/test/asn1_internal_test.c
index 38ef610..194a073 100644
--- a/test/asn1_internal_test.c
+++ b/test/asn1_internal_test.c
@@ -91,8 +91,9 @@ static int test_standard_methods()
return 0;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_tbl_standard);
ADD_TEST(test_standard_methods);
+ return 1;
}
diff --git a/test/asn1_string_table_test.c b/test/asn1_string_table_test.c
index 7e542b9..2913414 100644
--- a/test/asn1_string_table_test.c
+++ b/test/asn1_string_table_test.c
@@ -70,7 +70,8 @@ static int test_string_tbl()
return rv;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_string_tbl);
+ return 1;
}
diff --git a/test/asynciotest.c b/test/asynciotest.c
index ee450da..aa6076b 100644
--- a/test/asynciotest.c
+++ b/test/asynciotest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL licenses, (the "License");
* you may not use this file except in compliance with the License.
@@ -362,22 +362,17 @@ static int test_asyncio(int test)
return testresult;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- int testresult = 0;
-
- if (!TEST_int_eq(argc, 3))
- goto end;
-
- cert = argv[1];
- privkey = argv[2];
+ if (!TEST_ptr(cert = test_get_argument(0))
+ || !TEST_ptr(privkey = test_get_argument(1)))
+ return 0;
ADD_ALL_TESTS(test_asyncio, 2);
+ return 1;
+}
- testresult = run_tests(argv[0]);
-
- end:
+void cleanup_tests(void)
+{
BIO_meth_free(methods_async);
-
- return testresult;
}
diff --git a/test/bad_dtls_test.c b/test/bad_dtls_test.c
index 9745ff8..2c10a1c 100644
--- a/test/bad_dtls_test.c
+++ b/test/bad_dtls_test.c
@@ -581,7 +581,8 @@ static int test_bad_dtls(void)
return testresult;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_bad_dtls);
+ return 1;
}
diff --git a/test/bftest.c b/test/bftest.c
index df2c9a7..cc509f2 100644
--- a/test/bftest.c
+++ b/test/bftest.c
@@ -435,7 +435,7 @@ static int test_bf_ofb64(void)
}
#endif
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
#ifndef OPENSSL_NO_BF
# ifdef CHARSET_EBCDIC
@@ -447,15 +447,16 @@ int test_main(int argc, char *argv[])
}
# endif
- ADD_ALL_TESTS(test_bf_ecb_raw, 2);
- ADD_ALL_TESTS(test_bf_ecb, NUM_TESTS);
- ADD_ALL_TESTS(test_bf_set_key, KEY_TEST_NUM-1);
- ADD_TEST(test_bf_cbc);
- ADD_TEST(test_bf_cfb64);
- ADD_TEST(test_bf_ofb64);
-
- if (argc > 1)
- return print_test_data();
+ if (test_get_argument(0) != NULL) {
+ print_test_data();
+ } else {
+ ADD_ALL_TESTS(test_bf_ecb_raw, 2);
+ ADD_ALL_TESTS(test_bf_ecb, NUM_TESTS);
+ ADD_ALL_TESTS(test_bf_set_key, KEY_TEST_NUM-1);
+ ADD_TEST(test_bf_cbc);
+ ADD_TEST(test_bf_cfb64);
+ ADD_TEST(test_bf_ofb64);
+ }
#endif
- return run_tests(argv[0]);
+ return 1;
}
diff --git a/test/bio_enc_test.c b/test/bio_enc_test.c
index bc49a79..8474dc5 100644
--- a/test/bio_enc_test.c
+++ b/test/bio_enc_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-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
@@ -212,7 +212,7 @@ static int test_bio_enc_chacha20_poly1305(int idx)
return do_test_bio_cipher(EVP_chacha20_poly1305(), idx);
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_ALL_TESTS(test_bio_enc_aes_128_cbc, 2);
ADD_ALL_TESTS(test_bio_enc_aes_128_ctr, 2);
@@ -224,4 +224,5 @@ void register_tests(void)
ADD_ALL_TESTS(test_bio_enc_chacha20_poly1305, 2);
# endif
# endif
+ return 1;
}
diff --git a/test/bioprinttest.c b/test/bioprinttest.c
index 2c51b7a..d35bffa 100644
--- a/test/bioprinttest.c
+++ b/test/bioprinttest.c
@@ -253,17 +253,15 @@ static int test_big(void)
}
-int test_main(int argc, char **argv)
+int setup_tests(void)
{
- if (argc == 2 && strcmp(argv[1], "-expected") == 0)
- justprint = 1;
+ justprint = test_has_option("-expected");
ADD_TEST(test_big);
ADD_ALL_TESTS(test_fp, nelem(pw_params));
ADD_ALL_TESTS(test_zu, nelem(zu_data));
ADD_ALL_TESTS(test_j, nelem(jf_data));
-
- return run_tests(argv[0]);
+ return 1;
}
/*
diff --git a/test/bntest.c b/test/bntest.c
index 59148b0..a570d00 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;
}
diff --git a/test/build.info b/test/build.info
index 7b8f654..2e8775e 100644
--- a/test/build.info
+++ b/test/build.info
@@ -13,7 +13,7 @@ IF[{- !$disabled{tests} -}]
testutil/driver.c testutil/tests.c testutil/cb.c testutil/stanza.c \
testutil/format_output.c testutil/tap_bio.c \
{- rebase_files("../apps", $target{apps_aux_src}) -} \
- testutil/test_main.c testutil/main.c
+ testutil/test_cleanup.c testutil/main.c testutil/init.c
INCLUDE[libtestutil.a]=.. ../include
DEPEND[libtestutil.a]=../libcrypto
@@ -159,7 +159,7 @@ INCLUDE_MAIN___test_libtestutil_OLB = /INCLUDE=MAIN
DEPEND[evp_test]=../libcrypto libtestutil.a
SOURCE[evp_extra_test]=evp_extra_test.c
- INCLUDE[evp_extra_test]=../include
+ INCLUDE[evp_extra_test]=.. ../include
DEPEND[evp_extra_test]=../libcrypto libtestutil.a
SOURCE[igetest]=igetest.c
diff --git a/test/casttest.c b/test/casttest.c
index 24cfbfd..0fdcb10 100644
--- a/test/casttest.c
+++ b/test/casttest.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
@@ -102,10 +102,11 @@ static int cast_test_iterations(void)
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_CAST
ADD_ALL_TESTS(cast_test_vector, OSSL_NELEM(k_len));
ADD_TEST(cast_test_iterations);
#endif
+ return 1;
}
diff --git a/test/chacha_internal_test.c b/test/chacha_internal_test.c
index e3d1c49..be44012 100644
--- a/test/chacha_internal_test.c
+++ b/test/chacha_internal_test.c
@@ -179,11 +179,12 @@ static int test_cha_cha_internal(int n)
return 1;
}
-void register_tests(void)
+int setup_tests(void)
{
#ifdef CPUID_OBJ
OPENSSL_cpuid_setup();
#endif
ADD_ALL_TESTS(test_cha_cha_internal, sizeof(ref));
+ return 1;
}
diff --git a/test/cipher_overhead_test.c b/test/cipher_overhead_test.c
index 6bf74a5..e93bf33 100644
--- a/test/cipher_overhead_test.c
+++ b/test/cipher_overhead_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-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
@@ -42,7 +42,8 @@ static int cipher_overhead(void)
return ret;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(cipher_overhead);
+ return 1;
}
diff --git a/test/cipherbytes_test.c b/test/cipherbytes_test.c
index bc3051e..6601f7b 100644
--- a/test/cipherbytes_test.c
+++ b/test/cipherbytes_test.c
@@ -129,22 +129,21 @@ err:
return ret;
}
-int test_main(int argc, char **argv)
+int setup_tests(void)
{
- int ret;
-
if (!TEST_ptr(ctx = SSL_CTX_new(TLS_server_method()))
|| !TEST_ptr(s = SSL_new(ctx)))
- return EXIT_FAILURE;
+ return 0;
ADD_TEST(test_empty);
ADD_TEST(test_unsupported);
ADD_TEST(test_v2);
ADD_TEST(test_v3);
- ret = run_tests(argv[0]);
+ return 1;
+}
+void cleanup_tests(void)
+{
SSL_free(s);
SSL_CTX_free(ctx);
-
- return ret;
}
diff --git a/test/cipherlist_test.c b/test/cipherlist_test.c
index f4d1b35..c193976 100644
--- a/test/cipherlist_test.c
+++ b/test/cipherlist_test.c
@@ -201,8 +201,9 @@ static int test_default_cipherlist_explicit()
EXECUTE_CIPHERLIST_TEST();
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(test_default_cipherlist_implicit);
ADD_TEST(test_default_cipherlist_explicit);
+ return 1;
}
diff --git a/test/ciphername_test.c b/test/ciphername_test.c
index 995c352..c2c3157 100644
--- a/test/ciphername_test.c
+++ b/test/ciphername_test.c
@@ -463,7 +463,8 @@ err:
return ret;
}
-void register_tests()
+int setup_tests(void)
{
ADD_TEST(test_cipher_name);
+ return 1;
}
diff --git a/test/clienthellotest.c b/test/clienthellotest.c
index dc58694..fbac8ea 100644
--- a/test/clienthellotest.c
+++ b/test/clienthellotest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2015-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
@@ -215,14 +215,11 @@ end:
return testresult;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- if (argc != 2)
- return EXIT_FAILURE;
-
- sessionfile = argv[1];
+ if (!TEST_ptr(sessionfile = test_get_argument(0)))
+ return 0;
ADD_ALL_TESTS(test_client_hello, TOTAL_NUM_TESTS);
-
- return run_tests(argv[0]);
+ return 1;
}
diff --git a/test/constant_time_test.c b/test/constant_time_test.c
index fdd4075..8575194 100644
--- a/test/constant_time_test.c
+++ b/test/constant_time_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2014-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
@@ -327,11 +327,12 @@ static int test_64values(int i)
return ret;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_sizeofs);
ADD_ALL_TESTS(test_binops, OSSL_NELEM(test_values));
ADD_ALL_TESTS(test_signed, OSSL_NELEM(signed_test_values));
ADD_ALL_TESTS(test_8values, OSSL_NELEM(test_values_8));
ADD_ALL_TESTS(test_64values, OSSL_NELEM(test_values_64));
+ return 1;
}
diff --git a/test/crltest.c b/test/crltest.c
index 048f67f..720c13b 100644
--- a/test/crltest.c
+++ b/test/crltest.c
@@ -364,23 +364,22 @@ static int test_unknown_critical_crl(int n)
return r;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- int status = EXIT_FAILURE;
-
if (!TEST_ptr(test_root = X509_from_strings(kCRLTestRoot))
|| !TEST_ptr(test_leaf = X509_from_strings(kCRLTestLeaf)))
- goto err;
+ return 0;
ADD_TEST(test_no_crl);
ADD_TEST(test_basic_crl);
ADD_TEST(test_bad_issuer_crl);
ADD_TEST(test_known_critical_crl);
ADD_ALL_TESTS(test_unknown_critical_crl, OSSL_NELEM(unknown_critical_crls));
+ return 1;
+}
- status = run_tests(argv[0]);
-err:
+void cleanup_tests(void)
+{
X509_free(test_root);
X509_free(test_leaf);
- return status;
}
diff --git a/test/ct_test.c b/test/ct_test.c
index 5deb758..9c46bb4 100644
--- a/test/ct_test.c
+++ b/test/ct_test.c
@@ -501,7 +501,7 @@ static int test_ctlog_from_base64(void)
}
#endif
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
#ifndef OPENSSL_NO_CT
if ((ct_dir = getenv("CT_DIR")) == NULL)
@@ -519,10 +519,8 @@ int test_main(int argc, char *argv[])
ADD_TEST(test_encode_tls_sct);
ADD_TEST(test_default_ct_policy_eval_ctx_time_is_now);
ADD_TEST(test_ctlog_from_base64);
-
- return run_tests(argv[0]);
#else
printf("No CT support\n");
- return EXIT_SUCCESS;
#endif
+ return 1;
}
diff --git a/test/d2i_test.c b/test/d2i_test.c
index 58fbe4a..0901b5d 100644
--- a/test/d2i_test.c
+++ b/test/d2i_test.c
@@ -107,10 +107,10 @@ static int test_bad_asn1()
}
/*
- * Usage: d2i_test <type> <file>, e.g.
+ * Usage: d2i_test <name> <type> <file>, e.g.
* d2i_test generalname bad_generalname.der
*/
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
const char *test_type_name;
const char *expected_error_string;
@@ -125,15 +125,13 @@ int test_main(int argc, char *argv[])
{"compare", ASN1_COMPARE}
};
- if (!TEST_int_eq(argc, 4)) {
- fprintf(stderr, "Usage: d2i_test item_name expected_error file.der\n");
- return 1;
+ if (!TEST_ptr(test_type_name = test_get_argument(0))
+ || !TEST_ptr(expected_error_string = test_get_argument(1))
+ || !TEST_ptr(test_file = test_get_argument(2))) {
+ TEST_note("Usage: d2i_test item_name expected_error file.der");
+ return 0;
}
- test_type_name = argv[1];
- expected_error_string = argv[2];
- test_file = argv[3];
-
item_type = ASN1_ITEM_lookup(test_type_name);
if (item_type == NULL) {
@@ -146,7 +144,7 @@ int test_main(int argc, char *argv[])
break;
TEST_note("\t%s", it->sname);
}
- return 1;
+ return 0;
}
for (i = 0; i < OSSL_NELEM(expected_errors); i++) {
@@ -158,10 +156,9 @@ int test_main(int argc, char *argv[])
if (expected_error == ASN1_UNKNOWN) {
TEST_error("Unknown expected error %s\n", expected_error_string);
- return 1;
+ return 0;
}
ADD_TEST(test_bad_asn1);
-
- return run_tests(argv[0]);
+ return 1;
}
diff --git a/test/danetest.c b/test/danetest.c
index a0fd0ce..b589ede 100644
--- a/test/danetest.c
+++ b/test/danetest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2015-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
@@ -409,22 +409,17 @@ end:
return ret;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- int ret = 0;
-
- if (argc != 4) {
+ if (!TEST_ptr(basedomain = test_get_argument(0))
+ || !TEST_ptr(CAfile = test_get_argument(1))
+ || !TEST_ptr(tlsafile = test_get_argument(2))) {
TEST_error("Usage error: danetest basedomain CAfile tlsafile");
return 0;
}
- basedomain = argv[1];
- CAfile = argv[2];
- tlsafile = argv[3];
ADD_TEST(run_tlsatest);
-
- ret = run_tests(argv[0]);
- return ret;
+ return 1;
}
#include <internal/dane.h>
diff --git a/test/destest.c b/test/destest.c
index d179692..26c5f83 100644
--- a/test/destest.c
+++ b/test/destest.c
@@ -693,7 +693,7 @@ static int test_des_quad_cksum(void)
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_DES
ADD_ALL_TESTS(test_des_ecb, NUM_TESTS);
@@ -717,4 +717,5 @@ void register_tests(void)
ADD_ALL_TESTS(test_input_align, 4);
ADD_ALL_TESTS(test_output_align, 4);
#endif
+ return 1;
}
diff --git a/test/dhtest.c b/test/dhtest.c
index ccae341..6403f77 100644
--- a/test/dhtest.c
+++ b/test/dhtest.c
@@ -19,13 +19,7 @@
#include <openssl/err.h>
#include "testutil.h"
-#ifdef OPENSSL_NO_DH
-int main(int argc, char *argv[])
-{
- printf("No DH support\n");
- return EXIT_SUCCESS;
-}
-#else
+#ifndef OPENSSL_NO_DH
# include <openssl/dh.h>
static int cb(int p, int n, BN_GENCB *arg);
@@ -507,11 +501,16 @@ static int rfc5114_test(void)
TEST_error("Test failed RFC5114 set %d\n", i + 1);
return 0;
}
+#endif
-void register_tests(void)
+int setup_tests(void)
{
+#ifdef OPENSSL_NO_DH
+ TEST_note("No DH support");
+#else
ADD_TEST(dh_test);
ADD_TEST(rfc5114_test);
-}
#endif
+ return 1;
+}
diff --git a/test/drbgtest.c b/test/drbgtest.c
index 37c5bde..90ed2ef 100644
--- a/test/drbgtest.c
+++ b/test/drbgtest.c
@@ -476,15 +476,11 @@ err:
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- if (argc != 1) {
- TEST_error("Usage: %s", argv[0]);
- return EXIT_FAILURE;
- }
app_data_index = RAND_DRBG_get_ex_new_index(0L, NULL, NULL, NULL, NULL);
ADD_ALL_TESTS(test_kats, OSSL_NELEM(drbg_test));
ADD_ALL_TESTS(test_error_checks, OSSL_NELEM(drbg_test));
- return run_tests(argv[0]);
+ return 1;
}
diff --git a/test/dsatest.c b/test/dsatest.c
index 9c5afa3..09a49fc 100644
--- a/test/dsatest.c
+++ b/test/dsatest.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
@@ -137,9 +137,10 @@ static int dsa_cb(int p, int n, BN_GENCB *arg)
}
#endif /* OPENSSL_NO_DSA */
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_DSA
ADD_TEST(dsa_test);
#endif
+ return 1;
}
diff --git a/test/dtls_mtu_test.c b/test/dtls_mtu_test.c
index 415f69e..dff65a7 100644
--- a/test/dtls_mtu_test.c
+++ b/test/dtls_mtu_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-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
@@ -189,7 +189,8 @@ static int run_mtu_tests(void)
return ret;
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(run_mtu_tests);
+ return 1;
}
diff --git a/test/dtlstest.c b/test/dtlstest.c
index b766802..1bf1735 100644
--- a/test/dtlstest.c
+++ b/test/dtlstest.c
@@ -93,22 +93,18 @@ static int test_dtls_unprocessed(int testidx)
return testresult;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- int testresult = 1;
-
- if (!TEST_int_eq(argc, 3))
- return 1;
-
- cert = argv[1];
- privkey = argv[2];
+ if (!TEST_ptr(cert = test_get_argument(0))
+ || !TEST_ptr(privkey = test_get_argument(1)))
+ return 0;
ADD_ALL_TESTS(test_dtls_unprocessed, NUM_TESTS);
+ return 1;
+}
- testresult = run_tests(argv[0]);
-
+void cleanup_tests(void)
+{
bio_f_tls_dump_filter_free();
bio_s_mempacket_test_free();
-
- return testresult;
}
diff --git a/test/dtlsv1listentest.c b/test/dtlsv1listentest.c
index b70c60e..e401ccf 100644
--- a/test/dtlsv1listentest.c
+++ b/test/dtlsv1listentest.c
@@ -348,9 +348,10 @@ static int dtls_listen_test(int i)
}
#endif
-void register_tests()
+int setup_tests()
{
#ifndef OPENSSL_NO_SOCK
ADD_ALL_TESTS(dtls_listen_test, (int)OSSL_NELEM(testpackets));
#endif
+ return 1;
}
diff --git a/test/ecdsatest.c b/test/ecdsatest.c
index ef3f54c..ed29bc7 100644
--- a/test/ecdsatest.c
+++ b/test/ecdsatest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2002-2017 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
*
* Licensed under the OpenSSL license (the "License"). You may not use
@@ -396,7 +396,7 @@ static int test_builtin(void)
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifdef OPENSSL_NO_EC
TEST_note("Elliptic curves are disabled.");
@@ -406,4 +406,5 @@ void register_tests(void)
ADD_TEST(x9_62_tests);
ADD_TEST(test_builtin);
#endif
+ return 1;
}
diff --git a/test/ecstresstest.c b/test/ecstresstest.c
index 5ea8f84..1cdb12b 100644
--- a/test/ecstresstest.c
+++ b/test/ecstresstest.c
@@ -123,39 +123,28 @@ static int atoi64(const char *in, int64_t *result)
* |num| times and prints the resulting X-coordinate. Otherwise runs the test
* the default number of times and compares against the expected result.
*/
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- const char *argv0 = argv[0];
+ const char *p;
if (!atoi64(NUM_REPEATS, &num_repeats)) {
TEST_error("Cannot parse " NUM_REPEATS);
- return EXIT_FAILURE;
+ return 0;
}
/*
* TODO(openssl-team): code under test/ should be able to reuse the option
* parsing framework currently in apps/.
*/
- argc--;
- argv++;
- while (argc >= 1) {
- if (strcmp(*argv, "-num") == 0) {
- if (--argc < 1
- || !atoi64(*++argv, &num_repeats)
- || num_repeats < 0) {
- TEST_error("Bad -num argument\n");
- return EXIT_FAILURE;
- }
- print_mode = 1;
- } else {
- TEST_error("Unknown option %s\n", *argv);
- return EXIT_FAILURE;
- }
- argc--;
- argv++;
+ p = test_get_option_argument("-num");
+ if (p != NULL) {
+ if (!atoi64(p, &num_repeats)
+ || num_repeats < 0)
+ return 0;
+ print_mode = 1;
}
#ifndef OPENSSL_NO_EC
ADD_TEST(test_curve);
#endif
- return run_tests(argv0);
+ return 1;
}
diff --git a/test/ectest.c b/test/ectest.c
index c6e60ac..85bb462 100644
--- a/test/ectest.c
+++ b/test/ectest.c
@@ -1430,15 +1430,13 @@ static const char rnd_seed[] =
"string to make the random number generator think it has randomness";
#endif
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- int result = EXIT_SUCCESS;
#ifndef OPENSSL_NO_EC
-
crv_len = EC_get_builtin_curves(NULL, 0);
if (!TEST_ptr(curves = OPENSSL_malloc(sizeof(*curves) * crv_len))
|| !TEST_true(EC_get_builtin_curves(curves, crv_len)))
- return EXIT_FAILURE;
+ return 0;
RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime may fail */
@@ -1453,9 +1451,11 @@ int test_main(int argc, char *argv[])
# endif
ADD_ALL_TESTS(internal_curve_test, crv_len);
ADD_ALL_TESTS(internal_curve_test_method, crv_len);
+#endif
+ return 1;
+}
- result = run_tests(argv[0]);
+void cleanup_tests(void)
+{
OPENSSL_free(curves);
-#endif
- return result;
}
diff --git a/test/enginetest.c b/test/enginetest.c
index 9b00c01..d32260f 100644
--- a/test/enginetest.c
+++ b/test/enginetest.c
@@ -12,13 +12,7 @@
#include <stdlib.h>
#include <openssl/e_os2.h>
-#ifdef OPENSSL_NO_ENGINE
-int main(int argc, char *argv[])
-{
- printf("No ENGINE support\n");
- return EXIT_SUCCESS;
-}
-#else
+#ifndef OPENSSL_NO_ENGINE
# include <openssl/buffer.h>
# include <openssl/crypto.h>
# include <openssl/engine.h>
@@ -180,9 +174,14 @@ static int test_engines(void)
ENGINE_free(block[loop]);
return to_return;
}
+#endif
-void register_tests(void)
+int setup_tests(void)
{
+#ifdef OPENSSL_NO_ENGINE
+ TEST_note("No ENGINE support");
+#else
ADD_TEST(test_engines);
-}
#endif
+ return 1;
+}
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c
index d780161..acccfe5 100644
--- a/test/evp_extra_test.c
+++ b/test/evp_extra_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2015-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
@@ -16,6 +16,7 @@
#include <openssl/rsa.h>
#include <openssl/x509.h>
#include "testutil.h"
+#include "e_os.h"
/*
* kExampleRSAKeyDER is an RSA private key in ASN.1, DER format. Of course, you
@@ -346,13 +347,13 @@ static int test_EVP_PKCS82PKEY(void)
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_EVP_DigestSignInit);
ADD_TEST(test_EVP_DigestVerifyInit);
- ADD_ALL_TESTS(test_d2i_AutoPrivateKey,
- sizeof(keydata) / sizeof(keydata[0]));
+ ADD_ALL_TESTS(test_d2i_AutoPrivateKey, OSSL_NELEM(keydata));
#ifndef OPENSSL_NO_EC
ADD_TEST(test_EVP_PKCS82PKEY);
#endif
+ return 1;
}
diff --git a/test/evp_test.c b/test/evp_test.c
index 8bfa5da..6fcf3c6 100644
--- a/test/evp_test.c
+++ b/test/evp_test.c
@@ -2510,16 +2510,15 @@ top:
return 1;
}
-static char * const *testfiles;
-
static int run_file_tests(int i)
{
EVP_TEST *t;
+ const char *testfile = test_get_argument(i);
int c;
if (!TEST_ptr(t = OPENSSL_zalloc(sizeof(*t))))
return 0;
- if (!test_start_file(&t->s, testfiles[i])) {
+ if (!test_start_file(&t->s, testfile)) {
OPENSSL_free(t);
return 0;
}
@@ -2544,15 +2543,15 @@ static int run_file_tests(int i)
return c == 0;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- if (argc < 2) {
- TEST_error("Usage: %s file...", argv[0]);
+ size_t n = test_get_argument_count();
+
+ if (n == 0) {
+ TEST_error("Usage: %s file...", test_get_program_name());
return 0;
}
- testfiles = &argv[1];
- ADD_ALL_TESTS(run_file_tests, argc - 1);
-
- return run_tests(argv[0]);
+ ADD_ALL_TESTS(run_file_tests, n);
+ return 1;
}
diff --git a/test/exdatatest.c b/test/exdatatest.c
index 9b88b1a..0ded7db 100644
--- a/test/exdatatest.c
+++ b/test/exdatatest.c
@@ -258,7 +258,8 @@ static int test_exdata(void)
return 0;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_exdata);
+ return 1;
}
diff --git a/test/exptest.c b/test/exptest.c
index 9de922e..1134712 100644
--- a/test/exptest.c
+++ b/test/exptest.c
@@ -198,8 +198,9 @@ static int test_mod_exp(int round)
return ret;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_mod_exp_zero);
ADD_ALL_TESTS(test_mod_exp, 200);
+ return 1;
}
diff --git a/test/gmdifftest.c b/test/gmdifftest.c
index 6869300..f7aa1a3 100644
--- a/test/gmdifftest.c
+++ b/test/gmdifftest.c
@@ -55,10 +55,11 @@ static int test_gmtime(int offset)
check_time(-offset * 1000L);
}
-void register_tests(void)
+int setup_tests(void)
{
if (sizeof(time_t) < 8)
TEST_info("Skipping; time_t is less than 64-bits");
else
ADD_ALL_TESTS_NOSUBTEST(test_gmtime, 1000000);
+ return 1;
}
diff --git a/test/hmactest.c b/test/hmactest.c
index e837391..2431be5 100644
--- a/test/hmactest.c
+++ b/test/hmactest.c
@@ -236,12 +236,13 @@ static char *pt(unsigned char *md, unsigned int len)
}
# endif
-void register_tests(void)
+int setup_tests(void)
{
ADD_ALL_TESTS(test_hmac_md5, 4);
ADD_TEST(test_hmac_single_shot);
ADD_TEST(test_hmac_bad);
ADD_TEST(test_hmac_run);
ADD_TEST(test_hmac_copy);
+ return 1;
}
diff --git a/test/ideatest.c b/test/ideatest.c
index 14d69dc..32fea47 100644
--- a/test/ideatest.c
+++ b/test/ideatest.c
@@ -108,11 +108,12 @@ static int test_idea_cfb64(void)
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_IDEA
ADD_TEST(test_idea_ecb);
ADD_TEST(test_idea_cbc);
ADD_TEST(test_idea_cfb64);
#endif
+ return 1;
}
diff --git a/test/igetest.c b/test/igetest.c
index a0fc623..a5c890e 100644
--- a/test/igetest.c
+++ b/test/igetest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2006-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
@@ -433,7 +433,7 @@ static int test_bi_ige_garble3(void)
return TEST_size_t_le(matches, sizeof checktext / 100);
}
-void register_tests(void)
+int setup_tests(void)
{
RAND_bytes(rkey, sizeof rkey);
RAND_bytes(rkey2, sizeof rkey2);
@@ -450,4 +450,5 @@ void register_tests(void)
ADD_TEST(test_bi_ige_garble3);
ADD_ALL_TESTS(test_ige_vectors, OSSL_NELEM(ige_test_vectors));
ADD_ALL_TESTS(test_bi_ige_vectors, OSSL_NELEM(bi_ige_test_vectors));
+ return 1;
}
diff --git a/test/lhash_test.c b/test/lhash_test.c
index 44ce623..704b180 100644
--- a/test/lhash_test.c
+++ b/test/lhash_test.c
@@ -220,8 +220,9 @@ end:
return testresult;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_int_lhash);
ADD_TEST(test_stress);
+ return 1;
}
diff --git a/test/md2test.c b/test/md2test.c
index 7a1436d..cda8469 100644
--- a/test/md2test.c
+++ b/test/md2test.c
@@ -58,9 +58,10 @@ static int test_md2(int n)
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_MD2
ADD_ALL_TESTS(test_md2, OSSL_NELEM(test));
#endif
+ return 1;
}
diff --git a/test/mdc2_internal_test.c b/test/mdc2_internal_test.c
index d696ea7..2c8d22d 100644
--- a/test/mdc2_internal_test.c
+++ b/test/mdc2_internal_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-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
@@ -64,7 +64,8 @@ static int test_mdc2(int idx)
return 1;
}
-void register_tests()
+int setup_tests()
{
ADD_ALL_TESTS(test_mdc2, OSSL_NELEM(tests));
+ return 1;
}
diff --git a/test/mdc2test.c b/test/mdc2test.c
index 724d6d3..4f29953 100644
--- a/test/mdc2test.c
+++ b/test/mdc2test.c
@@ -69,9 +69,10 @@ static int test_mdc2(void)
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_MDC2
ADD_TEST(test_mdc2);
#endif
+ return 1;
}
diff --git a/test/modes_internal_test.c b/test/modes_internal_test.c
index b3a2b10..ea463ab 100644
--- a/test/modes_internal_test.c
+++ b/test/modes_internal_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-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
@@ -949,33 +949,22 @@ static void benchmark_gcm128(const unsigned char *K, size_t Klen,
#endif
}
-int test_main(int argc, char **argv)
+int setup_tests(void)
{
- int result = 0;
- int iter_argv;
- int benchmark = 0;
-
- 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;
+ if (test_has_option("-h")) {
+ printf("-h\tThis help\n");
+ printf("-b\tBenchmark gcm128 in addition to the tests\n");
+ return 1;
}
ADD_ALL_TESTS(test_cts128, OSSL_NELEM(cts128_vectors));
ADD_ALL_TESTS(test_cts128_nist, OSSL_NELEM(cts128_vectors));
ADD_ALL_TESTS(test_gcm128, OSSL_NELEM(gcm128_vectors));
+ return 1;
+}
- result = run_tests(argv[0]);
-
- if (benchmark)
+void cleanup_tests(void)
+{
+ if (test_has_option("-b"))
benchmark_gcm128(K1, sizeof(K1), IV1, sizeof(IV1));
-
- return result;
-
- help:
- printf("-h\tThis help\n");
- printf("-b\tBenchmark gcm128 in addition to the tests\n");
-
- return 0;
}
diff --git a/test/packettest.c b/test/packettest.c
index 5fe6a13..3f38e20 100644
--- a/test/packettest.c
+++ b/test/packettest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2015-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
@@ -460,7 +460,7 @@ static int test_PACKET_as_length_prefixed_2()
return 1;
}
-void register_tests(void)
+int setup_tests(void)
{
unsigned int i;
@@ -490,4 +490,5 @@ void register_tests(void)
ADD_TEST(test_PACKET_get_length_prefixed_3);
ADD_TEST(test_PACKET_as_length_prefixed_1);
ADD_TEST(test_PACKET_as_length_prefixed_2);
+ return 1;
}
diff --git a/test/pbelutest.c b/test/pbelutest.c
index 84cb263..3ed5e96 100644
--- a/test/pbelutest.c
+++ b/test/pbelutest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2015-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
@@ -43,7 +43,8 @@ static int test_pbelu(void)
return 0;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_pbelu);
+ return 1;
}
diff --git a/test/pemtest.c b/test/pemtest.c
index c573278..dfef80d 100644
--- a/test/pemtest.c
+++ b/test/pemtest.c
@@ -69,8 +69,9 @@ static int test_invalid(void)
return 1;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_b64);
ADD_TEST(test_invalid);
+ return 1;
}
diff --git a/test/pkey_meth_test.c b/test/pkey_meth_test.c
index 414fc3c..5e6a7d4 100644
--- a/test/pkey_meth_test.c
+++ b/test/pkey_meth_test.c
@@ -52,7 +52,8 @@ static int test_asn1_meths()
return good;
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(test_asn1_meths);
+ return 1;
}
diff --git a/test/poly1305_internal_test.c b/test/poly1305_internal_test.c
index a6825d2..592f4b6 100644
--- a/test/poly1305_internal_test.c
+++ b/test/poly1305_internal_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-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
@@ -1609,31 +1609,20 @@ static int test_poly1305(int idx)
return 1;
}
-int test_main(int argc, char **argv)
+int setup_tests(void)
{
- int result = 0;
- int iter_argv;
- int benchmark = 0;
-
- 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;
+ if (test_has_option("-h")) {
+ printf("-h\tThis help\n");
+ printf("-b\tBenchmark in addition to the tests\n");
+ return 1;
}
ADD_ALL_TESTS(test_poly1305, OSSL_NELEM(tests));
+ return 1;
+}
- result = run_tests(argv[0]);
-
- if (benchmark)
+void cleanup_tests(void)
+{
+ if (test_has_option("-b"))
benchmark_poly1305();
-
- return result;
-
- help:
- printf("-h\tThis help\n");
- printf("-b\tBenchmark in addition to the tests\n");
-
- return 0;
}
diff --git a/test/randtest.c b/test/randtest.c
index 8ef5943..47d28f4 100644
--- a/test/randtest.c
+++ b/test/randtest.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
@@ -103,7 +103,8 @@ static int fips_random_tests(void)
return ret;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(fips_random_tests);
+ return 1;
}
diff --git a/test/rc2test.c b/test/rc2test.c
index 0561576..6323d81 100644
--- a/test/rc2test.c
+++ b/test/rc2test.c
@@ -59,9 +59,10 @@ static int test_rc2(const int n)
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_RC2
ADD_ALL_TESTS(test_rc2, OSSL_NELEM(RC2key));
#endif
+ return 1;
}
diff --git a/test/rc4test.c b/test/rc4test.c
index bf2ec31..b2032fd 100644
--- a/test/rc4test.c
+++ b/test/rc4test.c
@@ -116,7 +116,7 @@ static int test_rc_bulk(void)
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_RC4
ADD_ALL_TESTS(test_rc4_encrypt, OSSL_NELEM(data_len));
@@ -124,4 +124,5 @@ void register_tests(void)
ADD_ALL_TESTS(test_rc4_multi_call, data_len[3]);
ADD_TEST(test_rc_bulk);
#endif
+ return 1;
}
diff --git a/test/rc5test.c b/test/rc5test.c
index d806b2e..16a0364 100644
--- a/test/rc5test.c
+++ b/test/rc5test.c
@@ -224,10 +224,11 @@ static int test_rc5_cbc(int n)
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_RC5
ADD_ALL_TESTS(test_rc5_ecb, OSSL_NELEM(RC5key));
ADD_ALL_TESTS(test_rc5_cbc, RC5_CBC_NUM);
#endif
+ return 1;
}
diff --git a/test/recordlentest.c b/test/recordlentest.c
index 57c4648..d0941ca 100644
--- a/test/recordlentest.c
+++ b/test/recordlentest.c
@@ -184,22 +184,17 @@ static int test_record_overflow(int idx)
return testresult;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- int testresult = 1;
-
- if (argc != 3) {
- TEST_error("Invalid argument count");
- return 1;
- }
- cert = argv[1];
- privkey = argv[2];
+ if (!TEST_ptr(cert = test_get_argument(0))
+ || !TEST_ptr(privkey = test_get_argument(1)))
+ return 0;
ADD_ALL_TESTS(test_record_overflow, TOTAL_RECORD_OVERFLOW_TESTS);
+ return 1;
+}
- testresult = run_tests(argv[0]);
-
+void cleanup_tests(void)
+{
bio_s_mempacket_test_free();
-
- return testresult;
}
diff --git a/test/rsa_test.c b/test/rsa_test.c
index e8980de..88464da 100644
--- a/test/rsa_test.c
+++ b/test/rsa_test.c
@@ -22,7 +22,7 @@
#include "testutil.h"
#ifdef OPENSSL_NO_RSA
-void register_tests(void)
+void setup_tests(void)
{
/* No tests */
}
@@ -328,9 +328,10 @@ err:
return ret;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_ALL_TESTS(test_rsa_pkcs1, 3);
ADD_ALL_TESTS(test_rsa_oaep, 3);
+ return 1;
}
#endif
diff --git a/test/sanitytest.c b/test/sanitytest.c
index 5a9e6bb..80a19e9 100644
--- a/test/sanitytest.c
+++ b/test/sanitytest.c
@@ -75,12 +75,13 @@ static int test_sanity_unsigned_convertion(void)
return 1;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_sanity_null_zero);
ADD_TEST(test_sanity_enum_size);
ADD_TEST(test_sanity_twos_complement);
ADD_TEST(test_sanity_sign);
ADD_TEST(test_sanity_unsigned_convertion);
+ return 1;
}
diff --git a/test/secmemtest.c b/test/secmemtest.c
index c7d4fe7..5592ce7 100644
--- a/test/secmemtest.c
+++ b/test/secmemtest.c
@@ -123,7 +123,8 @@ static int test_sec_mem(void)
#endif
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_sec_mem);
+ return 1;
}
diff --git a/test/shlibloadtest.c b/test/shlibloadtest.c
index c57ca8f..131d1f6 100644
--- a/test/shlibloadtest.c
+++ b/test/shlibloadtest.c
@@ -175,28 +175,26 @@ end:
#endif
-int test_main(int argc, char **argv)
+int setup_tests(void)
{
- if (argc != 4) {
- TEST_error("Unexpected number of arguments");
- return EXIT_FAILURE;
- }
+ const char *p = test_get_argument(0);
- if (strcmp(argv[1], "-crypto_first") == 0) {
+ if (strcmp(p, "-crypto_first") == 0) {
test_type = CRYPTO_FIRST;
- } else if (strcmp(argv[1], "-ssl_first") == 0) {
+ } else if (strcmp(p, "-ssl_first") == 0) {
test_type = SSL_FIRST;
- } else if (strcmp(argv[1], "-just_crypto") == 0) {
+ } else if (strcmp(p, "-just_crypto") == 0) {
test_type = JUST_CRYPTO;
} else {
TEST_error("Unrecognised argument");
- return EXIT_FAILURE;
+ return 0;
}
- path_crypto = argv[2];
- path_ssl = argv[3];
+ if (!TEST_ptr(path_crypto = test_get_argument(1))
+ || !TEST_ptr(path_ssl = test_get_argument(2)))
+ return 0;
#if defined(DSO_DLFCN) || defined(DSO_WIN32)
ADD_TEST(test_lib);
#endif
- return run_tests(argv[0]);
+ return 1;
}
diff --git a/test/siphash_internal_test.c b/test/siphash_internal_test.c
index 0114af1..ca24339 100644
--- a/test/siphash_internal_test.c
+++ b/test/siphash_internal_test.c
@@ -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;
}
diff --git a/test/srptest.c b/test/srptest.c
index ed5bf61..bb1682e 100644
--- a/test/srptest.c
+++ b/test/srptest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2011-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
@@ -264,7 +264,7 @@ static int run_srp_tests(void)
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifdef OPENSSL_NO_SRP
printf("No SRP support\n");
@@ -272,4 +272,5 @@ void register_tests(void)
ADD_TEST(run_srp_tests);
ADD_TEST(run_srp_kat);
#endif
+ return 1;
}
diff --git a/test/ssl_cert_table_internal_test.c b/test/ssl_cert_table_internal_test.c
index 0fa5e4e..e9529c6 100644
--- a/test/ssl_cert_table_internal_test.c
+++ b/test/ssl_cert_table_internal_test.c
@@ -74,7 +74,8 @@ static int test_ssl_cert_table()
return 1;
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(test_ssl_cert_table);
+ return 1;
}
diff --git a/test/ssl_test.c b/test/ssl_test.c
index e5f0f30..44232db 100644
--- a/test/ssl_test.c
+++ b/test/ssl_test.c
@@ -428,23 +428,22 @@ err:
return ret;
}
-int test_main(int argc, char **argv)
+int setup_tests(void)
{
- int result = EXIT_FAILURE;
long num_tests;
- if (!TEST_int_eq(argc, 2)
- || !TEST_ptr(conf = NCONF_new(NULL))
+ if (!TEST_ptr(conf = NCONF_new(NULL))
/* argv[1] should point to the test conf file */
- || !TEST_int_gt(NCONF_load(conf, argv[1], NULL), 0)
+ || !TEST_int_gt(NCONF_load(conf, test_get_argument(0), NULL), 0)
|| !TEST_int_ne(NCONF_get_number_e(conf, NULL, "num_tests",
&num_tests), 0))
- goto err;
+ return 0;
- ADD_ALL_TESTS(test_handshake, (int)(num_tests));
- result = run_tests(argv[0]);
+ ADD_ALL_TESTS(test_handshake, (int)num_tests);
+ return 1;
+}
-err:
+void cleanup_tests(void)
+{
NCONF_free(conf);
- return result;
}
diff --git a/test/ssl_test_ctx_test.c b/test/ssl_test_ctx_test.c
index 0877535..c72bcb0 100644
--- a/test/ssl_test_ctx_test.c
+++ b/test/ssl_test_ctx_test.c
@@ -215,25 +215,23 @@ static int test_bad_configuration(int idx)
return 1;
}
-int test_main(int argc, char **argv)
+int setup_tests(void)
{
- int result = 0;
-
- if (argc != 2) {
- TEST_info("Missing file argument");
- goto end;
+ if (!TEST_ptr(conf = NCONF_new(NULL)))
+ return 0;
+ /* argument should point to test/ssl_test_ctx_test.conf */
+ if (!TEST_int_gt(NCONF_load(conf, test_get_argument(0), NULL), 0)) {
+ TEST_note("Missing file argument");
+ return 0;
}
- if (!TEST_ptr(conf = NCONF_new(NULL))
- /* argv[1] should point to test/ssl_test_ctx_test.conf */
- || !TEST_int_gt(NCONF_load(conf, argv[1], NULL), 0))
- goto end;
ADD_TEST(test_empty_configuration);
ADD_TEST(test_good_configuration);
ADD_ALL_TESTS(test_bad_configuration, OSSL_NELEM(bad_configurations));
- result = run_tests(argv[0]);
+ return 1;
+}
-end:
+void cleanup_tests(void)
+{
NCONF_free(conf);
- return result;
}
diff --git a/test/sslapitest.c b/test/sslapitest.c
index ea68f0b..d8324f8 100644
--- a/test/sslapitest.c
+++ b/test/sslapitest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-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
@@ -2703,17 +2703,11 @@ static int test_ssl_clear(int idx)
return testresult;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- int testresult = 1;
-
- if (argc != 3) {
- TEST_error("Wrong argument count");
+ if (!TEST_ptr(cert = test_get_argument(0))
+ || !TEST_ptr(privkey = test_get_argument(1)))
return 0;
- }
-
- cert = argv[1];
- privkey = argv[2];
ADD_TEST(test_large_message_tls);
ADD_TEST(test_large_message_tls_read_ahead);
@@ -2759,10 +2753,10 @@ int test_main(int argc, char *argv[])
ADD_ALL_TESTS(test_serverinfo, 8);
ADD_ALL_TESTS(test_export_key_mat, 4);
ADD_ALL_TESTS(test_ssl_clear, 2);
+ return 1;
+}
- testresult = run_tests(argv[0]);
-
+void cleanup_tests(void)
+{
bio_s_mempacket_test_free();
-
- return testresult;
}
diff --git a/test/sslbuffertest.c b/test/sslbuffertest.c
index 72cb987..6010976 100644
--- a/test/sslbuffertest.c
+++ b/test/sslbuffertest.c
@@ -150,31 +150,33 @@ static int test_func(int test)
return result;
}
-int test_main(int argc, char *argv[])
+int global_init(void)
{
- int testresult = EXIT_FAILURE;
-
CRYPTO_set_mem_debug(1);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
+ return 1;
+}
- if (argc != 3) {
- TEST_error("Invalid argument count\n");
- goto end;
- }
+int setup_tests(void)
+{
+ char *cert, *pkey;
+
+ if (!TEST_ptr(cert = test_get_argument(0))
+ || !TEST_ptr(pkey = test_get_argument(1)))
+ return 0;
if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),
- &serverctx, &clientctx, argv[1], argv[2])) {
+ &serverctx, &clientctx, cert, pkey)) {
TEST_error("Failed to create SSL_CTX pair\n");
- goto end;
+ return 0;
}
ADD_ALL_TESTS(test_func, 9);
+ return 1;
+}
- testresult = run_tests(argv[0]);
-
- end:
+void cleanup_tests(void)
+{
SSL_CTX_free(clientctx);
SSL_CTX_free(serverctx);
-
- return testresult;
}
diff --git a/test/sslcorrupttest.c b/test/sslcorrupttest.c
index a92e0d7..a0bca38 100644
--- a/test/sslcorrupttest.c
+++ b/test/sslcorrupttest.c
@@ -248,24 +248,24 @@ static int test_ssl_corrupt(int testidx)
return testresult;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- int ret = EXIT_FAILURE, n;
+ int n;
- if (argc != 3) {
- TEST_error("Usage error: require cert and private key files");
- return ret;
+ if (!TEST_ptr(cert = test_get_argument(0))
+ || !TEST_ptr(privkey = test_get_argument(1))) {
+ TEST_note("Usage error: require cert and private key files");
+ return 0;
}
- cert = argv[1];
- privkey = argv[2];
n = setup_cipher_list();
- if (n > 0) {
+ if (n > 0)
ADD_ALL_TESTS(test_ssl_corrupt, n);
- ret = run_tests(argv[0]);
- }
+ return 1;
+}
+
+void cleanup_tests(void)
+{
bio_f_tls_corrupt_filter_free();
OPENSSL_free(cipher_list);
-
- return ret;
}
diff --git a/test/stack_test.c b/test/stack_test.c
index dbf5c91..ba2ceaf 100644
--- a/test/stack_test.c
+++ b/test/stack_test.c
@@ -362,10 +362,11 @@ end:
return testresult;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_int_stack);
ADD_TEST(test_uchar_stack);
ADD_TEST(test_SS_stack);
ADD_TEST(test_SU_stack);
+ return 1;
}
diff --git a/test/test_test.c b/test/test_test.c
index 051058f..ae16d82 100644
--- a/test/test_test.c
+++ b/test/test_test.c
@@ -509,7 +509,7 @@ static int test_bn_output(int n)
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_int);
ADD_TEST(test_uint);
@@ -530,4 +530,5 @@ void register_tests(void)
ADD_TEST(test_single_eval);
ADD_TEST(test_output);
ADD_ALL_TESTS(test_bn_output, OSSL_NELEM(bn_output_tests));
+ return 1;
}
diff --git a/test/testutil.h b/test/testutil.h
index 7be9fb9..9786579 100644
--- a/test/testutil.h
+++ b/test/testutil.h
@@ -17,34 +17,31 @@
#include <openssl/bn.h>
/*-
- * Simple unit tests should implement register_tests().
+ * Simple unit tests should implement setup_tests().
+ * This function should return zero if the registration process fails.
* To register tests, call ADD_TEST or ADD_ALL_TESTS:
*
- * void register_tests(void)
+ * int setup_tests(void)
* {
* ADD_TEST(test_foo);
* ADD_ALL_TESTS(test_bar, num_test_bar);
+ * return 1;
* }
*
- * Tests that need to perform custom setup or read command-line arguments should
- * implement test_main():
+ * Tests that require clean up after execution should implement:
*
- * int test_main(int argc, char *argv[])
- * {
- * int ret;
+ * void cleanup_tests(void);
*
- * // Custom setup ...
+ * The cleanup_tests function will be called even if setup_tests()
+ * returns failure.
*
- * ADD_TEST(test_foo);
- * ADD_ALL_TESTS(test_bar, num_test_bar);
- * // Add more tests ...
+ * In some cases, early initialization before the framework is set up
+ * may be needed. In such a case, this should be implemented:
*
- * ret = run_tests(argv[0]);
+ * int global_init(void);
*
- * // Custom teardown ...
- *
- * return ret;
- * }
+ * This function should return zero if there is an unrecoverable error and
+ * non-zero if the intialization was successful.
*/
/* Adds a simple test case. */
@@ -124,30 +121,38 @@
# endif /* __STDC_VERSION__ */
/*
- * Internal helpers. Test programs shouldn't use these directly, but should
- * rather link to one of the helper main() methods.
+ * Tests that need access to command line arguments should use the functions:
+ * test_get_argument(int n) to get the nth argument, the first argument is
+ * argument 0. This function returns NULL on error.
+ * test_get_argument_count() to get the count of the arguments.
+ * test_has_option(const char *) to check if the specified option was passed.
+ * test_get_option_argument(const char *) to get an option which includes an
+ * argument. NULL is returns if the option is not found.
+ * const char *test_get_program_name(void) returns the name of the test program
+ * being executed.
*/
+const char *test_get_program_name(void);
+char *test_get_argument(size_t n);
+size_t test_get_argument_count(void);
+int test_has_option(const char *option);
+const char *test_get_option_argument(const char *option);
-/* setup_test() should be called as the first thing in a test main(). */
-void setup_test(void);
/*
- * finish_test() should be called as the last thing in a test main().
- * The result of run_tests() should be the input to finish_test().
+ * Internal helpers. Test programs shouldn't use these directly, but should
+ * rather link to one of the helper main() methods.
*/
-__owur int finish_test(int ret);
void add_test(const char *test_case_name, int (*test_fn) ());
void add_all_tests(const char *test_case_name, int (*test_fn)(int idx), int num,
int subtest);
-__owur int run_tests(const char *test_prog_name);
-void set_test_title(const char *title);
/*
- * Declarations for user defined functions
+ * Declarations for user defined functions.
+ * The first two return a boolean indicating that the test should not proceed.
*/
-void register_tests(void);
-int test_main(int argc, char *argv[]);
-
+int global_init(void);
+int setup_tests(void);
+void cleanup_tests(void);
/*
* Test assumption verification helpers.
diff --git a/test/testutil/driver.c b/test/testutil/driver.c
index dc236b7..cf4296a 100644
--- a/test/testutil/driver.c
+++ b/test/testutil/driver.c
@@ -95,13 +95,11 @@ static int gcd(int a, int b)
return a;
}
-void setup_test()
+void setup_test_framework()
{
char *TAP_levels = getenv("HARNESS_OSSL_LEVEL");
char *test_seed = getenv("OPENSSL_TEST_RAND_ORDER");
- test_open_streams();
-
level = TAP_levels != NULL ? 4 * atoi(TAP_levels) : 0;
if (test_seed != NULL) {
@@ -121,7 +119,7 @@ void setup_test()
#endif
}
-int finish_test(int ret)
+int pulldown_test_framework(int ret)
{
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (should_report_leaks()
@@ -129,8 +127,6 @@ int finish_test(int ret)
return EXIT_FAILURE;
#endif
- test_close_streams();
-
return ret;
}
@@ -150,10 +146,28 @@ void set_test_title(const char *title)
test_title = title == NULL ? NULL : strdup(title);
}
+PRINTF_FORMAT(2, 3) static void test_verdict(int pass, const char *extra, ...)
+{
+ va_list ap;
+
+ test_flush_stdout();
+ test_flush_stderr();
+
+ test_printf_stdout("%*s%s", level, "", pass ? "ok" : "not ok");
+ if (extra != NULL) {
+ test_printf_stdout(" ");
+ va_start(ap, extra);
+ test_vprintf_stdout(extra, ap);
+ va_end(ap);
+ }
+ test_printf_stdout("\n");
+ test_flush_stdout();
+}
+
int run_tests(const char *test_prog_name)
{
int num_failed = 0;
- char *verdict = NULL;
+ int verdict = 1;
int ii, i, jj, j, jstep;
int permute[OSSL_NELEM(all_tests)];
@@ -185,18 +199,12 @@ int run_tests(const char *test_prog_name)
set_test_title(all_tests[i].test_case_name);
ret = all_tests[i].test_fn();
- test_flush_stdout();
- test_flush_stderr();
-
- verdict = "ok";
+ verdict = 1;
if (!ret) {
- verdict = "not ok";
+ verdict = 0;
++num_failed;
}
- test_printf_stdout("%*s%s %d - %s\n", level, "", verdict, ii + 1,
- test_title);
- test_flush_stdout();
- test_flush_stderr();
+ test_verdict(verdict, "%d - %s", ii + 1, test_title);
finalize(ret);
} else {
int num_failed_inner = 0;
@@ -225,39 +233,33 @@ int run_tests(const char *test_prog_name)
set_test_title(NULL);
ret = all_tests[i].param_test_fn(j);
- test_flush_stdout();
- test_flush_stderr();
-
if (!ret)
++num_failed_inner;
finalize(ret);
if (all_tests[i].subtest) {
- verdict = "ok";
+ verdict = 1;
if (!ret) {
- verdict = "not ok";
+ verdict = 0;
++num_failed_inner;
}
if (test_title != NULL)
- test_printf_stdout("%*s%s %d - %s\n", level, "",
- verdict, jj + 1, test_title);
+ test_verdict(verdict, "%d - %s", jj + 1, test_title);
else
- test_printf_stdout("%*s%s %d - iteration %d\n", level,
- "", verdict, jj + 1, j + 1);
- test_flush_stdout();
+ test_verdict(verdict, "%d - iteration %d",
+ jj + 1, j + 1);
}
}
level -= 4;
- verdict = "ok";
+ verdict = 1;
if (num_failed_inner) {
- verdict = "not ok";
+ verdict = 0;
++num_failed;
}
- test_printf_stdout("%*s%s %d - %s\n", level, "", verdict, ii + 1,
- all_tests[i].test_case_name);
- test_flush_stdout();
+ test_verdict(verdict, "%d - %s", ii + 1,
+ all_tests[i].test_case_name);
}
}
if (num_failed != 0)
diff --git a/test/evp_test.h b/test/testutil/init.c
similarity index 79%
copy from test/evp_test.h
copy to test/testutil/init.c
index 5402e1e..5095c7f 100644
--- a/test/evp_test.h
+++ b/test/testutil/init.c
@@ -7,5 +7,9 @@
* https://www.openssl.org/source/license.html
*/
-typedef struct evp_test_buffer_st EVP_TEST_BUFFER;
-DEFINE_STACK_OF(EVP_TEST_BUFFER)
+#include "../testutil.h"
+
+int global_init(void)
+{
+ return 1;
+}
diff --git a/test/testutil/main.c b/test/testutil/main.c
index 435a358..34abcb2 100644
--- a/test/testutil/main.c
+++ b/test/testutil/main.c
@@ -8,13 +8,99 @@
*/
#include "../testutil.h"
+#include "../../e_os.h"
+#include "output.h"
+#include "tu_local.h"
+
+#include <string.h>
+
+static size_t arg_count;
+static char **args;
+static unsigned char arg_used[1000];
+
+static void check_arg_usage(void)
+{
+ size_t i, n = arg_count < OSSL_NELEM(arg_used) ? arg_count
+ : OSSL_NELEM(arg_used);
+
+ for (i = 0; i < n; i++)
+ if (!arg_used[i+1])
+ test_printf_stderr("Warning ignored command-line argument %d: %s\n",
+ i, args[i+1]);
+ if (i < arg_count)
+ test_printf_stderr("Warning arguments %zu and later unchecked\n", i);
+}
int main(int argc, char *argv[])
{
- int ret;
- setup_test();
+ int ret = EXIT_FAILURE;
+
+ test_open_streams();
+
+ if (!global_init()) {
+ test_printf_stderr("Global init failed - aborting\n");
+ return ret;
+ }
+
+ arg_count = argc - 1;
+ args = argv;
+
+ setup_test_framework();
+
+ if (setup_tests())
+ ret = run_tests(argv[0]);
+ cleanup_tests();
+ check_arg_usage();
+
+ ret = pulldown_test_framework(ret);
+ test_close_streams();
+ return ret;
+}
+
+const char *test_get_program_name(void)
+{
+ return args[0];
+}
+
+char *test_get_argument(size_t n)
+{
+ if (n > arg_count)
+ return NULL;
+ if (n + 1 < OSSL_NELEM(arg_used))
+ arg_used[n + 1] = 1;
+ return args[n + 1];
+}
+
+size_t test_get_argument_count(void)
+{
+ return arg_count;
+}
- ret = test_main(argc, argv);
+int test_has_option(const char *option)
+{
+ size_t i;
- return finish_test(ret);
+ for (i = 1; i <= arg_count; i++)
+ if (strcmp(args[i], option) == 0) {
+ arg_used[i] = 1;
+ return 1;
+ }
+ return 0;
}
+
+const char *test_get_option_argument(const char *option)
+{
+ size_t i, n = strlen(option);
+
+ for (i = 1; i <= arg_count; i++)
+ if (strncmp(args[i], option, n) == 0) {
+ arg_used[i] = 1;
+ if (args[i][n] == '\0' && i + 1 < arg_count) {
+ arg_used[++i] = 1;
+ return args[i];
+ }
+ return args[i] + n;
+ }
+ return NULL;
+}
+
diff --git a/test/testutil/stanza.c b/test/testutil/stanza.c
index 070ff80..8a8f0cc 100644
--- a/test/testutil/stanza.c
+++ b/test/testutil/stanza.c
@@ -14,6 +14,7 @@
#include "e_os.h"
#include "../testutil.h"
+#include "tu_local.h"
int test_start_file(STANZA *s, const char *testfile)
{
diff --git a/test/evp_test.h b/test/testutil/test_cleanup.c
similarity index 79%
copy from test/evp_test.h
copy to test/testutil/test_cleanup.c
index 5402e1e..0fdd2e9 100644
--- a/test/evp_test.h
+++ b/test/testutil/test_cleanup.c
@@ -7,5 +7,8 @@
* https://www.openssl.org/source/license.html
*/
-typedef struct evp_test_buffer_st EVP_TEST_BUFFER;
-DEFINE_STACK_OF(EVP_TEST_BUFFER)
+#include "../testutil.h"
+
+void cleanup_tests(void)
+{
+}
diff --git a/test/testutil/test_main.c b/test/testutil/test_main.c
deleted file mode 100644
index 3fa08b6..0000000
--- a/test/testutil/test_main.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright 2016-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
- * in the file LICENSE in the source distribution or at
- * https://www.openssl.org/source/license.html
- */
-
-#include "../testutil.h"
-#include "output.h"
-
-#include <stdio.h>
-
-int test_main(int argc, char *argv[])
-{
- if (argc > 1)
- test_printf_stderr("Warning: ignoring extra command-line arguments.\n");
-
- register_tests();
- return run_tests(argv[0]);
-}
diff --git a/test/testutil/tu_local.h b/test/testutil/tu_local.h
index 5f69a13..d2e65b5 100644
--- a/test/testutil/tu_local.h
+++ b/test/testutil/tu_local.h
@@ -10,6 +10,7 @@
#include <stdlib.h> /* size_t */
#include <openssl/bn.h>
#include <openssl/bio.h>
+#include "../testutil.h"
int subtest_level(void);
int openssl_error_cb(const char *str, size_t len, void *u);
@@ -43,3 +44,8 @@ void test_fail_memory_message(const char *prefix, const char *file,
const unsigned char *m1, size_t l1,
const unsigned char *m2, size_t l2);
+void setup_test_framework(void);
+__owur int pulldown_test_framework(int ret);
+
+__owur int run_tests(const char *test_prog_name);
+void set_test_title(const char *title);
diff --git a/test/threadstest.c b/test/threadstest.c
index 60064d6..ee09f86 100644
--- a/test/threadstest.c
+++ b/test/threadstest.c
@@ -184,9 +184,10 @@ static int test_thread_local(void)
return 1;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_lock);
ADD_TEST(test_once);
ADD_TEST(test_thread_local);
+ return 1;
}
diff --git a/test/time_offset_test.c b/test/time_offset_test.c
index 6660aee..3560f4c 100644
--- a/test/time_offset_test.c
+++ b/test/time_offset_test.c
@@ -109,7 +109,8 @@ static int test_offset(int idx)
return 1;
}
-void register_tests()
+int setup_tests()
{
ADD_ALL_TESTS(test_offset, OSSL_NELEM(tests));
+ return 1;
}
diff --git a/test/tls13encryptiontest.c b/test/tls13encryptiontest.c
index fe81aa4..667f953 100644
--- a/test/tls13encryptiontest.c
+++ b/test/tls13encryptiontest.c
@@ -398,7 +398,8 @@ static int test_tls13_encryption(void)
return ret;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_tls13_encryption);
+ return 1;
}
diff --git a/test/tls13secretstest.c b/test/tls13secretstest.c
index e052d0b..9f32fdf 100644
--- a/test/tls13secretstest.c
+++ b/test/tls13secretstest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-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
@@ -384,7 +384,8 @@ static int test_handshake_secrets(void)
return ret;
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(test_handshake_secrets);
+ return 1;
}
diff --git a/test/uitest.c b/test/uitest.c
index 6fef137..d2828f8 100644
--- a/test/uitest.c
+++ b/test/uitest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2002-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
@@ -88,8 +88,9 @@ static int test_new_ui()
return ok;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_old);
ADD_TEST(test_new_ui);
+ return 1;
}
diff --git a/test/v3ext.c b/test/v3ext.c
index 9fbdfd2..14ae499 100644
--- a/test/v3ext.c
+++ b/test/v3ext.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-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
@@ -37,17 +37,11 @@ end:
return ret;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- int ret;
-
- if (argc != 2) {
- TEST_error("Usage error");
+ if (!TEST_ptr(infile = test_get_argument(0)))
return 0;
- }
- infile = argv[1];
ADD_TEST(test_pathlen);
- ret = run_tests(argv[0]);
- return ret;
+ return 1;
}
diff --git a/test/v3nametest.c b/test/v3nametest.c
index aaeab54..0f89260 100644
--- a/test/v3nametest.c
+++ b/test/v3nametest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2012-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
@@ -353,7 +353,8 @@ static int call_run_cert(int i)
return failed == 0;
}
-void register_tests(void)
+int setup_tests(void)
{
- ADD_ALL_TESTS(call_run_cert, sizeof(name_fns) / sizeof(name_fns[0]));
+ ADD_ALL_TESTS(call_run_cert, OSSL_NELEM(name_fns));
+ return 1;
}
diff --git a/test/verify_extra_test.c b/test/verify_extra_test.c
index a0df29d..83d93cd 100644
--- a/test/verify_extra_test.c
+++ b/test/verify_extra_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2015-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
@@ -15,6 +15,10 @@
#include <openssl/err.h>
#include "testutil.h"
+static const char *roots_f;
+static const char *untrusted_f;
+static const char *bad_f;
+
static STACK_OF(X509) *load_certs_from_file(const char *filename)
{
STACK_OF(X509) *certs;
@@ -83,9 +87,7 @@ static STACK_OF(X509) *load_certs_from_file(const char *filename)
* CA=FALSE, and will therefore incorrectly verify bad
*
*/
-static int test_alt_chains_cert_forgery(const char *roots_f,
- const char *untrusted_f,
- const char *bad_f)
+static int test_alt_chains_cert_forgery(void)
{
int ret = 0;
int i;
@@ -136,14 +138,15 @@ static int test_alt_chains_cert_forgery(const char *roots_f,
return ret;
}
-int test_main(int argc, char **argv)
+int setup_tests(void)
{
- if (argc != 4) {
+ if (!TEST_ptr(roots_f = test_get_argument(0))
+ || !TEST_ptr(untrusted_f = test_get_argument(1))
+ || !TEST_ptr(bad_f = test_get_argument(2))) {
TEST_error("usage: verify_extra_test roots.pem untrusted.pem bad.pem\n");
- return EXIT_FAILURE;
+ return 0;
}
- if (!TEST_true(test_alt_chains_cert_forgery(argv[1], argv[2], argv[3])))
- return EXIT_FAILURE;
- return EXIT_SUCCESS;
+ ADD_TEST(test_alt_chains_cert_forgery);
+ return 1;
}
diff --git a/test/wpackettest.c b/test/wpackettest.c
index 5c7ea10..773eef0 100644
--- a/test/wpackettest.c
+++ b/test/wpackettest.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-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
@@ -360,10 +360,8 @@ static int test_WPACKET_memcpy(void)
return 1;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- int testresult = 0;
-
if (!TEST_ptr(buf = BUF_MEM_new()))
return 0;
@@ -373,8 +371,10 @@ int test_main(int argc, char *argv[])
ADD_TEST(test_WPACKET_set_flags);
ADD_TEST(test_WPACKET_allocate_bytes);
ADD_TEST(test_WPACKET_memcpy);
- testresult = run_tests(argv[0]);
+ return 1;
+}
+void cleanup_tests(void)
+{
BUF_MEM_free(buf);
- return testresult;
}
diff --git a/test/x509_check_cert_pkey_test.c b/test/x509_check_cert_pkey_test.c
index 003bab8..1cad49e 100644
--- a/test/x509_check_cert_pkey_test.c
+++ b/test/x509_check_cert_pkey_test.c
@@ -20,8 +20,12 @@
* t: API type, "cert" for X509_ and "req" for X509_REQ_ APIs.
* e: expected, "ok" for success, "failed" for what should fail.
*/
-static int test_x509_check_cert_pkey(const char *c, const char *k,
- const char *t, const char *e)
+static const char *c;
+static const char *k;
+static const char *t;
+static const char *e;
+
+static int test_x509_check_cert_pkey(void)
{
BIO *bio = NULL;
X509 *x509 = NULL;
@@ -102,13 +106,17 @@ failed:
return ret;
}
-int test_main(int argc, char **argv)
+int setup_tests(void)
{
- if (!TEST_int_eq(argc, 5)) {
- TEST_info("usage: x509_check_cert_pkey cert.pem|cert.req"
+ if (!TEST_ptr(c = test_get_argument(0))
+ || !TEST_ptr(k = test_get_argument(1))
+ || !TEST_ptr(t = test_get_argument(2))
+ || !TEST_ptr(e = test_get_argument(3))) {
+ TEST_note("usage: x509_check_cert_pkey cert.pem|cert.req"
" key.pem cert|req <expected>");
- return 1;
+ return 0;
}
- return !test_x509_check_cert_pkey(argv[1], argv[2], argv[3], argv[4]);
+ ADD_TEST(test_x509_check_cert_pkey);
+ return 1;
}
diff --git a/test/x509_dup_cert_test.c b/test/x509_dup_cert_test.c
index 2ce469a..e639c01 100644
--- a/test/x509_dup_cert_test.c
+++ b/test/x509_dup_cert_test.c
@@ -14,12 +14,13 @@
#include "testutil.h"
-static int test_509_dup_cert(const char *cert_f)
+static int test_509_dup_cert(int n)
{
int ret = 0;
X509_STORE_CTX *sctx = NULL;
X509_STORE *store = NULL;
X509_LOOKUP *lookup = NULL;
+ const char *cert_f = test_get_argument(n);
if (TEST_ptr(store = X509_STORE_new())
&& TEST_ptr(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()))
@@ -32,12 +33,15 @@ static int test_509_dup_cert(const char *cert_f)
return ret;
}
-int test_main(int argc, char **argv)
+int setup_tests(void)
{
- if (!TEST_int_eq(argc, 2)) {
- TEST_info("usage: x509_dup_cert_test cert.pem");
- return 1;
+ size_t n = test_get_argument_count();
+
+ if (!TEST_int_gt(n, 0)) {
+ TEST_note("usage: x509_dup_cert_test cert.pem...");
+ return 0;
}
- return !test_509_dup_cert(argv[1]);
+ ADD_ALL_TESTS(test_509_dup_cert, n);
+ return 1;
}
diff --git a/test/x509_internal_test.c b/test/x509_internal_test.c
index 220231f..17517cd 100644
--- a/test/x509_internal_test.c
+++ b/test/x509_internal_test.c
@@ -57,7 +57,8 @@ static int test_standard_exts()
return good;
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(test_standard_exts);
+ return 1;
}
diff --git a/test/x509_time_test.c b/test/x509_time_test.c
index d863126..8f82016 100644
--- a/test/x509_time_test.c
+++ b/test/x509_time_test.c
@@ -424,10 +424,11 @@ static int test_days(int n)
return r;
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(test_x509_cmp_time_current);
ADD_ALL_TESTS(test_x509_cmp_time, OSSL_NELEM(x509_cmp_tests));
ADD_ALL_TESTS(test_x509_time, OSSL_NELEM(x509_format_tests));
ADD_ALL_TESTS(test_days, OSSL_NELEM(day_of_week_tests));
+ return 1;
}
diff --git a/test/x509aux.c b/test/x509aux.c
index 7bfacfd..13a2ffc 100644
--- a/test/x509aux.c
+++ b/test/x509aux.c
@@ -19,10 +19,6 @@
#include "e_os.h"
#include "testutil.h"
-
-/* List of files, from argv */
-static char **files;
-
static int test_certs(int num)
{
int c;
@@ -33,7 +29,7 @@ static int test_certs(int num)
typedef X509 *(*d2i_X509_t)(X509 **, const unsigned char **, long);
typedef int (*i2d_X509_t)(X509 *, unsigned char **);
int err = 0;
- BIO *fp = BIO_new_file(files[num], "r");
+ BIO *fp = BIO_new_file(test_get_argument(num), "r");
if (!TEST_ptr(fp))
return 0;
@@ -156,14 +152,15 @@ static int test_certs(int num)
return 0;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- if (argc < 2) {
- TEST_error("usage: %s certfile...", argv[0]);
+ size_t n = test_get_argument_count();
+
+ if (n == 0) {
+ TEST_error("usage: %s certfile...", test_get_program_name());
return 0;
}
- files = &argv[1];
- ADD_ALL_TESTS(test_certs, argc - 1);
- return run_tests(argv[0]);
+ ADD_ALL_TESTS(test_certs, n);
+ return 1;
}
More information about the openssl-commits
mailing list