Skip to content

Commit

Permalink
fix: replace UT_ASSERTs with GTEST asserts
Browse files Browse the repository at this point in the history
Ref. #569
  • Loading branch information
EuphoricThinking committed Sep 2, 2024
1 parent 89b660c commit d2cf678
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 10 deletions.
28 changes: 28 additions & 0 deletions test/common/test_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,34 @@ static inline void UT_OUT(const char *format, ...) {
fprintf(stdout, "\n");
}

static inline bool UT_LOG_ERR(const char *format, ...) {
va_list args_list;
va_start(args_list, format);
vfprintf(stderr, format, args_list);
va_end(args_list);

fprintf(stderr, "\n");

// For lazy evaluation in GTEST_OUT_*
return false;
}

// Assertions which does not impact the program execution
// Formatting is intended to resemble GTEST assertions outputs
#define GTEST_OUT_EQ(lhs, rhs) \
((bool)(((lhs) == (rhs)) || \
UT_LOG_ERR("%s:%d %s - assertion failure\nExpected: %s == %s, " \
"actual: (0x%llx) vs (0x%llx)", \
__FILE__, __LINE__, __func__, #lhs, #rhs, \
(unsigned long long)(lhs), (unsigned long long)(rhs))))

#define GTEST_OUT_NE(lhs, rhs) \
((bool)(((lhs) != (rhs)) || \
UT_LOG_ERR("%s:%d %s - assertion failure\nExpected: %s != %s, " \
"actual: (0x%llx) vs (0x%llx)", \
__FILE__, __LINE__, __func__, #lhs, #rhs, \
(unsigned long long)(lhs), (unsigned long long)(rhs))))

// Assert a condition is true at runtime
#define UT_ASSERT(cnd) \
((void)((cnd) || (UT_FATAL("%s:%d %s - assertion failure: %s", __FILE__, \
Expand Down
10 changes: 8 additions & 2 deletions test/memspaces/memspace_fixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct memspaceGetTest : ::numaNodesTest,
auto [isQuerySupported, memspaceGet] = this->GetParam();

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

hMemspace = memspaceGet();
Expand All @@ -80,10 +80,16 @@ struct memspaceProviderTest : ::memspaceGetTest {
void SetUp() override {
::memspaceGetTest::SetUp();

if (::memspaceGetTest::IsSkipped()) {
if (numa_available() == -1 || numa_all_nodes_ptr == nullptr) {
GTEST_SKIP();
}

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

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

umf_result_t ret =
umfMemoryProviderCreateFromMemspace(hMemspace, nullptr, &hProvider);
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);
Expand Down
23 changes: 19 additions & 4 deletions test/memspaces/memspace_highest_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@
static bool canQueryBandwidth(size_t nodeId) {
hwloc_topology_t topology = nullptr;
int ret = hwloc_topology_init(&topology);
UT_ASSERTeq(ret, 0);

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

ret = hwloc_topology_load(topology);
UT_ASSERTeq(ret, 0);

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

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

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

// Setup initiator structure.
struct hwloc_location initiator;
Expand All @@ -30,7 +40,12 @@ static bool canQueryBandwidth(size_t nodeId) {
numaNode, &initiator, 0, &value);

hwloc_topology_destroy(topology);
return (ret == 0);

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

INSTANTIATE_TEST_SUITE_P(memspaceLowestLatencyTest, memspaceGetTest,
Expand Down
27 changes: 23 additions & 4 deletions test/memspaces/memspace_lowest_latency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,30 @@
#include "memspace_internal.h"
#include "test_helpers.h"

/*
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) {
hwloc_topology_t topology = nullptr;
int ret = hwloc_topology_init(&topology);
UT_ASSERTeq(ret, 0);

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

ret = hwloc_topology_load(topology);
UT_ASSERTeq(ret, 0);

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

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

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

// Setup initiator structure.
struct hwloc_location initiator;
Expand All @@ -30,7 +44,12 @@ static bool canQueryLatency(size_t nodeId) {
&initiator, 0, &value);

hwloc_topology_destroy(topology);
return (ret == 0);

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

INSTANTIATE_TEST_SUITE_P(memspaceLowestLatencyTest, memspaceGetTest,
Expand Down

0 comments on commit d2cf678

Please sign in to comment.