LLVM OpenMP 22.0.0git
internal-util-test.cpp
Go to the documentation of this file.
1#include "InternalEvent.h"
2#include <omp-tools.h>
3
4#include "gtest/gtest.h"
5
6using namespace omptest;
7using namespace util;
8
9TEST(InternalUtility, ExpectedDefault_Integer) {
10 // int: -2147483648 (decimal) = 0x80000000 (hexadecimal)
11 EXPECT_EQ(expectedDefault(int), 0x80000000);
12 EXPECT_EQ(expectedDefault(int), (0x1 << 31));
13 // int64_t: -9223372036854775808 (decimal) = 0x8000000000000000 (hexadecimal)
14 EXPECT_EQ(expectedDefault(int64_t), 0x8000000000000000);
15 EXPECT_EQ(expectedDefault(int64_t), (0x1L << 63));
16}
17
18TEST(InternalUtility, ExpectedDefault_Zero) {
19 // Expectedly zero
20 EXPECT_EQ(expectedDefault(size_t), 0);
21 EXPECT_EQ(expectedDefault(unsigned int), 0);
22 EXPECT_EQ(expectedDefault(ompt_id_t), 0);
23 EXPECT_EQ(expectedDefault(ompt_dispatch_t), 0);
24 EXPECT_EQ(expectedDefault(ompt_device_time_t), 0);
25}
26
27TEST(InternalUtility, ExpectedDefault_Nullpointer) {
28 // Expectedly nullptr
29 EXPECT_EQ(expectedDefault(const char *), nullptr);
30 EXPECT_EQ(expectedDefault(const void *), nullptr);
31 EXPECT_EQ(expectedDefault(int *), nullptr);
32 EXPECT_EQ(expectedDefault(void *), nullptr);
33 EXPECT_EQ(expectedDefault(ompt_data_t *), nullptr);
34 EXPECT_EQ(expectedDefault(ompt_device_t *), nullptr);
35 EXPECT_EQ(expectedDefault(ompt_frame_t *), nullptr);
36 EXPECT_EQ(expectedDefault(ompt_function_lookup_t), nullptr);
37 EXPECT_EQ(expectedDefault(ompt_id_t *), nullptr);
38}
39
40TEST(InternalUtility, MakeHexString_PointerValues) {
41 // IsPointer should only affect zero value
42 EXPECT_EQ(makeHexString(0, /*IsPointer=*/true), "(nil)");
43 EXPECT_EQ(makeHexString(0, /*IsPointer=*/false), "0x0");
44 EXPECT_EQ(makeHexString(255, /*IsPointer=*/true), "0xff");
45 EXPECT_EQ(makeHexString(255, /*IsPointer=*/false), "0xff");
46}
47
48TEST(InternalUtility, MakeHexString_MinimumBytes) {
49 // Return a minimum length, based on the (minimum) requested bytes
50 EXPECT_EQ(makeHexString(15, /*IsPointer=*/true, /*MinBytes=*/0), "0xf");
51 EXPECT_EQ(makeHexString(15, /*IsPointer=*/true, /*MinBytes=*/1), "0x0f");
52 EXPECT_EQ(makeHexString(255, /*IsPointer=*/true, /*MinBytes=*/0), "0xff");
53 EXPECT_EQ(makeHexString(255, /*IsPointer=*/true, /*MinBytes=*/1), "0xff");
54 EXPECT_EQ(makeHexString(255, /*IsPointer=*/true, /*MinBytes=*/2), "0x00ff");
55 EXPECT_EQ(makeHexString(255, /*IsPointer=*/true, /*MinBytes=*/3), "0x0000ff");
56 EXPECT_EQ(makeHexString(255, /*IsPointer=*/true, /*MinBytes=*/4),
57 "0x000000ff");
58 EXPECT_EQ(makeHexString(255, /*IsPointer=*/true, /*MinBytes=*/5),
59 "0x00000000ff");
60 EXPECT_EQ(makeHexString(255, /*IsPointer=*/true, /*MinBytes=*/6),
61 "0x0000000000ff");
62 EXPECT_EQ(makeHexString(255, /*IsPointer=*/true, /*MinBytes=*/7),
63 "0x000000000000ff");
64 EXPECT_EQ(makeHexString(255, /*IsPointer=*/true, /*MinBytes=*/8),
65 "0x00000000000000ff");
66
67 // Default to four bytes, if request exceeds eight byte range
68 EXPECT_EQ(makeHexString(255, /*IsPointer=*/true, /*MinBytes=*/9),
69 "0x000000ff");
70
71 // Disregard requested minimum byte width, if actual value exceeds it
72 EXPECT_EQ(makeHexString(1024, /*IsPointer=*/true, /*MinBytes=*/1), "0x400");
73}
74
75TEST(InternalUtility, MakeHexString_HexBase) {
76 // Cut off "0x" when requested
77 EXPECT_EQ(makeHexString(0, /*IsPointer=*/true, /*MinBytes=*/0,
78 /*ShowHexBase=*/false),
79 "(nil)");
80 EXPECT_EQ(makeHexString(0, /*IsPointer=*/false, /*MinBytes=*/0,
81 /*ShowHexBase=*/false),
82 "0");
83 EXPECT_EQ(makeHexString(0, /*IsPointer=*/false, /*MinBytes=*/1,
84 /*ShowHexBase=*/false),
85 "00");
86 EXPECT_EQ(makeHexString(255, /*IsPointer=*/true,
87 /*MinBytes=*/2,
88 /*ShowHexBase=*/false),
89 "00ff");
90}
Declares internal event representations along the default CTOR definition.
#define expectedDefault(TypeName)
#define TEST(test_suite_name, test_name)
std::string makeHexString(uint64_t Data, bool IsPointer=true, size_t DataBytes=0, bool ShowHexBase=true)
String manipulation helper function.