Skip to content

Commit

Permalink
fix: replace UT_ASSERTs with GTEST asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
EuphoricThinking committed Sep 19, 2024
1 parent 8ad26b6 commit b3b1954
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/memory_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops,
}

void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider) {
hProvider->ops.finalize(hProvider->provider_priv);
umf_ba_global_free(hProvider);
if (hProvider) {
hProvider->ops.finalize(hProvider->provider_priv);
umf_ba_global_free(hProvider);
}
}

static void
Expand Down
2 changes: 1 addition & 1 deletion test/memspaces/memspace_highest_capacity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct memspaceHighestCapacityProviderTest : ::numaNodesTest {
::numaNodesTest::SetUp();

umf_const_memspace_handle_t hMemspace = umfMemspaceHighestCapacityGet();
UT_ASSERTne(hMemspace, nullptr);
ASSERT_NE(hMemspace, nullptr);

umf_result_t ret =
umfMemoryProviderCreateFromMemspace(hMemspace, nullptr, &hProvider);
Expand Down
57 changes: 46 additions & 11 deletions test/provider_os_memory_multiple_numa_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ std::vector<int> get_available_cpus() {
CPU_ZERO(mask);

int ret = sched_getaffinity(0, sizeof(cpu_set_t), mask);
UT_ASSERTeq(ret, 0);

if (ret != 0) {
available_cpus.emplace_back(-__LINE__);
CPU_FREE(mask);

return available_cpus;
}

// Get all available cpus.
printf("All CPUs: ");
for (size_t i = 0; i < CPU_SETSIZE; ++i) {
Expand Down Expand Up @@ -88,13 +95,21 @@ struct testNuma : testing::Test {
ASSERT_NE(os_memory_provider, nullptr);
}

struct bitmask *retrieve_nodemask(void *addr) {
std::pair<int, bitmask *> retrieve_nodemask(void *addr) {
struct bitmask *retrieved_nodemask = numa_allocate_nodemask();
UT_ASSERTne(nodemask, nullptr);

if (nodemask == nullptr) {
return std::make_pair(__LINE__, nodemask);
}

int ret = get_mempolicy(nullptr, retrieved_nodemask->maskp,
nodemask->size, addr, MPOL_F_ADDR);
UT_ASSERTeq(ret, 0);
return retrieved_nodemask;

if (ret != 0) {
return std::make_pair(__LINE__, retrieved_nodemask);
}

return std::pair(0, retrieved_nodemask);
}

void TearDown() override {
Expand Down Expand Up @@ -241,7 +256,18 @@ TEST_P(testNumaOnEachNode, checkModeInterleaveSingleNode) {
EXPECT_NODE_EQ(ptr, numa_node_number);
}

struct testNumaOnEachCpu : testNuma, testing::WithParamInterface<int> {};
struct testNumaOnEachCpu : testNuma, testing::WithParamInterface<int> {
void SetUp() override {
::testNuma::SetUp();

int cpuNumber = this->GetParam();

if (cpuNumber < 0) {
GTEST_FAIL() << "ret is not equal to 0 in " << __FILE__ << ": "
<< -cpuNumber;
}
}
};

INSTANTIATE_TEST_SUITE_P(testNumaNodesAllocationsAllCpus, testNumaOnEachCpu,
::testing::ValuesIn(get_available_cpus()));
Expand All @@ -260,7 +286,7 @@ TEST_P(testNumaOnEachCpu, checkModePreferredEmptyNodeset) {
int ret = sched_setaffinity(0, sizeof(cpu_set_t), mask);
CPU_FREE(mask);

UT_ASSERTeq(ret, 0);
ASSERT_EQ(ret, 0);

umf_os_memory_provider_params_t os_memory_provider_params =
UMF_OS_MEMORY_PROVIDER_PARAMS_TEST;
Expand All @@ -275,7 +301,7 @@ TEST_P(testNumaOnEachCpu, checkModePreferredEmptyNodeset) {

// Verify we're on the expected CPU
int cpu_check = sched_getcpu();
UT_ASSERTeq(cpu, cpu_check);
ASSERT_EQ(cpu, cpu_check);

int numa_node_number = numa_node_of_cpu(cpu);
printf("Got CPU: %d, got numa node: %d\n", cpu, numa_node_number);
Expand All @@ -297,7 +323,7 @@ TEST_P(testNumaOnEachCpu, checkModeLocal) {
int ret = sched_setaffinity(0, sizeof(cpu_set_t), mask);
CPU_FREE(mask);

UT_ASSERTeq(ret, 0);
ASSERT_EQ(ret, 0);

umf_os_memory_provider_params_t os_memory_provider_params =
UMF_OS_MEMORY_PROVIDER_PARAMS_TEST;
Expand All @@ -312,7 +338,7 @@ TEST_P(testNumaOnEachCpu, checkModeLocal) {

// Verify we're on the expected CPU
int cpu_check = sched_getcpu();
UT_ASSERTeq(cpu, cpu_check);
ASSERT_EQ(cpu, cpu_check);

int numa_node_number = numa_node_of_cpu(cpu);
printf("Got CPU: %d, got numa node: %d\n", cpu, numa_node_number);
Expand Down Expand Up @@ -391,7 +417,16 @@ TEST_F(testNuma, checkModeInterleave) {
EXPECT_NODE_EQ((char *)ptr + page_size * i, numa_nodes[index]);
}

bitmask *retrieved_nodemask = retrieve_nodemask(ptr);
auto [fileLine, retrieved_nodemask] = retrieve_nodemask(ptr);
if (fileLine != 0) {
if (retrieved_nodemask == nullptr) {
GTEST_FAIL() << "retrieved_nodemask is nullptr " << __FILE__ << ": "
<< fileLine;
} else {
GTEST_FAIL() << "ret is not equal to 0 " << __FILE__ << ": "
<< fileLine;
}
}
int ret = numa_bitmask_equal(retrieved_nodemask, nodemask);
numa_bitmask_free(retrieved_nodemask);

Expand Down

0 comments on commit b3b1954

Please sign in to comment.