From 8f2c9f7f0e35a0b465e612d7d0d078055c41f5db Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 22 Nov 2016 00:36:08 +0100 Subject: [PATCH] Add timer.c unit test Signed-off-by: Joachim Nilsson --- tests/Makefile.am | 1 + tests/timer.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/timer.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 4d9da9b..ad629ea 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,6 +2,7 @@ EXTRA_DIST = check.h CLEANFILES = *~ *.trs *.log TESTS = +TESTS += timer check_PROGRAMS = $(TESTS) diff --git a/tests/timer.c b/tests/timer.c new file mode 100644 index 0000000..e643b85 --- /dev/null +++ b/tests/timer.c @@ -0,0 +1,28 @@ +#include "check.h" +#include +#include + +#define TIMEOUT 2 /* 2 sec */ +struct timeval start; + +static void cb(uev_t *w, void *UNUSED(arg), int UNUSED(events)) +{ + struct timeval now; + + gettimeofday(&now, NULL); + fail_unless(now.tv_sec == start.tv_sec + TIMEOUT); + + uev_exit(w->ctx); +} + +int main(void) +{ + uev_t w; + uev_ctx_t ctx; + + uev_init(&ctx); + uev_timer_init(&ctx, &w, cb, NULL, TIMEOUT * 1000, 0); + gettimeofday(&start, NULL); + + return uev_run(&ctx, 0); +}