tdb2: tdb_expand on empty database now tested.
[ccan] / ccan / tdb2 / test / run-fls.c
1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/free.c>
3 #include <ccan/tdb2/lock.c>
4 #include <ccan/tdb2/io.c>
5 #include <ccan/tap/tap.h>
6
7 static unsigned int dumb_fls(uint64_t num)
8 {
9         int i;
10
11         for (i = 63; i >= 0; i--) {
12                 if (num & (1ULL << i))
13                         break;
14         }
15         return i + 1;
16 }
17
18 int main(int argc, char *argv[])
19 {
20         unsigned int i, j;
21
22         plan_tests(64 * 64 + 2);
23
24         ok1(fls64(0) == 0);
25         ok1(dumb_fls(0) == 0);
26
27         for (i = 0; i < 64; i++) {
28                 for (j = 0; j < 64; j++) {
29                         uint64_t val = (1ULL << i) | (1ULL << j);
30                         ok(fls64(val) == dumb_fls(val),
31                            "%llu -> %u should be %u", (long long)val,
32                            fls64(val), dumb_fls(val));
33                 }
34         }
35         return exit_status();
36 }