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)
This commit is contained in:
parent
603ddbdb75
commit
68e49bf223
6 changed files with 31 additions and 9 deletions
|
@ -10,7 +10,7 @@
|
|||
IF[{- !$disabled{tests} -}]
|
||||
LIBS_NO_INST=libtestutil.a
|
||||
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}) -} \
|
||||
testutil/test_main.c testutil/main.c
|
||||
INCLUDE[libtestutil.a]=.. ../include
|
||||
|
|
|
@ -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, ...)
|
||||
PRINTF_FORMAT(3, 4);
|
||||
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
|
||||
|
@ -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_info(...) test_info(__FILE__, __LINE__, __VA_ARGS__)
|
||||
# endif
|
||||
# define TEST_openssl_errors test_openssl_errors
|
||||
|
||||
/*
|
||||
* 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);
|
|||
# define TEST_check(condition) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
ERR_print_errors_fp(stderr); \
|
||||
TEST_openssl_errors(); \
|
||||
OPENSSL_assert(!#condition); \
|
||||
} \
|
||||
} while (0)
|
||||
|
|
16
test/testutil/cb.c
Normal file
16
test/testutil/cb.c
Normal file
|
@ -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);
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue