<< "\n";
}
+static ::testing::AssertionResult ErrorEquals(coveragemap_error Expected,
+ Error E) {
+ coveragemap_error Found;
+ std::string FoundMsg;
+ handleAllErrors(std::move(E), [&](const CoverageMapError &CME) {
+ Found = CME.get();
+ FoundMsg = CME.message();
+ });
+ if (Expected == Found)
+ return ::testing::AssertionSuccess();
+ return ::testing::AssertionFailure() << "error: " << FoundMsg << "\n";
+}
+
namespace llvm {
namespace coverage {
void PrintTo(const Counter &C, ::std::ostream *os) {
return CoverageMapping::load(CoverageReaders, *ProfileReader);
}
- void loadCoverageMapping(bool EmitFilenames = true) {
+ Error loadCoverageMapping(bool EmitFilenames = true) {
readProfCounts();
writeAndReadCoverageRegions(EmitFilenames);
auto CoverageOrErr = readOutputFunctions();
- ASSERT_TRUE(NoError(CoverageOrErr.takeError()));
+ if (!CoverageOrErr)
+ return CoverageOrErr.takeError();
LoadedCoverage = std::move(CoverageOrErr.get());
+ return Error::success();
}
};
// in order to preserve that information during possible sorting of CMRs.
addCMR(Counter::getCounter(0), FileNames[I], I, 1, I, 1);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
for (unsigned I = 0; I < N; ++I) {
CoverageData Data = LoadedCoverage->getCoverageForFile(FileNames[I]);
}
}
+TEST_P(CoverageMappingTest, load_coverage_with_bogus_function_name) {
+ InstrProfRecord RecordFunc1("", 0x1234, {10});
+ NoError(ProfileWriter.addRecord(std::move(RecordFunc1)));
+ startFunction("", 0x1234);
+ addCMR(Counter::getCounter(0), "foo", 1, 1, 5, 5);
+ ErrorEquals(coveragemap_error::malformed, loadCoverageMapping());
+}
+
TEST_P(CoverageMappingTest, load_coverage_for_several_functions) {
InstrProfRecord RecordFunc1("func1", 0x1234, {10});
NoError(ProfileWriter.addRecord(std::move(RecordFunc1)));
startFunction("func2", 0x2345);
addCMR(Counter::getCounter(0), "bar", 2, 2, 6, 6);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
const auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
EXPECT_EQ(2, std::distance(FunctionRecords.begin(), FunctionRecords.end()));
addCMR(Counter::getCounter(1), "file1", 1, 1, 4, 7);
addCMR(Counter::getCounter(2), "file1", 5, 8, 9, 1);
addCMR(Counter::getCounter(3), "file1", 10, 10, 11, 11);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
TEST_P(CoverageMappingTest, uncovered_function) {
startFunction("func", 0x1234);
addCMR(Counter::getZero(), "file1", 1, 2, 3, 4);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
startFunction("func", 0x1234);
addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
addCMR(Counter::getCounter(1), "file1", 1, 1, 4, 7);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
addCMR(Counter::getCounter(1), "file1", 3, 3, 4, 4);
addCMR(Counter::getCounter(2), "file1", 3, 3, 4, 4);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
addCMR(Counter::getCounter(1), "file1", 1, 1, 9, 9);
addCMR(Counter::getCounter(2), "file1", 3, 3, 5, 5);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
addCMR(Counter::getCounter(1), "file1", 3, 3, 4, 4);
addCMR(Counter::getCounter(1), "include1", 6, 6, 7, 7);
addExpansionCMR("file1", "include1", 3, 3, 4, 4);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
addExpansionCMR("file", "include1", 3, 1, 3, 5);
addExpansionCMR("file", "include2", 3, 1, 3, 5);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
CoverageData Data = LoadedCoverage->getCoverageForFile("file");
std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
startFunction("file1:func", 0x1234);
addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
std::vector<std::string> Names;
for (const auto &Func : LoadedCoverage->getCoveredFunctions())
startFunction("<unknown>:func", 0x1234);
addCMR(Counter::getCounter(0), "", 1, 1, 9, 9);
- loadCoverageMapping(/*EmitFilenames=*/false);
+ NoError(loadCoverageMapping(/*EmitFilenames=*/false));
std::vector<std::string> Names;
for (const auto &Func : LoadedCoverage->getCoveredFunctions())
addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
addExpansionCMR("main", "expanded", 9, 1, 9, 5);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
std::vector<const FunctionRecord *> Instantiations =
LoadedCoverage->getInstantiations("expanded");
addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
addExpansionCMR("main", "expanded", 4, 1, 4, 5);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
CoverageData Data = LoadedCoverage->getCoverageForFile("expanded");
std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
startFunction("func", 0x1234);
addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
- loadCoverageMapping();
+ NoError(loadCoverageMapping());
auto Funcs = LoadedCoverage->getCoveredFunctions();
unsigned NumFuncs = std::distance(Funcs.begin(), Funcs.end());