@@ -53,7 +53,16 @@ using ipcTestParams =
5353struct umfIpcTest : umf_test::test,
5454 ::testing::WithParamInterface<ipcTestParams> {
5555 umfIpcTest () {}
56- void SetUp () override { test::SetUp (); }
56+ void SetUp () override {
57+ test::SetUp ();
58+ auto [pool_ops, pool_params, provider_ops, provider_params, accessor] =
59+ this ->GetParam ();
60+ poolOps = pool_ops;
61+ poolParams = pool_params;
62+ providerOps = provider_ops;
63+ providerParams = provider_params;
64+ memAccessor = accessor;
65+ }
5766
5867 void TearDown () override { test::TearDown (); }
5968
@@ -62,11 +71,9 @@ struct umfIpcTest : umf_test::test,
6271 // from memoryPool.hpp
6372 umf_memory_provider_handle_t hProvider;
6473 umf_memory_pool_handle_t hPool;
65- auto [pool_ops, pool_params, provider_ops, provider_params, accessor] =
66- this ->GetParam ();
6774
6875 auto ret =
69- umfMemoryProviderCreate (provider_ops, provider_params , &hProvider);
76+ umfMemoryProviderCreate (providerOps, providerParams , &hProvider);
7077 EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
7178
7279 auto trace = [](void *trace_context, const char *name) {
@@ -87,12 +94,10 @@ struct umfIpcTest : umf_test::test,
8794 umf_memory_provider_handle_t hTraceProvider =
8895 traceProviderCreate (hProvider, true , (void *)&stat, trace);
8996
90- ret = umfPoolCreate (pool_ops , hTraceProvider, pool_params ,
97+ ret = umfPoolCreate (poolOps , hTraceProvider, poolParams ,
9198 UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &hPool);
9299 EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
93100
94- memAccessor = accessor;
95-
96101 return umf::pool_unique_handle_t (hPool, &umfPoolDestroy);
97102 }
98103
@@ -111,6 +116,10 @@ struct umfIpcTest : umf_test::test,
111116 static constexpr int NTHREADS = 10 ;
112117 stats_type stat;
113118 MemoryAccessor *memAccessor = nullptr ;
119+ umf_memory_pool_ops_t *poolOps = nullptr ;
120+ void *poolParams = nullptr ;
121+ umf_memory_provider_ops_t *providerOps = nullptr ;
122+ void *providerParams = nullptr ;
114123};
115124
116125TEST_P (umfIpcTest, GetIPCHandleSize) {
@@ -122,6 +131,16 @@ TEST_P(umfIpcTest, GetIPCHandleSize) {
122131 EXPECT_GT (size, 0 );
123132}
124133
134+ TEST_P (umfIpcTest, GetIPCHandleSizeInvalidArgs) {
135+ size_t size = 0 ;
136+ umf_result_t ret = umfPoolGetIPCHandleSize (nullptr , &size);
137+ EXPECT_EQ (ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
138+
139+ umf::pool_unique_handle_t pool = makePool ();
140+ ret = umfPoolGetIPCHandleSize (pool.get (), nullptr );
141+ EXPECT_EQ (ret, UMF_RESULT_ERROR_INVALID_ARGUMENT);
142+ }
143+
125144TEST_P (umfIpcTest, GetIPCHandleInvalidArgs) {
126145 constexpr size_t SIZE = 100 ;
127146 umf_ipc_handle_t ipcHandle = nullptr ;
@@ -209,6 +228,113 @@ TEST_P(umfIpcTest, BasicFlow) {
209228 EXPECT_EQ (stat.closeCount , stat.openCount );
210229}
211230
231+ TEST_P (umfIpcTest, GetPoolByOpenedHandle) {
232+ constexpr size_t SIZE = 100 ;
233+ constexpr size_t NUM_ALLOCS = 100 ;
234+ constexpr size_t NUM_POOLS = 4 ;
235+ void *ptrs[NUM_ALLOCS];
236+ void *openedPtrs[NUM_POOLS][NUM_ALLOCS];
237+ std::vector<umf::pool_unique_handle_t > pools_to_open;
238+ umf::pool_unique_handle_t pool = makePool ();
239+
240+ for (size_t i = 0 ; i < NUM_POOLS; ++i) {
241+ pools_to_open.push_back (makePool ());
242+ }
243+
244+ for (size_t i = 0 ; i < NUM_ALLOCS; ++i) {
245+ void *ptr = umfPoolMalloc (pool.get (), SIZE);
246+ ASSERT_NE (ptr, nullptr );
247+ ptrs[i] = ptr;
248+ }
249+
250+ for (size_t i = 0 ; i < NUM_ALLOCS; ++i) {
251+ umf_ipc_handle_t ipcHandle = nullptr ;
252+ size_t handleSize = 0 ;
253+ umf_result_t ret = umfGetIPCHandle (ptrs[i], &ipcHandle, &handleSize);
254+ ASSERT_EQ (ret, UMF_RESULT_SUCCESS);
255+
256+ for (size_t pool_id = 0 ; pool_id < NUM_POOLS; pool_id++) {
257+ void *ptr = nullptr ;
258+ ret =
259+ umfOpenIPCHandle (pools_to_open[pool_id].get (), ipcHandle, &ptr);
260+ ASSERT_EQ (ret, UMF_RESULT_SUCCESS);
261+ openedPtrs[pool_id][i] = ptr;
262+ }
263+
264+ ret = umfPutIPCHandle (ipcHandle);
265+ ASSERT_EQ (ret, UMF_RESULT_SUCCESS);
266+ }
267+
268+ for (size_t pool_id = 0 ; pool_id < NUM_POOLS; pool_id++) {
269+ for (size_t i = 0 ; i < NUM_ALLOCS; ++i) {
270+ umf_memory_pool_handle_t openedPool =
271+ umfPoolByPtr (openedPtrs[pool_id][i]);
272+ EXPECT_EQ (openedPool, pools_to_open[pool_id].get ());
273+ }
274+ }
275+
276+ for (size_t pool_id = 0 ; pool_id < NUM_POOLS; pool_id++) {
277+ for (size_t i = 0 ; i < NUM_ALLOCS; ++i) {
278+ umf_result_t ret = umfCloseIPCHandle (openedPtrs[pool_id][i]);
279+ EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
280+ }
281+ }
282+
283+ for (size_t i = 0 ; i < NUM_ALLOCS; ++i) {
284+ umf_result_t ret = umfFree (ptrs[i]);
285+ EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
286+ }
287+ }
288+
289+ TEST_P (umfIpcTest, AllocFreeAllocTest) {
290+ constexpr size_t SIZE = 64 * 1024 ;
291+ umf::pool_unique_handle_t pool = makePool ();
292+ void *ptr = umfPoolMalloc (pool.get (), SIZE);
293+ EXPECT_NE (ptr, nullptr );
294+
295+ umf_ipc_handle_t ipcHandle = nullptr ;
296+ size_t handleSize = 0 ;
297+ umf_result_t ret = umfGetIPCHandle (ptr, &ipcHandle, &handleSize);
298+ ASSERT_EQ (ret, UMF_RESULT_SUCCESS);
299+
300+ void *opened_ptr = nullptr ;
301+ ret = umfOpenIPCHandle (pool.get (), ipcHandle, &opened_ptr);
302+ ASSERT_EQ (ret, UMF_RESULT_SUCCESS);
303+
304+ ret = umfCloseIPCHandle (opened_ptr);
305+ EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
306+
307+ ret = umfPutIPCHandle (ipcHandle);
308+ EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
309+
310+ ret = umfPoolFree (pool.get (), ptr);
311+ EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
312+
313+ ptr = umfPoolMalloc (pool.get (), SIZE);
314+ ASSERT_NE (ptr, nullptr );
315+
316+ ret = umfGetIPCHandle (ptr, &ipcHandle, &handleSize);
317+ ASSERT_EQ (ret, UMF_RESULT_SUCCESS);
318+
319+ ret = umfOpenIPCHandle (pool.get (), ipcHandle, &opened_ptr);
320+ ASSERT_EQ (ret, UMF_RESULT_SUCCESS);
321+
322+ ret = umfCloseIPCHandle (opened_ptr);
323+ EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
324+
325+ ret = umfPutIPCHandle (ipcHandle);
326+ EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
327+
328+ ret = umfPoolFree (pool.get (), ptr);
329+ EXPECT_EQ (ret, UMF_RESULT_SUCCESS);
330+
331+ pool.reset (nullptr );
332+ EXPECT_EQ (stat.allocCount , stat.getCount );
333+ EXPECT_EQ (stat.getCount , stat.putCount );
334+ EXPECT_EQ (stat.openCount , stat.getCount );
335+ EXPECT_EQ (stat.openCount , stat.closeCount );
336+ }
337+
212338TEST_P (umfIpcTest, ConcurrentGetPutHandles) {
213339 std::vector<void *> ptrs;
214340 constexpr size_t ALLOC_SIZE = 100 ;
0 commit comments