]> granicus.if.org Git - llvm/commitdiff
[llvm-cov] Generate "report" for given source paths if sources are specified.
authorMax Moroz <mmoroz@chromium.org>
Fri, 13 Oct 2017 14:44:51 +0000 (14:44 +0000)
committerMax Moroz <mmoroz@chromium.org>
Fri, 13 Oct 2017 14:44:51 +0000 (14:44 +0000)
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

test/tools/llvm-cov/Inputs/sources_specified/abs.h [new file with mode: 0644]
test/tools/llvm-cov/Inputs/sources_specified/extra/dec.h [new file with mode: 0644]
test/tools/llvm-cov/Inputs/sources_specified/extra/inc.h [new file with mode: 0644]
test/tools/llvm-cov/Inputs/sources_specified/main.cc [new file with mode: 0644]
test/tools/llvm-cov/Inputs/sources_specified/main.covmapping [new file with mode: 0644]
test/tools/llvm-cov/Inputs/sources_specified/main.profdata [new file with mode: 0644]
test/tools/llvm-cov/sources-specified.test [new file with mode: 0644]
tools/llvm-cov/CodeCoverage.cpp
tools/llvm-cov/CoverageReport.cpp
tools/llvm-cov/CoverageReport.h

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 (file)
index 0000000..f13c517
--- /dev/null
@@ -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 (file)
index 0000000..178e1ea
--- /dev/null
@@ -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 (file)
index 0000000..5086aaa
--- /dev/null
@@ -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 (file)
index 0000000..cda21f1
--- /dev/null
@@ -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 (file)
index 0000000..95f22f5
Binary files /dev/null and b/test/tools/llvm-cov/Inputs/sources_specified/main.covmapping differ
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 (file)
index 0000000..aeee1ab
Binary files /dev/null and b/test/tools/llvm-cov/Inputs/sources_specified/main.profdata differ
diff --git a/test/tools/llvm-cov/sources-specified.test b/test/tools/llvm-cov/sources-specified.test
new file mode 100644 (file)
index 0000000..cd19adf
--- /dev/null
@@ -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
index 8d9f4d022cafb88bb91eec124865c298e32f4be2..2ecd7ea6b90d2931070ab4de4ac863b53e48d0f9 100644 (file)
@@ -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 "
index 56745308b79a58924dda43d7abcd47ed98f0de87..f930f730d23e5df359b161b23aa6a5547ec61e97 100644 (file)
@@ -364,7 +364,12 @@ void CoverageReport::renderFileReports(raw_ostream &OS) const {
   std::vector<std::string> 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<std::string> Files) const {
+  renderFileReports(OS, Files, CoverageFiltersMatchAll());
 }
 
 void CoverageReport::renderFileReports(
index 4126c319f4355e7657a16efb8ffe189404dc9447..1c9e68e832f39609f3ce32eef027d40480294584 100644 (file)
@@ -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<std::string> Files) const;
+
   /// Render file reports for the files specified in \p Files and the functions
   /// in \p Filters.
   void renderFileReports(raw_ostream &OS, ArrayRef<std::string> Files,