1 //===- llvm/unittest/XRay/FDRTraceWriterTest.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/XRay/BlockIndexer.h"
10 #include "llvm/XRay/FDRLogBuilder.h"
11 #include "llvm/XRay/FDRRecords.h"
12 #include "gmock/gmock.h"
13 #include "gtest/gtest.h"
19 using ::testing::ElementsAre
;
21 using ::testing::Field
;
23 using ::testing::SizeIs
;
25 // This test ensures that we can index blocks that follow version 3 of the log
27 TEST(FDRBlockIndexerTest
, IndexBlocksV3
) {
28 auto Block0
= LogBuilder()
29 .add
<BufferExtents
>(80)
30 .add
<NewBufferRecord
>(1)
31 .add
<WallclockRecord
>(1, 2)
33 .add
<NewCPUIDRecord
>(1, 2)
34 .add
<FunctionRecord
>(RecordTypes::ENTER
, 1, 1)
35 .add
<FunctionRecord
>(RecordTypes::EXIT
, 1, 100)
37 auto Block1
= LogBuilder()
38 .add
<BufferExtents
>(80)
39 .add
<NewBufferRecord
>(1)
40 .add
<WallclockRecord
>(1, 2)
42 .add
<NewCPUIDRecord
>(1, 2)
43 .add
<FunctionRecord
>(RecordTypes::ENTER
, 1, 1)
44 .add
<FunctionRecord
>(RecordTypes::EXIT
, 1, 100)
46 auto Block2
= LogBuilder()
47 .add
<BufferExtents
>(80)
48 .add
<NewBufferRecord
>(2)
49 .add
<WallclockRecord
>(1, 2)
51 .add
<NewCPUIDRecord
>(2, 2)
52 .add
<FunctionRecord
>(RecordTypes::ENTER
, 1, 1)
53 .add
<FunctionRecord
>(RecordTypes::EXIT
, 1, 100)
55 BlockIndexer::Index Index
;
56 BlockIndexer
Indexer(Index
);
57 // Iterate through the contrived blocks we have created above.
58 for (auto B
: {std::ref(Block0
), std::ref(Block1
), std::ref(Block2
)}) {
59 // For each record in the block, we apply the indexer.
60 for (auto &R
: B
.get())
61 ASSERT_FALSE(errorToBool(R
->apply(Indexer
)));
62 ASSERT_FALSE(errorToBool(Indexer
.flush()));
65 ASSERT_THAT(Index
.size(), Eq(2u));
66 auto T1Blocks
= Index
.find({1, 1});
67 ASSERT_THAT(T1Blocks
, Not(Eq(Index
.end())));
69 // Expect only six records, because we're ignoring the BufferExtents record.
70 EXPECT_THAT(T1Blocks
->second
,
71 ElementsAre(Field(&BlockIndexer::Block::Records
, SizeIs(6u)),
72 Field(&BlockIndexer::Block::Records
, SizeIs(6u))));
73 auto T2Blocks
= Index
.find({1, 2});
74 ASSERT_THAT(T2Blocks
, Not(Eq(Index
.end())));
75 EXPECT_THAT(T2Blocks
->second
, ElementsAre(Field(&BlockIndexer::Block::Records
,
79 // FIXME: Support indexing V2 and V1 blocks.