[llvm] r315685 - [llvm-cov] Generate "report" for given source paths if sources are specified.

Max Moroz via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 13 07:44:51 PDT 2017


Author: dor1s
Date: Fri Oct 13 07:44:51 2017
New Revision: 315685

URL: http://llvm.org/viewvc/llvm-project?rev=315685&view=rev
Log:
[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

Added:
    llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/
    llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/abs.h
    llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/extra/
    llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/extra/dec.h
    llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/extra/inc.h
    llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.cc
    llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.covmapping   (with props)
    llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.profdata   (with props)
    llvm/trunk/test/tools/llvm-cov/sources-specified.test
Modified:
    llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
    llvm/trunk/tools/llvm-cov/CoverageReport.cpp
    llvm/trunk/tools/llvm-cov/CoverageReport.h

Added: llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/abs.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/abs.h?rev=315685&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/abs.h (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/abs.h Fri Oct 13 07:44:51 2017
@@ -0,0 +1,5 @@
+int abs(int x) {
+  if (x < 0)
+    return -x;
+  return x;
+}

Added: llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/extra/dec.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/extra/dec.h?rev=315685&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/extra/dec.h (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/extra/dec.h Fri Oct 13 07:44:51 2017
@@ -0,0 +1,3 @@
+int dec(int x) {
+  return x + 1;
+}

Added: llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/extra/inc.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/extra/inc.h?rev=315685&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/extra/inc.h (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/extra/inc.h Fri Oct 13 07:44:51 2017
@@ -0,0 +1,3 @@
+int inc(int x) {
+  return x + 1;
+}

Added: llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.cc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.cc?rev=315685&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.cc (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.cc Fri Oct 13 07:44:51 2017
@@ -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);
+}

Added: llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.covmapping
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.covmapping?rev=315685&view=auto
==============================================================================
Binary file - no diff available.

Propchange: llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.covmapping
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.profdata
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.profdata?rev=315685&view=auto
==============================================================================
Binary file - no diff available.

Propchange: llvm/trunk/test/tools/llvm-cov/Inputs/sources_specified/main.profdata
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: llvm/trunk/test/tools/llvm-cov/sources-specified.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/sources-specified.test?rev=315685&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/sources-specified.test (added)
+++ llvm/trunk/test/tools/llvm-cov/sources-specified.test Fri Oct 13 07:44:51 2017
@@ -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

Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=315685&r1=315684&r2=315685&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Fri Oct 13 07:44:51 2017
@@ -947,7 +947,10 @@ int CodeCoverageTool::report(int argc, c
 
   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 "

Modified: llvm/trunk/tools/llvm-cov/CoverageReport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageReport.cpp?rev=315685&r1=315684&r2=315685&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageReport.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CoverageReport.cpp Fri Oct 13 07:44:51 2017
@@ -364,7 +364,12 @@ void CoverageReport::renderFileReports(r
   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(

Modified: llvm/trunk/tools/llvm-cov/CoverageReport.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageReport.h?rev=315685&r1=315684&r2=315685&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageReport.h (original)
+++ llvm/trunk/tools/llvm-cov/CoverageReport.h Fri Oct 13 07:44:51 2017
@@ -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,




More information about the llvm-commits mailing list