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 Aug 30, 2024
1 parent 89b660c commit ec6c973
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion test/memspaces/memspace_fixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ TEST_P(memspaceProviderTest, allocLocalMt) {
int mode = -1;
std::vector<size_t> boundNodeIds;
size_t allocNodeId = SIZE_MAX;
getAllocationPolicy(ptr, maxNodeId, mode, boundNodeIds, allocNodeId);
ASSERT_NO_FATAL_FAILURE(getAllocationPolicy(ptr, maxNodeId, mode, boundNodeIds, allocNodeId));

// Get the CPUs associated with the specified NUMA node.
hwloc_obj_t allocNodeObj =
Expand Down
6 changes: 3 additions & 3 deletions test/memspaces/memspace_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ void getAllocationPolicy(void *ptr, unsigned long maxNodeId, int &mode,
// Get policy and the nodes associated with this policy.
int ret = get_mempolicy(&memMode, memNodeMasks.data(),
nrUlongs * bitsPerUlong, ptr, MPOL_F_ADDR);
UT_ASSERTeq(ret, 0);
ASSERT_EQ(ret, 0);
mode = memMode;

UT_ASSERTeq(boundNodeIds.size(), 0);
ASSERT_EQ(boundNodeIds.size(), 0);
for (size_t i = 0; i <= maxNodeId; i++) {
const size_t memNodeMaskIdx = ((i + bitsPerUlong) / bitsPerUlong) - 1;
const auto &memNodeMask = memNodeMasks.at(memNodeMaskIdx);
Expand All @@ -52,7 +52,7 @@ void getAllocationPolicy(void *ptr, unsigned long maxNodeId, int &mode,
// Get the node that allocated the memory at 'ptr'.
int nodeId = -1;
ret = get_mempolicy(&nodeId, nullptr, 0, ptr, MPOL_F_ADDR | MPOL_F_NODE);
UT_ASSERTeq(ret, 0);
ASSERT_EQ(ret, 0);
allocNodeId = static_cast<size_t>(nodeId);
}

Expand Down
47 changes: 24 additions & 23 deletions test/memspaces/memspace_host_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,27 @@ struct memspaceHostAllProviderTest : ::memspaceHostAllTest {

TEST_F(numaNodesTest, memspaceGet) {
umf_const_memspace_handle_t hMemspace = umfMemspaceHostAllGet();
UT_ASSERTne(hMemspace, nullptr);
ASSERT_NE(hMemspace, nullptr);

// Confirm that the HOST ALL memspace is composed of all available NUMA nodes.
UT_ASSERTeq(hMemspace->size, nodeIds.size());
ASSERT_EQ(hMemspace->size, nodeIds.size());
for (size_t i = 0; i < hMemspace->size; i++) {
// NUMA memory target internally casts the config directly into priv.
// TODO: Use the memory target API when it becomes available.
struct umf_numa_memtarget_config_t *numaTargetCfg =
(struct umf_numa_memtarget_config_t *)hMemspace->nodes[i]->priv;
UT_ASSERT(std::find(nodeIds.begin(), nodeIds.end(),
numaTargetCfg->physical_id) != nodeIds.end());
ASSERT_NE(std::find(nodeIds.begin(), nodeIds.end(),
numaTargetCfg->physical_id),
nodeIds.end());
}
}

TEST_F(memspaceHostAllTest, providerFromHostAllMemspace) {
umf_memory_provider_handle_t hProvider = nullptr;
umf_result_t ret =
umfMemoryProviderCreateFromMemspace(hMemspace, nullptr, &hProvider);
UT_ASSERTeq(ret, UMF_RESULT_SUCCESS);
UT_ASSERTne(hProvider, nullptr);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
ASSERT_NE(hProvider, nullptr);

umfMemoryProviderDestroy(hProvider);
}
Expand All @@ -81,13 +82,13 @@ TEST_F(memspaceHostAllProviderTest, allocFree) {
size_t alignment = 0;

umf_result_t ret = umfMemoryProviderAlloc(hProvider, size, alignment, &ptr);
UT_ASSERTeq(ret, UMF_RESULT_SUCCESS);
UT_ASSERTne(ptr, nullptr);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
ASSERT_NE(ptr, nullptr);

memset(ptr, 0xFF, size);

ret = umfMemoryProviderFree(hProvider, ptr, size);
UT_ASSERTeq(ret, UMF_RESULT_SUCCESS);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
}

TEST_F(memspaceHostAllProviderTest, hostAllDefaults) {
Expand All @@ -96,7 +97,7 @@ TEST_F(memspaceHostAllProviderTest, hostAllDefaults) {
// default kernel path (no mbind).

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

umf_memory_provider_handle_t hProvider = nullptr;
umf_result_t ret = umfMemoryProviderCreateFromMemspace(
Expand All @@ -110,14 +111,14 @@ TEST_F(memspaceHostAllProviderTest, hostAllDefaults) {
size_t alignment = 0;

ret = umfMemoryProviderAlloc(hProvider, size, alignment, &ptr1);
UT_ASSERTeq(ret, UMF_RESULT_SUCCESS);
UT_ASSERTne(ptr1, nullptr);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
ASSERT_NE(ptr1, nullptr);
memset(ptr1, 0xFF, size);

// Create single allocation using mmap
void *ptr2 = mmap(nullptr, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
UT_ASSERTne(ptr2, nullptr);
ASSERT_NE(ptr2, nullptr);
memset(ptr2, 0xFF, size);

// Compare UMF and kernel default allocation policy
Expand All @@ -127,28 +128,28 @@ TEST_F(memspaceHostAllProviderTest, hostAllDefaults) {

int ret2 = get_mempolicy(&memMode1, nodemask1->maskp, nodemask1->size, ptr1,
MPOL_F_ADDR);
UT_ASSERTeq(ret2, 0);
ASSERT_EQ(ret2, 0);
ret2 = get_mempolicy(&memMode2, nodemask2->maskp, nodemask2->size, ptr2,
MPOL_F_ADDR);
UT_ASSERTeq(ret2, 0);
UT_ASSERTeq(memMode1, memMode2);
UT_ASSERTeq(nodemask1->size, nodemask2->size);
UT_ASSERTeq(numa_bitmask_equal(nodemask1, nodemask2), 1);
ASSERT_EQ(ret2, 0);
ASSERT_EQ(memMode1, memMode2);
ASSERT_EQ(nodemask1->size, nodemask2->size);
ASSERT_EQ(numa_bitmask_equal(nodemask1, nodemask2), 1);

int nodeId1 = -1, nodeId2 = -1;
ret2 = get_mempolicy(&nodeId1, nullptr, 0, ptr1, MPOL_F_ADDR | MPOL_F_NODE);
UT_ASSERTeq(ret2, 0);
ASSERT_EQ(ret2, 0);
ret2 = get_mempolicy(&nodeId2, nullptr, 0, ptr2, MPOL_F_ADDR | MPOL_F_NODE);
UT_ASSERTeq(ret2, 0);
UT_ASSERTeq(nodeId1, nodeId2);
ASSERT_EQ(ret2, 0);
ASSERT_EQ(nodeId1, nodeId2);

numa_free_nodemask(nodemask2);
numa_free_nodemask(nodemask1);

ret2 = munmap(ptr2, size);
UT_ASSERTeq(ret2, 0);
ASSERT_EQ(ret2, 0);

ret = umfMemoryProviderFree(hProvider, ptr1, size);
UT_ASSERTeq(ret, UMF_RESULT_SUCCESS);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
umfMemoryProviderDestroy(hProvider);
}

0 comments on commit ec6c973

Please sign in to comment.