Skip to content

Commit 28de2e0

Browse files
authored
[offload][omptest] Add internal unittests for ompTest (llvm#698)
2 parents 7c9a129 + fd47efe commit 28de2e0

File tree

6 files changed

+653
-11
lines changed

6 files changed

+653
-11
lines changed

offload/test/ompTest/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ target_include_directories(omptest
6363

6464
if(LIBOMPTEST_BUILD_UNITTESTS)
6565
include(GoogleTest)
66-
add_executable(omptest-unittests test/main-test.cpp)
66+
add_executable(omptest-unittests
67+
68+
test/main-test.cpp
69+
test/internal-event-test.cpp
70+
test/internal-util-test.cpp
71+
)
6772
target_link_libraries(omptest-unittests omptest)
6873
target_link_libraries(omptest-unittests gtest gtest_main)
6974
endif()

offload/test/ompTest/include/InternalEvent.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111

1212
namespace omptest {
1313

14+
namespace util {
15+
16+
/// String manipulation helper function. Takes up to 8 bytes of data and returns
17+
/// their hexadecimal representation as string. The data can be expanded to the
18+
/// given size in bytes and will by default be prefixed with '0x'.
19+
std::string makeHexString(uint64_t Data, bool IsPointer = true,
20+
size_t DataBytes = 0, bool ShowHexBase = true);
21+
22+
} // namespace util
23+
1424
namespace internal {
1525
// clang-format off
1626
event_class_w_custom_body(AssertionSyncPoint, \

offload/test/ompTest/src/InternalEvent.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
#include <sstream>
55

66
using namespace omptest;
7+
using namespace util;
78

8-
/// String manipulation helper function. Takes up to 8 bytes of data and returns
9-
/// their hexadecimal representation as string. The data can be truncated to a
10-
/// certain size in bytes and will by default be prefixed with '0x'.
11-
std::string makeHexString(uint64_t Data, bool IsPointer = true,
12-
size_t DataBytes = 0, bool ShowHexBase = true) {
9+
std::string util::makeHexString(uint64_t Data, bool IsPointer, size_t MinBytes,
10+
bool ShowHexBase) {
1311
if (Data == 0 && IsPointer)
1412
return "(nil)";
1513

@@ -21,10 +19,10 @@ std::string makeHexString(uint64_t Data, bool IsPointer = true,
2119
if (ShowHexBase)
2220
os << "0x";
2321

24-
// Default to 32bit (8 hex digits) width if exceeding 64bit or zero value
25-
size_t NumDigits = (DataBytes > 0 && DataBytes < 9) ? (DataBytes << 1) : 8;
22+
// Default to 32bit (8 hex digits) width, if exceeding 64bit or zero value
23+
size_t NumDigits = (MinBytes > 0 && MinBytes < 9) ? (MinBytes << 1) : 8;
2624

27-
if (DataBytes > 0)
25+
if (MinBytes > 0)
2826
os << std::setfill('0') << std::setw(NumDigits);
2927

3028
os << std::hex << Data;
@@ -55,6 +53,7 @@ std::string internal::ParallelBegin::toString() const {
5553
}
5654

5755
std::string internal::ParallelEnd::toString() const {
56+
// TODO: Should we expose more detailed info here?
5857
std::string S{"OMPT Callback ParallelEnd"};
5958
return S;
6059
}
@@ -77,7 +76,7 @@ std::string internal::Dispatch::toString() const {
7776
S.append(" kind=").append(std::to_string(Kind));
7877
// TODO Check what to print for instance in all different cases
7978
if (Kind == ompt_dispatch_iteration) {
80-
S.append(" instance[it=")
79+
S.append(" instance=[it=")
8180
.append(std::to_string(Instance.value))
8281
.append(1, ']');
8382
} else if (Kind == ompt_dispatch_section) {
@@ -133,6 +132,7 @@ std::string internal::SyncRegion::toString() const {
133132
}
134133

135134
std::string internal::Target::toString() const {
135+
// TODO Should we canonicalize the string prefix (use "OMPT ..." everywhere)?
136136
std::string S{"Callback Target: target_id="};
137137
S.append(std::to_string(TargetId));
138138
S.append(" kind=").append(std::to_string(Kind));
@@ -143,6 +143,7 @@ std::string internal::Target::toString() const {
143143
}
144144

145145
std::string internal::TargetEmi::toString() const {
146+
// TODO Should we canonicalize the string prefix (use "OMPT ..." everywhere)?
146147
std::string S{"Callback Target EMI: kind="};
147148
S.append(std::to_string(Kind));
148149
S.append(" endpoint=").append(std::to_string(Endpoint));
@@ -338,7 +339,7 @@ std::string internal::BufferRecord::toString() const {
338339
break;
339340
}
340341
default:
341-
S.append("Unsupported record type: ").append(std::to_string(Record.type));
342+
S.append(" (unsupported record type)");
342343
break;
343344
}
344345

0 commit comments

Comments
 (0)