]>
git.saurik.com Git - redis.git/blob - deps/jemalloc/test/allocm.c
80be673b8fdb50cc46d5b99fe34495d26431fb67
1 #define JEMALLOC_MANGLE
2 #include "jemalloc_test.h"
5 /* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
6 #define MAXALIGN ((size_t)0x2000000LU)
14 size_t nsz
, rsz
, sz
, alignment
, total
;
18 malloc_printf("Test begin\n");
22 r
= nallocm(&nsz
, sz
, 0);
23 if (r
!= ALLOCM_SUCCESS
) {
24 malloc_printf("Unexpected nallocm() error\n");
28 r
= allocm(&p
, &rsz
, sz
, 0);
29 if (r
!= ALLOCM_SUCCESS
) {
30 malloc_printf("Unexpected allocm() error\n");
34 malloc_printf("Real size smaller than expected\n");
36 malloc_printf("nallocm()/allocm() rsize mismatch\n");
37 if (dallocm(p
, 0) != ALLOCM_SUCCESS
)
38 malloc_printf("Unexpected dallocm() error\n");
40 r
= allocm(&p
, NULL
, sz
, 0);
41 if (r
!= ALLOCM_SUCCESS
) {
42 malloc_printf("Unexpected allocm() error\n");
45 if (dallocm(p
, 0) != ALLOCM_SUCCESS
)
46 malloc_printf("Unexpected dallocm() error\n");
49 r
= nallocm(&nsz
, sz
, ALLOCM_ZERO
);
50 if (r
!= ALLOCM_SUCCESS
) {
51 malloc_printf("Unexpected nallocm() error\n");
55 r
= allocm(&p
, &rsz
, sz
, ALLOCM_ZERO
);
56 if (r
!= ALLOCM_SUCCESS
) {
57 malloc_printf("Unexpected allocm() error\n");
61 malloc_printf("nallocm()/allocm() rsize mismatch\n");
62 if (dallocm(p
, 0) != ALLOCM_SUCCESS
)
63 malloc_printf("Unexpected dallocm() error\n");
65 #if LG_SIZEOF_PTR == 3
66 alignment
= UINT64_C(0x8000000000000000);
67 sz
= UINT64_C(0x8000000000000000);
69 alignment
= 0x80000000LU
;
73 r
= nallocm(&nsz
, sz
, ALLOCM_ALIGN(alignment
));
74 if (r
== ALLOCM_SUCCESS
) {
76 "Expected error for nallocm(&nsz, %zu, %#x)\n",
77 sz
, ALLOCM_ALIGN(alignment
));
80 r
= allocm(&p
, &rsz
, sz
, ALLOCM_ALIGN(alignment
));
81 if (r
== ALLOCM_SUCCESS
) {
83 "Expected error for allocm(&p, %zu, %#x)\n",
84 sz
, ALLOCM_ALIGN(alignment
));
87 malloc_printf("nallocm()/allocm() rsize mismatch\n");
89 #if LG_SIZEOF_PTR == 3
90 alignment
= UINT64_C(0x4000000000000000);
91 sz
= UINT64_C(0x8400000000000001);
93 alignment
= 0x40000000LU
;
97 r
= nallocm(&nsz
, sz
, ALLOCM_ALIGN(alignment
));
98 if (r
!= ALLOCM_SUCCESS
)
99 malloc_printf("Unexpected nallocm() error\n");
101 r
= allocm(&p
, &rsz
, sz
, ALLOCM_ALIGN(alignment
));
102 if (r
== ALLOCM_SUCCESS
) {
104 "Expected error for allocm(&p, %zu, %#x)\n",
105 sz
, ALLOCM_ALIGN(alignment
));
109 #if LG_SIZEOF_PTR == 3
110 sz
= UINT64_C(0xfffffffffffffff0);
115 r
= nallocm(&nsz
, sz
, ALLOCM_ALIGN(alignment
));
116 if (r
== ALLOCM_SUCCESS
) {
118 "Expected error for nallocm(&nsz, %zu, %#x)\n",
119 sz
, ALLOCM_ALIGN(alignment
));
122 r
= allocm(&p
, &rsz
, sz
, ALLOCM_ALIGN(alignment
));
123 if (r
== ALLOCM_SUCCESS
) {
125 "Expected error for allocm(&p, %zu, %#x)\n",
126 sz
, ALLOCM_ALIGN(alignment
));
129 malloc_printf("nallocm()/allocm() rsize mismatch\n");
131 for (i
= 0; i
< NITER
; i
++)
135 alignment
<= MAXALIGN
;
138 malloc_printf("Alignment: %zu\n", alignment
);
140 sz
< 3 * alignment
&& sz
< (1U << 31);
141 sz
+= (alignment
>> (LG_SIZEOF_PTR
-1)) - 1) {
142 for (i
= 0; i
< NITER
; i
++) {
144 r
= nallocm(&nsz
, sz
,
145 ALLOCM_ALIGN(alignment
) | ALLOCM_ZERO
);
146 if (r
!= ALLOCM_SUCCESS
) {
148 "nallocm() error for size %zu"
154 r
= allocm(&ps
[i
], &rsz
, sz
,
155 ALLOCM_ALIGN(alignment
) | ALLOCM_ZERO
);
156 if (r
!= ALLOCM_SUCCESS
) {
158 "allocm() error for size %zu"
165 "Real size smaller than"
170 "nallocm()/allocm() rsize"
173 if ((uintptr_t)p
& (alignment
-1)) {
175 "%p inadequately aligned for"
176 " alignment: %zu\n", p
, alignment
);
178 sallocm(ps
[i
], &rsz
, 0);
180 if (total
>= (MAXALIGN
<< 1))
183 for (i
= 0; i
< NITER
; i
++) {
192 malloc_printf("Test end\n");