]> git.ozlabs.org Git - ccan/blob - ccan/timer/test/run-ff.c
0f398d55721075aa21182994c05edbb812245bab
[ccan] / ccan / timer / test / run-ff.c
1 #include <ccan/timer/timer.h>
2 /* Include the C files directly. */
3 #include <ccan/timer/timer.c>
4 #include <ccan/tap/tap.h>
5
6 static struct timeabs timeabs_from_usec(unsigned long long usec)
7 {
8         struct timeabs epoch = { { 0, 0 } };
9         return timeabs_add(epoch, time_from_usec(usec));
10 }
11
12 int main(void)
13 {
14         struct timers timers;
15         struct timer t;
16         struct list_head expired;
17
18         /* This is how many tests you plan to run */
19         plan_tests(3);
20
21         timers_init(&timers, timeabs_from_usec(1364726722653919ULL));
22         timer_add(&timers, &t, timeabs_from_usec(1364726722703919ULL));
23         timers_expire(&timers, timeabs_from_usec(1364726722653920ULL), &expired);
24         ok1(list_empty(&expired));
25         timers_expire(&timers, timeabs_from_usec(1364726725454187ULL), &expired);
26         ok1(!list_empty(&expired));
27         ok1(list_top(&expired, struct timer, list) == &t);
28
29         timers_cleanup(&timers);
30
31         /* This exits depending on whether all tests passed */
32         return exit_status();
33 }