From 0f0b700ab697c0c9e58a27aa400cc9e0612ff9e7 Mon Sep 17 00:00:00 2001 From: Kristi Belcher Date: Tue, 8 Oct 2024 14:04:20 -0700 Subject: [PATCH] trying to fix mem leak in test --- .../integration/resource_aware_pool_tests.cpp | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/tests/integration/resource_aware_pool_tests.cpp b/tests/integration/resource_aware_pool_tests.cpp index 3550f09f0..a6100c389 100644 --- a/tests/integration/resource_aware_pool_tests.cpp +++ b/tests/integration/resource_aware_pool_tests.cpp @@ -29,6 +29,35 @@ void host_sleep(int* ptr) ptr++; } +TEST(ResourceAwarePool_Host_Test, Check_States_Host) +{ + auto& rm = umpire::ResourceManager::getInstance(); + auto pool = rm.makeAllocator("rap-pool-host", rm.getAllocator("HOST")); + + Host h1, h2; + Resource r1{h1}, r2{h2}; + + int* ptr = static_cast(pool.allocate(r1, 1024)); + int* compare_ptr1 = ptr; + + EXPECT_EQ(getResource(pool, ptr), r1); + EXPECT_EQ(getPendingSize(pool), 0); + + host_sleep(ptr); + + pool.deallocate(r1, ptr); + EXPECT_EQ(getPendingSize(pool), 0); // When only using host, there will be no pending chunks + + ptr = static_cast(pool.allocate(r2, 2048)); + int* compare_ptr2 = ptr; + + EXPECT_TRUE(r1 == r2); + EXPECT_EQ(compare_ptr1, compare_ptr2); // only 1 host resource available, no possible data race + + pool.deallocate(r2, ptr); + pool.release(); +} + #if defined(UMPIRE_ENABLE_CUDA) || defined(UMPIRE_ENABLE_HIP) using clock_value_t = long long; @@ -128,31 +157,3 @@ TEST_P(ResourceAwarePoolTest, Check_States) INSTANTIATE_TEST_SUITE_P(ResourceAwarePoolTests, ResourceAwarePoolTest, ::testing::ValuesIn(get_allocator_strings())); #endif - -TEST(ResourceAwarePool_Host_Test, Check_States_Host) -{ - auto& rm = umpire::ResourceManager::getInstance(); - auto pool = rm.makeAllocator("rap-pool-host", rm.getAllocator("HOST")); - - Host h1, h2; - Resource r1{h1}, r2{h2}; - - int* ptr = static_cast(pool.allocate(r1, 1024)); - int* compare_ptr1 = ptr; - - EXPECT_EQ(getResource(pool, ptr), r1); - EXPECT_EQ(getPendingSize(pool), 0); - - host_sleep(ptr); - - pool.deallocate(ptr); - EXPECT_EQ(getPendingSize(pool), 0); // When only using host, there will be no pending chunks - - ptr = static_cast(pool.allocate(r2, 2048)); - int* compare_ptr2 = ptr; - - EXPECT_TRUE(r1 == r2); - EXPECT_EQ(compare_ptr1, compare_ptr2); // only 1 host resource available, no possible data race - - pool.release(); -}