@@ -52,11 +52,8 @@ using ipcTestParams =
52
52
53
53
struct umfIpcTest : umf_test::test,
54
54
::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 (); }
60
57
61
58
void TearDown () override { test::TearDown (); }
62
59
@@ -74,7 +71,9 @@ struct umfIpcTest : umf_test::test,
74
71
75
72
auto trace = [](void *trace_context, const char *name) {
76
73
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 ) {
78
77
++stat->getCount ;
79
78
} else if (std::strcmp (name, " put_ipc_handle" ) == 0 ) {
80
79
++stat->putCount ;
@@ -98,22 +97,26 @@ struct umfIpcTest : umf_test::test,
98
97
}
99
98
100
99
struct stats_type {
100
+ std::atomic<size_t > allocCount;
101
101
std::atomic<size_t > getCount;
102
102
std::atomic<size_t > putCount;
103
103
std::atomic<size_t > openCount;
104
104
std::atomic<size_t > closeCount;
105
105
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 ) {}
107
109
};
108
110
109
- umf::pool_unique_handle_t pool;
110
111
static constexpr int NTHREADS = 10 ;
111
112
stats_type stat;
112
113
MemoryAccessor *memAccessor = nullptr ;
113
114
};
114
115
115
116
TEST_P (umfIpcTest, GetIPCHandleSize) {
116
117
size_t size = 0 ;
118
+ umf::pool_unique_handle_t pool = makePool ();
119
+
117
120
umf_result_t ret = umfPoolGetIPCHandleSize (pool.get (), &size);
118
121
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
119
122
EXPECT_GT (size, 0 );
@@ -122,6 +125,7 @@ TEST_P(umfIpcTest, GetIPCHandleSize) {
122
125
TEST_P (umfIpcTest, BasicFlow) {
123
126
constexpr size_t SIZE = 100 ;
124
127
std::vector<int > expected_data (SIZE);
128
+ umf::pool_unique_handle_t pool = makePool ();
125
129
int *ptr = (int *)umfPoolMalloc (pool.get (), SIZE * sizeof (int ));
126
130
EXPECT_NE (ptr, nullptr );
127
131
@@ -172,6 +176,7 @@ TEST_P(umfIpcTest, BasicFlow) {
172
176
ret = umfPoolFree (pool.get (), ptr);
173
177
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
174
178
179
+ pool.reset (nullptr );
175
180
EXPECT_EQ (stat.getCount , 1 );
176
181
EXPECT_EQ (stat.putCount , stat.getCount );
177
182
// TODO: enale check below once cache for open IPC handles is implemented
@@ -183,6 +188,8 @@ TEST_P(umfIpcTest, ConcurrentGetPutHandles) {
183
188
std::vector<void *> ptrs;
184
189
constexpr size_t ALLOC_SIZE = 100 ;
185
190
constexpr size_t NUM_POINTERS = 100 ;
191
+ umf::pool_unique_handle_t pool = makePool ();
192
+
186
193
for (size_t i = 0 ; i < NUM_POINTERS; ++i) {
187
194
void *ptr = umfPoolMalloc (pool.get (), ALLOC_SIZE);
188
195
EXPECT_NE (ptr, nullptr );
@@ -221,15 +228,16 @@ TEST_P(umfIpcTest, ConcurrentGetPutHandles) {
221
228
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
222
229
}
223
230
224
- EXPECT_GE (stat.getCount , NUM_POINTERS);
225
- EXPECT_LE (stat.getCount , NUM_POINTERS * NTHREADS);
231
+ pool.reset (nullptr );
226
232
EXPECT_EQ (stat.putCount , stat.getCount );
227
233
}
228
234
229
235
TEST_P (umfIpcTest, ConcurrentOpenCloseHandles) {
230
236
std::vector<void *> ptrs;
231
237
constexpr size_t ALLOC_SIZE = 100 ;
232
238
constexpr size_t NUM_POINTERS = 100 ;
239
+ umf::pool_unique_handle_t pool = makePool ();
240
+
233
241
for (size_t i = 0 ; i < NUM_POINTERS; ++i) {
234
242
void *ptr = umfPoolMalloc (pool.get (), ALLOC_SIZE);
235
243
EXPECT_NE (ptr, nullptr );
@@ -249,8 +257,8 @@ TEST_P(umfIpcTest, ConcurrentOpenCloseHandles) {
249
257
250
258
umf_test::syncthreads_barrier syncthreads (NTHREADS);
251
259
252
- auto openHandlesFn = [this , &ipcHandles, &openedIpcHandles,
253
- &syncthreads ](size_t tid) {
260
+ auto openHandlesFn = [this , &ipcHandles, &openedIpcHandles, &syncthreads,
261
+ &pool ](size_t tid) {
254
262
syncthreads ();
255
263
for (auto ipcHandle : ipcHandles) {
256
264
void *ptr;
@@ -282,6 +290,11 @@ TEST_P(umfIpcTest, ConcurrentOpenCloseHandles) {
282
290
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
283
291
}
284
292
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);
285
298
EXPECT_EQ (stat.openCount , stat.closeCount );
286
299
}
287
300
0 commit comments