Skip to content

Commit

Permalink
fix: replace UT_ASSERTs with GTEST asserts
Browse files Browse the repository at this point in the history
Added enums

Ref. oneapi-src#569
  • Loading branch information
EuphoricThinking committed Sep 12, 2024
1 parent d2cf678 commit d580a36
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
2 changes: 2 additions & 0 deletions test/common/test_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ extern "C" {
// Needed for CI
#define TEST_SKIP_ERROR_CODE 125

enum assert_res {SUCCESS_RES, FATAL_RES, SKIP_RES};

static inline void UT_FATAL(const char *format, ...) {
va_list args_list;
va_start(args_list, format);
Expand Down
21 changes: 14 additions & 7 deletions test/memspaces/memspace_fixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ struct numaNodesTest : ::umf_test::test {
unsigned long maxNodeId = 0;
};

using isQuerySupportedFunc = bool (*)(size_t);
using isQuerySupportedFunc = assert_res (*)(size_t);
using memspaceGetFunc = umf_const_memspace_handle_t (*)();
using memspaceGetParams = std::tuple<isQuerySupportedFunc, memspaceGetFunc>;


struct memspaceGetTest : ::numaNodesTest,
::testing::WithParamInterface<memspaceGetParams> {
void SetUp() override {
Expand All @@ -65,14 +66,22 @@ struct memspaceGetTest : ::numaNodesTest,

auto [isQuerySupported, memspaceGet] = this->GetParam();

if (!isQuerySupported(nodeIds.front())) {
GTEST_FAIL();
}
assertQueryResult(isQuerySupported);

hMemspace = memspaceGet();
ASSERT_NE(hMemspace, nullptr);
}

void assertQueryResult(assert_res (*isQuerySupported) (size_t)) {
assert_res queryCheck = isQuerySupported(nodeIds.front());
if (queryCheck == SKIP_RES) {
GTEST_SKIP();
}
else if (queryCheck == FATAL_RES) {
GTEST_FAIL();
}
}

umf_const_memspace_handle_t hMemspace = nullptr;
};

Expand All @@ -86,9 +95,7 @@ struct memspaceProviderTest : ::memspaceGetTest {

auto [isQuerySupported, memspaceGet] = ::memspaceGetTest::GetParam();

if (!isQuerySupported(nodeIds.front())) {
GTEST_FAIL();
}
assertQueryResult(isQuerySupported);

umf_result_t ret =
umfMemoryProviderCreateFromMemspace(hMemspace, nullptr, &hProvider);
Expand Down
19 changes: 10 additions & 9 deletions test/memspaces/memspace_highest_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
#include "memspace_internal.h"
#include "test_helpers.h"

static bool canQueryBandwidth(size_t nodeId) {
static assert_res canQueryBandwidth(size_t nodeId) {
hwloc_topology_t topology = nullptr;
int ret = hwloc_topology_init(&topology);

if (!GTEST_OUT_EQ(ret, 0)) {
return false;
if (!GTEST_OUT_EQ(ret, 0)){
return FATAL_RES;
}

ret = hwloc_topology_load(topology);

if (!GTEST_OUT_EQ(ret, 0)) {
return false;
return FATAL_RES;
}

hwloc_obj_t numaNode =
hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, nodeId);

if (!GTEST_OUT_NE(numaNode, nullptr)) {
return false;
if (!GTEST_OUT_NE(numaNode, nullptr)){
return FATAL_RES;
}

// Setup initiator structure.
Expand All @@ -42,9 +42,10 @@ static bool canQueryBandwidth(size_t nodeId) {
hwloc_topology_destroy(topology);

if (!GTEST_OUT_EQ(ret, 0)) {
return false;
} else {
return true;
return SKIP_RES;
}
else {
return SUCCESS_RES;
}
}

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 @@ -60,7 +60,7 @@ TEST_F(memspaceHighestCapacityProviderTest, highestCapacityVerify) {
memset(ptr, 0, alloc_size);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);

int nodeId;
int nodeId = 0;

ASSERT_NO_FATAL_FAILURE(getNumaNodeByPtr(ptr, &nodeId));

Expand Down
17 changes: 9 additions & 8 deletions test/memspaces/memspace_lowest_latency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
canQueryLatency is used in a parameter generator as a functional pointer and is not a standalone test, thus it cannot contain GTEST asserts. EXPECT_* or ADD_FAILURE() do not cancel the execution of the code following after, but they interfere with GTEST_SKIP() in fixtures: the execution of the tests included in the suite assigned to the given fixture is not cancelled if EXPECT_* or ADD_FAILURE() are used. Therefore a custom logging macro is used.
*/

static bool canQueryLatency(size_t nodeId) {
static assert_res canQueryLatency(size_t nodeId) {
hwloc_topology_t topology = nullptr;
int ret = hwloc_topology_init(&topology);

if (!GTEST_OUT_EQ(ret, 0)) {
return false;
return FATAL_RES;
}

ret = hwloc_topology_load(topology);

if (!GTEST_OUT_EQ(ret, 0)) {
return false;
return FATAL_RES;
}

hwloc_obj_t numaNode =
hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, nodeId);

if (!GTEST_OUT_NE(numaNode, nullptr)) {
return false;
return FATAL_RES;
}

// Setup initiator structure.
Expand All @@ -45,10 +45,11 @@ static bool canQueryLatency(size_t nodeId) {

hwloc_topology_destroy(topology);

if (!GTEST_OUT_EQ(ret, 0)) {
return false;
} else {
return true;
if (!GTEST_OUT_EQ(ret, 0)) {
return SKIP_RES;
}
else {
return SUCCESS_RES;
}
}

Expand Down

0 comments on commit d580a36

Please sign in to comment.