From e3329bec26ae1150d3ca11af88a32f427086b2f0 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Fri, 9 Jun 2017 18:30:18 +0200 Subject: [PATCH] make it possible to pass a single timing test to run --- demos/timing.c | 87 ++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/demos/timing.c b/demos/timing.c index 61f509e..fa5cdcd 100644 --- a/demos/timing.c +++ b/demos/timing.c @@ -133,7 +133,7 @@ static void init_timer(void) fprintf(stderr, "Clock Skew: %lu\n", (unsigned long)skew); } -static int time_keysched(void) +static void time_keysched(void) { unsigned long x, y1; ulong64 t1, c1; @@ -165,12 +165,10 @@ static int time_keysched(void) #undef DO1 } tally_results(0); - - return 0; } #ifdef LTC_ECB_MODE -static int time_cipher_ecb(void) +static void time_cipher_ecb(void) { unsigned long x, y1; ulong64 t1, t2, c1, c2, a1, a2; @@ -237,15 +235,13 @@ static int time_cipher_ecb(void) #undef DO1 } tally_results(1); - - return 0; } #else -static int time_cipher_ecb(void) { fprintf(stderr, "NO ECB\n"); return 0; } +static void time_cipher_ecb(void) { fprintf(stderr, "NO ECB\n"); return 0; } #endif #ifdef LTC_CBC_MODE -static int time_cipher_cbc(void) +static void time_cipher_cbc(void) { unsigned long x, y1; ulong64 t1, t2, c1, c2, a1, a2; @@ -312,15 +308,13 @@ static int time_cipher_cbc(void) #undef DO1 } tally_results(1); - - return 0; } #else -static int time_cipher_cbc(void) { fprintf(stderr, "NO CBC\n"); return 0; } +static void time_cipher_cbc(void) { fprintf(stderr, "NO CBC\n"); return 0; } #endif #ifdef LTC_CTR_MODE -static int time_cipher_ctr(void) +static void time_cipher_ctr(void) { unsigned long x, y1; ulong64 t1, t2, c1, c2, a1, a2; @@ -387,15 +381,13 @@ static int time_cipher_ctr(void) #undef DO1 } tally_results(1); - - return 0; } #else -static int time_cipher_ctr(void) { fprintf(stderr, "NO CTR\n"); return 0; } +static void time_cipher_ctr(void) { fprintf(stderr, "NO CTR\n"); return 0; } #endif #ifdef LTC_LRW_MODE -static int time_cipher_lrw(void) +static void time_cipher_lrw(void) { unsigned long x, y1; ulong64 t1, t2, c1, c2, a1, a2; @@ -464,15 +456,13 @@ static int time_cipher_lrw(void) #undef DO1 } tally_results(1); - - return 0; } #else -static int time_cipher_lrw(void) { fprintf(stderr, "NO LRW\n"); return 0; } +static void time_cipher_lrw(void) { fprintf(stderr, "NO LRW\n"); return 0; } #endif -static int time_hash(void) +static void time_hash(void) { unsigned long x, y1, len; ulong64 t1, t2, c1, c2; @@ -519,8 +509,6 @@ static int time_hash(void) #undef DO1 } tally_results(2); - - return 0; } /*#warning you need an mp_rand!!!*/ @@ -1399,9 +1387,36 @@ static void time_encmacs(void) time_encmacs_(32); } -int main(void) +#define LTC_TEST_FN(f) { f, #f } +int main(int argc, char **argv) { int err; + +const struct +{ + void (*fn)(void); + const char* name; +} test_functions[] = { + LTC_TEST_FN(time_keysched), + LTC_TEST_FN(time_cipher_ecb), + LTC_TEST_FN(time_cipher_cbc), + LTC_TEST_FN(time_cipher_ctr), + LTC_TEST_FN(time_cipher_lrw), + LTC_TEST_FN(time_hash), + LTC_TEST_FN(time_macs), + LTC_TEST_FN(time_encmacs), + LTC_TEST_FN(time_prng), + LTC_TEST_FN(time_mult), + LTC_TEST_FN(time_sqr), + LTC_TEST_FN(time_rsa), + LTC_TEST_FN(time_dsa), + LTC_TEST_FN(time_ecc), + LTC_TEST_FN(time_dh), + LTC_TEST_FN(time_katja) +}; +char *single_test = NULL; +unsigned int i; + init_timer(); register_all_ciphers(); register_all_hashes(); @@ -1423,22 +1438,16 @@ if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT exit(EXIT_FAILURE); } -time_keysched(); -time_cipher_ecb(); -time_cipher_cbc(); -time_cipher_ctr(); -time_cipher_lrw(); -time_hash(); -time_macs(); -time_encmacs(); -time_prng(); -time_mult(); -time_sqr(); -time_rsa(); -time_dsa(); -time_ecc(); -time_katja(); -time_dh(); +/* single test name from commandline */ +if (argc > 1) single_test = argv[1]; + +for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) { + if (single_test && strstr(test_functions[i].name, single_test) == NULL) { + continue; + } + test_functions[i].fn(); +} + return EXIT_SUCCESS; }