]>
git.saurik.com Git - redis.git/blob - deps/jemalloc/test/posix_memalign.c
7 #define JEMALLOC_MANGLE
8 #include "jemalloc_test.h"
10 #define CHUNK 0x400000
11 /* #define MAXALIGN ((size_t)0x80000000000LLU) */
12 #define MAXALIGN ((size_t)0x2000000LLU)
18 size_t alignment
, size
, total
;
23 fprintf(stderr
, "Test begin\n");
25 /* Test error conditions. */
26 for (alignment
= 0; alignment
< sizeof(void *); alignment
++) {
27 err
= JEMALLOC_P(posix_memalign
)(&p
, alignment
, 1);
30 "Expected error for invalid alignment %zu\n",
35 for (alignment
= sizeof(size_t); alignment
< MAXALIGN
;
37 err
= JEMALLOC_P(posix_memalign
)(&p
, alignment
+ 1, 1);
40 "Expected error for invalid alignment %zu\n",
45 #if LG_SIZEOF_PTR == 3
46 alignment
= 0x8000000000000000LLU
;
47 size
= 0x8000000000000000LLU
;
49 alignment
= 0x80000000LU
;
52 err
= JEMALLOC_P(posix_memalign
)(&p
, alignment
, size
);
55 "Expected error for posix_memalign(&p, %zu, %zu)\n",
59 #if LG_SIZEOF_PTR == 3
60 alignment
= 0x4000000000000000LLU
;
61 size
= 0x8400000000000001LLU
;
63 alignment
= 0x40000000LU
;
66 err
= JEMALLOC_P(posix_memalign
)(&p
, alignment
, size
);
69 "Expected error for posix_memalign(&p, %zu, %zu)\n",
74 #if LG_SIZEOF_PTR == 3
75 size
= 0xfffffffffffffff0LLU
;
79 err
= JEMALLOC_P(posix_memalign
)(&p
, alignment
, size
);
82 "Expected error for posix_memalign(&p, %zu, %zu)\n",
86 for (i
= 0; i
< NITER
; i
++)
90 alignment
<= MAXALIGN
;
93 fprintf(stderr
, "Alignment: %zu\n", alignment
);
95 size
< 3 * alignment
&& size
< (1U << 31);
96 size
+= (alignment
>> (LG_SIZEOF_PTR
-1)) - 1) {
97 for (i
= 0; i
< NITER
; i
++) {
98 err
= JEMALLOC_P(posix_memalign
)(&ps
[i
],
102 "Error for size %zu (0x%zx): %s\n",
103 size
, size
, strerror(err
));
106 total
+= JEMALLOC_P(malloc_usable_size
)(ps
[i
]);
107 if (total
>= (MAXALIGN
<< 1))
110 for (i
= 0; i
< NITER
; i
++) {
112 JEMALLOC_P(free
)(ps
[i
]);
119 fprintf(stderr
, "Test end\n");