diff options
author | Emilia Kasper <emilia@openssl.org> | 2016-11-07 16:53:15 +0100 |
---|---|---|
committer | Emilia Kasper <emilia@openssl.org> | 2016-11-09 16:07:16 +0100 |
commit | e364c3b24e38bd60d40487e0a532261348a9bb10 (patch) | |
tree | 82e621604899af53aebd34ced7d7dbc381678d84 /test/d2i_test.c | |
parent | 7380737d77e89edd17651b04e439223a47ea833e (diff) | |
download | openssl-e364c3b24e38bd60d40487e0a532261348a9bb10.tar.gz |
Add main() test methods to reduce test boilerplate.
Simple tests only need to implement register_tests().
Tests that need a custom main() should implement test_main(). This will
be wrapped in a main() that performs common setup/teardown (currently
crypto-mdebug).
Note that for normal development, enable-asan is usually
sufficient for detecting leaks, and more versatile.
enable-crypto-mdebug is stricter as it will also
insist that all static variables be freed. This is useful for debugging
library init/deinit; however, it also means that test_main() must free
everything it allocates.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'test/d2i_test.c')
-rw-r--r-- | test/d2i_test.c | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/test/d2i_test.c b/test/d2i_test.c index e12f249242..e771e01362 100644 --- a/test/d2i_test.c +++ b/test/d2i_test.c @@ -13,6 +13,7 @@ #include <string.h> #include "testutil.h" +#include "test_main_custom.h" #include <openssl/asn1.h> #include <openssl/asn1t.h> @@ -109,12 +110,10 @@ static int test_bad_asn1() * Usage: d2i_test <type> <file>, e.g. * d2i_test generalname bad_generalname.der */ -int main(int argc, char **argv) +int test_main(int argc, char *argv[]) { - int result = 0; const char *test_type_name; const char *expected_error_string; - const char *p = getenv("OPENSSL_DEBUG_MEMORY"); size_t i; @@ -126,10 +125,6 @@ int main(int argc, char **argv) {"compare", ASN1_COMPARE} }; - if (p != NULL && strcmp(p, "on") == 0) - CRYPTO_set_mem_debug(1); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - if (argc != 4) { fprintf(stderr, "Usage: d2i_test item_name expected_error file.der\n"); @@ -169,12 +164,5 @@ int main(int argc, char **argv) ADD_TEST(test_bad_asn1); - result = run_tests(argv[0]); - -#ifndef OPENSSL_NO_CRYPTO_MDEBUG - if (CRYPTO_mem_leaks_fp(stderr) <= 0) - result = 1; -#endif - - return result; + return run_tests(argv[0]); } |