@@ -39,7 +39,7 @@ struct PerfSpeEventsTestHelper : public testing::Test {
3939 }
4040
4141protected:
42- using LBREntry = DataAggregator::LBREntry ;
42+ using Trace = DataAggregator::Trace ;
4343
4444 void initalizeLLVM () {
4545 llvm::InitializeAllTargetInfos ();
@@ -73,40 +73,20 @@ struct PerfSpeEventsTestHelper : public testing::Test {
7373 std::unique_ptr<ObjectFile> ObjFile;
7474 std::unique_ptr<BinaryContext> BC;
7575
76- // @return true if LBREntries are equal.
77- bool checkLBREntry (const LBREntry &Lhs, const LBREntry &Rhs) {
78- return Lhs.From == Rhs.From && Lhs.To == Rhs.To &&
79- Lhs.Mispred == Rhs.Mispred ;
80- }
81-
8276 // Parse and check SPE brstack as LBR.
83- void parseAndCheckBrstackEvents (
84- uint64_t PID,
85- const std::vector<SmallVector<LBREntry, 2 >> &ExpectedSamples) {
86- int NumSamples = 0 ;
87-
77+ void parseAndCheckBrstackEvents (uint64_t PID, uint64_t From, uint64_t To,
78+ uint64_t Count, size_t SampleSize) {
8879 DataAggregator DA (" <pseudo input>" );
8980 DA.ParsingBuf = opts::ReadPerfEvents;
9081 DA.BC = BC.get ();
9182 DataAggregator::MMapInfo MMap;
9283 DA.BinaryMMapInfo .insert (std::make_pair (PID, MMap));
9384
94- // Process buffer.
95- while (DA.hasData ()) {
96- ErrorOr<DataAggregator::PerfBranchSample> SampleRes =
97- DA.parseBranchSample ();
98- if (std::error_code EC = SampleRes.getError ())
99- EXPECT_NE (EC, std::errc::no_such_process);
100-
101- DataAggregator::PerfBranchSample &Sample = SampleRes.get ();
102- EXPECT_EQ (Sample.LBR .size (), ExpectedSamples[NumSamples].size ());
103-
104- // Check the parsed LBREntries.
105- for (auto [Actual, Expected] :
106- zip_equal (Sample.LBR , ExpectedSamples[NumSamples]))
107- EXPECT_TRUE (checkLBREntry (Actual, Expected));
108- ++NumSamples;
109- }
85+ DA.parseBranchEvents ();
86+
87+ EXPECT_EQ (DA.BranchLBRs .size (), SampleSize);
88+ EXPECT_EQ (DA.BranchLBRs [Trace (From, To)].MispredCount , Count);
89+ EXPECT_EQ (DA.BranchLBRs [Trace (From, To)].TakenCount , Count);
11090 }
11191};
11292
@@ -130,14 +110,10 @@ TEST_F(PerfSpeEventsTestHelper, SpeBranchesWithBrstack) {
130110 " 1234 0xc001/0xc002/P/-/-/13/-/-\n "
131111 " 1234 0xd001/0xd002/M/-/-/7/RET/-\n "
132112 " 1234 0xe001/0xe002/P/-/-/14/RET/-\n "
113+ " 1234 0xd001/0xd002/M/-/-/7/RET/-\n "
133114 " 1234 0xf001/0xf002/MN/-/-/8/COND/-\n " ;
134115
135- std::vector<SmallVector<LBREntry>> ExpectedSamples = {
136- {{{0xa001 , 0xa002 , false }}}, {{{0xb001 , 0xb002 , false }}},
137- {{{0xc001 , 0xc002 , false }}}, {{{0xd001 , 0xd002 , true }}},
138- {{{0xe001 , 0xe002 , false }}}, {{{0xf001 , 0xf002 , true }}},
139- };
140- parseAndCheckBrstackEvents (1234 , ExpectedSamples);
116+ parseAndCheckBrstackEvents (1234 , 0xd001 , 0xd002 , 2 , 6 );
141117}
142118
143119#endif
0 commit comments