diff --git a/test/bbs_e2e_sign_n_proof.c b/test/bbs_e2e_sign_n_proof.c index 1ac2fa2..dec7d84 100644 --- a/test/bbs_e2e_sign_n_proof.c +++ b/test/bbs_e2e_sign_n_proof.c @@ -82,42 +82,42 @@ bbs_e2e_sign_n_proof () bbs_secret_key sk; bbs_public_key pk; - BBS_BENCH_START () + BBS_BENCH_START (keygen) if (BBS_OK != bbs_keygen_full[cipher_suite_index] (sk, pk)) { puts ("Error during key generation"); return 1; } - BBS_BENCH_END ("bbs_keygen_full") + BBS_BENCH_END (keygen, "bbs_keygen_full") bbs_signature sig; static char msg1[] = "I am a message"; static char msg2[] = "And so am I. Crazy..."; static char header[] = "But I am a header!"; - BBS_BENCH_START () + BBS_BENCH_START (sign) if (BBS_OK != sign[cipher_suite_index] (sk, pk, sig, (uint8_t*) header, strlen (header), 2, msg1, strlen (msg1), msg2, strlen (msg2))) { puts ("Error during signing"); return 1; } - BBS_BENCH_END ("bbs_sign (2 messages, 1 header)") + BBS_BENCH_END (sign, "bbs_sign (2 messages, 1 header)") - BBS_BENCH_START () + BBS_BENCH_START (verify) if (BBS_OK != verify[cipher_suite_index] (pk, sig, (uint8_t*) header, strlen (header), 2, msg1, strlen (msg1), msg2, strlen (msg2))) { puts ("Error during signature verification"); return 1; } - BBS_BENCH_END ("bbs_verify (2 messages, 1 header)") + BBS_BENCH_END (verify, "bbs_verify (2 messages, 1 header)") uint8_t proof[BBS_PROOF_LEN (1)]; uint64_t disclosed_indexes[] = {0}; static char ph[] = "I am a challenge nonce!"; - BBS_BENCH_START () + BBS_BENCH_START (proof_gen) if (BBS_OK != proof_gen[cipher_suite_index] (pk, sig, proof, (uint8_t*) header, strlen (header), (uint8_t*) ph, strlen (ph), disclosed_indexes, 1, 2, msg1, strlen (msg1), msg2, strlen (msg2))) @@ -125,9 +125,9 @@ bbs_e2e_sign_n_proof () puts ("Error during proof generation"); return 1; } - BBS_BENCH_END ("bbs_proof_gen (2 messages, 1 header, 1 disclosed index)") + BBS_BENCH_END (proof_gen, "bbs_proof_gen (2 messages, 1 header, 1 disclosed index)") - BBS_BENCH_START () + BBS_BENCH_START (proof_verify) if (BBS_OK != proof_verify[cipher_suite_index] (pk, proof, BBS_PROOF_LEN (1), (uint8_t*) header, strlen (header), (uint8_t*) ph, strlen (ph), disclosed_indexes, 1, 2, msg1, strlen (msg1))) @@ -135,7 +135,7 @@ bbs_e2e_sign_n_proof () puts ("Error during proof verification"); return 1; } - BBS_BENCH_END ("bbs_proof_verify (2 messages, 1 header, 1 disclosed index)") + BBS_BENCH_END (proof_verify, "bbs_proof_verify (2 messages, 1 header, 1 disclosed index)") } return 0; diff --git a/test/bbs_fix_proof_gen.c b/test/bbs_fix_proof_gen.c index 640cb66..5884351 100644 --- a/test/bbs_fix_proof_gen.c +++ b/test/bbs_fix_proof_gen.c @@ -405,7 +405,7 @@ bbs_fix_proof_gen () } uint8_t proof1[BBS_PROOF_LEN (0)]; - BBS_BENCH_START () + BBS_BENCH_START (mocked_proof_gen) if (BBS_OK != mocked_proof_gen (test_case, test_case.proof1_public_key, test_case.proof1_signature, proof1, test_case.proof1_header, @@ -419,7 +419,7 @@ bbs_fix_proof_gen () puts ("Error during proof 1 generation"); return 1; } - BBS_BENCH_END ("Valid Single Message Proof"); + BBS_BENCH_END (mocked_proof_gen, "Valid Single Message Proof"); ASSERT_EQ_PTR ("proof 1 generation", proof1, test_case.proof1_proof, @@ -448,7 +448,6 @@ bbs_fix_proof_gen () puts ("Error during proof 2 generation"); return 1; } - BBS_BENCH_END ("Valid Multi-Message, All Messages Disclosed Proof") ASSERT_EQ_PTR ("proof 2 generation", proof2, test_case.proof2_proof, @@ -478,7 +477,6 @@ bbs_fix_proof_gen () puts ("Error during proof 3 generation"); return 1; } - BBS_BENCH_END ("Valid Multi-Message, Some Messages Disclosed Proof") ASSERT_EQ_PTR ("proof 3 generation", proof3, test_case.proof3_proof, diff --git a/test/test_util.h b/test/test_util.h index eb74a68..ca4e2de 100644 --- a/test/test_util.h +++ b/test/test_util.h @@ -31,20 +31,18 @@ } -struct timespec tp_start; - -struct timespec tp_end; - #ifdef ENABLE_BENCHMARK -#define BBS_BENCH_START() \ - clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tp_start); -#define BBS_BENCH_END(hint) \ - clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tp_end); \ - fprintf (stdout, "%s: %" PRIu64 " ns\n", hint, \ - (((uint64_t) tp_end.tv_sec * 1000000000) + tp_end.tv_nsec) - \ - (((uint64_t) tp_start.tv_sec * 1000000000) + tp_start.tv_nsec)); +#define BBS_BENCH_START(hint) \ + struct timespec tp_start_ ## hint; \ + struct timespec tp_end_ ## hint; \ + clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tp_start_ ## hint); +#define BBS_BENCH_END(hint,info) \ + clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tp_end_ ## hint); \ + fprintf (stdout, "%s: %" PRIu64 " ns\n", info, \ + (((uint64_t) tp_end_ ## hint.tv_sec * 1000000000) + tp_end_ ## hint.tv_nsec) - \ + (((uint64_t) tp_start_ ## hint.tv_sec * 1000000000) + tp_start_ ## hint .tv_nsec)); #else -#define BBS_BENCH_START() -#define BBS_BENCH_END(hint) +#define BBS_BENCH_START(hint) +#define BBS_BENCH_END(hint, info) #endif #endif /* TEST_UTIL_H */