20
20
#include < numeric>
21
21
#include < tuple>
22
22
23
+ #ifdef UMF_TEST_PROVIDER_FREE_NOT_SUPPORTED
24
+ #define get_umf_result_of_free (expected_result ) UMF_RESULT_ERROR_NOT_SUPPORTED
25
+ #else
26
+ #define get_umf_result_of_free (expected_result ) (expected_result)
27
+ #endif
28
+
23
29
class MemoryAccessor {
24
30
public:
25
31
virtual void fill (void *ptr, size_t size, const void *pattern,
@@ -172,7 +178,7 @@ TEST_P(umfIpcTest, GetIPCHandleInvalidArgs) {
172
178
EXPECT_EQ (ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
173
179
174
180
ret = umfFree (ptr);
175
- EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
181
+ EXPECT_EQ (ret, get_umf_result_of_free ( UMF_RESULT_SUCCESS) );
176
182
}
177
183
178
184
TEST_P (umfIpcTest, BasicFlow) {
@@ -227,7 +233,19 @@ TEST_P(umfIpcTest, BasicFlow) {
227
233
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
228
234
229
235
ret = umfPoolFree (pool.get (), ptr);
230
- EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
236
+ EXPECT_EQ (ret, get_umf_result_of_free (UMF_RESULT_SUCCESS));
237
+
238
+ // Test if umfCloseIPCHandle() did not corrupt the pool
239
+ // and if umfPoolMalloc() works correctly after umfCloseIPCHandle().
240
+ ptr = (int *)umfPoolMalloc (pool.get (), SIZE);
241
+ EXPECT_NE (ptr, nullptr );
242
+
243
+ // use the allocated memory - fill it with a 0xAB pattern
244
+ const uint32_t pattern = 0xAB ;
245
+ memAccessor->fill (ptr, SIZE, &pattern, sizeof (pattern));
246
+
247
+ ret = umfPoolFree (pool.get (), ptr);
248
+ EXPECT_EQ (ret, get_umf_result_of_free (UMF_RESULT_SUCCESS));
231
249
232
250
pool.reset (nullptr );
233
251
EXPECT_EQ (stat.getCount , 1 );
@@ -291,7 +309,7 @@ TEST_P(umfIpcTest, GetPoolByOpenedHandle) {
291
309
292
310
for (size_t i = 0 ; i < NUM_ALLOCS; ++i) {
293
311
umf_result_t ret = umfFree (ptrs[i]);
294
- EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
312
+ EXPECT_EQ (ret, get_umf_result_of_free ( UMF_RESULT_SUCCESS) );
295
313
}
296
314
}
297
315
@@ -317,7 +335,7 @@ TEST_P(umfIpcTest, AllocFreeAllocTest) {
317
335
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
318
336
319
337
ret = umfPoolFree (pool.get (), ptr);
320
- EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
338
+ EXPECT_EQ (ret, get_umf_result_of_free ( UMF_RESULT_SUCCESS) );
321
339
322
340
ptr = umfPoolMalloc (pool.get (), SIZE);
323
341
ASSERT_NE (ptr, nullptr );
@@ -339,7 +357,19 @@ TEST_P(umfIpcTest, AllocFreeAllocTest) {
339
357
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
340
358
341
359
ret = umfPoolFree (pool.get (), ptr);
342
- EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
360
+ EXPECT_EQ (ret, get_umf_result_of_free (UMF_RESULT_SUCCESS));
361
+
362
+ // Test if umfCloseIPCHandle() did not corrupt the pool
363
+ // and if umfPoolMalloc() works correctly after umfCloseIPCHandle().
364
+ ptr = umfPoolMalloc (pool.get (), SIZE);
365
+ EXPECT_NE (ptr, nullptr );
366
+
367
+ // use the allocated memory - fill it with a 0xAB pattern
368
+ const uint32_t pattern = 0xAB ;
369
+ memAccessor->fill (ptr, SIZE, &pattern, sizeof (pattern));
370
+
371
+ ret = umfPoolFree (pool.get (), ptr);
372
+ EXPECT_EQ (ret, get_umf_result_of_free (UMF_RESULT_SUCCESS));
343
373
344
374
pool.reset (nullptr );
345
375
EXPECT_EQ (stat.allocCount , stat.getCount );
@@ -391,7 +421,7 @@ TEST_P(umfIpcTest, openInTwoPools) {
391
421
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
392
422
393
423
ret = umfPoolFree (pool1.get (), ptr);
394
- EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
424
+ EXPECT_EQ (ret, get_umf_result_of_free ( UMF_RESULT_SUCCESS) );
395
425
396
426
pool1.reset (nullptr );
397
427
pool2.reset (nullptr );
@@ -442,7 +472,7 @@ TEST_P(umfIpcTest, ConcurrentGetPutHandles) {
442
472
443
473
for (void *ptr : ptrs) {
444
474
umf_result_t ret = umfPoolFree (pool.get (), ptr);
445
- EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
475
+ EXPECT_EQ (ret, get_umf_result_of_free ( UMF_RESULT_SUCCESS) );
446
476
}
447
477
448
478
pool.reset (nullptr );
@@ -504,7 +534,7 @@ TEST_P(umfIpcTest, ConcurrentOpenCloseHandles) {
504
534
505
535
for (void *ptr : ptrs) {
506
536
umf_result_t ret = umfPoolFree (pool.get (), ptr);
507
- EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
537
+ EXPECT_EQ (ret, get_umf_result_of_free ( UMF_RESULT_SUCCESS) );
508
538
}
509
539
510
540
pool.reset (nullptr );
0 commit comments