Skip to content

Commit 44dc69a

Browse files
committed
Refactor IPC tests
1 parent 6c2c767 commit 44dc69a

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

test/ipcFixtures.hpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,8 @@ using ipcTestParams =
5252

5353
struct umfIpcTest : umf_test::test,
5454
::testing::WithParamInterface<ipcTestParams> {
55-
umfIpcTest() : pool(nullptr, nullptr) {}
56-
void SetUp() override {
57-
test::SetUp();
58-
this->pool = makePool();
59-
}
55+
umfIpcTest() {}
56+
void SetUp() override { test::SetUp(); }
6057

6158
void TearDown() override { test::TearDown(); }
6259

@@ -74,7 +71,9 @@ struct umfIpcTest : umf_test::test,
7471

7572
auto trace = [](void *trace_context, const char *name) {
7673
stats_type *stat = static_cast<stats_type *>(trace_context);
77-
if (std::strcmp(name, "get_ipc_handle") == 0) {
74+
if (std::strcmp(name, "alloc") == 0) {
75+
++stat->allocCount;
76+
} else if (std::strcmp(name, "get_ipc_handle") == 0) {
7877
++stat->getCount;
7978
} else if (std::strcmp(name, "put_ipc_handle") == 0) {
8079
++stat->putCount;
@@ -98,22 +97,26 @@ struct umfIpcTest : umf_test::test,
9897
}
9998

10099
struct stats_type {
100+
std::atomic<size_t> allocCount;
101101
std::atomic<size_t> getCount;
102102
std::atomic<size_t> putCount;
103103
std::atomic<size_t> openCount;
104104
std::atomic<size_t> closeCount;
105105

106-
stats_type() : getCount(0), putCount(0), openCount(0), closeCount(0) {}
106+
stats_type()
107+
: allocCount(0), getCount(0), putCount(0), openCount(0),
108+
closeCount(0) {}
107109
};
108110

109-
umf::pool_unique_handle_t pool;
110111
static constexpr int NTHREADS = 10;
111112
stats_type stat;
112113
MemoryAccessor *memAccessor = nullptr;
113114
};
114115

115116
TEST_P(umfIpcTest, GetIPCHandleSize) {
116117
size_t size = 0;
118+
umf::pool_unique_handle_t pool = makePool();
119+
117120
umf_result_t ret = umfPoolGetIPCHandleSize(pool.get(), &size);
118121
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
119122
EXPECT_GT(size, 0);
@@ -122,6 +125,7 @@ TEST_P(umfIpcTest, GetIPCHandleSize) {
122125
TEST_P(umfIpcTest, BasicFlow) {
123126
constexpr size_t SIZE = 100;
124127
std::vector<int> expected_data(SIZE);
128+
umf::pool_unique_handle_t pool = makePool();
125129
int *ptr = (int *)umfPoolMalloc(pool.get(), SIZE * sizeof(int));
126130
EXPECT_NE(ptr, nullptr);
127131

@@ -172,6 +176,7 @@ TEST_P(umfIpcTest, BasicFlow) {
172176
ret = umfPoolFree(pool.get(), ptr);
173177
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
174178

179+
pool.reset(nullptr);
175180
EXPECT_EQ(stat.getCount, 1);
176181
EXPECT_EQ(stat.putCount, stat.getCount);
177182
// TODO: enale check below once cache for open IPC handles is implemented
@@ -183,6 +188,8 @@ TEST_P(umfIpcTest, ConcurrentGetPutHandles) {
183188
std::vector<void *> ptrs;
184189
constexpr size_t ALLOC_SIZE = 100;
185190
constexpr size_t NUM_POINTERS = 100;
191+
umf::pool_unique_handle_t pool = makePool();
192+
186193
for (size_t i = 0; i < NUM_POINTERS; ++i) {
187194
void *ptr = umfPoolMalloc(pool.get(), ALLOC_SIZE);
188195
EXPECT_NE(ptr, nullptr);
@@ -221,15 +228,16 @@ TEST_P(umfIpcTest, ConcurrentGetPutHandles) {
221228
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
222229
}
223230

224-
EXPECT_GE(stat.getCount, NUM_POINTERS);
225-
EXPECT_LE(stat.getCount, NUM_POINTERS * NTHREADS);
231+
pool.reset(nullptr);
226232
EXPECT_EQ(stat.putCount, stat.getCount);
227233
}
228234

229235
TEST_P(umfIpcTest, ConcurrentOpenCloseHandles) {
230236
std::vector<void *> ptrs;
231237
constexpr size_t ALLOC_SIZE = 100;
232238
constexpr size_t NUM_POINTERS = 100;
239+
umf::pool_unique_handle_t pool = makePool();
240+
233241
for (size_t i = 0; i < NUM_POINTERS; ++i) {
234242
void *ptr = umfPoolMalloc(pool.get(), ALLOC_SIZE);
235243
EXPECT_NE(ptr, nullptr);
@@ -249,8 +257,8 @@ TEST_P(umfIpcTest, ConcurrentOpenCloseHandles) {
249257

250258
umf_test::syncthreads_barrier syncthreads(NTHREADS);
251259

252-
auto openHandlesFn = [this, &ipcHandles, &openedIpcHandles,
253-
&syncthreads](size_t tid) {
260+
auto openHandlesFn = [this, &ipcHandles, &openedIpcHandles, &syncthreads,
261+
&pool](size_t tid) {
254262
syncthreads();
255263
for (auto ipcHandle : ipcHandles) {
256264
void *ptr;
@@ -282,6 +290,11 @@ TEST_P(umfIpcTest, ConcurrentOpenCloseHandles) {
282290
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
283291
}
284292

293+
pool.reset(nullptr);
294+
EXPECT_EQ(stat.getCount, stat.allocCount);
295+
EXPECT_EQ(stat.putCount, stat.getCount);
296+
// TODO: enale check below once cache for open IPC handles is implemented
297+
// EXPECT_EQ(stat.openCount, stat.allocCount);
285298
EXPECT_EQ(stat.openCount, stat.closeCount);
286299
}
287300

0 commit comments

Comments
 (0)