1 #define CCAN_LIKELY_DEBUG 1
2 #include <ccan/likely/likely.c>
3 #include <ccan/likely/likely.h>
4 #include <ccan/tap/tap.h>
7 static bool one_seems_likely(unsigned int val)
14 static bool one_seems_unlikely(unsigned int val)
16 if (unlikely(val == 1))
21 static bool likely_one_unlikely_two(unsigned int val1, unsigned int val2)
23 /* Same line, check we don't get confused! */
24 if (likely(val1 == 1) && unlikely(val2 == 2))
29 int main(int argc, char *argv[])
35 /* Correct guesses. */
37 ok1(likely_stats(0, 90) == NULL);
38 one_seems_unlikely(2);
39 ok1(likely_stats(0, 90) == NULL);
41 /* Incorrect guesses. */
44 /* Hasn't been hit 4 times, so this fails */
45 ok1(!likely_stats(4, 90));
46 bad = likely_stats(3, 90);
47 ok(strends(bad, "run-debug.c:9:likely(val == 1) correct 33% (1/3)"),
48 "likely_stats returned %s", bad);
50 /* Nothing else above 90% */
51 ok1(!likely_stats(0, 90));
53 /* This should get everything. */
54 bad = likely_stats(0, 100);
55 ok(strends(bad, "run-debug.c:16:unlikely(val == 1) correct 100% (1/1)"),
56 "likely_stats returned %s", bad);
58 /* Nothing left (table is actually cleared) */
59 ok1(!likely_stats(0, 100));
61 /* Make sure unlikely works */
62 one_seems_unlikely(0);
63 one_seems_unlikely(2);
64 one_seems_unlikely(1);
66 bad = likely_stats(0, 90);
67 ok(strends(bad, "run-debug.c:16:unlikely(val == 1) correct 66% (2/3)"),
68 "likely_stats returned %s", bad);
69 ok1(!likely_stats(0, 100));
71 likely_one_unlikely_two(1, 1);
72 likely_one_unlikely_two(1, 1);
73 likely_one_unlikely_two(1, 1);
74 ok1(!likely_stats(0, 90));
75 likely_one_unlikely_two(1, 2);
77 bad = likely_stats(0, 90);
78 ok(strends(bad, "run-debug.c:24:unlikely(val2 == 2) correct 75% (3/4)"),
79 "likely_stats returned %s", bad);
80 bad = likely_stats(0, 100);
81 ok(strends(bad, "run-debug.c:24:likely(val1 == 1) correct 100% (4/4)"),
82 "likely_stats returned %s", bad);
84 ok1(!likely_stats(0, 100));