]>
git.saurik.com Git - redis.git/blob - deps/jemalloc/test/bitmap.c
b2cb63004bca0de6f4e21408e0e2925006114414
1 #define JEMALLOC_MANGLE
2 #include "jemalloc_test.h"
4 #if (LG_BITMAP_MAXBITS > 12)
7 # define MAXBITS (1U << LG_BITMAP_MAXBITS)
11 test_bitmap_size(void)
16 for (i
= 1; i
<= MAXBITS
; i
++) {
17 size_t size
= bitmap_size(i
);
18 assert(size
>= prev_size
);
24 test_bitmap_init(void)
28 for (i
= 1; i
<= MAXBITS
; i
++) {
30 bitmap_info_init(&binfo
, i
);
33 bitmap_t
*bitmap
= malloc(sizeof(bitmap_t
) *
34 bitmap_info_ngroups(&binfo
));
35 bitmap_init(bitmap
, &binfo
);
37 for (j
= 0; j
< i
; j
++)
38 assert(bitmap_get(bitmap
, &binfo
, j
) == false);
50 for (i
= 1; i
<= MAXBITS
; i
++) {
52 bitmap_info_init(&binfo
, i
);
55 bitmap_t
*bitmap
= malloc(sizeof(bitmap_t
) *
56 bitmap_info_ngroups(&binfo
));
57 bitmap_init(bitmap
, &binfo
);
59 for (j
= 0; j
< i
; j
++)
60 bitmap_set(bitmap
, &binfo
, j
);
61 assert(bitmap_full(bitmap
, &binfo
));
68 test_bitmap_unset(void)
72 for (i
= 1; i
<= MAXBITS
; i
++) {
74 bitmap_info_init(&binfo
, i
);
77 bitmap_t
*bitmap
= malloc(sizeof(bitmap_t
) *
78 bitmap_info_ngroups(&binfo
));
79 bitmap_init(bitmap
, &binfo
);
81 for (j
= 0; j
< i
; j
++)
82 bitmap_set(bitmap
, &binfo
, j
);
83 assert(bitmap_full(bitmap
, &binfo
));
84 for (j
= 0; j
< i
; j
++)
85 bitmap_unset(bitmap
, &binfo
, j
);
86 for (j
= 0; j
< i
; j
++)
87 bitmap_set(bitmap
, &binfo
, j
);
88 assert(bitmap_full(bitmap
, &binfo
));
99 for (i
= 1; i
<= MAXBITS
; i
++) {
101 bitmap_info_init(&binfo
, i
);
104 bitmap_t
*bitmap
= malloc(sizeof(bitmap_t
) *
105 bitmap_info_ngroups(&binfo
));
106 bitmap_init(bitmap
, &binfo
);
108 /* Iteratively set bits starting at the beginning. */
109 for (j
= 0; j
< i
; j
++)
110 assert(bitmap_sfu(bitmap
, &binfo
) == j
);
111 assert(bitmap_full(bitmap
, &binfo
));
114 * Iteratively unset bits starting at the end, and
115 * verify that bitmap_sfu() reaches the unset bits.
117 for (j
= i
- 1; j
>= 0; j
--) {
118 bitmap_unset(bitmap
, &binfo
, j
);
119 assert(bitmap_sfu(bitmap
, &binfo
) == j
);
120 bitmap_unset(bitmap
, &binfo
, j
);
122 assert(bitmap_get(bitmap
, &binfo
, 0) == false);
125 * Iteratively set bits starting at the beginning, and
126 * verify that bitmap_sfu() looks past them.
128 for (j
= 1; j
< i
; j
++) {
129 bitmap_set(bitmap
, &binfo
, j
- 1);
130 assert(bitmap_sfu(bitmap
, &binfo
) == j
);
131 bitmap_unset(bitmap
, &binfo
, j
);
133 assert(bitmap_sfu(bitmap
, &binfo
) == i
- 1);
134 assert(bitmap_full(bitmap
, &binfo
));
143 malloc_printf("Test begin\n");
151 malloc_printf("Test end\n");