[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 00:04:47 PST 2024
https://github.com/whentojump updated https://github.com/llvm/llvm-project/pull/80952
>From 51f53d710084d34e66d773d8d3354ca06388a340 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 7c63de6f3c345..45bddd7284461 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 dd6af47757e24b6e3cccda7d5d814a54217a6b7a 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 abc4c49ecae98..72f956ac04fc0 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 f6b0fda54b1b894406294c3e7c02e38625b4794e 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/tools/llvm-cov/SourceCoverageViewHTML.cpp | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
index 72f956ac04fc0..b93d8cb035306 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 0a07a74371dcb5204a1419ffe6d8562e0567e222 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 73b7ffe16a963..580da45ecfc0d 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