1 #include "test/jemalloc_test.h"
2
3 #define MAXALIGN (((size_t)1) << 22)
4 #define NITER 3
5
TEST_BEGIN(test_basic)6 TEST_BEGIN(test_basic)
7 {
8 void *ptr = mallocx(64, 0);
9 sdallocx(ptr, 64, 0);
10 }
11 TEST_END
12
TEST_BEGIN(test_alignment_and_size)13 TEST_BEGIN(test_alignment_and_size)
14 {
15 size_t nsz, sz, alignment, total;
16 unsigned i;
17 void *ps[NITER];
18
19 for (i = 0; i < NITER; i++)
20 ps[i] = NULL;
21
22 for (alignment = 8;
23 alignment <= MAXALIGN;
24 alignment <<= 1) {
25 total = 0;
26 for (sz = 1;
27 sz < 3 * alignment && sz < (1U << 31);
28 sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
29 for (i = 0; i < NITER; i++) {
30 nsz = nallocx(sz, MALLOCX_ALIGN(alignment) |
31 MALLOCX_ZERO);
32 ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) |
33 MALLOCX_ZERO);
34 total += nsz;
35 if (total >= (MAXALIGN << 1))
36 break;
37 }
38 for (i = 0; i < NITER; i++) {
39 if (ps[i] != NULL) {
40 sdallocx(ps[i], sz,
41 MALLOCX_ALIGN(alignment));
42 ps[i] = NULL;
43 }
44 }
45 }
46 }
47 }
48 TEST_END
49
50 int
main(void)51 main(void)
52 {
53
54 return (test(
55 test_basic,
56 test_alignment_and_size));
57 }
58