Skip to content

Commit 18ba358

Browse files
committed
Updated the test case.
1 parent 0ec7079 commit 18ba358

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

bolt/unittests/Profile/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ target_link_libraries(ProfileTests
2222
foreach (tgt ${BOLT_TARGETS_TO_BUILD})
2323
string(TOUPPER "${tgt}" upper)
2424
target_compile_definitions(ProfileTests PRIVATE "${upper}_AVAILABLE")
25+
# Enable exceptions for GTEST EXPECT_NO_THROW
26+
target_compile_options(ProfileTests PRIVATE "-fexceptions")
2527
endforeach()

bolt/unittests/Profile/PerfSpeEvents.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct PerfSpeEventsTestHelper : public testing::Test {
4040

4141
protected:
4242
using Trace = DataAggregator::Trace;
43+
using TakenBranchInfo = DataAggregator::TakenBranchInfo;
44+
using TraceHash = DataAggregator::TraceHash;
4345
struct MockBranchInfo {
4446
uint64_t From;
4547
uint64_t To;
@@ -79,6 +81,23 @@ struct PerfSpeEventsTestHelper : public testing::Test {
7981
std::unique_ptr<ObjectFile> ObjFile;
8082
std::unique_ptr<BinaryContext> BC;
8183

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+
82101
// Parse and check SPE brstack as LBR.
83102
void parseAndCheckBrstackEvents(
84103
uint64_t PID, const std::vector<MockBranchInfo> &ExpectedSamples) {
@@ -91,25 +110,18 @@ struct PerfSpeEventsTestHelper : public testing::Test {
91110
DA.parseBranchEvents();
92111

93112
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);
113125
}
114126
}
115127
};

0 commit comments

Comments
 (0)