diff options
author | Alan Phipps <a-phipps@ti.com> | 2020-12-28 11:20:48 -0600 |
---|---|---|
committer | Alan Phipps <a-phipps@ti.com> | 2021-01-05 09:51:51 -0600 |
commit | 9f2967bcfe2f7d1fc02281f0098306c90c2c10a5 (patch) | |
tree | a29793dac7b81d67601905911a389a2cf2cdde2e /llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp | |
parent | 53c3acb89fcc25ba7ef1f1d76a79c241eeacb7f0 (diff) | |
download | llvm-9f2967bcfe2f7d1fc02281f0098306c90c2c10a5.zip llvm-9f2967bcfe2f7d1fc02281f0098306c90c2c10a5.tar.gz llvm-9f2967bcfe2f7d1fc02281f0098306c90c2c10a5.tar.bz2 |
[Coverage] Add support for Branch Coverage in LLVM Source-Based Code Coverage
This is an enhancement to LLVM Source-Based Code Coverage in clang to track how
many times individual branch-generating conditions are taken (evaluate to TRUE)
and not taken (evaluate to FALSE). Individual conditions may comprise larger
boolean expressions using boolean logical operators. This functionality is
very similar to what is supported by GCOV except that it is very closely
anchored to the ASTs.
Differential Revision: https://reviews.llvm.org/D84467
Diffstat (limited to 'llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp')
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp index 9d10def..4db5624 100644 --- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp @@ -313,6 +313,8 @@ static void emitColumnLabelsForIndex(raw_ostream &OS, Columns.emplace_back(tag("td", "Line Coverage", "column-entry-bold")); if (Opts.ShowRegionSummary) Columns.emplace_back(tag("td", "Region Coverage", "column-entry-bold")); + if (Opts.ShowBranchSummary) + Columns.emplace_back(tag("td", "Branch Coverage", "column-entry-bold")); OS << tag("tr", join(Columns.begin(), Columns.end(), "")); } @@ -378,6 +380,10 @@ void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF, AddCoverageTripleToColumn(FCS.RegionCoverage.getCovered(), FCS.RegionCoverage.getNumRegions(), FCS.RegionCoverage.getPercentCovered()); + if (Opts.ShowBranchSummary) + AddCoverageTripleToColumn(FCS.BranchCoverage.getCovered(), + FCS.BranchCoverage.getNumBranches(), + FCS.BranchCoverage.getPercentCovered()); if (IsTotals) OS << tag("tr", join(Columns.begin(), Columns.end(), ""), "light-row-bold"); @@ -650,6 +656,72 @@ void SourceCoverageViewHTML::renderExpansionView(raw_ostream &OS, OS << EndExpansionDiv; } +void SourceCoverageViewHTML::renderBranchView(raw_ostream &OS, BranchView &BRV, + unsigned ViewDepth) { + // Render the child subview. + if (getOptions().Debug) + errs() << "Branch at line " << BRV.getLine() << '\n'; + + OS << BeginExpansionDiv; + OS << BeginPre; + for (const auto &R : BRV.Regions) { + // Calculate TruePercent and False Percent. + double TruePercent = 0.0; + double FalsePercent = 0.0; + unsigned Total = R.ExecutionCount + R.FalseExecutionCount; + + if (!getOptions().ShowBranchCounts && Total != 0) { + TruePercent = ((double)(R.ExecutionCount) / (double)Total) * 100.0; + FalsePercent = ((double)(R.FalseExecutionCount) / (double)Total) * 100.0; + } + + // Display Line + Column. + std::string LineNoStr = utostr(uint64_t(R.LineStart)); + std::string ColNoStr = utostr(uint64_t(R.ColumnStart)); + std::string TargetName = "L" + LineNoStr; + + OS << " Branch ("; + OS << tag("span", + a("#" + TargetName, tag("span", LineNoStr + ":" + ColNoStr), + TargetName), + "line-number") + + "): ["; + + if (R.Folded) { + OS << "Folded - Ignored]\n"; + continue; + } + + // Display TrueCount or TruePercent. + std::string TrueColor = R.ExecutionCount ? "None" : "red"; + std::string TrueCovClass = + (R.ExecutionCount > 0) ? "covered-line" : "uncovered-line"; + + OS << tag("span", "True", TrueColor); + OS << ": "; + if (getOptions().ShowBranchCounts) + OS << tag("span", formatCount(R.ExecutionCount), TrueCovClass) << ", "; + else + OS << format("%0.2f", TruePercent) << "%, "; + + // Display FalseCount or FalsePercent. + std::string FalseColor = R.FalseExecutionCount ? "None" : "red"; + std::string FalseCovClass = + (R.FalseExecutionCount > 0) ? "covered-line" : "uncovered-line"; + + OS << tag("span", "False", FalseColor); + OS << ": "; + if (getOptions().ShowBranchCounts) + OS << tag("span", formatCount(R.FalseExecutionCount), FalseCovClass); + else + OS << format("%0.2f", FalsePercent) << "%"; + + OS << "]\n"; + } + OS << EndPre; + OS << EndExpansionDiv; +} + void SourceCoverageViewHTML::renderInstantiationView(raw_ostream &OS, InstantiationView &ISV, unsigned ViewDepth) { |