diff options
author | Richard Levitte <levitte@openssl.org> | 2017-04-28 14:48:13 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2017-04-28 15:59:46 +0200 |
commit | 68e49bf22384c33494886eb95d78f1f69f433781 (patch) | |
tree | b8cbbef2d6a6ce3779d873d809c88ce99ec2ae8f /test/testutil | |
parent | 603ddbdb7527710c293a762aa5eed51ad05646b3 (diff) | |
download | openssl-new-68e49bf22384c33494886eb95d78f1f69f433781.tar.gz |
testutil: Add OpenSSL error stack printing wrapper TEST_openssl_errors
Also added a internal error printing callback to be used both with
ERR_print_errors_cb() and with CRYPTO_mem_leaks_cb
Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3345)
Diffstat (limited to 'test/testutil')
-rw-r--r-- | test/testutil/cb.c | 16 | ||||
-rw-r--r-- | test/testutil/driver.c | 10 | ||||
-rw-r--r-- | test/testutil/tests.c | 5 | ||||
-rw-r--r-- | test/testutil/tu_local.h | 3 |
4 files changed, 27 insertions, 7 deletions
diff --git a/test/testutil/cb.c b/test/testutil/cb.c new file mode 100644 index 0000000000..a291eaaa49 --- /dev/null +++ b/test/testutil/cb.c @@ -0,0 +1,16 @@ +/* + * 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 "output.h" +#include "tu_local.h" + +int openssl_error_cb(const char *str, size_t len, void *u) +{ + return test_printf_stderr("%*s# %s", subtest_level(), "", str); +} diff --git a/test/testutil/driver.c b/test/testutil/driver.c index 6689a781cd..786bc38f2b 100644 --- a/test/testutil/driver.c +++ b/test/testutil/driver.c @@ -84,11 +84,6 @@ static int should_report_leaks() } #endif -static int err_cb(const char *str, size_t len, void *u) -{ - return test_puts_stderr(str); -} - void setup_test() { char *TAP_levels = getenv("HARNESS_OSSL_LEVEL"); @@ -108,7 +103,8 @@ void setup_test() int finish_test(int ret) { #ifndef OPENSSL_NO_CRYPTO_MDEBUG - if (should_report_leaks() && CRYPTO_mem_leaks_cb(err_cb, NULL) <= 0) + if (should_report_leaks() + && CRYPTO_mem_leaks_cb(openssl_error_cb, NULL) <= 0) return EXIT_FAILURE; #endif @@ -122,7 +118,7 @@ static void finalize(int success) if (success) ERR_clear_error(); else - ERR_print_errors_cb(err_cb, NULL); + ERR_print_errors_cb(openssl_error_cb, NULL); } int run_tests(const char *test_prog_name) diff --git a/test/testutil/tests.c b/test/testutil/tests.c index 6dfe2424ef..0efaa064b6 100644 --- a/test/testutil/tests.c +++ b/test/testutil/tests.c @@ -111,6 +111,11 @@ void test_error(const char *file, int line, const char *desc, ...) va_end(ap); } +void test_openssl_errors(void) +{ + ERR_print_errors_cb(openssl_error_cb, NULL); +} + /* * Define some comparisons between pairs of various types. * These functions return 1 if the test is true. diff --git a/test/testutil/tu_local.h b/test/testutil/tu_local.h index 620fccd278..ad50fca39e 100644 --- a/test/testutil/tu_local.h +++ b/test/testutil/tu_local.h @@ -7,4 +7,7 @@ * https://www.openssl.org/source/license.html */ +#include <stdlib.h> /* size_t */ + int subtest_level(void); +int openssl_error_cb(const char *str, size_t len, void *u); |