]>
git.saurik.com Git - redis.git/blob - deps/jemalloc/test/posix_memalign.c
1 #define JEMALLOC_MANGLE
2 #include "jemalloc_test.h"
5 /* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
6 #define MAXALIGN ((size_t)0x2000000LU)
12 size_t alignment
, size
, total
;
17 malloc_printf("Test begin\n");
19 /* Test error conditions. */
20 for (alignment
= 0; alignment
< sizeof(void *); alignment
++) {
21 err
= posix_memalign(&p
, alignment
, 1);
24 "Expected error for invalid alignment %zu\n",
29 for (alignment
= sizeof(size_t); alignment
< MAXALIGN
;
31 err
= posix_memalign(&p
, alignment
+ 1, 1);
34 "Expected error for invalid alignment %zu\n",
39 #if LG_SIZEOF_PTR == 3
40 alignment
= UINT64_C(0x8000000000000000);
41 size
= UINT64_C(0x8000000000000000);
43 alignment
= 0x80000000LU
;
46 err
= posix_memalign(&p
, alignment
, size
);
49 "Expected error for posix_memalign(&p, %zu, %zu)\n",
53 #if LG_SIZEOF_PTR == 3
54 alignment
= UINT64_C(0x4000000000000000);
55 size
= UINT64_C(0x8400000000000001);
57 alignment
= 0x40000000LU
;
60 err
= posix_memalign(&p
, alignment
, size
);
63 "Expected error for posix_memalign(&p, %zu, %zu)\n",
68 #if LG_SIZEOF_PTR == 3
69 size
= UINT64_C(0xfffffffffffffff0);
73 err
= posix_memalign(&p
, alignment
, size
);
76 "Expected error for posix_memalign(&p, %zu, %zu)\n",
80 for (i
= 0; i
< NITER
; i
++)
84 alignment
<= MAXALIGN
;
87 malloc_printf("Alignment: %zu\n", alignment
);
89 size
< 3 * alignment
&& size
< (1U << 31);
90 size
+= (alignment
>> (LG_SIZEOF_PTR
-1)) - 1) {
91 for (i
= 0; i
< NITER
; i
++) {
92 err
= posix_memalign(&ps
[i
],
96 "Error for size %zu (%#zx): %s\n",
97 size
, size
, strerror(err
));
100 total
+= malloc_usable_size(ps
[i
]);
101 if (total
>= (MAXALIGN
<< 1))
104 for (i
= 0; i
< NITER
; i
++) {
113 malloc_printf("Test end\n");