@@ -39,7 +39,7 @@ struct PerfSpeEventsTestHelper : public testing::Test {
39
39
}
40
40
41
41
protected:
42
- using LBREntry = DataAggregator::LBREntry ;
42
+ using Trace = DataAggregator::Trace ;
43
43
44
44
void initalizeLLVM () {
45
45
llvm::InitializeAllTargetInfos ();
@@ -73,40 +73,20 @@ struct PerfSpeEventsTestHelper : public testing::Test {
73
73
std::unique_ptr<ObjectFile> ObjFile;
74
74
std::unique_ptr<BinaryContext> BC;
75
75
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
-
82
76
// 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) {
88
79
DataAggregator DA (" <pseudo input>" );
89
80
DA.ParsingBuf = opts::ReadPerfEvents;
90
81
DA.BC = BC.get ();
91
82
DataAggregator::MMapInfo MMap;
92
83
DA.BinaryMMapInfo .insert (std::make_pair (PID, MMap));
93
84
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);
110
90
}
111
91
};
112
92
@@ -130,14 +110,10 @@ TEST_F(PerfSpeEventsTestHelper, SpeBranchesWithBrstack) {
130
110
" 1234 0xc001/0xc002/P/-/-/13/-/-\n "
131
111
" 1234 0xd001/0xd002/M/-/-/7/RET/-\n "
132
112
" 1234 0xe001/0xe002/P/-/-/14/RET/-\n "
113
+ " 1234 0xd001/0xd002/M/-/-/7/RET/-\n "
133
114
" 1234 0xf001/0xf002/MN/-/-/8/COND/-\n " ;
134
115
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 );
141
117
}
142
118
143
119
#endif
0 commit comments