summaryrefslogtreecommitdiffstats
path: root/test/cmp_ctx_test.c
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2019-12-13 19:50:20 +0100
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>2020-02-17 07:43:58 +0100
commitebf3006917e0e968af4a5d5c2c6379c5b866f801 (patch)
tree3bfed793977233531aeec46da7de1c9044f9ca69 /test/cmp_ctx_test.c
parentfcc25beb7b430fb0588accbb63bf369d914eacba (diff)
improve CMP logging according to comments on CMP chunk 7 preview
in particular: consolidate documentation of CMP logging and error reporting functions fix compilation problem with clang on some platforms rename OSSL_CMP_log etc. to ossl_cmp_log etc. since these macros are CMP-internal move chopping of trailing separator to ossl_cmp_add_error_txt(), also fix handling of leading separator internalize X509_print_ex_brief() as x509_print_ex_brief() Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de> (Merged from https://github.com/openssl/openssl/pull/10620)
Diffstat (limited to 'test/cmp_ctx_test.c')
-rw-r--r--test/cmp_ctx_test.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/test/cmp_ctx_test.c b/test/cmp_ctx_test.c
index c007cfb35e..e6b6f24854 100644
--- a/test/cmp_ctx_test.c
+++ b/test/cmp_ctx_test.c
@@ -195,7 +195,7 @@ static int execute_CTX_reqExtensions_have_SAN_test(
{
OSSL_CMP_CTX *ctx = fixture->ctx;
const int len = 16;
- unsigned char str[16 /* = len */ ];
+ unsigned char str[16 /* = len */];
ASN1_OCTET_STRING *data = NULL;
X509_EXTENSION *ext = NULL;
X509_EXTENSIONS *exts = NULL;
@@ -234,7 +234,6 @@ static int test_CTX_reqExtensions_have_SAN(void)
return result;
}
-#ifndef OPENSSL_NO_TRACE
static int test_log_line;
static int test_log_cb_res = 0;
static int test_log_cb(const char *func, const char *file, int line,
@@ -242,21 +241,20 @@ static int test_log_cb(const char *func, const char *file, int line,
{
test_log_cb_res =
# ifndef PEDANTIC
- (strcmp(func, "execute_cmp_ctx_log_cb_test") == 0
- || strcmp(func, "(unknown function)") == 0) &&
+ (TEST_str_eq(func, "execute_cmp_ctx_log_cb_test")
+ || TEST_str_eq(func, "(unknown function)")) &&
# endif
- (strcmp(file, OPENSSL_FILE) == 0 || strcmp(file, "(no file)") == 0)
- && (line == test_log_line || line == 0)
- && (level == OSSL_CMP_LOG_INFO || level == -1)
- && strcmp(msg, "ok\n") == 0;
+ (TEST_str_eq(file, OPENSSL_FILE)
+ || TEST_str_eq(file, "(no file)"))
+ && (TEST_int_eq(line, test_log_line) || TEST_int_eq(line, 0))
+ && (TEST_int_eq(level, OSSL_CMP_LOG_INFO) || TEST_int_eq(level, -1))
+ && TEST_str_eq(msg, "ok");
return 1;
}
-#endif
static int execute_cmp_ctx_log_cb_test(OSSL_CMP_CTX_TEST_FIXTURE *fixture)
{
int res = 1;
-#if !defined OPENSSL_NO_TRACE && !defined OPENSSL_NO_STDIO
OSSL_CMP_CTX *ctx = fixture->ctx;
OSSL_TRACE(ALL, "this general trace message is not shown by default\n");
@@ -267,30 +265,29 @@ static int execute_cmp_ctx_log_cb_test(OSSL_CMP_CTX_TEST_FIXTURE *fixture)
if (!TEST_true(OSSL_CMP_CTX_set_log_cb(ctx, NULL))) {
res = 0;
} else {
- OSSL_CMP_err("this should be printed as CMP error message");
- OSSL_CMP_warn("this should be printed as CMP warning message");
- OSSL_CMP_debug("this should not be printed");
+ ossl_cmp_err(ctx, "this should be printed as CMP error message");
+ ossl_cmp_warn(ctx, "this should be printed as CMP warning message");
+ ossl_cmp_debug(ctx, "this should not be printed");
TEST_true(OSSL_CMP_CTX_set_log_verbosity(ctx, OSSL_CMP_LOG_DEBUG));
- OSSL_CMP_debug("this should be printed as CMP debug message");
+ ossl_cmp_debug(ctx, "this should be printed as CMP debug message");
TEST_true(OSSL_CMP_CTX_set_log_verbosity(ctx, OSSL_CMP_LOG_INFO));
}
if (!TEST_true(OSSL_CMP_CTX_set_log_cb(ctx, test_log_cb))) {
res = 0;
} else {
test_log_line = OPENSSL_LINE + 1;
- OSSL_CMP_log2(INFO, "%s%c", "o", 'k');
+ ossl_cmp_log2(INFO, ctx, "%s%c", "o", 'k');
if (!TEST_int_eq(test_log_cb_res, 1))
res = 0;
OSSL_CMP_CTX_set_log_verbosity(ctx, OSSL_CMP_LOG_ERR);
test_log_cb_res = -1; /* callback should not be called at all */
test_log_line = OPENSSL_LINE + 1;
- OSSL_CMP_log2(INFO, "%s%c", "o", 'k');
+ ossl_cmp_log2(INFO, ctx, "%s%c", "o", 'k');
if (!TEST_int_eq(test_log_cb_res, -1))
res = 0;
}
OSSL_CMP_log_close();
OSSL_CMP_log_close(); /* multiple calls should be harmless */
-#endif
return res;
}
@@ -715,9 +712,7 @@ DEFINE_SET_GET_ARG_FN(set, get, option, 16, int)
DEFINE_SET_GET_BASE_TEST(OSSL_CMP_CTX, set, get, 0, option_16, int, -1, IS_0, \
1 /* true */, DROP)
-#ifndef OPENSSL_NO_TRACE
DEFINE_SET_CB_TEST(log_cb)
-#endif
DEFINE_SET_TEST_DEFAULT(OSSL_CMP, CTX, 1, 1, serverPath, char, IS_0)
DEFINE_SET_TEST(OSSL_CMP, CTX, 1, 1, serverName, char)
@@ -788,13 +783,11 @@ int setup_tests(void)
/* various CMP options: */
ADD_TEST(test_CTX_set_get_option_16);
/* CMP-specific callback for logging and outputting the error queue: */
-#ifndef OPENSSL_NO_TRACE
ADD_TEST(test_CTX_set_get_log_cb);
-#endif
/*
* also tests OSSL_CMP_log_open(), OSSL_CMP_CTX_set_log_verbosity(),
- * OSSL_CMP_err(), OSSL_CMP_warn(), * OSSL_CMP_debug(),
- * OSSL_CMP_log2(), ossl_cmp_log_parse_metadata(), and OSSL_CMP_log_close()
+ * ossl_cmp_err(), ossl_cmp_warn(), * ossl_cmp_debug(),
+ * ossl_cmp_log2(), ossl_cmp_log_parse_metadata(), and OSSL_CMP_log_close()
* with OSSL_CMP_severity OSSL_CMP_LOG_ERR/WARNING/DEBUG/INFO:
*/
ADD_TEST(test_cmp_ctx_log_cb);