From b5d60b88466047579c9e25cddf7bf763ae047ab9 Mon Sep 17 00:00:00 2001 From: Max Moroz Date: Fri, 13 Oct 2017 14:44:51 +0000 Subject: [PATCH] [llvm-cov] Generate "report" for given source paths if sources are specified. Summary: Documentation says that user can specify sources for both "show" and "report" commands. "Show" command respects specified sources, but "report" does not. It is useful to have both "show" and "report" generated for specified sources. Also added tests to for both commands with sources specified. Reviewers: vsk, kcc Reviewed By: vsk Differential Revision: https://reviews.llvm.org/D38860 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315685 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm-cov/Inputs/sources_specified/abs.h | 5 ++++ .../Inputs/sources_specified/extra/dec.h | 3 ++ .../Inputs/sources_specified/extra/inc.h | 3 ++ .../llvm-cov/Inputs/sources_specified/main.cc | 9 ++++++ .../Inputs/sources_specified/main.covmapping | Bin 0 -> 624 bytes .../Inputs/sources_specified/main.profdata | Bin 0 -> 880 bytes test/tools/llvm-cov/sources-specified.test | 28 ++++++++++++++++++ tools/llvm-cov/CodeCoverage.cpp | 5 +++- tools/llvm-cov/CoverageReport.cpp | 7 ++++- tools/llvm-cov/CoverageReport.h | 3 ++ 10 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 test/tools/llvm-cov/Inputs/sources_specified/abs.h create mode 100644 test/tools/llvm-cov/Inputs/sources_specified/extra/dec.h create mode 100644 test/tools/llvm-cov/Inputs/sources_specified/extra/inc.h create mode 100644 test/tools/llvm-cov/Inputs/sources_specified/main.cc create mode 100644 test/tools/llvm-cov/Inputs/sources_specified/main.covmapping create mode 100644 test/tools/llvm-cov/Inputs/sources_specified/main.profdata create mode 100644 test/tools/llvm-cov/sources-specified.test diff --git a/test/tools/llvm-cov/Inputs/sources_specified/abs.h b/test/tools/llvm-cov/Inputs/sources_specified/abs.h new file mode 100644 index 00000000000..f13c5177c58 --- /dev/null +++ b/test/tools/llvm-cov/Inputs/sources_specified/abs.h @@ -0,0 +1,5 @@ +int abs(int x) { + if (x < 0) + return -x; + return x; +} diff --git a/test/tools/llvm-cov/Inputs/sources_specified/extra/dec.h b/test/tools/llvm-cov/Inputs/sources_specified/extra/dec.h new file mode 100644 index 00000000000..178e1ea8c26 --- /dev/null +++ b/test/tools/llvm-cov/Inputs/sources_specified/extra/dec.h @@ -0,0 +1,3 @@ +int dec(int x) { + return x + 1; +} diff --git a/test/tools/llvm-cov/Inputs/sources_specified/extra/inc.h b/test/tools/llvm-cov/Inputs/sources_specified/extra/inc.h new file mode 100644 index 00000000000..5086aaa1e38 --- /dev/null +++ b/test/tools/llvm-cov/Inputs/sources_specified/extra/inc.h @@ -0,0 +1,3 @@ +int inc(int x) { + return x + 1; +} diff --git a/test/tools/llvm-cov/Inputs/sources_specified/main.cc b/test/tools/llvm-cov/Inputs/sources_specified/main.cc new file mode 100644 index 00000000000..cda21f1f57a --- /dev/null +++ b/test/tools/llvm-cov/Inputs/sources_specified/main.cc @@ -0,0 +1,9 @@ +#include "abs.h" +#include "extra/dec.h" +#include "extra/inc.h" + +int main() { + int x = 0; + inc(x); + return abs(x); +} diff --git a/test/tools/llvm-cov/Inputs/sources_specified/main.covmapping b/test/tools/llvm-cov/Inputs/sources_specified/main.covmapping new file mode 100644 index 0000000000000000000000000000000000000000..95f22f53b4de82ec12e613453fee532872b430db GIT binary patch literal 624 zcmd1FDa%dHFUu`SEiOq(EJ>6*u%MAih9N%6I5DX>lMzU#q$Y#u%se2So0yr$00JyP zJfD$)!4gO_0rAJ0`?EZz?_D4TWOD&A2vk+hbc4YiayYHdKsCtwIj8nq$p7z z7=CoJ2^d3q8L71O6DR@bB_}g7Ffy{TFft0TFflT+Gw`r7vNG^7F)}l7GlHZT1(=u^ QnP3cNkYXMdP%>cv0PSAIm;e9( literal 0 HcmV?d00001 diff --git a/test/tools/llvm-cov/Inputs/sources_specified/main.profdata b/test/tools/llvm-cov/Inputs/sources_specified/main.profdata new file mode 100644 index 0000000000000000000000000000000000000000..aeee1ab7f7dee506fcd8920bcd06aa85b2a89f3b GIT binary patch literal 880 zcmeyLQ&5zjmf6U{fE_3>L&Vvj(n3%grk)kbXGEi+Tn4Ci1_5=L2r9jx4W<)S+<_OS z6IJ}dWSGsU;tf&|7s5<~=~h_C4pvC4_yKiJtm<)zC#>Vbs-D4=2dnsk-Mm=EKh*JI z6*rLP$0{CShh6-RBX)5!C+y<(IK&wlKGxiyxG#Cvz(D(+tkSpUz83_#bSA89;W5!2Ee@mvmIum1k~S&F#p3O(CB+;@&NYb BF;@Tp literal 0 HcmV?d00001 diff --git a/test/tools/llvm-cov/sources-specified.test b/test/tools/llvm-cov/sources-specified.test new file mode 100644 index 00000000000..cd19adf52fe --- /dev/null +++ b/test/tools/llvm-cov/sources-specified.test @@ -0,0 +1,28 @@ +RUN: llvm-cov report -instr-profile %S/Inputs/sources_specified/main.profdata \ +RUN: %S/Inputs/sources_specified/main.covmapping \ +RUN: %S/Inputs/sources_specified/main.cc %S/Inputs/sources_specified/extra \ +RUN: | FileCheck -check-prefix=REPORT %s + +RUN: llvm-cov show -instr-profile %S/Inputs/sources_specified/main.profdata \ +RUN: %S/Inputs/sources_specified/main.covmapping \ +RUN: %S/Inputs/sources_specified/main.cc %S/Inputs/sources_specified/extra \ +RUN: | FileCheck -check-prefix=SHOW %s + + +REPORT: {{^}}main.cc{{.*}} +REPORT: {{^}}extra{{[/\\]}}{{dec|inc}}.h{{.*}} +REPORT: {{^}}extra{{[/\\]}}{{dec|inc}}.h{{.*}} +REPORT-NOT: {{^}}abs.h{{.*}} + +SHOW: {{.*}}main.cc{{.*}} +SHOW: {{.*}}extra{{[/\\]}}{{dec|inc}}.h{{.*}} +SHOW: {{.*}}extra{{[/\\]}}{{dec|inc}}.h{{.*}} +SHOW-NOT: {{.*}}abs.h{{.*}} + +Instructions for regenerating the test: + +clang -mllvm -enable-name-compression=false -fprofile-instr-generate -fcoverage-mapping main.cc -o main + +LLVM_PROFILE_FILE="main.raw" ./main +llvm-profdata merge main.raw -o main.profdata +llvm-cov convert-for-testing ./main -o ./main.covmapping diff --git a/tools/llvm-cov/CodeCoverage.cpp b/tools/llvm-cov/CodeCoverage.cpp index 8d9f4d022ca..2ecd7ea6b90 100644 --- a/tools/llvm-cov/CodeCoverage.cpp +++ b/tools/llvm-cov/CodeCoverage.cpp @@ -947,7 +947,10 @@ int CodeCoverageTool::report(int argc, const char **argv, CoverageReport Report(ViewOpts, *Coverage.get()); if (!ShowFunctionSummaries) { - Report.renderFileReports(llvm::outs()); + if (SourceFiles.empty()) + Report.renderFileReports(llvm::outs()); + else + Report.renderFileReports(llvm::outs(), SourceFiles); } else { if (SourceFiles.empty()) { error("Source files must be specified when -show-functions=true is " diff --git a/tools/llvm-cov/CoverageReport.cpp b/tools/llvm-cov/CoverageReport.cpp index 56745308b79..f930f730d23 100644 --- a/tools/llvm-cov/CoverageReport.cpp +++ b/tools/llvm-cov/CoverageReport.cpp @@ -364,7 +364,12 @@ void CoverageReport::renderFileReports(raw_ostream &OS) const { std::vector UniqueSourceFiles; for (StringRef SF : Coverage.getUniqueSourceFiles()) UniqueSourceFiles.emplace_back(SF.str()); - renderFileReports(OS, UniqueSourceFiles, CoverageFiltersMatchAll()); + renderFileReports(OS, UniqueSourceFiles); +} + +void CoverageReport::renderFileReports( + raw_ostream &OS, ArrayRef Files) const { + renderFileReports(OS, Files, CoverageFiltersMatchAll()); } void CoverageReport::renderFileReports( diff --git a/tools/llvm-cov/CoverageReport.h b/tools/llvm-cov/CoverageReport.h index 4126c319f43..1c9e68e832f 100644 --- a/tools/llvm-cov/CoverageReport.h +++ b/tools/llvm-cov/CoverageReport.h @@ -47,6 +47,9 @@ public: /// Render file reports for every unique file in the coverage mapping. void renderFileReports(raw_ostream &OS) const; + /// Render file reports for the files specified in \p Files. + void renderFileReports(raw_ostream &OS, ArrayRef Files) const; + /// Render file reports for the files specified in \p Files and the functions /// in \p Filters. void renderFileReports(raw_ostream &OS, ArrayRef Files, -- 2.50.1