From a8a4bddfada6d8253046a2912f224a25f61ef7df Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Wed, 12 May 2021 16:58:11 +0200 Subject: [PATCH] p11test: Debug level from commandline This replaces the debug level defined at build time with -NDEBUG, which turned out to be quite confusing. Fixes #2304 --- src/tests/p11test/Makefile.am | 2 +- src/tests/p11test/p11test.c | 6 +++++- src/tests/p11test/p11test_case_readonly.c | 6 ------ src/tests/p11test/p11test_common.h | 13 +++++++------ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/tests/p11test/Makefile.am b/src/tests/p11test/Makefile.am index f7cc67e3..abc2d5a1 100644 --- a/src/tests/p11test/Makefile.am +++ b/src/tests/p11test/Makefile.am @@ -31,7 +31,7 @@ p11test_SOURCES = p11test.c p11test_loader.c \ p11test_case_pss_oaep.c \ p11test_case_interface.c \ p11test_helpers.c -p11test_CFLAGS = -DNDEBUG $(CMOCKA_CFLAGS) +p11test_CFLAGS = $(CMOCKA_CFLAGS) p11test_LDADD = $(OPTIONAL_OPENSSL_LIBS) $(CMOCKA_LIBS) if WIN32 diff --git a/src/tests/p11test/p11test.c b/src/tests/p11test/p11test.c index 457a7b63..dbac167d 100644 --- a/src/tests/p11test/p11test.c +++ b/src/tests/p11test/p11test.c @@ -37,6 +37,7 @@ /* Global variable keeping information about token we are using */ token_info_t token; +int debug_flag = 0; void display_usage() { fprintf(stdout, @@ -98,7 +99,7 @@ int main(int argc, char** argv) { token.slot_id = (unsigned long) -1; token.log.outfile = NULL; - while ((command = getopt(argc, argv, "?hm:s:p:io:")) != -1) { + while ((command = getopt(argc, argv, "?hm:s:p:io:v")) != -1) { switch (command) { case 'o': token.log.outfile = strdup(optarg); @@ -120,6 +121,9 @@ int main(int argc, char** argv) { case '?': display_usage(); return 0; + case 'v': + debug_flag = 1; + break; default: break; } diff --git a/src/tests/p11test/p11test_case_readonly.c b/src/tests/p11test/p11test_case_readonly.c index df39ecb4..60ad0407 100644 --- a/src/tests/p11test/p11test_case_readonly.c +++ b/src/tests/p11test/p11test_case_readonly.c @@ -498,9 +498,7 @@ int verify_message(test_cert_t *o, token_info_t *info, CK_BYTE *message, CK_FUNCTION_LIST_PTR fp = info->function_pointer; CK_MECHANISM sign_mechanism = { mech->mech, NULL_PTR, 0 }; static int verify_support = 1; -#ifndef NDEBUG char *name; -#endif if (!verify_support) goto openssl_verify; @@ -531,15 +529,11 @@ int verify_message(test_cert_t *o, token_info_t *info, CK_BYTE *message, /* Final */ rv = fp->C_VerifyFinal(info->session_handle, sign, sign_length); -#ifndef NDEBUG name = "C_VerifyFinal"; -#endif } else { rv = fp->C_Verify(info->session_handle, message, message_length, sign, sign_length); -#ifndef NDEBUG name = "C_Verify"; -#endif } if (rv == CKR_OK) { mech->result_flags |= FLAGS_SIGN; diff --git a/src/tests/p11test/p11test_common.h b/src/tests/p11test/p11test_common.h index 1122e8e3..d3eb1040 100644 --- a/src/tests/p11test/p11test_common.h +++ b/src/tests/p11test/p11test_common.h @@ -33,12 +33,12 @@ #define MAX_MECHS 200 -#ifndef NDEBUG - #define debug_print(fmt, ...) \ - { fprintf(stderr, fmt "\n", ##__VA_ARGS__); } while (0) -#else - #define debug_print(fmt, ...) -#endif +#define debug_print(fmt, ...) \ + do { \ + if (debug_flag) { \ + fprintf(stderr, fmt "\n", ##__VA_ARGS__); \ + } \ + } while (0) #define FLAGS_SIGN 0x01 #define FLAGS_SIGN_OPENSSL 0x02 @@ -89,6 +89,7 @@ typedef struct { } token_info_t; extern token_info_t token; +extern int debug_flag; #endif /* P11TEST_COMMON_H */