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)
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
/*
- * 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
}
#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");
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
return test_intern(&uint64_test_package);
}
-void register_tests(void)
+int setup_tests(void)
{
#if OPENSSL_API_COMPAT < 0x10200000L
ADD_TEST(test_long_32bit);
ADD_TEST(test_uint32);
ADD_TEST(test_int64);
ADD_TEST(test_uint64);
+ return 1;
}
return 0;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_tbl_standard);
ADD_TEST(test_standard_methods);
+ return 1;
}
/*
- * 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.
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;
}
return testresult;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_bad_dtls);
+ return 1;
}
}
#endif
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
#ifndef OPENSSL_NO_BF
# ifdef CHARSET_EBCDIC
}
# 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;
}
/*
- * 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
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);
ADD_ALL_TESTS(test_bio_enc_chacha20_poly1305, 2);
# endif
# endif
+ return 1;
}
}
-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;
}
/*
/*
- * 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
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;
}
}
-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);
#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;
}
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
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
/*
- * 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
}
#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;
}
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;
}
/*
- * 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
return ret;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(cipher_overhead);
+ return 1;
}
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;
}
EXECUTE_CIPHERLIST_TEST();
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(test_default_cipherlist_implicit);
ADD_TEST(test_default_cipherlist_explicit);
+ return 1;
}
return ret;
}
-void register_tests()
+int setup_tests(void)
{
ADD_TEST(test_cipher_name);
+ return 1;
}
/*
- * 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
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;
}
/*
- * 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
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;
}
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;
}
}
#endif
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
#ifndef OPENSSL_NO_CT
if ((ct_dir = getenv("CT_DIR")) == NULL)
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;
}
}
/*
- * 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;
{"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) {
break;
TEST_note("\t%s", it->sname);
}
- return 1;
+ return 0;
}
for (i = 0; i < OSSL_NELEM(expected_errors); i++) {
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;
}
/*
- * 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
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>
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_DES
ADD_ALL_TESTS(test_des_ecb, NUM_TESTS);
ADD_ALL_TESTS(test_input_align, 4);
ADD_ALL_TESTS(test_output_align, 4);
#endif
+ return 1;
}
#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);
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;
+}
}
-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;
}
/*
- * 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
}
#endif /* OPENSSL_NO_DSA */
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_DSA
ADD_TEST(dsa_test);
#endif
+ return 1;
}
/*
- * 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
return ret;
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(run_mtu_tests);
+ return 1;
}
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;
}
}
#endif
-void register_tests()
+int setup_tests()
{
#ifndef OPENSSL_NO_SOCK
ADD_ALL_TESTS(dtls_listen_test, (int)OSSL_NELEM(testpackets));
#endif
+ return 1;
}
/*
- * 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
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifdef OPENSSL_NO_EC
TEST_note("Elliptic curves are disabled.");
ADD_TEST(x9_62_tests);
ADD_TEST(test_builtin);
#endif
+ return 1;
}
* |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;
}
"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 */
# 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;
}
#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>
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;
+}
/*
- * 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
#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
}
#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;
}
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;
}
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;
}
return 0;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_exdata);
+ return 1;
}
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;
}
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;
}
}
# 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;
}
}
#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;
}
/*
- * 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
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);
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;
}
return testresult;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_int_lhash);
ADD_TEST(test_stress);
+ return 1;
}
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_MD2
ADD_ALL_TESTS(test_md2, OSSL_NELEM(test));
#endif
+ return 1;
}
/*
- * 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
return 1;
}
-void register_tests()
+int setup_tests()
{
ADD_ALL_TESTS(test_mdc2, OSSL_NELEM(tests));
+ return 1;
}
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_MDC2
ADD_TEST(test_mdc2);
#endif
+ return 1;
}
/*
- * 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
#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;
}
/*
- * 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
return 1;
}
-void register_tests(void)
+int setup_tests(void)
{
unsigned int i;
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;
}
/*
- * 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
return 0;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_pbelu);
+ return 1;
}
return 1;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_b64);
ADD_TEST(test_invalid);
+ return 1;
}
return good;
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(test_asn1_meths);
+ return 1;
}
/*
- * 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
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;
}
/*
- * 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
return ret;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(fips_random_tests);
+ return 1;
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_RC2
ADD_ALL_TESTS(test_rc2, OSSL_NELEM(RC2key));
#endif
+ return 1;
}
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifndef OPENSSL_NO_RC4
ADD_ALL_TESTS(test_rc4_encrypt, OSSL_NELEM(data_len));
ADD_ALL_TESTS(test_rc4_multi_call, data_len[3]);
ADD_TEST(test_rc_bulk);
#endif
+ return 1;
}
}
#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;
}
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;
}
#include "testutil.h"
#ifdef OPENSSL_NO_RSA
-void register_tests(void)
+void setup_tests(void)
{
/* No tests */
}
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
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;
}
#endif
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_sec_mem);
+ return 1;
}
#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;
}
&& 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);
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;
}
/*
- * 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
}
#endif
-void register_tests(void)
+int setup_tests(void)
{
#ifdef OPENSSL_NO_SRP
printf("No SRP support\n");
ADD_TEST(run_srp_tests);
ADD_TEST(run_srp_kat);
#endif
+ return 1;
}
return 1;
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(test_ssl_cert_table);
+ return 1;
}
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;
}
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;
}
/*
- * 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
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);
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;
}
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;
}
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;
}
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_int);
ADD_TEST(test_uint);
ADD_TEST(test_single_eval);
ADD_TEST(test_output);
ADD_ALL_TESTS(test_bn_output, OSSL_NELEM(bn_output_tests));
+ return 1;
}
#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. */
# 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.
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) {
#endif
}
-int finish_test(int ret)
+int pulldown_test_framework(int ret)
{
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (should_report_leaks()
return EXIT_FAILURE;
#endif
- test_close_streams();
-
return ret;
}
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)];
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;
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)
--- /dev/null
+/*
+ * Copyright 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"
+
+int global_init(void)
+{
+ return 1;
+}
*/
#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;
+}
+
#include "e_os.h"
#include "../testutil.h"
+#include "tu_local.h"
int test_start_file(STANZA *s, const char *testfile)
{
--- /dev/null
+/*
+ * Copyright 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"
+
+void cleanup_tests(void)
+{
+}
+++ /dev/null
-/*
- * 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]);
-}
#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);
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);
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;
}
return 1;
}
-void register_tests()
+int setup_tests()
{
ADD_ALL_TESTS(test_offset, OSSL_NELEM(tests));
+ return 1;
}
return ret;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_tls13_encryption);
+ return 1;
}
/*
- * 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
return ret;
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(test_handshake_secrets);
+ return 1;
}
/*
- * 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
return ok;
}
-void register_tests(void)
+int setup_tests(void)
{
ADD_TEST(test_old);
ADD_TEST(test_new_ui);
+ return 1;
}
/*
- * 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
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;
}
/*
- * 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
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;
}
/*
- * 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
#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;
* 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;
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;
}
/*
- * 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
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;
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;
}
* 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;
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;
}
#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()))
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;
}
return good;
}
-void register_tests()
+int setup_tests()
{
ADD_TEST(test_standard_exts);
+ return 1;
}
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;
}
#include "e_os.h"
#include "testutil.h"
-
-/* List of files, from argv */
-static char **files;
-
static int test_certs(int num)
{
int c;
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;
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;
}