Skip to content

Commit d2cf678

Browse files
fix: replace UT_ASSERTs with GTEST asserts
Ref. #569
1 parent 89b660c commit d2cf678

File tree

4 files changed

+78
-10
lines changed

4 files changed

+78
-10
lines changed

test/common/test_helpers.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,34 @@ static inline void UT_OUT(const char *format, ...) {
4242
fprintf(stdout, "\n");
4343
}
4444

45+
static inline bool UT_LOG_ERR(const char *format, ...) {
46+
va_list args_list;
47+
va_start(args_list, format);
48+
vfprintf(stderr, format, args_list);
49+
va_end(args_list);
50+
51+
fprintf(stderr, "\n");
52+
53+
// For lazy evaluation in GTEST_OUT_*
54+
return false;
55+
}
56+
57+
// Assertions which does not impact the program execution
58+
// Formatting is intended to resemble GTEST assertions outputs
59+
#define GTEST_OUT_EQ(lhs, rhs) \
60+
((bool)(((lhs) == (rhs)) || \
61+
UT_LOG_ERR("%s:%d %s - assertion failure\nExpected: %s == %s, " \
62+
"actual: (0x%llx) vs (0x%llx)", \
63+
__FILE__, __LINE__, __func__, #lhs, #rhs, \
64+
(unsigned long long)(lhs), (unsigned long long)(rhs))))
65+
66+
#define GTEST_OUT_NE(lhs, rhs) \
67+
((bool)(((lhs) != (rhs)) || \
68+
UT_LOG_ERR("%s:%d %s - assertion failure\nExpected: %s != %s, " \
69+
"actual: (0x%llx) vs (0x%llx)", \
70+
__FILE__, __LINE__, __func__, #lhs, #rhs, \
71+
(unsigned long long)(lhs), (unsigned long long)(rhs))))
72+
4573
// Assert a condition is true at runtime
4674
#define UT_ASSERT(cnd) \
4775
((void)((cnd) || (UT_FATAL("%s:%d %s - assertion failure: %s", __FILE__, \

test/memspaces/memspace_fixtures.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct memspaceGetTest : ::numaNodesTest,
6666
auto [isQuerySupported, memspaceGet] = this->GetParam();
6767

6868
if (!isQuerySupported(nodeIds.front())) {
69-
GTEST_SKIP();
69+
GTEST_FAIL();
7070
}
7171

7272
hMemspace = memspaceGet();
@@ -80,10 +80,16 @@ struct memspaceProviderTest : ::memspaceGetTest {
8080
void SetUp() override {
8181
::memspaceGetTest::SetUp();
8282

83-
if (::memspaceGetTest::IsSkipped()) {
83+
if (numa_available() == -1 || numa_all_nodes_ptr == nullptr) {
8484
GTEST_SKIP();
8585
}
8686

87+
auto [isQuerySupported, memspaceGet] = ::memspaceGetTest::GetParam();
88+
89+
if (!isQuerySupported(nodeIds.front())) {
90+
GTEST_FAIL();
91+
}
92+
8793
umf_result_t ret =
8894
umfMemoryProviderCreateFromMemspace(hMemspace, nullptr, &hProvider);
8995
ASSERT_EQ(ret, UMF_RESULT_SUCCESS);

test/memspaces/memspace_highest_bandwidth.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,23 @@
1212
static bool canQueryBandwidth(size_t nodeId) {
1313
hwloc_topology_t topology = nullptr;
1414
int ret = hwloc_topology_init(&topology);
15-
UT_ASSERTeq(ret, 0);
15+
16+
if (!GTEST_OUT_EQ(ret, 0)) {
17+
return false;
18+
}
19+
1620
ret = hwloc_topology_load(topology);
17-
UT_ASSERTeq(ret, 0);
21+
22+
if (!GTEST_OUT_EQ(ret, 0)) {
23+
return false;
24+
}
1825

1926
hwloc_obj_t numaNode =
2027
hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, nodeId);
21-
UT_ASSERTne(numaNode, nullptr);
28+
29+
if (!GTEST_OUT_NE(numaNode, nullptr)) {
30+
return false;
31+
}
2232

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

3242
hwloc_topology_destroy(topology);
33-
return (ret == 0);
43+
44+
if (!GTEST_OUT_EQ(ret, 0)) {
45+
return false;
46+
} else {
47+
return true;
48+
}
3449
}
3550

3651
INSTANTIATE_TEST_SUITE_P(memspaceLowestLatencyTest, memspaceGetTest,

test/memspaces/memspace_lowest_latency.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,30 @@
99
#include "memspace_internal.h"
1010
#include "test_helpers.h"
1111

12+
/*
13+
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.
14+
*/
15+
1216
static bool canQueryLatency(size_t nodeId) {
1317
hwloc_topology_t topology = nullptr;
1418
int ret = hwloc_topology_init(&topology);
15-
UT_ASSERTeq(ret, 0);
19+
20+
if (!GTEST_OUT_EQ(ret, 0)) {
21+
return false;
22+
}
23+
1624
ret = hwloc_topology_load(topology);
17-
UT_ASSERTeq(ret, 0);
25+
26+
if (!GTEST_OUT_EQ(ret, 0)) {
27+
return false;
28+
}
1829

1930
hwloc_obj_t numaNode =
2031
hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, nodeId);
21-
UT_ASSERTne(numaNode, nullptr);
32+
33+
if (!GTEST_OUT_NE(numaNode, nullptr)) {
34+
return false;
35+
}
2236

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

3246
hwloc_topology_destroy(topology);
33-
return (ret == 0);
47+
48+
if (!GTEST_OUT_EQ(ret, 0)) {
49+
return false;
50+
} else {
51+
return true;
52+
}
3453
}
3554

3655
INSTANTIATE_TEST_SUITE_P(memspaceLowestLatencyTest, memspaceGetTest,

0 commit comments

Comments
 (0)