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