]>
Commit | Line | Data |
---|---|---|
a78e148b | 1 | #define JEMALLOC_MANGLE |
2 | #include "jemalloc_test.h" | |
3 | ||
4 | #define CHUNK 0x400000 | |
4934f93d | 5 | /* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */ |
6 | #define MAXALIGN ((size_t)0x2000000LU) | |
a78e148b | 7 | #define NITER 4 |
8 | ||
9 | int | |
10 | main(void) | |
11 | { | |
12 | size_t alignment, size, total; | |
13 | unsigned i; | |
14 | int err; | |
15 | void *p, *ps[NITER]; | |
16 | ||
4934f93d | 17 | malloc_printf("Test begin\n"); |
a78e148b | 18 | |
19 | /* Test error conditions. */ | |
20 | for (alignment = 0; alignment < sizeof(void *); alignment++) { | |
4934f93d | 21 | err = posix_memalign(&p, alignment, 1); |
a78e148b | 22 | if (err != EINVAL) { |
4934f93d | 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) { | |
4934f93d | 31 | err = posix_memalign(&p, alignment + 1, 1); |
a78e148b | 32 | if (err == 0) { |
4934f93d | 33 | malloc_printf( |
a78e148b | 34 | "Expected error for invalid alignment %zu\n", |
35 | alignment + 1); | |
36 | } | |
37 | } | |
38 | ||
39 | #if LG_SIZEOF_PTR == 3 | |
4934f93d | 40 | alignment = UINT64_C(0x8000000000000000); |
41 | size = UINT64_C(0x8000000000000000); | |
a78e148b | 42 | #else |
43 | alignment = 0x80000000LU; | |
44 | size = 0x80000000LU; | |
45 | #endif | |
4934f93d | 46 | err = posix_memalign(&p, alignment, size); |
a78e148b | 47 | if (err == 0) { |
4934f93d | 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 | |
4934f93d | 54 | alignment = UINT64_C(0x4000000000000000); |
55 | size = UINT64_C(0x8400000000000001); | |
a78e148b | 56 | #else |
57 | alignment = 0x40000000LU; | |
58 | size = 0x84000001LU; | |
59 | #endif | |
4934f93d | 60 | err = posix_memalign(&p, alignment, size); |
a78e148b | 61 | if (err == 0) { |
4934f93d | 62 | malloc_printf( |
a78e148b | 63 | "Expected error for posix_memalign(&p, %zu, %zu)\n", |
64 | alignment, size); | |
65 | } | |
66 | ||
4934f93d | 67 | alignment = 0x10LU; |
a78e148b | 68 | #if LG_SIZEOF_PTR == 3 |
4934f93d | 69 | size = UINT64_C(0xfffffffffffffff0); |
a78e148b | 70 | #else |
71 | size = 0xfffffff0LU; | |
72 | #endif | |
4934f93d | 73 | err = posix_memalign(&p, alignment, size); |
a78e148b | 74 | if (err == 0) { |
4934f93d | 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; | |
4934f93d | 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++) { | |
4934f93d | 92 | err = posix_memalign(&ps[i], |
a78e148b | 93 | alignment, size); |
94 | if (err) { | |
4934f93d | 95 | malloc_printf( |
96 | "Error for size %zu (%#zx): %s\n", | |
a78e148b | 97 | size, size, strerror(err)); |
98 | exit(1); | |
99 | } | |
4934f93d | 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) { | |
4934f93d | 106 | free(ps[i]); |
a78e148b | 107 | ps[i] = NULL; |
108 | } | |
109 | } | |
110 | } | |
111 | } | |
112 | ||
4934f93d | 113 | malloc_printf("Test end\n"); |
a78e148b | 114 | return (0); |
115 | } |