X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fbitmap%2Ftest%2Frun.c;h=efd245d7774ef58f81a3d601e64f77744b77884d;hb=3f642347378afc9e1db1768d88c9f5b2baffe9ba;hp=5911a363429d204330225991af08733797aec429;hpb=ea15c79c29a3d86a36316e9b3c707cb6f5d0582b;p=ccan diff --git a/ccan/bitmap/test/run.c b/ccan/bitmap/test/run.c index 5911a363..efd245d7 100644 --- a/ccan/bitmap/test/run.c +++ b/ccan/bitmap/test/run.c @@ -1,6 +1,9 @@ #include #include #include +#include + +#include int bitmap_sizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, @@ -11,13 +14,21 @@ int bitmap_sizes[] = { #define NSIZES ARRAY_SIZE(bitmap_sizes) #define NTESTS 9 -static void test_sizes(int nbits) +static void test_sizes(int nbits, bool dynalloc) { - bitmap *bitmap = bitmap_alloc(nbits); + BITMAP_DECLARE(sbitmap, nbits); + uint32_t marker; + bitmap *bitmap; int i, j; bool wrong; - ok1(bitmap != NULL); + if (dynalloc) { + bitmap = bitmap_alloc(nbits); + ok1(bitmap != NULL); + } else { + bitmap = sbitmap; + marker = 0xdeadbeef; + } bitmap_zero(bitmap, nbits); wrong = false; @@ -78,20 +89,28 @@ static void test_sizes(int nbits) wrong = wrong || bitmap_full(bitmap, nbits); } ok1(!wrong); - - free(bitmap); + + if (dynalloc) { + free(bitmap); + } else { + ok1(marker == 0xdeadbeef); + } } int main(void) { int i; + bool dynalloc; /* This is how many tests you plan to run */ - plan_tests(NSIZES * NTESTS); + plan_tests(NSIZES * NTESTS * 2); for (i = 0; i < NSIZES; i++) { - diag("Testing %d-bit bitmap", bitmap_sizes[i]); - test_sizes(bitmap_sizes[i]); + foreach_int(dynalloc, false, true) { + diag("Testing %d-bit bitmap (%s allocation)", + bitmap_sizes[i], dynalloc ? "dynamic" : "static"); + test_sizes(bitmap_sizes[i], dynalloc); + } } /* This exits depending on whether all tests passed */