@@ -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,30 +97,60 @@ 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 );
120
123
}
121
124
125
+ TEST_P (umfIpcTest, GetIPCHandleInvalidArgs) {
126
+ constexpr size_t SIZE = 100 ;
127
+ umf_ipc_handle_t ipcHandle = nullptr ;
128
+ size_t handleSize = 0 ;
129
+ umf_result_t ret = umfGetIPCHandle (nullptr , &ipcHandle, &handleSize);
130
+ EXPECT_EQ (ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
131
+
132
+ void *ptr = (void *)0xBAD ;
133
+ ret = umfGetIPCHandle (ptr, &ipcHandle, &handleSize);
134
+ EXPECT_EQ (ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
135
+
136
+ umf::pool_unique_handle_t pool = makePool ();
137
+ ptr = umfPoolMalloc (pool.get (), SIZE);
138
+ EXPECT_NE (ptr, nullptr );
139
+
140
+ ret = umfGetIPCHandle (ptr, nullptr , &handleSize);
141
+ EXPECT_EQ (ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
142
+
143
+ ret = umfGetIPCHandle (ptr, &ipcHandle, nullptr );
144
+ EXPECT_EQ (ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
145
+
146
+ ret = umfFree (ptr);
147
+ EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
148
+ }
149
+
122
150
TEST_P (umfIpcTest, BasicFlow) {
123
151
constexpr size_t SIZE = 100 ;
124
152
std::vector<int > expected_data (SIZE);
153
+ umf::pool_unique_handle_t pool = makePool ();
125
154
int *ptr = (int *)umfPoolMalloc (pool.get (), SIZE * sizeof (int ));
126
155
EXPECT_NE (ptr, nullptr );
127
156
@@ -172,6 +201,7 @@ TEST_P(umfIpcTest, BasicFlow) {
172
201
ret = umfPoolFree (pool.get (), ptr);
173
202
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
174
203
204
+ pool.reset (nullptr );
175
205
EXPECT_EQ (stat.getCount , 1 );
176
206
EXPECT_EQ (stat.putCount , stat.getCount );
177
207
// TODO: enale check below once cache for open IPC handles is implemented
@@ -183,6 +213,8 @@ TEST_P(umfIpcTest, ConcurrentGetPutHandles) {
183
213
std::vector<void *> ptrs;
184
214
constexpr size_t ALLOC_SIZE = 100 ;
185
215
constexpr size_t NUM_POINTERS = 100 ;
216
+ umf::pool_unique_handle_t pool = makePool ();
217
+
186
218
for (size_t i = 0 ; i < NUM_POINTERS; ++i) {
187
219
void *ptr = umfPoolMalloc (pool.get (), ALLOC_SIZE);
188
220
EXPECT_NE (ptr, nullptr );
@@ -221,15 +253,16 @@ TEST_P(umfIpcTest, ConcurrentGetPutHandles) {
221
253
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
222
254
}
223
255
224
- EXPECT_GE (stat.getCount , NUM_POINTERS);
225
- EXPECT_LE (stat.getCount , NUM_POINTERS * NTHREADS);
256
+ pool.reset (nullptr );
226
257
EXPECT_EQ (stat.putCount , stat.getCount );
227
258
}
228
259
229
260
TEST_P (umfIpcTest, ConcurrentOpenCloseHandles) {
230
261
std::vector<void *> ptrs;
231
262
constexpr size_t ALLOC_SIZE = 100 ;
232
263
constexpr size_t NUM_POINTERS = 100 ;
264
+ umf::pool_unique_handle_t pool = makePool ();
265
+
233
266
for (size_t i = 0 ; i < NUM_POINTERS; ++i) {
234
267
void *ptr = umfPoolMalloc (pool.get (), ALLOC_SIZE);
235
268
EXPECT_NE (ptr, nullptr );
@@ -249,8 +282,8 @@ TEST_P(umfIpcTest, ConcurrentOpenCloseHandles) {
249
282
250
283
umf_test::syncthreads_barrier syncthreads (NTHREADS);
251
284
252
- auto openHandlesFn = [this , &ipcHandles, &openedIpcHandles,
253
- &syncthreads ](size_t tid) {
285
+ auto openHandlesFn = [this , &ipcHandles, &openedIpcHandles, &syncthreads,
286
+ &pool ](size_t tid) {
254
287
syncthreads ();
255
288
for (auto ipcHandle : ipcHandles) {
256
289
void *ptr;
@@ -282,6 +315,11 @@ TEST_P(umfIpcTest, ConcurrentOpenCloseHandles) {
282
315
EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
283
316
}
284
317
318
+ pool.reset (nullptr );
319
+ EXPECT_EQ (stat.getCount , stat.allocCount );
320
+ EXPECT_EQ (stat.putCount , stat.getCount );
321
+ // TODO: enale check below once cache for open IPC handles is implemented
322
+ // EXPECT_EQ(stat.openCount, stat.allocCount);
285
323
EXPECT_EQ (stat.openCount , stat.closeCount );
286
324
}
287
325
0 commit comments