| 136 | mallctl("thread.tcache.flush", NULL, NULL, NULL, 0); |
| 137 | } |
| 138 | TEST_END |
| 139 | |
| 140 | TEST_BEGIN(test_oom) { |
| 141 | size_t largemax; |
| 142 | bool oom; |
| 143 | void *ptrs[3]; |
| 144 | unsigned i; |
| 145 | |
| 146 | /* |
| 147 | * It should be impossible to allocate three objects that each consume |
| 148 | * nearly half the virtual address space. |
| 149 | */ |
| 150 | largemax = get_large_size(get_nlarge()-1); |
| 151 | oom = false; |
| 152 | for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) { |
| 153 | ptrs[i] = smallocx(largemax, 0).ptr; |
| 154 | if (ptrs[i] == NULL) { |
| 155 | oom = true; |
| 156 | } |
| 157 | } |
| 158 | assert_true(oom, |
| 159 | "Expected OOM during series of calls to smallocx(size=%zu, 0)", |
| 160 | largemax); |
| 161 | for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) { |
| 162 | if (ptrs[i] != NULL) { |
| 163 | dallocx(ptrs[i], 0); |
| 164 | } |
| 165 | } |
| 166 | purge(); |
| 167 | |
| 168 | #if LG_SIZEOF_PTR == 3 |
| 169 | assert_ptr_null(smallocx(0x8000000000000000ULL, |
| 170 | MALLOCX_ALIGN(0x8000000000000000ULL)).ptr, |
| 171 | "Expected OOM for smallocx()"); |
| 172 | assert_ptr_null(smallocx(0x8000000000000000ULL, |
| 173 | MALLOCX_ALIGN(0x80000000)).ptr, |
| 174 | "Expected OOM for smallocx()"); |
| 175 | #else |
| 176 | assert_ptr_null(smallocx(0x80000000UL, MALLOCX_ALIGN(0x80000000UL)).ptr, |
| 177 | "Expected OOM for smallocx()"); |
| 178 | #endif |
| 179 | } |
| 180 | TEST_END |
| 181 | |
| 182 | /* Re-enable the "-Walloc-size-larger-than=" warning */ |
nothing calls this directly
no test coverage detected