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>
7 1, 2, 3, 4, 5, 6, 7, 8,
12 #define NSIZES ARRAY_SIZE(bitmap_sizes)
15 static void test_sizes(int nbits, bool dynalloc)
17 BITMAP_DECLARE(sbitmap, nbits);
24 bitmap = bitmap_alloc(nbits);
31 bitmap_zero(bitmap, nbits);
33 for (i = 0; i < nbits; i++) {
34 wrong = wrong || bitmap_test_bit(bitmap, i);
38 bitmap_fill(bitmap, nbits);
40 for (i = 0; i < nbits; i++) {
41 wrong = wrong || !bitmap_test_bit(bitmap, i);
46 for (i = 0; i < nbits; i++) {
47 bitmap_zero(bitmap, nbits);
48 bitmap_set_bit(bitmap, i);
49 for (j = 0; j < nbits; j++) {
52 wrong = wrong || (bitmap_test_bit(bitmap, j) != val);
58 for (i = 0; i < nbits; i++) {
59 bitmap_fill(bitmap, nbits);
60 bitmap_clear_bit(bitmap, i);
61 for (j = 0; j < nbits; j++) {
64 wrong = wrong || (bitmap_test_bit(bitmap, j) != val);
69 bitmap_zero(bitmap, nbits);
70 ok1(bitmap_empty(bitmap, nbits));
73 for (i = 0; i < nbits; i++) {
74 bitmap_zero(bitmap, nbits);
75 bitmap_set_bit(bitmap, i);
76 wrong = wrong || bitmap_empty(bitmap, nbits);
80 bitmap_fill(bitmap, nbits);
81 ok1(bitmap_full(bitmap, nbits));
84 for (i = 0; i < nbits; i++) {
85 bitmap_fill(bitmap, nbits);
86 bitmap_clear_bit(bitmap, i);
87 wrong = wrong || bitmap_full(bitmap, nbits);
94 ok1(marker == 0xdeadbeef);
103 /* This is how many tests you plan to run */
104 plan_tests(NSIZES * NTESTS * 2);
106 for (i = 0; i < NSIZES; i++) {
107 foreach_int(dynalloc, false, true) {
108 diag("Testing %d-bit bitmap (%s allocation)",
109 bitmap_sizes[i], dynalloc ? "dynamic" : "static");
110 test_sizes(bitmap_sizes[i], dynalloc);
114 /* This exits depending on whether all tests passed */
115 return exit_status();