[llvm] [llvm-cov][CoverageView] minor fix/improvement to HTML and text coverage output (PR #80952)
Wentao Zhang via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 7 02:54:21 PST 2024
https://github.com/whentojump updated https://github.com/llvm/llvm-project/pull/80952
>From fd726de97fbc421168cbe0b10c879fe1fe385e2e Mon Sep 17 00:00:00 2001
From: Wentao Zhang <zhangwt1997 at gmail.com>
Date: Wed, 7 Feb 2024 02:30:12 -0500
Subject: [PATCH 1/4] [llvm-cov][CoverageView] add the missing condition for
MC/DC in hasSubViews()
Otherwise the generated HTML will place elements unpredictably. Most
notably, the MC/DC view boxes are often placed at the page top instead
of inline next to the actual code.
---
llvm/tools/llvm-cov/SourceCoverageView.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp
index 7c63de6f3c345a..45bddd72844610 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp
@@ -139,7 +139,7 @@ bool SourceCoverageView::shouldRenderRegionMarkers(
bool SourceCoverageView::hasSubViews() const {
return !ExpansionSubViews.empty() || !InstantiationSubViews.empty() ||
- !BranchSubViews.empty();
+ !BranchSubViews.empty() || !MCDCSubViews.empty();
}
std::unique_ptr<SourceCoverageView>
>From 40d54317e9100a7c39cc1b949a09992a3c9c01c1 Mon Sep 17 00:00:00 2001
From: Wentao Zhang <zhangwt1997 at gmail.com>
Date: Wed, 7 Feb 2024 02:34:33 -0500
Subject: [PATCH 2/4] [llvm-cov][CoverageViewHTML] add style for selected line
Highlight the selected line. One major benefit is, if the page is
relatively short, the line pointed by #Ln in URL may not be on top, and
this highlight can help quickly locate the line.
---
llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
index abc4c49ecae98e..72f956ac04fc0e 100644
--- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
@@ -246,6 +246,9 @@ tr:hover {
tr:last-child {
border-bottom: none;
}
+tr:has(> td >a:target) > td.code > pre {
+ background-color: #ffa;
+}
)";
const char *EndHeader = "</head>";
>From 22fb258047b9cf740b82530dee2af4311fa6e723 Mon Sep 17 00:00:00 2001
From: Wentao Zhang <zhangwt1997 at gmail.com>
Date: Wed, 7 Feb 2024 02:43:52 -0500
Subject: [PATCH 3/4] [llvm-cov][CoverageViewHTML] remove name="Ln" attribute
in the link within MC/DC views
Or it would conflict with the link at actual lines and jumping via URLs
containing #Ln would fail
---
llvm/test/tools/llvm-cov/mcdc-general-none.test | 2 +-
llvm/test/tools/llvm-cov/mcdc-general.test | 2 +-
llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp | 6 ++----
3 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/llvm/test/tools/llvm-cov/mcdc-general-none.test b/llvm/test/tools/llvm-cov/mcdc-general-none.test
index 07700cb51fa5e0..b57b35d49c8c11 100644
--- a/llvm/test/tools/llvm-cov/mcdc-general-none.test
+++ b/llvm/test/tools/llvm-cov/mcdc-general-none.test
@@ -53,7 +53,7 @@
// RUN: rm -rf %t.html.dir
// RUN: llvm-cov show --show-mcdc-summary --show-mcdc %S/Inputs/mcdc-general.o -instr-profile %t.profdata -path-equivalence=.,%S/Inputs -format html -o %t.html.dir
// RUN: FileCheck -check-prefix=HTML -input-file=%t.html.dir/coverage/mcdc-general.cpp.html %s
-// HTML-COUNT-4: MC/DC Decision Region (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>
+// HTML-COUNT-4: MC/DC Decision Region (<span class='line-number'><a href='#L{{[0-9]+}}'><span>
// RUN: FileCheck -check-prefix HTML-INDEX -input-file %t.html.dir/index.html %s
// HTML-INDEX-LABEL: <table>
diff --git a/llvm/test/tools/llvm-cov/mcdc-general.test b/llvm/test/tools/llvm-cov/mcdc-general.test
index 753036bedaf170..220b506c19c725 100644
--- a/llvm/test/tools/llvm-cov/mcdc-general.test
+++ b/llvm/test/tools/llvm-cov/mcdc-general.test
@@ -119,7 +119,7 @@
// RUN: rm -rf %t.html.dir
// RUN: llvm-cov show --show-mcdc-summary --show-mcdc %S/Inputs/mcdc-general.o -instr-profile %t.profdata -path-equivalence=.,%S/Inputs -format html -o %t.html.dir
// RUN: FileCheck -check-prefix=HTML -input-file=%t.html.dir/coverage/mcdc-general.cpp.html %s
-// HTML-COUNT-4: MC/DC Decision Region (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>
+// HTML-COUNT-4: MC/DC Decision Region (<span class='line-number'><a href='#L{{[0-9]+}}'><span>
// RUN: FileCheck -check-prefix HTML-INDEX -input-file %t.html.dir/index.html %s
// HTML-INDEX-LABEL: <table>
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
index 72f956ac04fc0e..b93d8cb035306b 100644
--- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
@@ -993,15 +993,13 @@ void SourceCoverageViewHTML::renderMCDCView(raw_ostream &OS, MCDCView &MRV,
std::string ColNoStr = Twine(DecisionRegion.ColumnStart).str();
std::string TargetName = "L" + LineNoStr;
OS << tag("span",
- a("#" + TargetName, tag("span", LineNoStr + ":" + ColNoStr),
- TargetName),
+ a("#" + TargetName, tag("span", LineNoStr + ":" + ColNoStr)),
"line-number") +
") to (";
LineNoStr = utostr(uint64_t(DecisionRegion.LineEnd));
ColNoStr = utostr(uint64_t(DecisionRegion.ColumnEnd));
OS << tag("span",
- a("#" + TargetName, tag("span", LineNoStr + ":" + ColNoStr),
- TargetName),
+ a("#" + TargetName, tag("span", LineNoStr + ":" + ColNoStr)),
"line-number") +
")\n\n";
>From 30a167d4245d55f762498f879763e574d9d572cf Mon Sep 17 00:00:00 2001
From: Wentao Zhang <zhangwt1997 at gmail.com>
Date: Wed, 7 Feb 2024 02:47:46 -0500
Subject: [PATCH 4/4] [llvm-cov][CoverageViewText] remove color for \n
---
llvm/tools/llvm-cov/SourceCoverageViewText.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
index 73b7ffe16a9637..580da45ecfc0d8 100644
--- a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
@@ -382,7 +382,8 @@ void SourceCoverageViewText::renderMCDCView(raw_ostream &OS, MCDCView &MRV,
colored_ostream(OS, raw_ostream::RED,
getOptions().Colors && Record.getPercentCovered() < 100.0,
/*Bold=*/false, /*BG=*/true)
- << format("%0.2f", Record.getPercentCovered()) << "%\n";
+ << format("%0.2f", Record.getPercentCovered()) << "%";
+ OS << "\n";
renderLinePrefix(OS, ViewDepth);
OS << "\n";
}
More information about the llvm-commits
mailing list