tdb2: feature support.
[ccan] / ccan / tdb2 / test / run-001-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/tdb2/hash.c>
6 #include <ccan/tdb2/transaction.c>
7 #include <ccan/tdb2/check.c>
8 #include <ccan/tap/tap.h>
9
10 static unsigned int dumb_fls(uint64_t num)
11 {
12         int i;
13
14         for (i = 63; i >= 0; i--) {
15                 if (num & (1ULL << i))
16                         break;
17         }
18         return i + 1;
19 }
20
21 int main(int argc, char *argv[])
22 {
23         unsigned int i, j;
24
25         plan_tests(64 * 64 + 2);
26
27         ok1(fls64(0) == 0);
28         ok1(dumb_fls(0) == 0);
29
30         for (i = 0; i < 64; i++) {
31                 for (j = 0; j < 64; j++) {
32                         uint64_t val = (1ULL << i) | (1ULL << j);
33                         ok(fls64(val) == dumb_fls(val),
34                            "%llu -> %u should be %u", (long long)val,
35                            fls64(val), dumb_fls(val));
36                 }
37         }
38         return exit_status();
39 }