]>
git.proxmox.com Git - rustc.git/blob - src/jemalloc/test/integration/mallocx.c
1 #include "test/jemalloc_test.h"
4 #define MAXALIGN (((size_t)1) << 25)
14 assert_zu_ne(nsz
, 0, "Unexpected nallocx() error");
16 assert_ptr_not_null(p
, "Unexpected mallocx() error");
18 assert_zu_ge(rsz
, sz
, "Real size smaller than expected");
19 assert_zu_eq(nsz
, rsz
, "nallocx()/sallocx() size mismatch");
23 assert_ptr_not_null(p
, "Unexpected mallocx() error");
26 nsz
= nallocx(sz
, MALLOCX_ZERO
);
27 assert_zu_ne(nsz
, 0, "Unexpected nallocx() error");
28 p
= mallocx(sz
, MALLOCX_ZERO
);
29 assert_ptr_not_null(p
, "Unexpected mallocx() error");
31 assert_zu_eq(nsz
, rsz
, "nallocx()/sallocx() rsize mismatch");
36 TEST_BEGIN(test_alignment_and_size
)
38 size_t nsz
, rsz
, sz
, alignment
, total
;
42 for (i
= 0; i
< NITER
; i
++)
46 alignment
<= MAXALIGN
;
50 sz
< 3 * alignment
&& sz
< (1U << 31);
51 sz
+= (alignment
>> (LG_SIZEOF_PTR
-1)) - 1) {
52 for (i
= 0; i
< NITER
; i
++) {
53 nsz
= nallocx(sz
, MALLOCX_ALIGN(alignment
) |
56 "nallocx() error for alignment=%zu, "
57 "size=%zu (%#zx)", alignment
, sz
, sz
);
58 ps
[i
] = mallocx(sz
, MALLOCX_ALIGN(alignment
) |
60 assert_ptr_not_null(ps
[i
],
61 "mallocx() error for alignment=%zu, "
62 "size=%zu (%#zx)", alignment
, sz
, sz
);
63 rsz
= sallocx(ps
[i
], 0);
65 "Real size smaller than expected for "
66 "alignment=%zu, size=%zu", alignment
, sz
);
67 assert_zu_eq(nsz
, rsz
,
68 "nallocx()/sallocx() size mismatch for "
69 "alignment=%zu, size=%zu", alignment
, sz
);
71 (void *)((uintptr_t)ps
[i
] & (alignment
-1)),
72 "%p inadequately aligned for"
73 " alignment=%zu, size=%zu", ps
[i
],
76 if (total
>= (MAXALIGN
<< 1))
79 for (i
= 0; i
< NITER
; i
++) {
96 test_alignment_and_size
));