@@ -40,6 +40,8 @@ struct PerfSpeEventsTestHelper : public testing::Test {
40
40
41
41
protected:
42
42
using Trace = DataAggregator::Trace;
43
+ using TakenBranchInfo = DataAggregator::TakenBranchInfo;
44
+ using TraceHash = DataAggregator::TraceHash;
43
45
struct MockBranchInfo {
44
46
uint64_t From;
45
47
uint64_t To;
@@ -79,6 +81,23 @@ struct PerfSpeEventsTestHelper : public testing::Test {
79
81
std::unique_ptr<ObjectFile> ObjFile;
80
82
std::unique_ptr<BinaryContext> BC;
81
83
84
+ // Helper function to export lists to show the mismatch
85
+ void exportBrStackEventMismatch (
86
+ const std::unordered_map<Trace, TakenBranchInfo, TraceHash> &BranchLBRs,
87
+ const std::vector<MockBranchInfo> &ExpectedSamples) {
88
+ // Simple export where they differ
89
+ llvm::errs () << " BranchLBRs items: \n " ;
90
+ for (const auto &AggrLBR : BranchLBRs)
91
+ llvm::errs () << " {" << AggrLBR.first .From << " , " << AggrLBR.first .To
92
+ << " , " << AggrLBR.second .TakenCount << " , "
93
+ << AggrLBR.second .MispredCount << " }" << " \n " ;
94
+
95
+ llvm::errs () << " Expected items: \n " ;
96
+ for (const MockBranchInfo &BI : ExpectedSamples)
97
+ llvm::errs () << " {" << BI.From << " , " << BI.To << " , " << BI.TakenCount
98
+ << " , " << BI.MispredCount << " }" << " \n " ;
99
+ }
100
+
82
101
// Parse and check SPE brstack as LBR.
83
102
void parseAndCheckBrstackEvents (
84
103
uint64_t PID, const std::vector<MockBranchInfo> &ExpectedSamples) {
@@ -91,25 +110,18 @@ struct PerfSpeEventsTestHelper : public testing::Test {
91
110
DA.parseBranchEvents ();
92
111
93
112
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
+ if (DA.BranchLBRs .size () != ExpectedSamples.size ())
114
+ exportBrStackEventMismatch (DA.BranchLBRs , ExpectedSamples);
115
+
116
+ for (const MockBranchInfo &BI : ExpectedSamples) {
117
+ // / Check whether the key exists, throws 'std::out_of_range'
118
+ // / if the container does not have an element with the specified key.
119
+ EXPECT_NO_THROW (DA.BranchLBRs .at (Trace (BI.From , BI.To )));
120
+
121
+ EXPECT_EQ (DA.BranchLBRs .at (Trace (BI.From , BI.To )).MispredCount ,
122
+ BI.MispredCount );
123
+ EXPECT_EQ (DA.BranchLBRs .at (Trace (BI.From , BI.To )).TakenCount ,
124
+ BI.TakenCount );
113
125
}
114
126
}
115
127
};
0 commit comments