forked from OSchip/llvm-project
[llvm-cov] Make some summary info fields private. NFC.
There's a bug in the way the line and region summary objects are merged. It would have been less likely to occur if those objects kept some data private. llvm-svn: 313416
This commit is contained in:
parent
b84e48447e
commit
c445e65d09
|
@ -362,8 +362,8 @@ class CoverageExporterJson {
|
|||
|
||||
// Start Line Coverage Summary.
|
||||
emitDictStart();
|
||||
emitDictElement("count", Summary.LineCoverage.NumLines);
|
||||
emitDictElement("covered", Summary.LineCoverage.Covered);
|
||||
emitDictElement("count", Summary.LineCoverage.getNumLines());
|
||||
emitDictElement("covered", Summary.LineCoverage.getCovered());
|
||||
emitDictElement("percent", Summary.LineCoverage.getPercentCovered());
|
||||
// End Line Coverage Summary.
|
||||
emitDictEnd();
|
||||
|
@ -372,8 +372,8 @@ class CoverageExporterJson {
|
|||
|
||||
// Start Function Coverage Summary.
|
||||
emitDictStart();
|
||||
emitDictElement("count", Summary.FunctionCoverage.NumFunctions);
|
||||
emitDictElement("covered", Summary.FunctionCoverage.Executed);
|
||||
emitDictElement("count", Summary.FunctionCoverage.getNumFunctions());
|
||||
emitDictElement("covered", Summary.FunctionCoverage.getExecuted());
|
||||
emitDictElement("percent", Summary.FunctionCoverage.getPercentCovered());
|
||||
// End Function Coverage Summary.
|
||||
emitDictEnd();
|
||||
|
@ -382,8 +382,8 @@ class CoverageExporterJson {
|
|||
|
||||
// Start Instantiation Coverage Summary.
|
||||
emitDictStart();
|
||||
emitDictElement("count", Summary.InstantiationCoverage.NumFunctions);
|
||||
emitDictElement("covered", Summary.InstantiationCoverage.Executed);
|
||||
emitDictElement("count", Summary.InstantiationCoverage.getNumFunctions());
|
||||
emitDictElement("covered", Summary.InstantiationCoverage.getExecuted());
|
||||
emitDictElement("percent",
|
||||
Summary.InstantiationCoverage.getPercentCovered());
|
||||
// End Function Coverage Summary.
|
||||
|
@ -393,11 +393,11 @@ class CoverageExporterJson {
|
|||
|
||||
// Start Region Coverage Summary.
|
||||
emitDictStart();
|
||||
emitDictElement("count", Summary.RegionCoverage.NumRegions);
|
||||
emitDictElement("covered", Summary.RegionCoverage.Covered);
|
||||
emitDictElement("count", Summary.RegionCoverage.getNumRegions());
|
||||
emitDictElement("covered", Summary.RegionCoverage.getCovered());
|
||||
emitDictElement("notcovered",
|
||||
Summary.RegionCoverage.NumRegions -
|
||||
Summary.RegionCoverage.Covered);
|
||||
Summary.RegionCoverage.getNumRegions() -
|
||||
Summary.RegionCoverage.getCovered());
|
||||
emitDictElement("percent", Summary.RegionCoverage.getPercentCovered());
|
||||
// End Region Coverage Summary.
|
||||
emitDictEnd();
|
||||
|
|
|
@ -185,11 +185,12 @@ void CoverageReport::render(const FileCoverageSummary &File,
|
|||
|
||||
if (Options.ShowRegionSummary) {
|
||||
OS << format("%*u", FileReportColumns[1],
|
||||
(unsigned)File.RegionCoverage.NumRegions);
|
||||
Options.colored_ostream(OS, FileCoverageColor) << format(
|
||||
"%*u", FileReportColumns[2], (unsigned)(File.RegionCoverage.NumRegions -
|
||||
File.RegionCoverage.Covered));
|
||||
if (File.RegionCoverage.NumRegions)
|
||||
(unsigned)File.RegionCoverage.getNumRegions());
|
||||
Options.colored_ostream(OS, FileCoverageColor)
|
||||
<< format("%*u", FileReportColumns[2],
|
||||
(unsigned)(File.RegionCoverage.getNumRegions() -
|
||||
File.RegionCoverage.getCovered()));
|
||||
if (File.RegionCoverage.getNumRegions())
|
||||
Options.colored_ostream(OS, FileCoverageColor)
|
||||
<< format("%*.2f", FileReportColumns[3] - 1,
|
||||
File.RegionCoverage.getPercentCovered())
|
||||
|
@ -199,11 +200,11 @@ void CoverageReport::render(const FileCoverageSummary &File,
|
|||
}
|
||||
|
||||
OS << format("%*u", FileReportColumns[4],
|
||||
(unsigned)File.FunctionCoverage.NumFunctions);
|
||||
(unsigned)File.FunctionCoverage.getNumFunctions());
|
||||
OS << format("%*u", FileReportColumns[5],
|
||||
(unsigned)(File.FunctionCoverage.NumFunctions -
|
||||
File.FunctionCoverage.Executed));
|
||||
if (File.FunctionCoverage.NumFunctions)
|
||||
(unsigned)(File.FunctionCoverage.getNumFunctions() -
|
||||
File.FunctionCoverage.getExecuted()));
|
||||
if (File.FunctionCoverage.getNumFunctions())
|
||||
Options.colored_ostream(OS, FuncCoverageColor)
|
||||
<< format("%*.2f", FileReportColumns[6] - 1,
|
||||
File.FunctionCoverage.getPercentCovered())
|
||||
|
@ -213,11 +214,11 @@ void CoverageReport::render(const FileCoverageSummary &File,
|
|||
|
||||
if (Options.ShowInstantiationSummary) {
|
||||
OS << format("%*u", FileReportColumns[7],
|
||||
(unsigned)File.InstantiationCoverage.NumFunctions);
|
||||
(unsigned)File.InstantiationCoverage.getNumFunctions());
|
||||
OS << format("%*u", FileReportColumns[8],
|
||||
(unsigned)(File.InstantiationCoverage.NumFunctions -
|
||||
File.InstantiationCoverage.Executed));
|
||||
if (File.InstantiationCoverage.NumFunctions)
|
||||
(unsigned)(File.InstantiationCoverage.getNumFunctions() -
|
||||
File.InstantiationCoverage.getExecuted()));
|
||||
if (File.InstantiationCoverage.getNumFunctions())
|
||||
Options.colored_ostream(OS, InstantiationCoverageColor)
|
||||
<< format("%*.2f", FileReportColumns[9] - 1,
|
||||
File.InstantiationCoverage.getPercentCovered())
|
||||
|
@ -227,11 +228,11 @@ void CoverageReport::render(const FileCoverageSummary &File,
|
|||
}
|
||||
|
||||
OS << format("%*u", FileReportColumns[10],
|
||||
(unsigned)File.LineCoverage.NumLines);
|
||||
(unsigned)File.LineCoverage.getNumLines());
|
||||
Options.colored_ostream(OS, LineCoverageColor) << format(
|
||||
"%*u", FileReportColumns[11],
|
||||
(unsigned)(File.LineCoverage.NumLines - File.LineCoverage.Covered));
|
||||
if (File.LineCoverage.NumLines)
|
||||
"%*u", FileReportColumns[11], (unsigned)(File.LineCoverage.getNumLines() -
|
||||
File.LineCoverage.getCovered()));
|
||||
if (File.LineCoverage.getNumLines())
|
||||
Options.colored_ostream(OS, LineCoverageColor)
|
||||
<< format("%*.2f", FileReportColumns[12] - 1,
|
||||
File.LineCoverage.getPercentCovered())
|
||||
|
@ -251,22 +252,22 @@ void CoverageReport::render(const FunctionCoverageSummary &Function,
|
|||
OS << column(DC.demangle(Function.Name), FunctionReportColumns[0],
|
||||
Column::RightTrim)
|
||||
<< format("%*u", FunctionReportColumns[1],
|
||||
(unsigned)Function.RegionCoverage.NumRegions);
|
||||
(unsigned)Function.RegionCoverage.getNumRegions());
|
||||
Options.colored_ostream(OS, FuncCoverageColor)
|
||||
<< format("%*u", FunctionReportColumns[2],
|
||||
(unsigned)(Function.RegionCoverage.NumRegions -
|
||||
Function.RegionCoverage.Covered));
|
||||
(unsigned)(Function.RegionCoverage.getNumRegions() -
|
||||
Function.RegionCoverage.getCovered()));
|
||||
Options.colored_ostream(
|
||||
OS, determineCoveragePercentageColor(Function.RegionCoverage))
|
||||
<< format("%*.2f", FunctionReportColumns[3] - 1,
|
||||
Function.RegionCoverage.getPercentCovered())
|
||||
<< '%';
|
||||
OS << format("%*u", FunctionReportColumns[4],
|
||||
(unsigned)Function.LineCoverage.NumLines);
|
||||
(unsigned)Function.LineCoverage.getNumLines());
|
||||
Options.colored_ostream(OS, LineCoverageColor)
|
||||
<< format("%*u", FunctionReportColumns[5],
|
||||
(unsigned)(Function.LineCoverage.NumLines -
|
||||
Function.LineCoverage.Covered));
|
||||
(unsigned)(Function.LineCoverage.getNumLines() -
|
||||
Function.LineCoverage.getCovered()));
|
||||
Options.colored_ostream(
|
||||
OS, determineCoveragePercentageColor(Function.LineCoverage))
|
||||
<< format("%*.2f", FunctionReportColumns[6] - 1,
|
||||
|
@ -391,7 +392,7 @@ void CoverageReport::renderFileReports(raw_ostream &OS,
|
|||
|
||||
bool EmptyFiles = false;
|
||||
for (const FileCoverageSummary &FCS : FileReports) {
|
||||
if (FCS.FunctionCoverage.NumFunctions)
|
||||
if (FCS.FunctionCoverage.getNumFunctions())
|
||||
render(FCS, OS);
|
||||
else
|
||||
EmptyFiles = true;
|
||||
|
@ -402,7 +403,7 @@ void CoverageReport::renderFileReports(raw_ostream &OS,
|
|||
<< "Files which contain no functions:\n";
|
||||
|
||||
for (const FileCoverageSummary &FCS : FileReports)
|
||||
if (!FCS.FunctionCoverage.NumFunctions)
|
||||
if (!FCS.FunctionCoverage.getNumFunctions())
|
||||
render(FCS, OS);
|
||||
}
|
||||
|
||||
|
|
|
@ -87,10 +87,8 @@ FunctionCoverageSummary::get(const InstantiationGroup &Group,
|
|||
Summary.RegionCoverage = Summaries[0].RegionCoverage;
|
||||
Summary.LineCoverage = Summaries[0].LineCoverage;
|
||||
for (const auto &FCS : Summaries.drop_front()) {
|
||||
Summary.RegionCoverage.Covered =
|
||||
std::max(FCS.RegionCoverage.Covered, Summary.RegionCoverage.Covered);
|
||||
Summary.LineCoverage.Covered =
|
||||
std::max(FCS.LineCoverage.Covered, Summary.LineCoverage.Covered);
|
||||
Summary.RegionCoverage.merge(FCS.RegionCoverage);
|
||||
Summary.LineCoverage.merge(FCS.LineCoverage);
|
||||
}
|
||||
return Summary;
|
||||
}
|
||||
|
|
|
@ -21,13 +21,14 @@
|
|||
namespace llvm {
|
||||
|
||||
/// \brief Provides information about region coverage for a function/file.
|
||||
struct RegionCoverageInfo {
|
||||
class RegionCoverageInfo {
|
||||
/// \brief The number of regions that were executed at least once.
|
||||
size_t Covered;
|
||||
|
||||
/// \brief The total number of regions in a function/file.
|
||||
size_t NumRegions;
|
||||
|
||||
public:
|
||||
RegionCoverageInfo() : Covered(0), NumRegions(0) {}
|
||||
|
||||
RegionCoverageInfo(size_t Covered, size_t NumRegions)
|
||||
|
@ -39,6 +40,14 @@ struct RegionCoverageInfo {
|
|||
return *this;
|
||||
}
|
||||
|
||||
void merge(const RegionCoverageInfo &RHS) {
|
||||
Covered = std::max(Covered, RHS.Covered);
|
||||
}
|
||||
|
||||
size_t getCovered() const { return Covered; }
|
||||
|
||||
size_t getNumRegions() const { return NumRegions; }
|
||||
|
||||
bool isFullyCovered() const { return Covered == NumRegions; }
|
||||
|
||||
double getPercentCovered() const {
|
||||
|
@ -49,13 +58,14 @@ struct RegionCoverageInfo {
|
|||
};
|
||||
|
||||
/// \brief Provides information about line coverage for a function/file.
|
||||
struct LineCoverageInfo {
|
||||
class LineCoverageInfo {
|
||||
/// \brief The number of lines that were executed at least once.
|
||||
size_t Covered;
|
||||
|
||||
/// \brief The total number of lines in a function/file.
|
||||
size_t NumLines;
|
||||
|
||||
public:
|
||||
LineCoverageInfo() : Covered(0), NumLines(0) {}
|
||||
|
||||
LineCoverageInfo(size_t Covered, size_t NumLines)
|
||||
|
@ -67,6 +77,14 @@ struct LineCoverageInfo {
|
|||
return *this;
|
||||
}
|
||||
|
||||
void merge(const LineCoverageInfo &RHS) {
|
||||
Covered = std::max(Covered, RHS.Covered);
|
||||
}
|
||||
|
||||
size_t getCovered() const { return Covered; }
|
||||
|
||||
size_t getNumLines() const { return NumLines; }
|
||||
|
||||
bool isFullyCovered() const { return Covered == NumLines; }
|
||||
|
||||
double getPercentCovered() const {
|
||||
|
@ -77,13 +95,14 @@ struct LineCoverageInfo {
|
|||
};
|
||||
|
||||
/// \brief Provides information about function coverage for a file.
|
||||
struct FunctionCoverageInfo {
|
||||
class FunctionCoverageInfo {
|
||||
/// \brief The number of functions that were executed.
|
||||
size_t Executed;
|
||||
|
||||
/// \brief The total number of functions in this file.
|
||||
size_t NumFunctions;
|
||||
|
||||
public:
|
||||
FunctionCoverageInfo() : Executed(0), NumFunctions(0) {}
|
||||
|
||||
FunctionCoverageInfo(size_t Executed, size_t NumFunctions)
|
||||
|
@ -95,6 +114,10 @@ struct FunctionCoverageInfo {
|
|||
++NumFunctions;
|
||||
}
|
||||
|
||||
size_t getExecuted() const { return Executed; }
|
||||
|
||||
size_t getNumFunctions() const { return NumFunctions; }
|
||||
|
||||
bool isFullyCovered() const { return Executed == NumFunctions; }
|
||||
|
||||
double getPercentCovered() const {
|
||||
|
|
|
@ -346,18 +346,19 @@ void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF,
|
|||
}
|
||||
|
||||
Columns.emplace_back(tag("td", tag("pre", Filename)));
|
||||
AddCoverageTripleToColumn(FCS.FunctionCoverage.Executed,
|
||||
FCS.FunctionCoverage.NumFunctions,
|
||||
AddCoverageTripleToColumn(FCS.FunctionCoverage.getExecuted(),
|
||||
FCS.FunctionCoverage.getNumFunctions(),
|
||||
FCS.FunctionCoverage.getPercentCovered());
|
||||
if (Opts.ShowInstantiationSummary)
|
||||
AddCoverageTripleToColumn(FCS.InstantiationCoverage.Executed,
|
||||
FCS.InstantiationCoverage.NumFunctions,
|
||||
AddCoverageTripleToColumn(FCS.InstantiationCoverage.getExecuted(),
|
||||
FCS.InstantiationCoverage.getNumFunctions(),
|
||||
FCS.InstantiationCoverage.getPercentCovered());
|
||||
AddCoverageTripleToColumn(FCS.LineCoverage.Covered, FCS.LineCoverage.NumLines,
|
||||
AddCoverageTripleToColumn(FCS.LineCoverage.getCovered(),
|
||||
FCS.LineCoverage.getNumLines(),
|
||||
FCS.LineCoverage.getPercentCovered());
|
||||
if (Opts.ShowRegionSummary)
|
||||
AddCoverageTripleToColumn(FCS.RegionCoverage.Covered,
|
||||
FCS.RegionCoverage.NumRegions,
|
||||
AddCoverageTripleToColumn(FCS.RegionCoverage.getCovered(),
|
||||
FCS.RegionCoverage.getNumRegions(),
|
||||
FCS.RegionCoverage.getPercentCovered());
|
||||
|
||||
OS << tag("tr", join(Columns.begin(), Columns.end(), ""), "light-row");
|
||||
|
@ -407,7 +408,7 @@ Error CoveragePrinterHTML::createIndexFile(
|
|||
CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles, Opts);
|
||||
bool EmptyFiles = false;
|
||||
for (unsigned I = 0, E = FileReports.size(); I < E; ++I) {
|
||||
if (FileReports[I].FunctionCoverage.NumFunctions)
|
||||
if (FileReports[I].FunctionCoverage.getNumFunctions())
|
||||
emitFileSummary(OSRef, SourceFiles[I], FileReports[I]);
|
||||
else
|
||||
EmptyFiles = true;
|
||||
|
@ -424,7 +425,7 @@ Error CoveragePrinterHTML::createIndexFile(
|
|||
"by the preprocessor.)\n");
|
||||
OSRef << BeginCenteredDiv << BeginTable;
|
||||
for (unsigned I = 0, E = FileReports.size(); I < E; ++I)
|
||||
if (!FileReports[I].FunctionCoverage.NumFunctions) {
|
||||
if (!FileReports[I].FunctionCoverage.getNumFunctions()) {
|
||||
std::string Link = buildLinkToFile(SourceFiles[I], FileReports[I]);
|
||||
OSRef << tag("tr", tag("td", tag("pre", Link)), "light-row") << '\n';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue