From bf596a9abd6dc05b0d15e8401d267696632350a4 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Fri, 25 Nov 2016 18:39:26 +0100 Subject: ipcpd, lib: Fix timerwheel issues / time_utils Timerwheel would skip some additions due to a missed wakeup signal. Addition of timespecs and timevals in the time utilities would overflow tv_nsec/tv_usec if the sum is an integer number of seconds. --- src/ipcpd/tests/timerwheel_test.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/ipcpd/tests') diff --git a/src/ipcpd/tests/timerwheel_test.c b/src/ipcpd/tests/timerwheel_test.c index 615e6e41..9274577a 100644 --- a/src/ipcpd/tests/timerwheel_test.c +++ b/src/ipcpd/tests/timerwheel_test.c @@ -54,16 +54,18 @@ int timerwheel_test(int argc, char ** argv) (void) argc; (void) argv; - srand(time(NULL)); - total = 0; + srand(time(NULL)); + resolution = rand() % (MAX_RESOLUTION - 1) + 1; elements = rand() % (MAX_ELEMENTS - 10) + 10; tw = timerwheel_create(resolution, resolution * elements); - if (tw == NULL) + if (tw == NULL) { + printf("Failed to create timerwheel.\n"); return -1; + } wait.tv_sec = (resolution * elements) / 1000; wait.tv_nsec = ((resolution * elements) % 1000) * MILLION; @@ -74,19 +76,24 @@ int timerwheel_test(int argc, char ** argv) int delay = rand() % (resolution * elements); int var = rand() % 5; check_total += var; - timerwheel_add(tw, - (void (*)(void *)) add, - (void *) &var, - sizeof(var), - delay); + if (timerwheel_add(tw, + (void (*)(void *)) add, + (void *) &var, + sizeof(var), + delay)) { + printf("Failed to add function."); + return -1; + } } nanosleep(&wait, NULL); timerwheel_destroy(tw); - if (total != check_total) + if (total != check_total) { + printf("Totals do not match.\n"); return -1; + } return 0; } -- cgit v1.2.3