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