[llvm] r287539 - [llvm-cov] Avoid 0% when reporting something that's 0/0
Alex Lorenz via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 21 06:00:05 PST 2016
Author: arphaman
Date: Mon Nov 21 08:00:04 2016
New Revision: 287539
URL: http://llvm.org/viewvc/llvm-project?rev=287539&view=rev
Log:
[llvm-cov] Avoid 0% when reporting something that's 0/0
This commit makes llvm-cov avoid showing 0% (0/0) coverage for things
like file function coverage, etc. in reports and HTML output. This can happen
for files like headers that have macros but no functions. This commit makes
llvm-cov report - (0/0) instead.
rdar://29246480
Differential Revision: https://reviews.llvm.org/D26615
Added:
llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.covmapping (with props)
llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.h
llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.proftext
llvm/trunk/test/tools/llvm-cov/zeroFunctionFile.c
Modified:
llvm/trunk/tools/llvm-cov/CoverageReport.cpp
llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp
Added: llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.covmapping
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.covmapping?rev=287539&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.covmapping
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.h?rev=287539&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.h (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.h Mon Nov 21 08:00:04 2016
@@ -0,0 +1,3 @@
+// This header has no functions
+
+#define NOFUNCTIONS(x) (x) > 0 ? 0 : 1
Added: llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.proftext?rev=287539&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.proftext (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/zeroFunctionFile.proftext Mon Nov 21 08:00:04 2016
@@ -0,0 +1,16 @@
+foo
+# Func Hash:
+13
+# Num Counters:
+2
+# Counter Values:
+1
+1
+
+main
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+1
Added: llvm/trunk/test/tools/llvm-cov/zeroFunctionFile.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/zeroFunctionFile.c?rev=287539&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/zeroFunctionFile.c (added)
+++ llvm/trunk/test/tools/llvm-cov/zeroFunctionFile.c Mon Nov 21 08:00:04 2016
@@ -0,0 +1,19 @@
+#include "Inputs/zeroFunctionFile.h"
+
+int foo(int x) {
+ return NOFUNCTIONS(x);
+}
+int main() {
+ return foo(2);
+}
+
+// RUN: llvm-profdata merge %S/Inputs/zeroFunctionFile.proftext -o %t.profdata
+
+// RUN: llvm-cov report %S/Inputs/zeroFunctionFile.covmapping -instr-profile %t.profdata 2>&1 | FileCheck --check-prefix=REPORT --strict-whitespace %s
+// REPORT: 0 0 - 0 0 - 0 0 - 0 0 -
+// REPORT-NO: 0%
+
+// RUN: llvm-cov show %S/Inputs/zeroFunctionFile.covmapping -format html -instr-profile %t.profdata -o %t.dir
+// RUN: FileCheck %s -input-file=%t.dir/index.html -check-prefix=HTML
+// HTML: <td class='column-entry-green'><pre>- (0/0)
+// HTML-NO: 0.00% (0/0)
Modified: llvm/trunk/tools/llvm-cov/CoverageReport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageReport.cpp?rev=287539&r1=287538&r2=287539&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageReport.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CoverageReport.cpp Mon Nov 21 08:00:04 2016
@@ -154,36 +154,48 @@ void CoverageReport::render(const FileCo
(unsigned)File.RegionCoverage.NumRegions);
Options.colored_ostream(OS, FileCoverageColor) << format(
"%*u", FileReportColumns[2], (unsigned)File.RegionCoverage.NotCovered);
- Options.colored_ostream(OS, FileCoverageColor)
- << format("%*.2f", FileReportColumns[3] - 1,
- File.RegionCoverage.getPercentCovered())
- << '%';
+ if (File.RegionCoverage.NumRegions)
+ Options.colored_ostream(OS, FileCoverageColor)
+ << format("%*.2f", FileReportColumns[3] - 1,
+ File.RegionCoverage.getPercentCovered())
+ << '%';
+ else
+ OS << column("-", FileReportColumns[3], Column::RightAlignment);
OS << format("%*u", FileReportColumns[4],
(unsigned)File.FunctionCoverage.NumFunctions);
OS << format("%*u", FileReportColumns[5],
(unsigned)(File.FunctionCoverage.NumFunctions -
File.FunctionCoverage.Executed));
- Options.colored_ostream(OS, FuncCoverageColor)
- << format("%*.2f", FileReportColumns[6] - 1,
- File.FunctionCoverage.getPercentCovered())
- << '%';
+ if (File.FunctionCoverage.NumFunctions)
+ Options.colored_ostream(OS, FuncCoverageColor)
+ << format("%*.2f", FileReportColumns[6] - 1,
+ File.FunctionCoverage.getPercentCovered())
+ << '%';
+ else
+ OS << column("-", FileReportColumns[6], Column::RightAlignment);
OS << format("%*u", FileReportColumns[7],
(unsigned)File.InstantiationCoverage.NumFunctions);
OS << format("%*u", FileReportColumns[8],
(unsigned)(File.InstantiationCoverage.NumFunctions -
File.InstantiationCoverage.Executed));
- Options.colored_ostream(OS, InstantiationCoverageColor)
- << format("%*.2f", FileReportColumns[9] - 1,
- File.InstantiationCoverage.getPercentCovered())
- << '%';
+ if (File.InstantiationCoverage.NumFunctions)
+ Options.colored_ostream(OS, InstantiationCoverageColor)
+ << format("%*.2f", FileReportColumns[9] - 1,
+ File.InstantiationCoverage.getPercentCovered())
+ << '%';
+ else
+ OS << column("-", FileReportColumns[9], Column::RightAlignment);
OS << format("%*u", FileReportColumns[10],
(unsigned)File.LineCoverage.NumLines);
Options.colored_ostream(OS, LineCoverageColor) << format(
"%*u", FileReportColumns[11], (unsigned)File.LineCoverage.NotCovered);
- Options.colored_ostream(OS, LineCoverageColor)
- << format("%*.2f", FileReportColumns[12] - 1,
- File.LineCoverage.getPercentCovered())
- << '%';
+ if (File.LineCoverage.NumLines)
+ Options.colored_ostream(OS, LineCoverageColor)
+ << format("%*.2f", FileReportColumns[12] - 1,
+ File.LineCoverage.getPercentCovered())
+ << '%';
+ else
+ OS << column("-", FileReportColumns[12], Column::RightAlignment);
OS << "\n";
}
Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp?rev=287539&r1=287538&r2=287539&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp Mon Nov 21 08:00:04 2016
@@ -307,13 +307,17 @@ void CoveragePrinterHTML::emitFileSummar
std::string S;
{
raw_string_ostream RSO{S};
- RSO << format("%*.2f", 7, Pctg) << "% (" << Hit << '/' << Total << ')';
+ if (Total)
+ RSO << format("%*.2f", 7, Pctg) << "% ";
+ else
+ RSO << "- ";
+ RSO << '(' << Hit << '/' << Total << ')';
}
const char *CellClass = "column-entry-yellow";
- if (Pctg < 80.0)
- CellClass = "column-entry-red";
- else if (Hit == Total)
+ if (Hit == Total)
CellClass = "column-entry-green";
+ else if (Pctg < 80.0)
+ CellClass = "column-entry-red";
Columns.emplace_back(tag("td", tag("pre", S), CellClass));
};
More information about the llvm-commits
mailing list