1 #define CCAN_TIMER_DEBUG
2 /* Include the C files directly. */
3 #include <ccan/timer/timer.c>
4 #include <ccan/tap/tap.h>
6 static void *test_alloc(size_t len, void *arg)
12 static void test_free(const void *p, void *arg)
20 static struct timemono timemono_from_nsec(unsigned long long nsec)
22 struct timemono epoch = { { 0, 0 } };
23 return timemono_add(epoch, time_from_nsec(nsec));
30 size_t num_allocs = 0;
31 const struct timemono epoch = { { 0, 0 } };
35 timers_set_allocator(test_alloc, test_free, &num_allocs);
36 timers_init(&timers, epoch);
39 timer_addmono(&timers, &t[0],
40 timemono_from_nsec(TIMER_GRANULARITY << TIMER_LEVEL_BITS));
41 timers_expire(&timers, timemono_from_nsec(1));
43 timer_del(&timers, &t[0]);
45 timers_cleanup(&timers);
48 /* Should restore defaults */
49 timers_set_allocator(NULL, NULL, NULL);
50 ok1(timer_alloc == timer_default_alloc);
51 ok1(timer_free == timer_default_free);
53 timers_init(&timers, epoch);
54 timer_addmono(&timers, &t[0],
55 timemono_from_nsec(TIMER_GRANULARITY << TIMER_LEVEL_BITS));
57 timers_cleanup(&timers);
60 /* This exits depending on whether all tests passed */