]>
git.saurik.com Git - redis.git/blob - deps/jemalloc/test/bitmap.c
1 #define JEMALLOC_MANGLE
2 #include "jemalloc_test.h"
5 * Avoid using the assert() from jemalloc_internal.h, since it requires
6 * internal libjemalloc functionality.
11 * Directly include the bitmap code, since it isn't exposed outside
14 #include "../src/bitmap.c"
16 #if (LG_BITMAP_MAXBITS > 12)
19 # define MAXBITS (1U << LG_BITMAP_MAXBITS)
23 test_bitmap_size(void)
28 for (i
= 1; i
<= MAXBITS
; i
++) {
29 size_t size
= bitmap_size(i
);
30 assert(size
>= prev_size
);
36 test_bitmap_init(void)
40 for (i
= 1; i
<= MAXBITS
; i
++) {
42 bitmap_info_init(&binfo
, i
);
45 bitmap_t bitmap
[bitmap_info_ngroups(&binfo
)];
46 bitmap_init(bitmap
, &binfo
);
48 for (j
= 0; j
< i
; j
++)
49 assert(bitmap_get(bitmap
, &binfo
, j
) == false);
60 for (i
= 1; i
<= MAXBITS
; i
++) {
62 bitmap_info_init(&binfo
, i
);
65 bitmap_t bitmap
[bitmap_info_ngroups(&binfo
)];
66 bitmap_init(bitmap
, &binfo
);
68 for (j
= 0; j
< i
; j
++)
69 bitmap_set(bitmap
, &binfo
, j
);
70 assert(bitmap_full(bitmap
, &binfo
));
76 test_bitmap_unset(void)
80 for (i
= 1; i
<= MAXBITS
; i
++) {
82 bitmap_info_init(&binfo
, i
);
85 bitmap_t bitmap
[bitmap_info_ngroups(&binfo
)];
86 bitmap_init(bitmap
, &binfo
);
88 for (j
= 0; j
< i
; j
++)
89 bitmap_set(bitmap
, &binfo
, j
);
90 assert(bitmap_full(bitmap
, &binfo
));
91 for (j
= 0; j
< i
; j
++)
92 bitmap_unset(bitmap
, &binfo
, j
);
93 for (j
= 0; j
< i
; j
++)
94 bitmap_set(bitmap
, &binfo
, j
);
95 assert(bitmap_full(bitmap
, &binfo
));
101 test_bitmap_sfu(void)
105 for (i
= 1; i
<= MAXBITS
; i
++) {
107 bitmap_info_init(&binfo
, i
);
110 bitmap_t bitmap
[bitmap_info_ngroups(&binfo
)];
111 bitmap_init(bitmap
, &binfo
);
113 /* Iteratively set bits starting at the beginning. */
114 for (j
= 0; j
< i
; j
++)
115 assert(bitmap_sfu(bitmap
, &binfo
) == j
);
116 assert(bitmap_full(bitmap
, &binfo
));
119 * Iteratively unset bits starting at the end, and
120 * verify that bitmap_sfu() reaches the unset bits.
122 for (j
= i
- 1; j
>= 0; j
--) {
123 bitmap_unset(bitmap
, &binfo
, j
);
124 assert(bitmap_sfu(bitmap
, &binfo
) == j
);
125 bitmap_unset(bitmap
, &binfo
, j
);
127 assert(bitmap_get(bitmap
, &binfo
, 0) == false);
130 * Iteratively set bits starting at the beginning, and
131 * verify that bitmap_sfu() looks past them.
133 for (j
= 1; j
< i
; j
++) {
134 bitmap_set(bitmap
, &binfo
, j
- 1);
135 assert(bitmap_sfu(bitmap
, &binfo
) == j
);
136 bitmap_unset(bitmap
, &binfo
, j
);
138 assert(bitmap_sfu(bitmap
, &binfo
) == i
- 1);
139 assert(bitmap_full(bitmap
, &binfo
));
147 fprintf(stderr
, "Test begin\n");
155 fprintf(stderr
, "Test end\n");