376 lines · plain
1# Tests for compatibility between llvm-cov and gcov. These work by2# comparing llvm-cov against reference outputs generated by gcov 4.2.3 4# Test fails on Windows where internal shell is used due to path separator5# mismatches.6UNSUPPORTED: system-windows7 8RUN: rm -rf %t9RUN: mkdir %t10RUN: cd %t11RUN: cp %p/Inputs/test* .12 13# Basic behaviour with no flags14RUN: llvm-cov gcov test.c 2> %t.err | FileCheck %s --check-prefixes=OUT,OUTFILE --match-full-lines --strict-whitespace15RUN: FileCheck %s --check-prefix=C --match-full-lines --strict-whitespace < test.cpp.gcov16RUN: diff -ub test_no_options.h.gcov test.h.gcov17RUN: count 0 < %t.err18 19# Same, but specifying the object directory20RUN: mkdir -p %t/objdir21RUN: cp test.gcno test.gcda %t/objdir22RUN: llvm-cov gcov -o objdir test.c | FileCheck %s --check-prefixes=OUT,OUTFILE23RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefix=OBJDIR24OBJDIR: 0:Graph:objdir/test.gcno25OBJDIR-NEXT: 0:Data:objdir/test.gcda26 27# Specifying an object file28RUN: llvm-cov gcov -o objdir/test.o test.c29RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefix=OBJDIR30 31# Specifying an object file that could be ambiguous with a directory32RUN: llvm-cov gcov -o objdir/test test.c33RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefix=OBJDIR34 35# With gcov output disabled36RUN: llvm-cov gcov -n test.c | FileCheck %s --check-prefix=OUT37 38# Print to stdout.39RUN: llvm-cov gcov -t test.c > stdout40RUN: llvm-cov gcov --stdout test.c | cmp stdout -41RUN: cat test_no_options.cpp.gcov test_no_options.h.gcov | diff -u - stdout42RUN: llvm-cov gcov -n -t test.c | count 043 44RUN: llvm-cov gcov test_paths.cpp 2>/dev/null | FileCheck %s --check-prefix=MISSING45RUN: ls a.c.gcov46MISSING: File 'src/a.c'47MISSING: Creating 'a.c.gcov'48 49# Preserve paths. This mangles the output filenames.50RUN: llvm-cov gcov -p test_paths.cpp 2>/dev/null | FileCheck %s --check-prefix=PRESERVE51RUN: ls src#a.c.gcov52PRESERVE: File 'src/a.c'53PRESERVE: Creating 'src#a.c.gcov'54 55# Long file names.56RUN: llvm-cov gcov -l test_paths.cpp57RUN: ls test_paths.cpp##a.c.gcov58 59# Long file names and preserve paths.60RUN: mkdir -p src && llvm-cov gcov -lp -gcno test_paths.gcno -gcda test_paths.gcda src/../test_paths.cpp61RUN: ls src#^#test_paths.cpp##src#a.c.gcov62 63# Hash pathnames.64RUN: llvm-cov gcov -x -gcno test_paths.gcno -gcda test_paths.gcda src/../test_paths.cpp65RUN: ls a.c##0c546a4dd99c1774b7b06e4fad16158c.gcov66 67# Function summaries. This changes stdout, but not the gcov files.68RUN: llvm-cov gcov test.c -f | FileCheck %s --check-prefixes=OUT,OUTFILE,OUT-F69RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefix=C70RUN: FileCheck --input-file=test.h.gcov %s --check-prefix=H71 72# All blocks. This doesn't affect stdout, only the gcov files.73RUN: llvm-cov gcov test.c -a | FileCheck %s --check-prefixes=OUT,OUTFILE74RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefixes=C,C-A75RUN: FileCheck --input-file=test.h.gcov %s --check-prefixes=H,H-A76 77# Branch probabilities.78RUN: llvm-cov gcov test.c -a -b | FileCheck %s --check-prefixes=OUT,OUTFILE,OUT-B79RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefixes=C,C-A,C-B80RUN: FileCheck --input-file=test.h.gcov %s --check-prefixes=H,H-A,H-B81 82# Function summaries including branch probabilities.83RUN: llvm-cov gcov test.c -a -b -f | FileCheck %s --check-prefixes=OUT,OUTFILE,OUT-F,OUT-B,OUT-FB --match-full-lines --strict-whitespace84RUN: FileCheck %s --check-prefixes=C,C-A,C-B --match-full-lines --strict-whitespace < test.cpp.gcov85RUN: FileCheck %s --check-prefixes=H,H-A,H-B --match-full-lines --strict-whitespace < test.h.gcov86 87 OUT-F:Function '_ZN1A1BEv'88 OUT-F-NEXT:Lines executed:100.00% of 189 OUT-FB-NEXT:No branches90 OUT-FB-NEXT:No calls91 OUT-F-EMPTY:92 OUT-F-NEXT:Function '_Z7uselessv'93 OUT-F-NEXT:Lines executed:0.00% of 194 OUT-FB-NEXT:No branches95 OUT-FB-NEXT:No calls96 OUT-F-EMPTY:97 OUT-F-NEXT:Function '_Z12more_uselessv'98 OUT-F-NEXT:Lines executed:0.00% of 299 OUT-FB-NEXT:No branches100 OUT-FB-NEXT:No calls101 OUT-F-EMPTY:102 OUT-F-NEXT:Function '_Z3foov'103 OUT-F-NEXT:Lines executed:100.00% of 3104 OUT-FB-NEXT:No branches105 OUT-FB-NEXT:No calls106 OUT-F-EMPTY:107 OUT-F-NEXT:Function '_Z3barv'108 OUT-F-NEXT:Lines executed:0.00% of 3109 OUT-FB-NEXT:No branches110 OUT-FB-NEXT:No calls111 OUT-F-EMPTY:112 OUT-F-NEXT:Function '_Z6assignii'113 OUT-F-NEXT:Lines executed:100.00% of 3114 OUT-FB-NEXT:No branches115 OUT-FB-NEXT:No calls116 OUT-F-EMPTY:117 OUT-F-NEXT:Function '_Z15initialize_gridv'118 OUT-F-NEXT:Lines executed:100.00% of 5119 OUT-FB-NEXT:No branches120 OUT-FB-NEXT:No calls121 OUT-F-EMPTY:122 OUT-F-NEXT:Function 'main'123 OUT-F-NEXT:Lines executed:92.00% of 25124 OUT-FB-NEXT:No branches125 OUT-FB-NEXT:No calls126 OUT-F-EMPTY:127 OUT-F-NEXT:Function '_ZN1AC2Ev'128 OUT-F-NEXT:Lines executed:100.00% of 1129 OUT-FB-NEXT:No branches130 OUT-FB-NEXT:No calls131 OUT-F-EMPTY:132 OUT:File 'test.cpp'133 OUT-NEXT:Lines executed:81.40% of 43134 OUT-B-NEXT:Branches executed:100.00% of 15135 OUT-B-NEXT:Taken at least once:86.67% of 15136 OUT-B-NEXT:No calls137OUTFILE-NEXT:Creating 'test.cpp.gcov'138 OUT-EMPTY:139 OUT-NEXT:File 'test.h'140 OUT-NEXT:Lines executed:100.00% of 1141 OUT-B-NEXT:No branches142 OUT-B-NEXT:No calls143OUTFILE-NEXT:Creating 'test.h.gcov'144 145# Summarize unconditional branches too.146RUN: llvm-cov gcov test.c -a -b -u | FileCheck %s --check-prefixes=OUT,OUTFILE,OUT-B147RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefixes=C,C-A,C-B,C-U148RUN: FileCheck --input-file=test.h.gcov %s --check-prefixes=H,H-A,H-B,H-U149 150# Absolute counts for branches.151RUN: llvm-cov gcov test.c -a -b -c -u152RUN: FileCheck --input-file=test.h.gcov %s --check-prefix=H-C153H-C: unconditional 0 taken 1154 155# Missing gcda file just gives 0 counts.156RUN: llvm-cov gcov test.c -gcda=no_such_gcda_file | FileCheck %s --check-prefix=NO-GCDA157RUN: diff -ub test_no_gcda.cpp.gcov test.cpp.gcov158RUN: diff -ub test_no_gcda.h.gcov test.h.gcov159NO-GCDA: File 'test.cpp'160NO-GCDA-NEXT: Lines executed:0.00% of 43161NO-GCDA-NEXT: Creating 'test.cpp.gcov'162NO-GCDA-EMPTY:163NO-GCDA-NEXT: File 'test.h'164NO-GCDA-NEXT: Lines executed:0.00% of 1165NO-GCDA-NEXT: Creating 'test.h.gcov'166 167# Invalid gcno file.168RUN: llvm-cov gcov test.c -gcno=test_read_fail.gcno169 170# Not a .gcda file. Error but keep the .gcov output.171RUN: echo invalid > not.gcda172RUN: llvm-cov gcov test.c -gcda=not.gcda 2> %t.err | FileCheck %s --check-prefix=NO-GCDA173RUN: FileCheck %s --check-prefix=NOT-GCDA < %t.err174NOT-GCDA: not.gcda:not a gcov data file175 176# Bad file checksum on gcda.177RUN: llvm-cov gcov test.c -gcda=test_file_checksum_fail.gcda 2> %t.err | FileCheck %s --check-prefix=NO-GCDA178 179# Bad function checksum on gcda180RUN: llvm-cov gcov test.c -gcda=test_func_checksum_fail.gcda 2> %t.err | FileCheck %s --check-prefix=NO-GCDA181 182# Has arcs from exit blocks183RUN-DISABLED: llvm-cov gcov test_exit_block_arcs.c 2>&1 | FileCheck %s -check-prefix=EXIT_BLOCK_ARCS184EXIT_BLOCK_ARCS: (main) has arcs from exit block.185 186 187 C: -: 0:Source:test.cpp188C-NEXT: -: 0:Graph:test.gcno189C-NEXT: -: 0:Data:test.gcda190C-NEXT: -: 0:Runs:1191C-NEXT: -: 0:Programs:1192C-NEXT: -: 1:#include "test.h"193C-NEXT: -: 2:#include <cstdlib>194C-NEXT: -: 3:195C-NEXT: -: 4:bool on = false;196C-NEXT: -: 5:int len = 42;197C-NEXT: -: 6:double grid[10][10] = {0};198C-NEXT: -: 7:const char * hello = "world";199C-NEXT: -: 8:const char * world = "hello";200C-NEXT: -: 9:201 C-B:function _ZN1A1BEv called 4294967296 returned 100% blocks executed 100%202C-NEXT:4294967296: 10:void A::B() {}203 C-A:4294967296: 10-block 0204 C-U:unconditional 0 taken 100%205 C-A:4294967296: 10-block 1206 C-U:unconditional 1 taken 100%207C-NEXT: -: 11:208 C-B:function _Z7uselessv called 0 returned 0% blocks executed 0%209C-NEXT: #####: 12:void useless() {}210 C-A: $$$$$: 12-block 0211 C-U:unconditional 0 never executed212 C-A: $$$$$: 12-block 1213 C-U:unconditional 1 never executed214C-NEXT: -: 13:215 C-B:function _Z12more_uselessv called 0 returned 0% blocks executed 0%216C-NEXT: #####: 14:double more_useless() {217C-NEXT: #####: 15: return 0;218 C-A: $$$$$: 15-block 0219 C-U:unconditional 0 never executed220 C-A: $$$$$: 15-block 1221 C-U:unconditional 1 never executed222C-NEXT: -: 16:}223C-NEXT: -: 17:224 C-B:function _Z3foov called 1 returned 100% blocks executed 100%225C-NEXT: 1: 18:int foo() {226C-NEXT: 1: 19: on = true;227 C-A: 1: 19-block 0228 C-U:unconditional 0 taken 100%229C-NEXT: 1: 20: return 3;230 C-A: 1: 20-block 0231 C-U:unconditional 0 taken 100%232C-NEXT: -: 21:}233C-NEXT: -: 22:234 C-B:function _Z3barv called 0 returned 0% blocks executed 0%235C-NEXT: #####: 23:int bar() {236C-NEXT: #####: 24: len--;237 C-A: $$$$$: 24-block 0238 C-U:unconditional 0 never executed239C-NEXT: #####: 25: return foo() + 45;240 C-A: $$$$$: 25-block 0241 C-U:unconditional 0 never executed242C-NEXT: -: 26:}243C-NEXT: -: 27:244 C-B:function _Z6assignii called 4 returned 100% blocks executed 100%245C-NEXT: 4: 28:void assign(int ii, int jj) {246 C-A: 4: 28-block 0247 C-U:unconditional 0 taken 100%248C-NEXT: 4: 29: grid[ii][jj] = (ii+1) * (jj+1);249C-NEXT: 4: 30:}250 C-A: 4: 30-block 0251 C-U:unconditional 0 taken 100%252C-NEXT: -: 31:253 C-B:function _Z15initialize_gridv called 1 returned 100% blocks executed 100%254C-NEXT: 1: 32:void initialize_grid() {255C-NEXT: 3: 33: for (int ii = 0; ii < 2; ii++)256 C-A: 1: 33-block 0257 C-U:unconditional 0 taken 100%258 C-A: 1: 33-block 1259 C-U:unconditional 1 taken 100%260 C-A: 3: 33-block 2261 C-B:branch {{[02]}} taken 67%262 C-B:branch {{[13]}} taken 33%263 C-A: 2: 33-block 3264 C-U:unconditional 4 taken 100%265C-NEXT: 6: 34: for (int jj = 0; jj < 2; jj++)266 C-A: 2: 34-block 0267 C-U:unconditional 0 taken 100%268 C-A: 6: 34-block 1269 C-B:branch {{[01]}} taken 67%270 C-B:branch {{[12]}} taken 33%271 C-A: 4: 34-block 2272 C-U:unconditional 3 taken 100%273C-NEXT: 6: 35: assign(ii, jj);274 C-A: 4: 35-block 0275 C-U:unconditional 0 taken 100%276 C-A: 2: 35-block 1277 C-U:unconditional 1 taken 100%278C-NEXT: 1: 36:}279 C-A: 1: 36-block 0280 C-U:unconditional 0 taken 100%281C-NEXT: -: 37:282 C-B:function main called 1 returned 100% blocks executed 94%283C-NEXT: 1: 38:int main() {284 C-A: 1: 38-block 0285 C-U:unconditional 0 taken 100%286C-NEXT: 1: 39: initialize_grid();287C-NEXT: -: 40:288C-NEXT: 1: 41: int a = 2;289C-NEXT: 1: 42: on = rand() % 2;290C-NEXT: 1: 43: if (on) {291 C-A: 1: 43-block 0292 C-B:branch 0 taken 100%293 C-B:branch 1 taken 0%294C-NEXT: 1: 44: foo();295C-NEXT: 1: 45: ++a;296C-NEXT: 1: 46: } else {297 C-A: 1: 46-block 0298 C-U:unconditional 0 taken 100%299C-NEXT: #####: 47: bar();300C-NEXT: #####: 48: a += rand();301 C-A: $$$$$: 48-block 0302 C-U:unconditional 0 never executed303C-NEXT: -: 49: }304C-NEXT: -: 50:305C-NEXT: 11: 51: for (int ii = 0; ii < 10; ++ii) {306 C-A: 1: 51-block 0307 C-U:unconditional 0 taken 100%308 C-A: 11: 51-block 1309 C-B:branch {{[01]}} taken 91%310 C-B:branch {{[12]}} taken 9%311 C-A: 10: 51-block 2312 C-U:unconditional 3 taken 100%313C-NEXT: 10: 52: switch (rand() % 5) {314 C-A: 10: 52-block 0315 C-B:branch 0 taken 10%316 C-B:branch 1 taken 20%317 C-B:branch 2 taken 0%318 C-B:branch 3 taken 40%319 C-B:branch 4 taken 30%320C-NEXT: -: 53: case 0:321C-NEXT: 2: 54: a += rand();322C-NEXT: 2: 55: break;323 C-A: 2: 55-block 0324 C-U:unconditional 0 taken 100%325C-NEXT: -: 56: case 1:326C-NEXT: -: 57: case 2:327C-NEXT: 4: 58: a += rand() / rand();328C-NEXT: 4: 59: break;329 C-A: 4: 59-block 0330 C-U:unconditional 0 taken 100%331C-NEXT: -: 60: case 3:332C-NEXT: 3: 61: a -= rand();333C-NEXT: 3: 62: break;334 C-A: 3: 62-block 0335 C-U:unconditional 0 taken 100%336C-NEXT: -: 63: default:337C-NEXT: 1: 64: a = -1;338C-NEXT: 1: 65: }339 C-A: 1: 65-block 0340 C-U:unconditional 0 taken 100%341C-NEXT: 10: 66: }342 C-A: 10: 66-block 0343 C-U:unconditional 0 taken 100%344C-NEXT: -: 67:345C-NEXT: 1: 68: A thing;346C-NEXT:4294967297: 69: for (uint64_t ii = 0; ii < 4294967296; ++ii)347 C-A: 1: 69-block 0348 C-U:unconditional 0 taken 100%349 C-A:4294967297: 69-block 1350 C-B:branch {{[01]}} taken 99%351 C-B:branch {{[12]}} taken 1%352 C-A:4294967296: 69-block 2353 C-U:unconditional 3 taken 100%354C-NEXT:4294967296: 70: thing.B();355 C-A:4294967296: 70-block 0356 C-U:unconditional 0 taken 100%357C-NEXT: -: 71:358C-NEXT: 1: 72: return a + 8 + grid[2][3] + len;359 C-A: 1: 72-block 0360 C-U:unconditional 0 taken 100%361C-NEXT: -: 73: return more_useless();362C-NEXT: -: 74:}363 364 H: -: 0:Source:test.h365H-NEXT: -: 0:Graph:test.gcno366H-NEXT: -: 0:Data:test.gcda367H-NEXT: -: 0:Runs:1368H-NEXT: -: 0:Programs:1369H-NEXT: -: 1:#include <stdint.h>370 H-B:function _ZN1AC2Ev called 1 returned 100% blocks executed 100%371H-NEXT: 1: 2:struct A {372 H-A: 1: 2-block 0373 H-U:unconditional 0 taken 100%374H-NEXT: -: 3: virtual void B();375H-NEXT: -: 4:};376