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
This commit is contained in:
Jakub Jelen 2021-05-12 16:58:11 +02:00
parent a69ab7c70c
commit a8a4bddfad
4 changed files with 13 additions and 14 deletions

View File

@ -31,7 +31,7 @@ p11test_SOURCES = p11test.c p11test_loader.c \
p11test_case_pss_oaep.c \ p11test_case_pss_oaep.c \
p11test_case_interface.c \ p11test_case_interface.c \
p11test_helpers.c p11test_helpers.c
p11test_CFLAGS = -DNDEBUG $(CMOCKA_CFLAGS) p11test_CFLAGS = $(CMOCKA_CFLAGS)
p11test_LDADD = $(OPTIONAL_OPENSSL_LIBS) $(CMOCKA_LIBS) p11test_LDADD = $(OPTIONAL_OPENSSL_LIBS) $(CMOCKA_LIBS)
if WIN32 if WIN32

View File

@ -37,6 +37,7 @@
/* Global variable keeping information about token we are using */ /* Global variable keeping information about token we are using */
token_info_t token; token_info_t token;
int debug_flag = 0;
void display_usage() { void display_usage() {
fprintf(stdout, fprintf(stdout,
@ -98,7 +99,7 @@ int main(int argc, char** argv) {
token.slot_id = (unsigned long) -1; token.slot_id = (unsigned long) -1;
token.log.outfile = NULL; 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) { switch (command) {
case 'o': case 'o':
token.log.outfile = strdup(optarg); token.log.outfile = strdup(optarg);
@ -120,6 +121,9 @@ int main(int argc, char** argv) {
case '?': case '?':
display_usage(); display_usage();
return 0; return 0;
case 'v':
debug_flag = 1;
break;
default: default:
break; break;
} }

View File

@ -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_FUNCTION_LIST_PTR fp = info->function_pointer;
CK_MECHANISM sign_mechanism = { mech->mech, NULL_PTR, 0 }; CK_MECHANISM sign_mechanism = { mech->mech, NULL_PTR, 0 };
static int verify_support = 1; static int verify_support = 1;
#ifndef NDEBUG
char *name; char *name;
#endif
if (!verify_support) if (!verify_support)
goto openssl_verify; goto openssl_verify;
@ -531,15 +529,11 @@ int verify_message(test_cert_t *o, token_info_t *info, CK_BYTE *message,
/* Final */ /* Final */
rv = fp->C_VerifyFinal(info->session_handle, rv = fp->C_VerifyFinal(info->session_handle,
sign, sign_length); sign, sign_length);
#ifndef NDEBUG
name = "C_VerifyFinal"; name = "C_VerifyFinal";
#endif
} else { } else {
rv = fp->C_Verify(info->session_handle, rv = fp->C_Verify(info->session_handle,
message, message_length, sign, sign_length); message, message_length, sign, sign_length);
#ifndef NDEBUG
name = "C_Verify"; name = "C_Verify";
#endif
} }
if (rv == CKR_OK) { if (rv == CKR_OK) {
mech->result_flags |= FLAGS_SIGN; mech->result_flags |= FLAGS_SIGN;

View File

@ -33,12 +33,12 @@
#define MAX_MECHS 200 #define MAX_MECHS 200
#ifndef NDEBUG #define debug_print(fmt, ...) \
#define debug_print(fmt, ...) \ do { \
{ fprintf(stderr, fmt "\n", ##__VA_ARGS__); } while (0) if (debug_flag) { \
#else fprintf(stderr, fmt "\n", ##__VA_ARGS__); \
#define debug_print(fmt, ...) } \
#endif } while (0)
#define FLAGS_SIGN 0x01 #define FLAGS_SIGN 0x01
#define FLAGS_SIGN_OPENSSL 0x02 #define FLAGS_SIGN_OPENSSL 0x02
@ -89,6 +89,7 @@ typedef struct {
} token_info_t; } token_info_t;
extern token_info_t token; extern token_info_t token;
extern int debug_flag;
#endif /* P11TEST_COMMON_H */ #endif /* P11TEST_COMMON_H */