Skip to content

Commit

Permalink
fix: replace UT_ASSERTs with GTEST asserts
Browse files Browse the repository at this point in the history
    If possible, change non-void functions to void by passing pointers
    Otherwise, introduce error-indicating return values

    Ref. #569
  • Loading branch information
EuphoricThinking committed Oct 14, 2024
1 parent 12a2b86 commit ced30bb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
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
52 changes: 39 additions & 13 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(-1);
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,16 @@ struct testNuma : testing::Test {
ASSERT_NE(os_memory_provider, nullptr);
}

struct bitmask *retrieve_nodemask(void *addr) {
struct bitmask *retrieved_nodemask = numa_allocate_nodemask();
UT_ASSERTne(nodemask, nullptr);
int ret = get_mempolicy(nullptr, retrieved_nodemask->maskp,
void retrieve_nodemask(void *addr, bitmask **retrieved_nodemask) {
*retrieved_nodemask = numa_allocate_nodemask();

ASSERT_NE(nodemask, nullptr);
ASSERT_NE(*retrieved_nodemask, nullptr);

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

ASSERT_EQ(ret, 0);
}

void TearDown() override {
Expand Down Expand Up @@ -241,7 +251,17 @@ 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() << "get_available_cpus() error";
}
}
};

INSTANTIATE_TEST_SUITE_P(testNumaNodesAllocationsAllCpus, testNumaOnEachCpu,
::testing::ValuesIn(get_available_cpus()));
Expand All @@ -260,7 +280,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 +295,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 +317,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 +332,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 +411,13 @@ TEST_F(testNuma, checkModeInterleave) {
EXPECT_NODE_EQ((char *)ptr + page_size * i, numa_nodes[index]);
}

bitmask *retrieved_nodemask = retrieve_nodemask(ptr);
bitmask *retrieved_nodemask = nullptr;
retrieve_nodemask(ptr, &retrieved_nodemask);

if (IS_SKIPPED_OR_FAILED()) {
return;
}

int ret = numa_bitmask_equal(retrieved_nodemask, nodemask);
numa_bitmask_free(retrieved_nodemask);

Expand Down

0 comments on commit ced30bb

Please sign in to comment.