]>
git.saurik.com Git - redis.git/blob - deps/jemalloc/test/aligned_alloc.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
;
16 malloc_printf("Test begin\n");
18 /* Test error conditions. */
21 p
= aligned_alloc(alignment
, 1);
22 if (p
!= NULL
|| get_errno() != EINVAL
) {
24 "Expected error for invalid alignment %zu\n", alignment
);
27 for (alignment
= sizeof(size_t); alignment
< MAXALIGN
;
30 p
= aligned_alloc(alignment
+ 1, 1);
31 if (p
!= NULL
|| get_errno() != EINVAL
) {
33 "Expected error for invalid alignment %zu\n",
38 #if LG_SIZEOF_PTR == 3
39 alignment
= UINT64_C(0x8000000000000000);
40 size
= UINT64_C(0x8000000000000000);
42 alignment
= 0x80000000LU
;
46 p
= aligned_alloc(alignment
, size
);
47 if (p
!= NULL
|| get_errno() != ENOMEM
) {
49 "Expected error for aligned_alloc(%zu, %zu)\n",
53 #if LG_SIZEOF_PTR == 3
54 alignment
= UINT64_C(0x4000000000000000);
55 size
= UINT64_C(0x8400000000000001);
57 alignment
= 0x40000000LU
;
61 p
= aligned_alloc(alignment
, size
);
62 if (p
!= NULL
|| get_errno() != ENOMEM
) {
64 "Expected error for aligned_alloc(%zu, %zu)\n",
69 #if LG_SIZEOF_PTR == 3
70 size
= UINT64_C(0xfffffffffffffff0);
75 p
= aligned_alloc(alignment
, size
);
76 if (p
!= NULL
|| get_errno() != ENOMEM
) {
78 "Expected error for aligned_alloc(&p, %zu, %zu)\n",
82 for (i
= 0; i
< NITER
; i
++)
86 alignment
<= MAXALIGN
;
89 malloc_printf("Alignment: %zu\n", alignment
);
91 size
< 3 * alignment
&& size
< (1U << 31);
92 size
+= (alignment
>> (LG_SIZEOF_PTR
-1)) - 1) {
93 for (i
= 0; i
< NITER
; i
++) {
94 ps
[i
] = aligned_alloc(alignment
, size
);
96 char buf
[BUFERROR_BUF
];
98 buferror(buf
, sizeof(buf
));
100 "Error for size %zu (%#zx): %s\n",
104 total
+= malloc_usable_size(ps
[i
]);
105 if (total
>= (MAXALIGN
<< 1))
108 for (i
= 0; i
< NITER
; i
++) {
117 malloc_printf("Test end\n");