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