1 //===- llvm/unittest/XRay/FDRBlockVerifierTest.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/Testing/Support/Error.h"
10 #include "llvm/XRay/BlockIndexer.h"
11 #include "llvm/XRay/BlockVerifier.h"
12 #include "llvm/XRay/FDRLogBuilder.h"
13 #include "llvm/XRay/FDRRecords.h"
14 #include "gmock/gmock.h"
15 #include "gtest/gtest.h"
21 using ::testing::ElementsAre
;
23 using ::testing::SizeIs
;
25 TEST(FDRBlockVerifierTest
, ValidBlocksV3
) {
26 auto Block0
= LogBuilder()
27 .add
<BufferExtents
>(80)
28 .add
<NewBufferRecord
>(1)
29 .add
<WallclockRecord
>(1, 2)
31 .add
<NewCPUIDRecord
>(1, 2)
32 .add
<FunctionRecord
>(RecordTypes::ENTER
, 1, 1)
33 .add
<FunctionRecord
>(RecordTypes::EXIT
, 1, 100)
35 auto Block1
= LogBuilder()
36 .add
<BufferExtents
>(80)
37 .add
<NewBufferRecord
>(1)
38 .add
<WallclockRecord
>(1, 2)
40 .add
<NewCPUIDRecord
>(1, 2)
41 .add
<FunctionRecord
>(RecordTypes::ENTER
, 1, 1)
42 .add
<FunctionRecord
>(RecordTypes::EXIT
, 1, 100)
44 auto Block2
= LogBuilder()
45 .add
<BufferExtents
>(80)
46 .add
<NewBufferRecord
>(2)
47 .add
<WallclockRecord
>(1, 2)
49 .add
<NewCPUIDRecord
>(2, 2)
50 .add
<FunctionRecord
>(RecordTypes::ENTER
, 1, 1)
51 .add
<FunctionRecord
>(RecordTypes::EXIT
, 1, 100)
53 BlockIndexer::Index Index
;
54 BlockIndexer
Indexer(Index
);
55 for (auto B
: {std::ref(Block0
), std::ref(Block1
), std::ref(Block2
)}) {
56 for (auto &R
: B
.get())
57 ASSERT_FALSE(errorToBool(R
->apply(Indexer
)));
58 ASSERT_FALSE(errorToBool(Indexer
.flush()));
61 BlockVerifier Verifier
;
62 for (auto &ProcessThreadBlocks
: Index
) {
63 auto &Blocks
= ProcessThreadBlocks
.second
;
64 for (auto &B
: Blocks
) {
65 for (auto *R
: B
.Records
)
66 ASSERT_FALSE(errorToBool(R
->apply(Verifier
)));
67 ASSERT_FALSE(errorToBool(Verifier
.verify()));
73 TEST(FDRBlockVerifierTest
, MissingPIDRecord
) {
74 auto Block
= LogBuilder()
75 .add
<BufferExtents
>(20)
76 .add
<NewBufferRecord
>(1)
77 .add
<WallclockRecord
>(1, 2)
78 .add
<NewCPUIDRecord
>(1, 2)
79 .add
<FunctionRecord
>(RecordTypes::ENTER
, 1, 1)
80 .add
<FunctionRecord
>(RecordTypes::EXIT
, 1, 100)
82 BlockVerifier Verifier
;
84 ASSERT_FALSE(errorToBool(R
->apply(Verifier
)));
85 ASSERT_FALSE(errorToBool(Verifier
.verify()));
88 TEST(FDRBlockVerifierTest
, MissingBufferExtents
) {
89 auto Block
= LogBuilder()
90 .add
<NewBufferRecord
>(1)
91 .add
<WallclockRecord
>(1, 2)
92 .add
<NewCPUIDRecord
>(1, 2)
93 .add
<FunctionRecord
>(RecordTypes::ENTER
, 1, 1)
94 .add
<FunctionRecord
>(RecordTypes::EXIT
, 1, 100)
96 BlockVerifier Verifier
;
98 ASSERT_FALSE(errorToBool(R
->apply(Verifier
)));
99 ASSERT_FALSE(errorToBool(Verifier
.verify()));
102 TEST(FDRBlockVerifierTest
, IgnoreRecordsAfterEOB
) {
103 auto Block
= LogBuilder()
104 .add
<NewBufferRecord
>(1)
105 .add
<WallclockRecord
>(1, 2)
106 .add
<NewCPUIDRecord
>(1, 2)
107 .add
<EndBufferRecord
>()
108 .add
<FunctionRecord
>(RecordTypes::ENTER
, 1, 1)
109 .add
<FunctionRecord
>(RecordTypes::EXIT
, 1, 100)
111 BlockVerifier Verifier
;
112 for (auto &R
: Block
)
113 ASSERT_FALSE(errorToBool(R
->apply(Verifier
)));
114 ASSERT_FALSE(errorToBool(Verifier
.verify()));
117 TEST(FDRBlockVerifierTest
, MalformedV2
) {
118 auto Block
= LogBuilder()
119 .add
<NewBufferRecord
>(1)
120 .add
<WallclockRecord
>(1, 2)
121 .add
<NewCPUIDRecord
>(1, 2)
122 .add
<FunctionRecord
>(RecordTypes::ENTER
, 1, 1)
123 .add
<FunctionRecord
>(RecordTypes::EXIT
, 1, 100)
124 .add
<NewBufferRecord
>(2)
126 BlockVerifier Verifier
;
128 ASSERT_THAT(Block
, SizeIs(6u));
129 EXPECT_THAT_ERROR(Block
[0]->apply(Verifier
), Succeeded());
130 EXPECT_THAT_ERROR(Block
[1]->apply(Verifier
), Succeeded());
131 EXPECT_THAT_ERROR(Block
[2]->apply(Verifier
), Succeeded());
132 EXPECT_THAT_ERROR(Block
[3]->apply(Verifier
), Succeeded());
133 EXPECT_THAT_ERROR(Block
[4]->apply(Verifier
), Succeeded());
134 EXPECT_THAT_ERROR(Block
[5]->apply(Verifier
), Failed());