@@ -136,18 +136,42 @@ TEST_P(umfPoolTest, allocFree) {
136
136
auto *ptr = umfPoolMalloc (pool.get (), allocSize);
137
137
ASSERT_NE (ptr, nullptr );
138
138
std::memset (ptr, 0 , allocSize);
139
- umfPoolFree (pool.get (), ptr);
139
+ umf_result_t umf_result = umfPoolFree (pool.get (), ptr);
140
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
140
141
}
141
142
142
143
TEST_P (umfPoolTest, allocFreeNonAlignedSizes) {
143
144
for (const auto &allocSize : nonAlignedAllocSizes) {
144
145
auto *ptr = umfPoolMalloc (pool.get (), allocSize);
145
146
ASSERT_NE (ptr, nullptr );
146
147
std::memset (ptr, 0 , allocSize);
147
- umfPoolFree (pool.get (), ptr);
148
+ umf_result_t umf_result = umfPoolFree (pool.get (), ptr);
149
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
148
150
}
149
151
}
150
152
153
+ TEST_P (umfPoolTest, allocFreeAligned) {
154
+ // ::aligned_alloc(alignment=4096, size=1) does not work under sanitizers for unknown reason
155
+ #if defined(_WIN32) || defined(__SANITIZE_ADDRESS__) || \
156
+ defined (__SANITIZE_THREAD__)
157
+ // TODO: implement support for windows
158
+ GTEST_SKIP ();
159
+ #else
160
+ if (!umf_test::isAlignedAllocSupported (pool.get ())) {
161
+ GTEST_SKIP ();
162
+ }
163
+
164
+ size_t alignment = 4 * 1024 ; // 4kB
165
+ void *ptr = umfPoolAlignedMalloc (pool.get (), 1 , alignment);
166
+ ASSERT_NE (ptr, nullptr );
167
+ ASSERT_TRUE (reinterpret_cast <uintptr_t >(ptr) % alignment == 0 );
168
+ *(reinterpret_cast <unsigned char *>(ptr)) = (unsigned char )0xFF ;
169
+
170
+ umf_result_t umf_result = umfPoolFree (pool.get (), ptr);
171
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
172
+ #endif
173
+ }
174
+
151
175
TEST_P (umfPoolTest, reallocFree) {
152
176
if (!umf_test::isReallocSupported (pool.get ())) {
153
177
GTEST_SKIP ();
@@ -160,7 +184,8 @@ TEST_P(umfPoolTest, reallocFree) {
160
184
auto *new_ptr = umfPoolRealloc (pool.get (), ptr, allocSize * multiplier);
161
185
ASSERT_NE (new_ptr, nullptr );
162
186
std::memset (new_ptr, 0 , allocSize * multiplier);
163
- umfPoolFree (pool.get (), new_ptr);
187
+ umf_result_t umf_result = umfPoolFree (pool.get (), new_ptr);
188
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
164
189
}
165
190
166
191
TEST_P (umfPoolTest, callocFree) {
@@ -174,7 +199,8 @@ TEST_P(umfPoolTest, callocFree) {
174
199
for (size_t i = 0 ; i < num; ++i) {
175
200
ASSERT_EQ (((int *)ptr)[i], 0 );
176
201
}
177
- umfPoolFree (pool.get (), ptr);
202
+ umf_result_t umf_result = umfPoolFree (pool.get (), ptr);
203
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
178
204
}
179
205
180
206
void pow2AlignedAllocHelper (umf_memory_pool_handle_t pool) {
@@ -195,9 +221,31 @@ void pow2AlignedAllocHelper(umf_memory_pool_handle_t pool) {
195
221
}
196
222
197
223
for (auto &ptr : allocs) {
198
- umfPoolFree (pool, ptr);
224
+ umf_result_t umf_result = umfPoolFree (pool, ptr);
225
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
199
226
}
200
227
}
228
+
229
+ // ::aligned_alloc(alignment=4096, size=1) does not work under sanitizers for unknown reason
230
+ #if !defined(__SANITIZE_ADDRESS__) && !defined(__SANITIZE_THREAD__)
231
+ // the same for size = 1
232
+ for (size_t alignment = 1 ; alignment <= maxAlignment; alignment <<= 1 ) {
233
+ std::vector<void *> allocs;
234
+
235
+ for (size_t alloc = 0 ; alloc < numAllocs; alloc++) {
236
+ auto *ptr = umfPoolAlignedMalloc (pool, 1 , alignment);
237
+ ASSERT_NE (ptr, nullptr );
238
+ ASSERT_TRUE (reinterpret_cast <uintptr_t >(ptr) % alignment == 0 );
239
+ *(reinterpret_cast <unsigned char *>(ptr)) = (unsigned char )0xFF ;
240
+ allocs.push_back (ptr);
241
+ }
242
+
243
+ for (auto &ptr : allocs) {
244
+ umf_result_t umf_result = umfPoolFree (pool, ptr);
245
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
246
+ }
247
+ }
248
+ #endif
201
249
}
202
250
203
251
TEST_P (umfPoolTest, pow2AlignedAlloc) {
@@ -227,7 +275,8 @@ TEST_P(umfPoolTest, multiThreadedMallocFree) {
227
275
}
228
276
229
277
for (auto allocation : allocations) {
230
- umfPoolFree (inPool, allocation);
278
+ umf_result_t umf_result = umfPoolFree (inPool, allocation);
279
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
231
280
}
232
281
};
233
282
@@ -280,7 +329,8 @@ TEST_P(umfPoolTest, multiThreadedReallocFree) {
280
329
for (auto allocation : allocations) {
281
330
auto *ptr =
282
331
umfPoolRealloc (inPool, allocation, allocSize * multiplier);
283
- umfPoolFree (inPool, ptr);
332
+ umf_result_t umf_result = umfPoolFree (inPool, ptr);
333
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
284
334
}
285
335
};
286
336
@@ -310,7 +360,8 @@ TEST_P(umfPoolTest, multiThreadedCallocFree) {
310
360
}
311
361
312
362
for (auto allocation : allocations) {
313
- umfPoolFree (inPool, allocation);
363
+ umf_result_t umf_result = umfPoolFree (inPool, allocation);
364
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
314
365
}
315
366
};
316
367
@@ -335,7 +386,8 @@ TEST_P(umfPoolTest, multiThreadedMallocFreeRandomSizes) {
335
386
}
336
387
337
388
for (auto allocation : allocations) {
338
- umfPoolFree (inPool, allocation);
389
+ umf_result_t umf_result = umfPoolFree (inPool, allocation);
390
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
339
391
}
340
392
};
341
393
@@ -375,7 +427,8 @@ TEST_P(umfMemTest, outOfMem) {
375
427
ASSERT_NE (allocations.back (), nullptr );
376
428
377
429
for (int i = 0 ; i < expectedRecycledPoolAllocs; i++) {
378
- umfPoolFree (hPool, allocations.back ());
430
+ umf_result_t umf_result = umfPoolFree (hPool, allocations.back ());
431
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
379
432
allocations.pop_back ();
380
433
}
381
434
@@ -385,7 +438,8 @@ TEST_P(umfMemTest, outOfMem) {
385
438
}
386
439
387
440
for (auto allocation : allocations) {
388
- umfPoolFree (hPool, allocation);
441
+ umf_result_t umf_result = umfPoolFree (hPool, allocation);
442
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
389
443
}
390
444
}
391
445
@@ -490,7 +544,8 @@ TEST_P(umfPoolTest, mallocUsableSize) {
490
544
// Make sure we can write to this memory
491
545
memset (ptr, 123 , result);
492
546
493
- umfPoolFree (pool.get (), ptr);
547
+ umf_result_t umf_result = umfPoolFree (pool.get (), ptr);
548
+ ASSERT_EQ (umf_result, UMF_RESULT_SUCCESS);
494
549
}
495
550
}
496
551
}
0 commit comments