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)
16 #define NTESTS_REALLOC 10
18 static void test_basic_alloc(int nbits)
22 bitmap = bitmap_alloc0(nbits);
24 ok1(bitmap_empty(bitmap, nbits));
28 bitmap = bitmap_alloc1(nbits);
30 ok1(bitmap_full(bitmap, nbits));
35 static void test_realloc(int obits, int nbits)
41 bitmap = bitmap_alloc0(obits);
43 ok1(bitmap_empty(bitmap, obits));
45 bitmap = bitmap_realloc1(bitmap, obits, nbits);
48 ok1(bitmap_empty(bitmap, obits));
50 ok1(bitmap_empty(bitmap, nbits));
53 for (i = obits; i < nbits; i++)
54 wrong = wrong || !bitmap_test_bit(bitmap, i);
59 bitmap = bitmap_alloc1(obits);
61 ok1(bitmap_full(bitmap, obits));
63 bitmap = bitmap_realloc0(bitmap, obits, nbits);
66 ok1(bitmap_full(bitmap, obits));
68 ok1(bitmap_full(bitmap, nbits));
71 for (i = obits; i < nbits; i++)
72 wrong = wrong || bitmap_test_bit(bitmap, i);
82 /* This is how many tests you plan to run */
83 plan_tests(NSIZES * NTESTS_BASE + NSIZES * NSIZES * NTESTS_REALLOC);
85 for (i = 0; i < NSIZES; i++) {
86 diag("Testing %d-bit bitmap", bitmap_sizes[i]);
87 test_basic_alloc(bitmap_sizes[i]);
90 for (i = 0; i < NSIZES; i++) {
91 for (j = 0; j < NSIZES; j++) {
92 diag("Testing %d-bit => %d-bit bitmap",
93 bitmap_sizes[i], bitmap_sizes[j]);
95 test_realloc(bitmap_sizes[i], bitmap_sizes[j]);
99 /* This exits depending on whether all tests passed */
100 return exit_status();