[llvm-exegesis][NFC] Return many CodeTemplates instead of one.
[llvm-complete.git] / unittests / XRay / FDRBlockIndexerTest.cpp
blob558840b111a6b4ea589bc8651584075173600354
1 //===- llvm/unittest/XRay/FDRTraceWriterTest.cpp ----------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
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"
15 namespace llvm {
16 namespace xray {
17 namespace {
19 using ::testing::ElementsAre;
20 using ::testing::Eq;
21 using ::testing::Field;
22 using ::testing::Not;
23 using ::testing::SizeIs;
25 // This test ensures that we can index blocks that follow version 3 of the log
26 // format.
27 TEST(FDRBlockIndexerTest, IndexBlocksV3) {
28 auto Block0 = LogBuilder()
29 .add<BufferExtents>(80)
30 .add<NewBufferRecord>(1)
31 .add<WallclockRecord>(1, 2)
32 .add<PIDRecord>(1)
33 .add<NewCPUIDRecord>(1, 2)
34 .add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
35 .add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
36 .consume();
37 auto Block1 = LogBuilder()
38 .add<BufferExtents>(80)
39 .add<NewBufferRecord>(1)
40 .add<WallclockRecord>(1, 2)
41 .add<PIDRecord>(1)
42 .add<NewCPUIDRecord>(1, 2)
43 .add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
44 .add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
45 .consume();
46 auto Block2 = LogBuilder()
47 .add<BufferExtents>(80)
48 .add<NewBufferRecord>(2)
49 .add<WallclockRecord>(1, 2)
50 .add<PIDRecord>(1)
51 .add<NewCPUIDRecord>(2, 2)
52 .add<FunctionRecord>(RecordTypes::ENTER, 1, 1)
53 .add<FunctionRecord>(RecordTypes::EXIT, 1, 100)
54 .consume();
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,
76 SizeIs(Eq(6u)))));
79 // FIXME: Support indexing V2 and V1 blocks.
81 } // namespace
82 } // namespace xray
83 } // namespace llvm