[llvm] r200740 - llvm-cov: Ignore missing .gcda files

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


Author: bogner
Date: Tue Feb  4 00:41:39 2014
New Revision: 200740

URL: http://llvm.org/viewvc/llvm-project?rev=200740&view=rev
Log:
llvm-cov: Ignore missing .gcda files

When gcov is run without gcda data, it acts as if the counts are all
zero and labels the file as - to indicate that there was no data. We
should do the same.

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

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

Added: llvm/trunk/test/tools/llvm-cov/Inputs/test_no_gcda.output
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_no_gcda.output?rev=200740&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_no_gcda.output (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_no_gcda.output Tue Feb  4 00:41:39 2014
@@ -0,0 +1,8 @@
+File 'test.cpp'
+Lines executed:0.00% of 38
+test.cpp:creating 'test.cpp.gcov'
+
+File './test.h'
+Lines executed:0.00% of 1
+./test.h:creating './test.h.gcov'
+

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=200740&r1=200739&r2=200740&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:39 2014
@@ -48,6 +48,11 @@ RUN: llvm-cov test.c -a -b -c -u | diff
 RUN: diff -aub test_-a_-b_-c_-u.cpp.gcov test.cpp.gcov
 RUN: diff -aub test_-a_-b_-c_-u.h.gcov test.h.gcov
 
+# Missing gcda file just gives 0 counts.
+RUN: llvm-cov test.c -gcda=no_such_gcda_file | diff -u test_no_gcda.output -
+RUN: diff -aub test_no_gcda.cpp.gcov test.cpp.gcov
+RUN: diff -aub test_no_gcda.h.gcov test.h.gcov
+
 # Invalid gcno file.
 RUN: not llvm-cov test.c -gcno=test_read_fail.gcno
 

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=200740&r1=200739&r2=200740&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/llvm-cov.cpp (original)
+++ llvm/trunk/tools/llvm-cov/llvm-cov.cpp Tue Feb  4 00:41:39 2014
@@ -84,13 +84,18 @@ int main(int argc, char **argv) {
 
   OwningPtr<MemoryBuffer> GCDA_Buff;
   if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
-    errs() << InputGCDA << ": " << ec.message() << "\n";
-    return 1;
-  }
-  GCOVBuffer GCDA_GB(GCDA_Buff.get());
-  if (!GF.readGCDA(GCDA_GB)) {
-    errs() << "Invalid .gcda File!\n";
-    return 1;
+    if (ec != errc::no_such_file_or_directory) {
+      errs() << InputGCDA << ": " << ec.message() << "\n";
+      return 1;
+    }
+    // Clear the filename to make it clear we didn't read anything.
+    InputGCDA = "-";
+  } else {
+    GCOVBuffer GCDA_GB(GCDA_Buff.get());
+    if (!GF.readGCDA(GCDA_GB)) {
+      errs() << "Invalid .gcda File!\n";
+      return 1;
+    }
   }
 
   if (DumpGCOV)





More information about the llvm-commits mailing list