2 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/trace.h>
14 static int test_trace_categories(void)
18 for (cat_num = -1; cat_num <= OSSL_TRACE_CATEGORY_NUM + 1; ++cat_num) {
19 const char *cat_name = OSSL_trace_get_category_name(cat_num);
20 int is_cat_name_eq = 0;
26 case OSSL_TRACE_CATEGORY_##name: \
27 is_cat_name_eq = TEST_str_eq(cat_name, #name); \
36 #ifndef OPENSSL_NO_ENGINE
38 CASE(ENGINE_REF_COUNT);
53 is_cat_name_eq = TEST_ptr_null(cat_name);
57 if (!TEST_true(is_cat_name_eq))
60 OSSL_trace_get_category_num(cat_name);
61 expected_ret = cat_name != NULL ? cat_num : -1;
62 if (!TEST_int_eq(expected_ret, ret_cat_num))
69 #ifndef OPENSSL_NO_TRACE
70 static void put_trace_output(void)
72 OSSL_TRACE_BEGIN(TLS) {
73 BIO_printf(trc_out, "Hello World\n");
74 BIO_printf(trc_out, "Good Bye Universe\n");
75 } OSSL_TRACE_END(TLS);
78 static int test_trace_channel(void)
80 static const char expected[] = "xyz-\nHello World\nGood Bye Universe\n-abc\n";
81 static const char expected_len = sizeof(expected) - 1;
87 bio = BIO_new(BIO_s_mem());
91 if (!TEST_int_eq(OSSL_trace_set_channel(OSSL_TRACE_CATEGORY_TLS, bio), 1))
94 if (!TEST_true(OSSL_trace_enabled(OSSL_TRACE_CATEGORY_TLS)))
97 if (!TEST_int_eq(OSSL_trace_set_prefix(OSSL_TRACE_CATEGORY_TLS, "xyz-"), 1))
99 if (!TEST_int_eq(OSSL_trace_set_suffix(OSSL_TRACE_CATEGORY_TLS, "-abc"), 1))
103 len = BIO_get_mem_data(bio, &p_buf);
104 if (!TEST_strn2_eq(p_buf, len, expected, expected_len))
106 if (!TEST_int_eq(OSSL_trace_set_channel(OSSL_TRACE_CATEGORY_TLS, NULL), 1))
117 OPT_TEST_DECLARE_USAGE("\n")
119 int setup_tests(void)
121 if (!test_skip_common_options()) {
122 TEST_error("Error parsing test options\n");
126 ADD_TEST(test_trace_categories);
127 #ifndef OPENSSL_NO_TRACE
128 ADD_TEST(test_trace_channel);
133 void cleanup_tests(void)