From a06cba4cb557ad87f389a1b2a526f82ea5e2ae9d Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Fri, 9 Jun 2017 13:34:26 +0200 Subject: [PATCH] fix tests when compiled for pthread --- tests/test.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/test.c b/tests/test.c index 76aab18..c0c4563 100644 --- a/tests/test.c +++ b/tests/test.c @@ -32,6 +32,10 @@ static const test_function test_functions[] = LTC_TEST_FN(katja_test), LTC_TEST_FN(file_test), LTC_TEST_FN(multi_test), + /* keep the prng_test always at the end as + * it has to be handled specially when + * testing with LTC_PTHREAD enabled + */ LTC_TEST_FN(prng_test), }; @@ -72,7 +76,7 @@ typedef struct pthread_t thread_id; const test_function* t; int err; - ulong64 ts; + ulong64 delta; } thread_info; static void *run(void *arg) @@ -82,7 +86,7 @@ static void *run(void *arg) ts = epoch_usec(); tinfo->err = tinfo->t->fn(); - tinfo->ts = epoch_usec() - ts; + tinfo->delta = epoch_usec() - ts; return arg; } @@ -322,6 +326,7 @@ int main(int argc, char **argv) if (fn_len < len) fn_len = len; #ifdef LTC_PTHREAD + if(test_functions[i].fn == prng_test) continue; tinfo[i].t = &test_functions[i]; x = pthread_create(&tinfo[i].thread_id, NULL, run, &tinfo[i]); if (x != 0) { @@ -348,20 +353,26 @@ int main(int argc, char **argv) fflush(stdout); #ifdef LTC_PTHREAD - x = pthread_join(tinfo[i].thread_id, (void**)&res); - if (x != 0){ - printf("\n\nFAILURE: pthread_join\n"); - return EXIT_FAILURE; + if(test_functions[i].fn != prng_test) { + x = pthread_join(tinfo[i].thread_id, (void**)&res); + if (x != 0){ + printf("\n\nFAILURE: pthread_join\n"); + return EXIT_FAILURE; + } + x = res->err; + delta = res->delta; + } + else { + ts = epoch_usec(); + x = test_functions[i].fn(); + delta = (long)(epoch_usec() - ts); } - ts = res->ts; - x = res->err; #else ts = epoch_usec(); x = test_functions[i].fn(); delta = (long)(epoch_usec() - ts); - dur += delta; #endif - real += dur; + real += delta; if (x == CRYPT_OK) { printf("passed %10.3fms", (double)(delta)/1000);