[llvm] r200741 - llvm-cov: Implement the object-directory flag

Justin Bogner mail at justinbogner.com
Mon Feb 3 22:41:43 PST 2014


Author: bogner
Date: Tue Feb  4 00:41:43 2014
New Revision: 200741

URL: http://llvm.org/viewvc/llvm-project?rev=200741&view=rev
Log:
llvm-cov: Implement the object-directory flag

Added:
    llvm/trunk/test/tools/llvm-cov/Inputs/test_objdir.cpp.gcov
    llvm/trunk/test/tools/llvm-cov/Inputs/test_objdir.h.gcov
Modified:
    llvm/trunk/test/tools/llvm-cov/llvm-cov.test
    llvm/trunk/tools/llvm-cov/llvm-cov.cpp

Added: llvm/trunk/test/tools/llvm-cov/Inputs/test_objdir.cpp.gcov
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_objdir.cpp.gcov?rev=200741&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_objdir.cpp.gcov (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_objdir.cpp.gcov Tue Feb  4 00:41:43 2014
@@ -0,0 +1,79 @@
+        -:    0:Source:test.cpp
+        -:    0:Graph:objdir/test.gcno
+        -:    0:Data:objdir/test.gcda
+        -:    0:Runs:2
+        -:    0:Programs:1
+        -:    1:#include "test.h"
+        -:    2:#include <cstdlib>
+        -:    3:
+        -:    4:bool on = false;
+        -:    5:int len = 42;
+        -:    6:double grid[10][10] = {0};
+        -:    7:const char * hello = "world";
+        -:    8:const char * world = "hello";
+        -:    9:
+8589934592:   10:void A::B() {}
+        -:   11:
+    #####:   12:void useless() {}
+        -:   13:
+        -:   14:double more_useless() {
+    #####:   15:  return 0;
+        -:   16:}
+        -:   17:
+        -:   18:int foo() {
+        2:   19:  on = true;
+        2:   20:  return 3;
+        -:   21:}
+        -:   22:
+        -:   23:int bar() {
+    #####:   24:  len--;
+    #####:   25:  return foo() + 45;
+        -:   26:}
+        -:   27:
+        8:   28:void assign(int ii, int jj) {
+        8:   29:  grid[ii][jj] = (ii+1) * (jj+1);
+        8:   30:}
+        -:   31:
+        -:   32:void initialize_grid() {
+       12:   33:  for (int ii = 0; ii < 2; ii++)
+       24:   34:    for (int jj = 0; jj < 2; jj++)
+       12:   35:      assign(ii, jj);
+        2:   36:}
+        -:   37:
+        -:   38:int main() {
+        2:   39:  initialize_grid();
+        -:   40:
+        2:   41:  int a = 2;
+        2:   42:  on = rand() % 2;
+        2:   43:  if (on) {
+        2:   44:    foo();
+        2:   45:    ++a;
+        2:   46:  } else {
+    #####:   47:    bar();
+    #####:   48:    a += rand();
+        -:   49:  }
+        -:   50:
+       44:   51:  for (int ii = 0; ii < 10; ++ii) {
+       20:   52:    switch (rand() % 5) {
+        -:   53:      case 0:
+        4:   54:        a += rand();
+        4:   55:        break;
+        -:   56:      case 1:
+        -:   57:      case 2:
+        2:   58:        a += rand() / rand();
+        2:   59:        break;
+        -:   60:      case 3:
+        6:   61:        a -= rand();
+        6:   62:        break;
+        -:   63:      default:
+        8:   64:        a = -1;
+        8:   65:    }
+       20:   66:  }
+        -:   67:
+        2:   68:  A thing;
+17179869188:   69:  for (uint64_t ii = 0; ii < 4294967296; ++ii)
+8589934592:   70:    thing.B();
+        -:   71:
+        2:   72:  return a + 8 + grid[2][3] + len;
+        -:   73:  return more_useless();
+        -:   74:}

Added: llvm/trunk/test/tools/llvm-cov/Inputs/test_objdir.h.gcov
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_objdir.h.gcov?rev=200741&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_objdir.h.gcov (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_objdir.h.gcov Tue Feb  4 00:41:43 2014
@@ -0,0 +1,8 @@
+        -:    0:Source:./test.h
+        -:    0:Graph:objdir/test.gcno
+        -:    0:Data:objdir/test.gcda
+        -:    0:Runs:2
+        -:    0:Programs:1
+        4:    1:struct A {
+        -:    2:  virtual void B();
+        -:    3:};

Modified: llvm/trunk/test/tools/llvm-cov/llvm-cov.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/llvm-cov.test?rev=200741&r1=200740&r2=200741&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/llvm-cov.test (original)
+++ llvm/trunk/test/tools/llvm-cov/llvm-cov.test Tue Feb  4 00:41:43 2014
@@ -14,6 +14,13 @@ RUN: llvm-cov test.c | diff -u test_no_o
 RUN: diff -aub test_no_options.cpp.gcov test.cpp.gcov
 RUN: diff -aub test_no_options.h.gcov test.h.gcov
 
+# Same, but specifying the object directory
+RUN: mkdir -p %t/objdir
+RUN: cp test.gcno test.gcda %t/objdir
+RUN: llvm-cov -o objdir test.c | diff -u test_no_options.output -
+RUN: diff -aub test_objdir.cpp.gcov test.cpp.gcov
+RUN: diff -aub test_objdir.h.gcov test.h.gcov
+
 # Function summaries. This changes stdout, but not the gcov files.
 RUN: llvm-cov test.c -f | diff -u test_-f.output -
 RUN: diff -aub test_no_options.cpp.gcov test.cpp.gcov

Modified: llvm/trunk/tools/llvm-cov/llvm-cov.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/llvm-cov.cpp?rev=200741&r1=200740&r2=200741&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/llvm-cov.cpp (original)
+++ llvm/trunk/tools/llvm-cov/llvm-cov.cpp Tue Feb  4 00:41:43 2014
@@ -12,10 +12,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/GCOV.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MemoryObject.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/system_error.h"
@@ -41,6 +43,10 @@ static cl::opt<bool> FuncSummary("f", cl
                                  cl::desc("Show coverage for each function"));
 static cl::alias FuncSummaryA("function-summaries", cl::aliasopt(FuncSummary));
 
+static cl::opt<std::string> ObjectDir("o", cl::value_desc("DIR"), cl::init(""),
+                                      cl::desc("Search for objects in DIR"));
+static cl::alias ObjectDirA("object-directory", cl::aliasopt(ObjectDir));
+
 static cl::opt<bool> UncondBranch("u", cl::init(false),
                                   cl::desc("Display unconditional branch info "
                                            "(requires -b)"));
@@ -64,10 +70,15 @@ int main(int argc, char **argv) {
 
   cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
 
+  SmallString<128> CoverageFileStem(ObjectDir);
+  if (CoverageFileStem.empty())
+    CoverageFileStem = sys::path::parent_path(SourceFile);
+  sys::path::append(CoverageFileStem, sys::path::stem(SourceFile));
+
   if (InputGCNO.empty())
-    InputGCNO = SourceFile.substr(0, SourceFile.rfind(".")) + ".gcno";
+    InputGCNO = (CoverageFileStem.str() + ".gcno").str();
   if (InputGCDA.empty())
-    InputGCDA = SourceFile.substr(0, SourceFile.rfind(".")) + ".gcda";
+    InputGCDA = (CoverageFileStem.str() + ".gcda").str();
 
   GCOVFile GF;
 





More information about the llvm-commits mailing list