]> git.saurik.com Git - redis.git/blame - deps/jemalloc/test/posix_memalign.c
redis-check-dump now understands dumps produced by Redis 2.6
[redis.git] / deps / jemalloc / test / posix_memalign.c
CommitLineData
a78e148b 1#define JEMALLOC_MANGLE
2#include "jemalloc_test.h"
3
4#define CHUNK 0x400000
ad4c0b41 5/* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
6#define MAXALIGN ((size_t)0x2000000LU)
a78e148b 7#define NITER 4
8
9int
10main(void)
11{
12 size_t alignment, size, total;
13 unsigned i;
14 int err;
15 void *p, *ps[NITER];
16
ad4c0b41 17 malloc_printf("Test begin\n");
a78e148b 18
19 /* Test error conditions. */
20 for (alignment = 0; alignment < sizeof(void *); alignment++) {
ad4c0b41 21 err = posix_memalign(&p, alignment, 1);
a78e148b 22 if (err != EINVAL) {
ad4c0b41 23 malloc_printf(
a78e148b 24 "Expected error for invalid alignment %zu\n",
25 alignment);
26 }
27 }
28
29 for (alignment = sizeof(size_t); alignment < MAXALIGN;
30 alignment <<= 1) {
ad4c0b41 31 err = posix_memalign(&p, alignment + 1, 1);
a78e148b 32 if (err == 0) {
ad4c0b41 33 malloc_printf(
a78e148b 34 "Expected error for invalid alignment %zu\n",
35 alignment + 1);
36 }
37 }
38
39#if LG_SIZEOF_PTR == 3
ad4c0b41 40 alignment = UINT64_C(0x8000000000000000);
41 size = UINT64_C(0x8000000000000000);
a78e148b 42#else
43 alignment = 0x80000000LU;
44 size = 0x80000000LU;
45#endif
ad4c0b41 46 err = posix_memalign(&p, alignment, size);
a78e148b 47 if (err == 0) {
ad4c0b41 48 malloc_printf(
a78e148b 49 "Expected error for posix_memalign(&p, %zu, %zu)\n",
50 alignment, size);
51 }
52
53#if LG_SIZEOF_PTR == 3
ad4c0b41 54 alignment = UINT64_C(0x4000000000000000);
55 size = UINT64_C(0x8400000000000001);
a78e148b 56#else
57 alignment = 0x40000000LU;
58 size = 0x84000001LU;
59#endif
ad4c0b41 60 err = posix_memalign(&p, alignment, size);
a78e148b 61 if (err == 0) {
ad4c0b41 62 malloc_printf(
a78e148b 63 "Expected error for posix_memalign(&p, %zu, %zu)\n",
64 alignment, size);
65 }
66
ad4c0b41 67 alignment = 0x10LU;
a78e148b 68#if LG_SIZEOF_PTR == 3
ad4c0b41 69 size = UINT64_C(0xfffffffffffffff0);
a78e148b 70#else
71 size = 0xfffffff0LU;
72#endif
ad4c0b41 73 err = posix_memalign(&p, alignment, size);
a78e148b 74 if (err == 0) {
ad4c0b41 75 malloc_printf(
a78e148b 76 "Expected error for posix_memalign(&p, %zu, %zu)\n",
77 alignment, size);
78 }
79
80 for (i = 0; i < NITER; i++)
81 ps[i] = NULL;
82
83 for (alignment = 8;
84 alignment <= MAXALIGN;
85 alignment <<= 1) {
86 total = 0;
ad4c0b41 87 malloc_printf("Alignment: %zu\n", alignment);
a78e148b 88 for (size = 1;
89 size < 3 * alignment && size < (1U << 31);
90 size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
91 for (i = 0; i < NITER; i++) {
ad4c0b41 92 err = posix_memalign(&ps[i],
a78e148b 93 alignment, size);
94 if (err) {
ad4c0b41 95 malloc_printf(
96 "Error for size %zu (%#zx): %s\n",
a78e148b 97 size, size, strerror(err));
98 exit(1);
99 }
ad4c0b41 100 total += malloc_usable_size(ps[i]);
a78e148b 101 if (total >= (MAXALIGN << 1))
102 break;
103 }
104 for (i = 0; i < NITER; i++) {
105 if (ps[i] != NULL) {
ad4c0b41 106 free(ps[i]);
a78e148b 107 ps[i] = NULL;
108 }
109 }
110 }
111 }
112
ad4c0b41 113 malloc_printf("Test end\n");
a78e148b 114 return (0);
115}