]>
git.saurik.com Git - redis.git/blob - deps/jemalloc/test/allocm.c
5 #define JEMALLOC_MANGLE
6 #include "jemalloc_test.h"
9 /* #define MAXALIGN ((size_t)0x80000000000LLU) */
10 #define MAXALIGN ((size_t)0x2000000LLU)
18 size_t sz
, alignment
, total
, tsz
;
22 fprintf(stderr
, "Test begin\n");
25 r
= JEMALLOC_P(allocm
)(&p
, &sz
, 42, 0);
26 if (r
!= ALLOCM_SUCCESS
) {
27 fprintf(stderr
, "Unexpected allocm() error\n");
31 fprintf(stderr
, "Real size smaller than expected\n");
32 if (JEMALLOC_P(dallocm
)(p
, 0) != ALLOCM_SUCCESS
)
33 fprintf(stderr
, "Unexpected dallocm() error\n");
35 r
= JEMALLOC_P(allocm
)(&p
, NULL
, 42, 0);
36 if (r
!= ALLOCM_SUCCESS
) {
37 fprintf(stderr
, "Unexpected allocm() error\n");
40 if (JEMALLOC_P(dallocm
)(p
, 0) != ALLOCM_SUCCESS
)
41 fprintf(stderr
, "Unexpected dallocm() error\n");
43 r
= JEMALLOC_P(allocm
)(&p
, NULL
, 42, ALLOCM_ZERO
);
44 if (r
!= ALLOCM_SUCCESS
) {
45 fprintf(stderr
, "Unexpected allocm() error\n");
48 if (JEMALLOC_P(dallocm
)(p
, 0) != ALLOCM_SUCCESS
)
49 fprintf(stderr
, "Unexpected dallocm() error\n");
51 #if LG_SIZEOF_PTR == 3
52 alignment
= 0x8000000000000000LLU
;
53 sz
= 0x8000000000000000LLU
;
55 alignment
= 0x80000000LU
;
58 r
= JEMALLOC_P(allocm
)(&p
, NULL
, sz
, ALLOCM_ALIGN(alignment
));
59 if (r
== ALLOCM_SUCCESS
) {
61 "Expected error for allocm(&p, %zu, 0x%x)\n",
62 sz
, ALLOCM_ALIGN(alignment
));
65 #if LG_SIZEOF_PTR == 3
66 alignment
= 0x4000000000000000LLU
;
67 sz
= 0x8400000000000001LLU
;
69 alignment
= 0x40000000LU
;
72 r
= JEMALLOC_P(allocm
)(&p
, NULL
, sz
, ALLOCM_ALIGN(alignment
));
73 if (r
== ALLOCM_SUCCESS
) {
75 "Expected error for allocm(&p, %zu, 0x%x)\n",
76 sz
, ALLOCM_ALIGN(alignment
));
80 #if LG_SIZEOF_PTR == 3
81 sz
= 0xfffffffffffffff0LLU
;
85 r
= JEMALLOC_P(allocm
)(&p
, NULL
, sz
, ALLOCM_ALIGN(alignment
));
86 if (r
== ALLOCM_SUCCESS
) {
88 "Expected error for allocm(&p, %zu, 0x%x)\n",
89 sz
, ALLOCM_ALIGN(alignment
));
92 for (i
= 0; i
< NITER
; i
++)
96 alignment
<= MAXALIGN
;
99 fprintf(stderr
, "Alignment: %zu\n", alignment
);
101 sz
< 3 * alignment
&& sz
< (1U << 31);
102 sz
+= (alignment
>> (LG_SIZEOF_PTR
-1)) - 1) {
103 for (i
= 0; i
< NITER
; i
++) {
104 r
= JEMALLOC_P(allocm
)(&ps
[i
], NULL
, sz
,
105 ALLOCM_ALIGN(alignment
) | ALLOCM_ZERO
);
106 if (r
!= ALLOCM_SUCCESS
) {
108 "Error for size %zu (0x%zx): %d\n",
112 if ((uintptr_t)p
& (alignment
-1)) {
114 "%p inadequately aligned for"
115 " alignment: %zu\n", p
, alignment
);
117 JEMALLOC_P(sallocm
)(ps
[i
], &tsz
, 0);
119 if (total
>= (MAXALIGN
<< 1))
122 for (i
= 0; i
< NITER
; i
++) {
124 JEMALLOC_P(dallocm
)(ps
[i
], 0);
131 fprintf(stderr
, "Test end\n");