Skip to content

Commit

Permalink
trying to fix mem leak in test
Browse files Browse the repository at this point in the history
  • Loading branch information
kab163 committed Oct 8, 2024
1 parent 50816bd commit 0f0b700
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions tests/integration/resource_aware_pool_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<umpire::strategy::ResourceAwarePool>("rap-pool-host", rm.getAllocator("HOST"));

Host h1, h2;
Resource r1{h1}, r2{h2};

int* ptr = static_cast<int*>(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<int*>(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;
Expand Down Expand Up @@ -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<umpire::strategy::ResourceAwarePool>("rap-pool-host", rm.getAllocator("HOST"));

Host h1, h2;
Resource r1{h1}, r2{h2};

int* ptr = static_cast<int*>(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<int*>(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();
}

0 comments on commit 0f0b700

Please sign in to comment.