1 #include <ccan/bitmap/bitmap.h>
2 #include <ccan/tap/tap.h>
3 #include <ccan/array_size/array_size.h>
4 #include <ccan/foreach/foreach.h>
6 #include <ccan/bitmap/bitmap.c>
9 1, 2, 3, 4, 5, 6, 7, 8,
11 64, 65, 127, 128, 129,
14 #define NSIZES ARRAY_SIZE(bitmap_sizes)
17 static void test_sizes(int nbits, bool dynalloc)
19 BITMAP_DECLARE(sbitmap, nbits);
26 bitmap = bitmap_alloc(nbits);
33 bitmap_zero(bitmap, nbits);
35 for (i = 0; i < nbits; i++) {
36 wrong = wrong || bitmap_test_bit(bitmap, i);
40 bitmap_fill(bitmap, nbits);
42 for (i = 0; i < nbits; i++) {
43 wrong = wrong || !bitmap_test_bit(bitmap, i);
48 for (i = 0; i < nbits; i++) {
49 bitmap_zero(bitmap, nbits);
50 bitmap_set_bit(bitmap, i);
51 for (j = 0; j < nbits; j++) {
54 wrong = wrong || (bitmap_test_bit(bitmap, j) != val);
60 for (i = 0; i < nbits; i++) {
61 bitmap_fill(bitmap, nbits);
62 bitmap_clear_bit(bitmap, i);
63 for (j = 0; j < nbits; j++) {
66 wrong = wrong || (bitmap_test_bit(bitmap, j) != val);
71 bitmap_zero(bitmap, nbits);
72 ok1(bitmap_empty(bitmap, nbits));
75 for (i = 0; i < nbits; i++) {
76 bitmap_zero(bitmap, nbits);
77 bitmap_set_bit(bitmap, i);
78 wrong = wrong || bitmap_empty(bitmap, nbits);
82 bitmap_fill(bitmap, nbits);
83 ok1(bitmap_full(bitmap, nbits));
86 for (i = 0; i < nbits; i++) {
87 bitmap_fill(bitmap, nbits);
88 bitmap_clear_bit(bitmap, i);
89 wrong = wrong || bitmap_full(bitmap, nbits);
96 ok1(marker == 0xdeadbeef);
105 /* This is how many tests you plan to run */
106 plan_tests(NSIZES * NTESTS * 2);
108 for (i = 0; i < NSIZES; i++) {
109 foreach_int(dynalloc, false, true) {
110 diag("Testing %d-bit bitmap (%s allocation)",
111 bitmap_sizes[i], dynalloc ? "dynamic" : "static");
112 test_sizes(bitmap_sizes[i], dynalloc);
116 /* This exits depending on whether all tests passed */
117 return exit_status();