Skip to content

Commit 04a08fc

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 ff242b7 commit 04a08fc

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

test/ipcAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ HostMemoryAccessor hostMemoryAccessor;
116116
INSTANTIATE_TEST_SUITE_P(umfIpcTestSuite, umfIpcTest,
117117
::testing::Values(ipcTestParams{
118118
umfProxyPoolOps(), nullptr, &IPC_MOCK_PROVIDER_OPS,
119-
nullptr, &hostMemoryAccessor}));
119+
nullptr, &hostMemoryAccessor, false}));

test/ipcFixtures.hpp

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,26 @@ class HostMemoryAccessor : public MemoryAccessor {
4646
}
4747
};
4848

49+
// ipcTestParams:
50+
// pool_ops, pool_params, provider_ops, provider_params, memoryAccessor, free_not_supp
51+
// free_not_supp (bool) - provider does not support the free() op
4952
using ipcTestParams =
5053
std::tuple<umf_memory_pool_ops_t *, void *, umf_memory_provider_ops_t *,
51-
void *, MemoryAccessor *>;
54+
void *, MemoryAccessor *, bool>;
5255

5356
struct umfIpcTest : umf_test::test,
5457
::testing::WithParamInterface<ipcTestParams> {
5558
umfIpcTest() {}
5659
void SetUp() override {
5760
test::SetUp();
58-
auto [pool_ops, pool_params, provider_ops, provider_params, accessor] =
59-
this->GetParam();
61+
auto [pool_ops, pool_params, provider_ops, provider_params, accessor,
62+
free_not_supp] = this->GetParam();
6063
poolOps = pool_ops;
6164
poolParams = pool_params;
6265
providerOps = provider_ops;
6366
providerParams = provider_params;
6467
memAccessor = accessor;
68+
freeNotSupported = free_not_supp;
6569
}
6670

6771
void TearDown() override { test::TearDown(); }
@@ -120,8 +124,18 @@ struct umfIpcTest : umf_test::test,
120124
void *poolParams = nullptr;
121125
umf_memory_provider_ops_t *providerOps = nullptr;
122126
void *providerParams = nullptr;
127+
bool freeNotSupported = false;
123128
};
124129

130+
static inline umf_result_t
131+
get_umf_result_of_free(bool freeNotSupported, umf_result_t expected_result) {
132+
if (freeNotSupported) {
133+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
134+
}
135+
136+
return expected_result;
137+
}
138+
125139
TEST_P(umfIpcTest, GetIPCHandleSize) {
126140
size_t size = 0;
127141
umf::pool_unique_handle_t pool = makePool();
@@ -163,7 +177,8 @@ TEST_P(umfIpcTest, GetIPCHandleInvalidArgs) {
163177
EXPECT_EQ(ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
164178

165179
ret = umfFree(ptr);
166-
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
180+
EXPECT_EQ(ret,
181+
get_umf_result_of_free(freeNotSupported, UMF_RESULT_SUCCESS));
167182
}
168183

169184
TEST_P(umfIpcTest, BasicFlow) {
@@ -218,7 +233,8 @@ TEST_P(umfIpcTest, BasicFlow) {
218233
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
219234

220235
ret = umfPoolFree(pool.get(), ptr);
221-
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
236+
EXPECT_EQ(ret,
237+
get_umf_result_of_free(freeNotSupported, UMF_RESULT_SUCCESS));
222238

223239
pool.reset(nullptr);
224240
EXPECT_EQ(stat.getCount, 1);
@@ -282,7 +298,8 @@ TEST_P(umfIpcTest, GetPoolByOpenedHandle) {
282298

283299
for (size_t i = 0; i < NUM_ALLOCS; ++i) {
284300
umf_result_t ret = umfFree(ptrs[i]);
285-
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
301+
EXPECT_EQ(ret,
302+
get_umf_result_of_free(freeNotSupported, UMF_RESULT_SUCCESS));
286303
}
287304
}
288305

@@ -308,7 +325,8 @@ TEST_P(umfIpcTest, AllocFreeAllocTest) {
308325
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
309326

310327
ret = umfPoolFree(pool.get(), ptr);
311-
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
328+
EXPECT_EQ(ret,
329+
get_umf_result_of_free(freeNotSupported, UMF_RESULT_SUCCESS));
312330

313331
ptr = umfPoolMalloc(pool.get(), SIZE);
314332
ASSERT_NE(ptr, nullptr);
@@ -330,7 +348,8 @@ TEST_P(umfIpcTest, AllocFreeAllocTest) {
330348
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
331349

332350
ret = umfPoolFree(pool.get(), ptr);
333-
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
351+
EXPECT_EQ(ret,
352+
get_umf_result_of_free(freeNotSupported, UMF_RESULT_SUCCESS));
334353

335354
pool.reset(nullptr);
336355
EXPECT_EQ(stat.allocCount, stat.getCount);
@@ -382,7 +401,8 @@ TEST_P(umfIpcTest, openInTwoPools) {
382401
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
383402

384403
ret = umfPoolFree(pool1.get(), ptr);
385-
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
404+
EXPECT_EQ(ret,
405+
get_umf_result_of_free(freeNotSupported, UMF_RESULT_SUCCESS));
386406

387407
pool1.reset(nullptr);
388408
pool2.reset(nullptr);
@@ -433,7 +453,8 @@ TEST_P(umfIpcTest, ConcurrentGetPutHandles) {
433453

434454
for (void *ptr : ptrs) {
435455
umf_result_t ret = umfPoolFree(pool.get(), ptr);
436-
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
456+
EXPECT_EQ(ret,
457+
get_umf_result_of_free(freeNotSupported, UMF_RESULT_SUCCESS));
437458
}
438459

439460
pool.reset(nullptr);
@@ -495,7 +516,8 @@ TEST_P(umfIpcTest, ConcurrentOpenCloseHandles) {
495516

496517
for (void *ptr : ptrs) {
497518
umf_result_t ret = umfPoolFree(pool.get(), ptr);
498-
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
519+
EXPECT_EQ(ret,
520+
get_umf_result_of_free(freeNotSupported, UMF_RESULT_SUCCESS));
499521
}
500522

501523
pool.reset(nullptr);

test/provider_os_memory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ umf_disjoint_pool_params_t disjointParams = disjointPoolParams();
387387
static std::vector<ipcTestParams> ipcTestParamsList = {
388388
#if (defined UMF_POOL_DISJOINT_ENABLED)
389389
{umfDisjointPoolOps(), &disjointParams, umfOsMemoryProviderOps(),
390-
&os_params, &hostAccessor},
390+
&os_params, &hostAccessor, false},
391391
#endif
392392
};
393393

0 commit comments

Comments
 (0)