1 #include "test/jemalloc_test.h"
2
TEST_BEGIN(test_ticker_tick)3 TEST_BEGIN(test_ticker_tick)
4 {
5 #define NREPS 2
6 #define NTICKS 3
7 ticker_t ticker;
8 int32_t i, j;
9
10 ticker_init(&ticker, NTICKS);
11 for (i = 0; i < NREPS; i++) {
12 for (j = 0; j < NTICKS; j++) {
13 assert_u_eq(ticker_read(&ticker), NTICKS - j,
14 "Unexpected ticker value (i=%d, j=%d)", i, j);
15 assert_false(ticker_tick(&ticker),
16 "Unexpected ticker fire (i=%d, j=%d)", i, j);
17 }
18 assert_u32_eq(ticker_read(&ticker), 0,
19 "Expected ticker depletion");
20 assert_true(ticker_tick(&ticker),
21 "Expected ticker fire (i=%d)", i);
22 assert_u32_eq(ticker_read(&ticker), NTICKS,
23 "Expected ticker reset");
24 }
25 #undef NTICKS
26 }
27 TEST_END
28
TEST_BEGIN(test_ticker_ticks)29 TEST_BEGIN(test_ticker_ticks)
30 {
31 #define NTICKS 3
32 ticker_t ticker;
33
34 ticker_init(&ticker, NTICKS);
35
36 assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
37 assert_false(ticker_ticks(&ticker, NTICKS), "Unexpected ticker fire");
38 assert_u_eq(ticker_read(&ticker), 0, "Unexpected ticker value");
39 assert_true(ticker_ticks(&ticker, NTICKS), "Expected ticker fire");
40 assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
41
42 assert_true(ticker_ticks(&ticker, NTICKS + 1), "Expected ticker fire");
43 assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value");
44 #undef NTICKS
45 }
46 TEST_END
47
TEST_BEGIN(test_ticker_copy)48 TEST_BEGIN(test_ticker_copy)
49 {
50 #define NTICKS 3
51 ticker_t ta, tb;
52
53 ticker_init(&ta, NTICKS);
54 ticker_copy(&tb, &ta);
55 assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
56 assert_true(ticker_ticks(&tb, NTICKS + 1), "Expected ticker fire");
57 assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
58
59 ticker_tick(&ta);
60 ticker_copy(&tb, &ta);
61 assert_u_eq(ticker_read(&tb), NTICKS - 1, "Unexpected ticker value");
62 assert_true(ticker_ticks(&tb, NTICKS), "Expected ticker fire");
63 assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value");
64 #undef NTICKS
65 }
66 TEST_END
67
68 int
main(void)69 main(void)
70 {
71
72 return (test(
73 test_ticker_tick,
74 test_ticker_ticks,
75 test_ticker_copy));
76 }
77