MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

ccan/ccan/timer/test/run.c:19–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19int main(void)
20{
21 struct timers timers;
22 struct timer t[64];
23 struct timemono earliest;
24 uint64_t i;
25 const struct timemono epoch = { { 0, 0 } };
26
27 /* This is how many tests you plan to run */
28 plan_tests(495);
29
30 timers_init(&timers, epoch);
31 ok1(timers_check(&timers, NULL));
32 ok1(!timer_earliest(&timers, &earliest));
33
34 timer_init(&t[0]);
35 /* timer_del can be called immediately after init. */
36 timer_del(&timers, &t[0]);
37
38 timer_addmono(&timers, &t[0], timemono_from_nsec(1));
39 ok1(timers_check(&timers, NULL));
40 ok1(timer_earliest(&timers, &earliest));
41 ok1(timemono_eq(earliest, grains_to_time(t[0].time)));
42 timer_del(&timers, &t[0]);
43 ok1(timers_check(&timers, NULL));
44 ok1(!timer_earliest(&timers, &earliest));
45
46 /* timer_del can be called twice, no problems. */
47 timer_del(&timers, &t[0]);
48
49 /* Check timer ordering. */
50 for (i = 0; i < 32; i++) {
51 timer_init(&t[i*2]);
52 timer_addmono(&timers, &t[i*2], timemono_from_nsec(1ULL << i));
53 ok1(timers_check(&timers, NULL));
54 timer_init(&t[i*2+1]);
55 timer_addmono(&timers, &t[i*2+1], timemono_from_nsec((1ULL << i) + 1));
56 ok1(timers_check(&timers, NULL));
57 }
58
59 for (i = 0; i < 32; i++) {
60 const struct timer *t1, *t2;
61
62 t1 = get_first(&timers);
63 ok1(t1 == &t[i*2] || t1 == &t[i*2+1]);
64 timer_del(&timers, (struct timer *)t1);
65 ok1(timers_check(&timers, NULL));
66
67 t2 = get_first(&timers);
68 ok1(t2 != t1 && (t2 == &t[i*2] || t2 == &t[i*2+1]));
69 timer_del(&timers, (struct timer *)t2);
70 ok1(timers_check(&timers, NULL));
71 }
72
73 /* Check expiry. */
74 for (i = 0; i < 32; i++) {
75 uint64_t exp = (uint64_t)TIMER_GRANULARITY << i;
76

Callers

nothing calls this directly

Calls 14

timers_initFunction · 0.85
timers_checkFunction · 0.85
timer_earliestFunction · 0.85
timer_initFunction · 0.85
timer_delFunction · 0.85
timer_addmonoFunction · 0.85
timemono_eqFunction · 0.85
grains_to_timeFunction · 0.85
get_firstFunction · 0.85
timers_expireFunction · 0.85
timers_cleanupFunction · 0.85
timer_addrelFunction · 0.85

Tested by

no test coverage detected