[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
Tue Feb 6 23:59:23 PST 2024
https://github.com/whentojump created https://github.com/llvm/llvm-project/pull/80952
1. add the missing condition for MC/DC in hasSubViews()
2. add style for selected line
3. remove name="Ln" attribute in the link within MC/DC views
4. remove color for \n
@evodius96 Comments are appreciated!
>From 9f33153745f284f4a50f17cf362413fe76376600 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..531c693710b69f 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 5ce5bf6b4d18665492e8336109e876e92f803807 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 e7b12b3d7e434c8d56b6770756dea5d0c5517cb4 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 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 133ddfb5e7a5c5d4be256a7f57462af68fe7cc27 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