MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / TEST_BEGIN

Function TEST_BEGIN

deps/jemalloc/test/integration/smallocx.c:138–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136 mallctl("thread.tcache.flush", NULL, NULL, NULL, 0);
137}
138TEST_END
139
140TEST_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}
180TEST_END
181
182/* Re-enable the "-Walloc-size-larger-than=" warning */

Callers

nothing calls this directly

Calls 4

get_large_sizeFunction · 0.70
get_nlargeFunction · 0.70
purgeFunction · 0.70
test_skipFunction · 0.50

Tested by

no test coverage detected