Skip to content

fix: substitute UT_ASSERTs with asserts from GTEST part 5 #744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/memory_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,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
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
Loading