@@ -40,6 +40,12 @@ struct PerfSpeEventsTestHelper : public testing::Test {
4040
4141protected:
4242 using Trace = DataAggregator::Trace;
43+ struct MockBranchInfo {
44+ uint64_t From;
45+ uint64_t To;
46+ uint64_t TakenCount;
47+ uint64_t MispredCount;
48+ };
4349
4450 void initalizeLLVM () {
4551 llvm::InitializeAllTargetInfos ();
@@ -74,8 +80,8 @@ struct PerfSpeEventsTestHelper : public testing::Test {
7480 std::unique_ptr<BinaryContext> BC;
7581
7682 // Parse and check SPE brstack as LBR.
77- void parseAndCheckBrstackEvents (uint64_t PID, uint64_t From, uint64_t To,
78- uint64_t Count, size_t SampleSize ) {
83+ void parseAndCheckBrstackEvents (
84+ uint64_t PID, const std::vector<MockBranchInfo> &ExpectedSamples ) {
7985 DataAggregator DA (" <pseudo input>" );
8086 DA.ParsingBuf = opts::ReadPerfEvents;
8187 DA.BC = BC.get ();
@@ -84,9 +90,27 @@ struct PerfSpeEventsTestHelper : public testing::Test {
8490
8591 DA.parseBranchEvents ();
8692
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);
93+ EXPECT_EQ (DA.BranchLBRs .size (), ExpectedSamples.size ());
94+ if (DA.BranchLBRs .size () != ExpectedSamples.size ()) {
95+ // Simple export where they differ
96+ llvm::errs () << " BranchLBRs items: \n " ;
97+ for (const auto &AggrLBR : DA.BranchLBRs )
98+ llvm::errs () << " {" << AggrLBR.first .From << " , " << AggrLBR.first .To
99+ << " , " << AggrLBR.second .TakenCount << " , "
100+ << AggrLBR.second .MispredCount << " }" << " \n " ;
101+
102+ llvm::errs () << " Expected items: \n " ;
103+ for (const MockBranchInfo &BI : ExpectedSamples)
104+ llvm::errs () << " {" << BI.From << " , " << BI.To << " , " << BI.TakenCount
105+ << " , " << BI.MispredCount << " }" << " \n " ;
106+ } else {
107+ for (const MockBranchInfo &BI : ExpectedSamples) {
108+ EXPECT_EQ (DA.BranchLBRs .at (Trace (BI.From , BI.To )).MispredCount ,
109+ BI.MispredCount );
110+ EXPECT_EQ (DA.BranchLBRs .at (Trace (BI.From , BI.To )).TakenCount ,
111+ BI.TakenCount );
112+ }
113+ }
90114 }
91115};
92116
@@ -107,13 +131,25 @@ TEST_F(PerfSpeEventsTestHelper, SpeBranchesWithBrstack) {
107131 opts::ArmSPE = true ;
108132 opts::ReadPerfEvents = " 1234 0xa001/0xa002/PN/-/-/10/COND/-\n "
109133 " 1234 0xb001/0xb002/P/-/-/4/RET/-\n "
110- " 1234 0xc001/0xc002 /P/-/-/13/-/-\n "
111- " 1234 0xd001/0xd002 /M/-/-/7/RET/-\n "
134+ " 1234 0xc456/0xc789 /P/-/-/13/-/-\n "
135+ " 1234 0xd123/0xd456 /M/-/-/7/RET/-\n "
112136 " 1234 0xe001/0xe002/P/-/-/14/RET/-\n "
113- " 1234 0xd001/0xd002/M/-/-/7/RET/-\n "
114- " 1234 0xf001/0xf002/MN/-/-/8/COND/-\n " ;
115-
116- parseAndCheckBrstackEvents (1234 , 0xd001 , 0xd002 , 2 , 6 );
137+ " 1234 0xd123/0xd456/M/-/-/7/RET/-\n "
138+ " 1234 0xf001/0xf002/MN/-/-/8/COND/-\n "
139+ " 1234 0xc456/0xc789/M/-/-/13/-/-\n " ;
140+
141+ // MockBranchInfo contains the aggregated information about
142+ // a Branch {From, To, TakenCount, MispredCount}.
143+ // Let's check the following example: {0xd123, 0xd456, 2, 2}.
144+ // This entry has a TakenCount = 2,
145+ // as we have two samples for (0xd123, 0xd456) in our input.
146+ // It also has MispredsCount = 2, as 'M' misprediction flag
147+ // appears in both cases.
148+ std::vector<MockBranchInfo> ExpectedSamples = {
149+ {0xa001 , 0xa002 , 1 , 0 }, {0xb001 , 0xb002 , 1 , 0 }, {0xc456 , 0xc789 , 2 , 1 },
150+ {0xd123 , 0xd456 , 2 , 2 }, {0xe001 , 0xe002 , 1 , 0 }, {0xf001 , 0xf002 , 1 , 1 }};
151+
152+ parseAndCheckBrstackEvents (1234 , ExpectedSamples);
117153}
118154
119155#endif
0 commit comments