]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/tests/bitmap_test.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / tests / bitmap_test.c
index 8eb5c35cc9f466a14517cb325b4bb780273cdb79..074e0a67f00c73c13246a49936f2ec437738d475 100644 (file)
@@ -32,6 +32,7 @@
 #include <tests/xnupost.h>
 #include <kern/kalloc.h>
 #include <kern/bits.h>
+#include <pexpert/pexpert.h>
 
 extern void dump_bitmap_next(bitmap_t *map, uint nbits);
 extern void dump_bitmap_lsb(bitmap_t *map, uint nbits);
@@ -73,6 +74,7 @@ test_bitmap(void)
                for (uint i = 0; i < nbits; i++) {
                        bitmap_set(map, i);
                }
+               assert(bitmap_is_full(map, nbits));
 
                int expected_result = nbits - 1;
                for (int i = bitmap_first(map, nbits); i >= 0; i = bitmap_next(map, i)) {
@@ -81,6 +83,21 @@ test_bitmap(void)
                }
                assert(expected_result == -1);
 
+               bitmap_zero(map, nbits);
+
+               assert(bitmap_first(map, nbits) == -1);
+               assert(bitmap_lsb_first(map, nbits) == -1);
+
+               bitmap_full(map, nbits);
+               assert(bitmap_is_full(map, nbits));
+
+               expected_result = nbits - 1;
+               for (int i = bitmap_first(map, nbits); i >= 0; i = bitmap_next(map, i)) {
+                       assert(i == expected_result);
+                       expected_result--;
+               }
+               assert(expected_result == -1);
+
                expected_result = 0;
                for (int i = bitmap_lsb_first(map, nbits); i >= 0; i = bitmap_lsb_next(map, nbits, i)) {
                        assert(i == expected_result);
@@ -90,11 +107,68 @@ test_bitmap(void)
 
                for (uint i = 0; i < nbits; i++) {
                        bitmap_clear(map, i);
+                       assert(!bitmap_is_full(map, nbits));
+                       bitmap_set(map, i);
+                       assert(bitmap_is_full(map, nbits));
                }
+
+               for (uint i = 0; i < nbits; i++) {
+                       bitmap_clear(map, i);
+               }
+               assert(bitmap_first(map, nbits) == -1);
+               assert(bitmap_lsb_first(map, nbits) == -1);
+
+               /* bitmap_not */
+               bitmap_not(map, map, nbits);
+               assert(bitmap_is_full(map, nbits));
+
+               bitmap_not(map, map, nbits);
                assert(bitmap_first(map, nbits) == -1);
                assert(bitmap_lsb_first(map, nbits) == -1);
 
+               /* bitmap_and */
+               bitmap_t *map0 = bitmap_alloc(nbits);
+               assert(bitmap_first(map0, nbits) == -1);
+
+               bitmap_t *map1 = bitmap_alloc(nbits);
+               bitmap_full(map1, nbits);
+               assert(bitmap_is_full(map1, nbits));
+
+               bitmap_and(map, map0, map1, nbits);
+               assert(bitmap_first(map, nbits) == -1);
+
+               bitmap_and(map, map1, map1, nbits);
+               assert(bitmap_is_full(map, nbits));
+
+               /* bitmap_and_not */
+               bitmap_and_not(map, map0, map1, nbits);
+               assert(bitmap_first(map, nbits) == -1);
+
+               bitmap_and_not(map, map1, map0, nbits);
+               assert(bitmap_is_full(map, nbits));
+
+               /* bitmap_equal */
+               for (uint i = 0; i < nbits; i++) {
+                       bitmap_clear(map, i);
+                       assert(!bitmap_equal(map, map1, nbits));
+                       bitmap_set(map, i);
+                       assert(bitmap_equal(map, map1, nbits));
+               }
+
+               /* bitmap_and_not_mask_first */
+               for (uint i = 0; i < nbits; i++) {
+                       bitmap_clear(map, i);
+                       expected_result = i;
+                       int result = bitmap_and_not_mask_first(map1, map, nbits);
+                       assert(result == expected_result);
+                       bitmap_set(map, i);
+                       result = bitmap_and_not_mask_first(map1, map, nbits);
+                       assert(result == -1);
+               }
+
                bitmap_free(map, nbits);
+               bitmap_free(map0, nbits);
+               bitmap_free(map1, nbits);
        }
 }