Commit ad887416 authored by Pauli's avatar Pauli
Browse files

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: default avatarRichard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3953)
parent d4453024
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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
+17 −13
Original line number Diff line number Diff line
/*
 * 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
+2 −1
Original line number Diff line number Diff line
@@ -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;
}
+2 −1
Original line number Diff line number Diff line
@@ -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;
}
+9 −14
Original line number Diff line number Diff line
/*
 * 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;
}
Loading