| 112 | mallctl("thread.tcache.flush", NULL, NULL, NULL, 0); |
| 113 | } |
| 114 | TEST_END |
| 115 | |
| 116 | TEST_BEGIN(test_oom) { |
| 117 | size_t largemax; |
| 118 | bool oom; |
| 119 | void *ptrs[3]; |
| 120 | unsigned i; |
| 121 | |
| 122 | /* |
| 123 | * It should be impossible to allocate three objects that each consume |
| 124 | * nearly half the virtual address space. |
| 125 | */ |
| 126 | largemax = get_large_size(get_nlarge()-1); |
| 127 | oom = false; |
| 128 | for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) { |
| 129 | ptrs[i] = mallocx(largemax, MALLOCX_ARENA(0)); |
| 130 | if (ptrs[i] == NULL) { |
| 131 | oom = true; |
| 132 | } |
| 133 | } |
| 134 | assert_true(oom, |
| 135 | "Expected OOM during series of calls to mallocx(size=%zu, 0)", |
| 136 | largemax); |
| 137 | for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) { |
| 138 | if (ptrs[i] != NULL) { |
| 139 | dallocx(ptrs[i], 0); |
| 140 | } |
| 141 | } |
| 142 | purge(); |
| 143 | |
| 144 | #if LG_SIZEOF_PTR == 3 |
| 145 | assert_ptr_null(mallocx(0x8000000000000000ULL, |
| 146 | MALLOCX_ALIGN(0x8000000000000000ULL)), |
| 147 | "Expected OOM for mallocx()"); |
| 148 | assert_ptr_null(mallocx(0x8000000000000000ULL, |
| 149 | MALLOCX_ALIGN(0x80000000)), |
| 150 | "Expected OOM for mallocx()"); |
| 151 | #else |
| 152 | assert_ptr_null(mallocx(0x80000000UL, MALLOCX_ALIGN(0x80000000UL)), |
| 153 | "Expected OOM for mallocx()"); |
| 154 | #endif |
| 155 | } |
| 156 | TEST_END |
| 157 | |
| 158 | /* Re-enable the "-Walloc-size-larger-than=" warning */ |
nothing calls this directly
no test coverage detected