1 //===- llvm/unittest/XRay/FDRRecordPrinterTest.cpp --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/raw_ostream.h"
10 #include "llvm/XRay/FDRRecords.h"
11 #include "llvm/XRay/RecordPrinter.h"
12 #include "gmock/gmock.h"
13 #include "gtest/gtest.h"
22 template <class RecordType
> struct Helper
{};
24 template <> struct Helper
<BufferExtents
> {
25 static std::unique_ptr
<Record
> construct() {
26 return make_unique
<BufferExtents
>(1);
29 static const char *expected() { return "<Buffer: size = 1 bytes>"; }
32 template <> struct Helper
<WallclockRecord
> {
33 static std::unique_ptr
<Record
> construct() {
34 return make_unique
<WallclockRecord
>(1, 2);
37 static const char *expected() { return "<Wall Time: seconds = 1.000002>"; }
40 template <> struct Helper
<NewCPUIDRecord
> {
41 static std::unique_ptr
<Record
> construct() {
42 return make_unique
<NewCPUIDRecord
>(1, 2);
45 static const char *expected() { return "<CPU: id = 1, tsc = 2>"; }
48 template <> struct Helper
<TSCWrapRecord
> {
49 static std::unique_ptr
<Record
> construct() {
50 return make_unique
<TSCWrapRecord
>(1);
53 static const char *expected() { return "<TSC Wrap: base = 1>"; }
56 template <> struct Helper
<CustomEventRecord
> {
57 static std::unique_ptr
<Record
> construct() {
58 return make_unique
<CustomEventRecord
>(4, 1, "data");
61 static const char *expected() {
62 return "<Custom Event: tsc = 1, size = 4, data = 'data'>";
66 template <> struct Helper
<CallArgRecord
> {
67 static std::unique_ptr
<Record
> construct() {
68 return make_unique
<CallArgRecord
>(1);
71 static const char *expected() {
72 return "<Call Argument: data = 1 (hex = 0x1)>";
76 template <> struct Helper
<PIDRecord
> {
77 static std::unique_ptr
<Record
> construct() {
78 return make_unique
<PIDRecord
>(1);
81 static const char *expected() { return "<PID: 1>"; }
84 template <> struct Helper
<NewBufferRecord
> {
85 static std::unique_ptr
<Record
> construct() {
86 return make_unique
<NewBufferRecord
>(1);
89 static const char *expected() { return "<Thread ID: 1>"; }
92 template <> struct Helper
<EndBufferRecord
> {
93 static std::unique_ptr
<Record
> construct() {
94 return make_unique
<EndBufferRecord
>();
97 static const char *expected() { return "<End of Buffer>"; }
100 template <class T
> class PrinterTest
: public ::testing::Test
{
103 raw_string_ostream OS
;
105 std::unique_ptr
<Record
> R
;
108 PrinterTest() : Data(), OS(Data
), P(OS
), R(Helper
<T
>::construct()) {}
111 TYPED_TEST_CASE_P(PrinterTest
);
113 TYPED_TEST_P(PrinterTest
, PrintsRecord
) {
114 ASSERT_NE(nullptr, this->R
);
115 ASSERT_FALSE(errorToBool(this->R
->apply(this->P
)));
117 EXPECT_THAT(this->Data
, Eq(Helper
<TypeParam
>::expected()));
120 REGISTER_TYPED_TEST_CASE_P(PrinterTest
, PrintsRecord
);
121 using FDRRecordTypes
=
122 ::testing::Types
<BufferExtents
, NewBufferRecord
, EndBufferRecord
,
123 NewCPUIDRecord
, TSCWrapRecord
, WallclockRecord
,
124 CustomEventRecord
, CallArgRecord
, BufferExtents
,
126 INSTANTIATE_TYPED_TEST_CASE_P(Records
, PrinterTest
, FDRRecordTypes
);
128 TEST(FDRRecordPrinterTest
, WriteFunctionRecordEnter
) {
130 raw_string_ostream
OS(Data
);
132 FunctionRecord
R(RecordTypes::ENTER
, 1, 2);
133 ASSERT_FALSE(errorToBool(R
.apply(P
)));
135 EXPECT_THAT(Data
, Eq("<Function Enter: #1 delta = +1>"));
138 TEST(FDRRecordPrinterTest
, WriteFunctionRecordExit
) {
140 raw_string_ostream
OS(Data
);
142 FunctionRecord
R(RecordTypes::EXIT
, 1, 2);
143 ASSERT_FALSE(errorToBool(R
.apply(P
)));
145 EXPECT_THAT(Data
, Eq("<Function Exit: #1 delta = +1>"));
148 TEST(FDRRecordPrinterTest
, WriteFunctionRecordTailExit
) {
150 raw_string_ostream
OS(Data
);
152 FunctionRecord
R(RecordTypes::TAIL_EXIT
, 1, 2);
153 ASSERT_FALSE(errorToBool(R
.apply(P
)));
155 EXPECT_THAT(Data
, Eq("<Function Tail Exit: #1 delta = +1>"));
158 TEST(FDRRecordPrinterTest
, WriteFunctionRecordEnterArg
) {
160 raw_string_ostream
OS(Data
);
162 FunctionRecord
R(RecordTypes::ENTER_ARG
, 1, 2);
163 ASSERT_FALSE(errorToBool(R
.apply(P
)));
165 EXPECT_THAT(Data
, Eq("<Function Enter With Arg: #1 delta = +1>"));