make it possible to pass a single timing test to run

This commit is contained in:
Steffen Jaeckel 2017-06-09 18:30:18 +02:00
parent e60d2076c5
commit e3329bec26

View File

@ -133,7 +133,7 @@ static void init_timer(void)
fprintf(stderr, "Clock Skew: %lu\n", (unsigned long)skew); fprintf(stderr, "Clock Skew: %lu\n", (unsigned long)skew);
} }
static int time_keysched(void) static void time_keysched(void)
{ {
unsigned long x, y1; unsigned long x, y1;
ulong64 t1, c1; ulong64 t1, c1;
@ -165,12 +165,10 @@ static int time_keysched(void)
#undef DO1 #undef DO1
} }
tally_results(0); tally_results(0);
return 0;
} }
#ifdef LTC_ECB_MODE #ifdef LTC_ECB_MODE
static int time_cipher_ecb(void) static void time_cipher_ecb(void)
{ {
unsigned long x, y1; unsigned long x, y1;
ulong64 t1, t2, c1, c2, a1, a2; ulong64 t1, t2, c1, c2, a1, a2;
@ -237,15 +235,13 @@ static int time_cipher_ecb(void)
#undef DO1 #undef DO1
} }
tally_results(1); tally_results(1);
return 0;
} }
#else #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 #endif
#ifdef LTC_CBC_MODE #ifdef LTC_CBC_MODE
static int time_cipher_cbc(void) static void time_cipher_cbc(void)
{ {
unsigned long x, y1; unsigned long x, y1;
ulong64 t1, t2, c1, c2, a1, a2; ulong64 t1, t2, c1, c2, a1, a2;
@ -312,15 +308,13 @@ static int time_cipher_cbc(void)
#undef DO1 #undef DO1
} }
tally_results(1); tally_results(1);
return 0;
} }
#else #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 #endif
#ifdef LTC_CTR_MODE #ifdef LTC_CTR_MODE
static int time_cipher_ctr(void) static void time_cipher_ctr(void)
{ {
unsigned long x, y1; unsigned long x, y1;
ulong64 t1, t2, c1, c2, a1, a2; ulong64 t1, t2, c1, c2, a1, a2;
@ -387,15 +381,13 @@ static int time_cipher_ctr(void)
#undef DO1 #undef DO1
} }
tally_results(1); tally_results(1);
return 0;
} }
#else #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 #endif
#ifdef LTC_LRW_MODE #ifdef LTC_LRW_MODE
static int time_cipher_lrw(void) static void time_cipher_lrw(void)
{ {
unsigned long x, y1; unsigned long x, y1;
ulong64 t1, t2, c1, c2, a1, a2; ulong64 t1, t2, c1, c2, a1, a2;
@ -464,15 +456,13 @@ static int time_cipher_lrw(void)
#undef DO1 #undef DO1
} }
tally_results(1); tally_results(1);
return 0;
} }
#else #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 #endif
static int time_hash(void) static void time_hash(void)
{ {
unsigned long x, y1, len; unsigned long x, y1, len;
ulong64 t1, t2, c1, c2; ulong64 t1, t2, c1, c2;
@ -519,8 +509,6 @@ static int time_hash(void)
#undef DO1 #undef DO1
} }
tally_results(2); tally_results(2);
return 0;
} }
/*#warning you need an mp_rand!!!*/ /*#warning you need an mp_rand!!!*/
@ -1399,9 +1387,36 @@ static void time_encmacs(void)
time_encmacs_(32); time_encmacs_(32);
} }
int main(void) #define LTC_TEST_FN(f) { f, #f }
int main(int argc, char **argv)
{ {
int err; 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(); init_timer();
register_all_ciphers(); register_all_ciphers();
register_all_hashes(); register_all_hashes();
@ -1423,22 +1438,16 @@ if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
time_keysched(); /* single test name from commandline */
time_cipher_ecb(); if (argc > 1) single_test = argv[1];
time_cipher_cbc();
time_cipher_ctr(); for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) {
time_cipher_lrw(); if (single_test && strstr(test_functions[i].name, single_test) == NULL) {
time_hash(); continue;
time_macs(); }
time_encmacs(); test_functions[i].fn();
time_prng(); }
time_mult();
time_sqr();
time_rsa();
time_dsa();
time_ecc();
time_katja();
time_dh();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }