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)
diff --git a/test/testutil.h b/test/testutil.h
index 1826470..f1c1bba 100644
--- a/test/testutil.h
+++ b/test/testutil.h
@@ -248,6 +248,7 @@
 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 @@
 #  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 @@
 # define TEST_check(condition)                  \
     do {                                        \
         if (!(condition)) {                     \
-            ERR_print_errors_fp(stderr);        \
+            TEST_openssl_errors();              \
             OPENSSL_assert(!#condition);        \
         }                                       \
     } while (0)