summaryrefslogtreecommitdiff
path: root/src/ipcpd/tests/timerwheel_test.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-11-25 18:39:26 +0100
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-11-25 18:39:26 +0100
commitbf596a9abd6dc05b0d15e8401d267696632350a4 (patch)
tree4ad06a26bea1e80ba292f516da3afb34478d5af6 /src/ipcpd/tests/timerwheel_test.c
parentaee22e3b33e3e051cbc0f99ca033faf5fac22990 (diff)
downloadouroboros-bf596a9abd6dc05b0d15e8401d267696632350a4.tar.gz
ouroboros-bf596a9abd6dc05b0d15e8401d267696632350a4.zip
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.
Diffstat (limited to 'src/ipcpd/tests/timerwheel_test.c')
-rw-r--r--src/ipcpd/tests/timerwheel_test.c25
1 files changed, 16 insertions, 9 deletions
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;
}