Skip to content

Commit 865e2b6

Browse files
committed
Enable running umfIpcTest tests when free() is not supported
Some memory providers (currently the devdax and the file providers) do not support the free() operation (free() always returns the UMF_RESULT_ERROR_NOT_SUPPORTED error). Add the UMF_TEST_PROVIDER_FREE_NOT_SUPPORTED define and the get_umf_result_of_free macro() to ipcFixtures.hpp to enable running umfIpcTest tests when free() is not supported. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 3f97929 commit 865e2b6

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

test/ipcFixtures.hpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#include <numeric>
2121
#include <tuple>
2222

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+
2329
class MemoryAccessor {
2430
public:
2531
virtual void fill(void *ptr, size_t size, const void *pattern,
@@ -172,7 +178,7 @@ TEST_P(umfIpcTest, GetIPCHandleInvalidArgs) {
172178
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
173179

174180
ret = umfFree(ptr);
175-
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
181+
EXPECT_EQ(ret, get_umf_result_of_free(UMF_RESULT_SUCCESS));
176182
}
177183

178184
TEST_P(umfIpcTest, BasicFlow) {
@@ -227,7 +233,19 @@ TEST_P(umfIpcTest, BasicFlow) {
227233
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
228234

229235
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));
231249

232250
pool.reset(nullptr);
233251
EXPECT_EQ(stat.getCount, 1);
@@ -291,7 +309,7 @@ TEST_P(umfIpcTest, GetPoolByOpenedHandle) {
291309

292310
for (size_t i = 0; i < NUM_ALLOCS; ++i) {
293311
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));
295313
}
296314
}
297315

@@ -317,7 +335,7 @@ TEST_P(umfIpcTest, AllocFreeAllocTest) {
317335
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
318336

319337
ret = umfPoolFree(pool.get(), ptr);
320-
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
338+
EXPECT_EQ(ret, get_umf_result_of_free(UMF_RESULT_SUCCESS));
321339

322340
ptr = umfPoolMalloc(pool.get(), SIZE);
323341
ASSERT_NE(ptr, nullptr);
@@ -339,7 +357,19 @@ TEST_P(umfIpcTest, AllocFreeAllocTest) {
339357
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
340358

341359
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));
343373

344374
pool.reset(nullptr);
345375
EXPECT_EQ(stat.allocCount, stat.getCount);
@@ -391,7 +421,7 @@ TEST_P(umfIpcTest, openInTwoPools) {
391421
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
392422

393423
ret = umfPoolFree(pool1.get(), ptr);
394-
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
424+
EXPECT_EQ(ret, get_umf_result_of_free(UMF_RESULT_SUCCESS));
395425

396426
pool1.reset(nullptr);
397427
pool2.reset(nullptr);
@@ -442,7 +472,7 @@ TEST_P(umfIpcTest, ConcurrentGetPutHandles) {
442472

443473
for (void *ptr : ptrs) {
444474
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));
446476
}
447477

448478
pool.reset(nullptr);
@@ -504,7 +534,7 @@ TEST_P(umfIpcTest, ConcurrentOpenCloseHandles) {
504534

505535
for (void *ptr : ptrs) {
506536
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));
508538
}
509539

510540
pool.reset(nullptr);

0 commit comments

Comments
 (0)