提交 68e49bf2 编写于 作者: R Richard Levitte

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: NAndy Polyakov <appro@openssl.org>
Reviewed-by: NRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3345)
上级 603ddbdb
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
IF[{- !$disabled{tests} -}] IF[{- !$disabled{tests} -}]
LIBS_NO_INST=libtestutil.a LIBS_NO_INST=libtestutil.a
SOURCE[libtestutil.a]=testutil/basic_output.c testutil/output_helpers.c \ SOURCE[libtestutil.a]=testutil/basic_output.c testutil/output_helpers.c \
testutil/driver.c testutil/tests.c \ testutil/driver.c testutil/tests.c testutil/cb.c \
{- rebase_files("../apps", $target{apps_aux_src}) -} \ {- rebase_files("../apps", $target{apps_aux_src}) -} \
testutil/test_main.c testutil/main.c testutil/test_main.c testutil/main.c
INCLUDE[libtestutil.a]=.. ../include INCLUDE[libtestutil.a]=.. ../include
......
...@@ -248,6 +248,7 @@ void test_error_c90(const char *desc, ...) PRINTF_FORMAT(1, 2); ...@@ -248,6 +248,7 @@ void test_error_c90(const char *desc, ...) PRINTF_FORMAT(1, 2);
void test_info(const char *file, int line, const char *desc, ...) void test_info(const char *file, int line, const char *desc, ...)
PRINTF_FORMAT(3, 4); PRINTF_FORMAT(3, 4);
void test_info_c90(const char *desc, ...) PRINTF_FORMAT(1, 2); void test_info_c90(const char *desc, ...) PRINTF_FORMAT(1, 2);
void test_openssl_errors(void);
/* /*
* The following macros provide wrapper calls to the test functions with * The following macros provide wrapper calls to the test functions with
...@@ -342,6 +343,7 @@ void test_info_c90(const char *desc, ...) PRINTF_FORMAT(1, 2); ...@@ -342,6 +343,7 @@ void test_info_c90(const char *desc, ...) PRINTF_FORMAT(1, 2);
# define TEST_error(...) test_error(__FILE__, __LINE__, __VA_ARGS__) # define TEST_error(...) test_error(__FILE__, __LINE__, __VA_ARGS__)
# define TEST_info(...) test_info(__FILE__, __LINE__, __VA_ARGS__) # define TEST_info(...) test_info(__FILE__, __LINE__, __VA_ARGS__)
# endif # endif
# define TEST_openssl_errors test_openssl_errors
/* /*
* For "impossible" conditions such as malloc failures or bugs in test code, * For "impossible" conditions such as malloc failures or bugs in test code,
...@@ -351,7 +353,7 @@ void test_info_c90(const char *desc, ...) PRINTF_FORMAT(1, 2); ...@@ -351,7 +353,7 @@ void test_info_c90(const char *desc, ...) PRINTF_FORMAT(1, 2);
# define TEST_check(condition) \ # define TEST_check(condition) \
do { \ do { \
if (!(condition)) { \ if (!(condition)) { \
ERR_print_errors_fp(stderr); \ TEST_openssl_errors(); \
OPENSSL_assert(!#condition); \ OPENSSL_assert(!#condition); \
} \ } \
} while (0) } while (0)
......
/*
* 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);
}
...@@ -84,11 +84,6 @@ static int should_report_leaks() ...@@ -84,11 +84,6 @@ static int should_report_leaks()
} }
#endif #endif
static int err_cb(const char *str, size_t len, void *u)
{
return test_puts_stderr(str);
}
void setup_test() void setup_test()
{ {
char *TAP_levels = getenv("HARNESS_OSSL_LEVEL"); char *TAP_levels = getenv("HARNESS_OSSL_LEVEL");
...@@ -108,7 +103,8 @@ void setup_test() ...@@ -108,7 +103,8 @@ void setup_test()
int finish_test(int ret) int finish_test(int ret)
{ {
#ifndef OPENSSL_NO_CRYPTO_MDEBUG #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; return EXIT_FAILURE;
#endif #endif
...@@ -122,7 +118,7 @@ static void finalize(int success) ...@@ -122,7 +118,7 @@ static void finalize(int success)
if (success) if (success)
ERR_clear_error(); ERR_clear_error();
else else
ERR_print_errors_cb(err_cb, NULL); ERR_print_errors_cb(openssl_error_cb, NULL);
} }
int run_tests(const char *test_prog_name) int run_tests(const char *test_prog_name)
......
...@@ -111,6 +111,11 @@ void test_error(const char *file, int line, const char *desc, ...) ...@@ -111,6 +111,11 @@ void test_error(const char *file, int line, const char *desc, ...)
va_end(ap); va_end(ap);
} }
void test_openssl_errors(void)
{
ERR_print_errors_cb(openssl_error_cb, NULL);
}
/* /*
* Define some comparisons between pairs of various types. * Define some comparisons between pairs of various types.
* These functions return 1 if the test is true. * These functions return 1 if the test is true.
......
...@@ -7,4 +7,7 @@ ...@@ -7,4 +7,7 @@
* https://www.openssl.org/source/license.html * https://www.openssl.org/source/license.html
*/ */
#include <stdlib.h> /* size_t */
int subtest_level(void); int subtest_level(void);
int openssl_error_cb(const char *str, size_t len, void *u);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册