1 # Tests for compatibility between llvm-cov and gcov. These work by
2 # comparing llvm-cov against reference outputs generated by gcov 4.2.
4 # Test fails on Windows where internal shell is used due to path separator
11 RUN: cp %p/Inputs/test* .
13 # Basic behaviour with no flags
14 RUN: llvm-cov gcov test.c 2> %t.err | FileCheck %s --check-prefixes=OUT,OUTFILE --match-full-lines --strict-whitespace
15 RUN: FileCheck %s --check-prefix=C --match-full-lines --strict-whitespace < test.cpp.gcov
16 RUN: diff -ub test_no_options.h.gcov test.h.gcov
19 # Same, but specifying the object directory
20 RUN: mkdir -p %t/objdir
21 RUN: cp test.gcno test.gcda %t/objdir
22 RUN: llvm-cov gcov -o objdir test.c | FileCheck %s --check-prefixes=OUT,OUTFILE
23 RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefix=OBJDIR
24 OBJDIR: 0:Graph:objdir/test.gcno
25 OBJDIR-NEXT: 0:Data:objdir/test.gcda
27 # Specifying an object file
28 RUN: llvm-cov gcov -o objdir/test.o test.c
29 RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefix=OBJDIR
31 # Specifying an object file that could be ambiguous with a directory
32 RUN: llvm-cov gcov -o objdir/test test.c
33 RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefix=OBJDIR
35 # With gcov output disabled
36 RUN: llvm-cov gcov -n test.c | FileCheck %s --check-prefix=OUT
39 RUN: llvm-cov gcov -t test.c > stdout
40 RUN: llvm-cov gcov --stdout test.c | cmp stdout -
41 RUN: cat test_no_options.cpp.gcov test_no_options.h.gcov | diff -u - stdout
42 RUN: llvm-cov gcov -n -t test.c | count 0
44 RUN: llvm-cov gcov test_paths.cpp 2>/dev/null | FileCheck %s --check-prefix=MISSING
46 MISSING: File 'src/a.c'
47 MISSING: Creating 'a.c.gcov'
49 # Preserve paths. This mangles the output filenames.
50 RUN: llvm-cov gcov -p test_paths.cpp 2>/dev/null | FileCheck %s --check-prefix=PRESERVE
52 PRESERVE: File 'src/a.c'
53 PRESERVE: Creating 'src#a.c.gcov'
56 RUN: llvm-cov gcov -l test_paths.cpp
57 RUN: ls test_paths.cpp##a.c.gcov
59 # Long file names and preserve paths.
60 RUN: mkdir -p src && llvm-cov gcov -lp -gcno test_paths.gcno -gcda test_paths.gcda src/../test_paths.cpp
61 RUN: ls src#^#test_paths.cpp##src#a.c.gcov
64 RUN: llvm-cov gcov -x -gcno test_paths.gcno -gcda test_paths.gcda src/../test_paths.cpp
65 RUN: ls a.c##0c546a4dd99c1774b7b06e4fad16158c.gcov
67 # Function summaries. This changes stdout, but not the gcov files.
68 RUN: llvm-cov gcov test.c -f | FileCheck %s --check-prefixes=OUT,OUTFILE,OUT-F
69 RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefix=C
70 RUN: FileCheck --input-file=test.h.gcov %s --check-prefix=H
72 # All blocks. This doesn't affect stdout, only the gcov files.
73 RUN: llvm-cov gcov test.c -a | FileCheck %s --check-prefixes=OUT,OUTFILE
74 RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefixes=C,C-A
75 RUN: FileCheck --input-file=test.h.gcov %s --check-prefixes=H,H-A
77 # Branch probabilities.
78 RUN: llvm-cov gcov test.c -a -b | FileCheck %s --check-prefixes=OUT,OUTFILE,OUT-B
79 RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefixes=C,C-A,C-B
80 RUN: FileCheck --input-file=test.h.gcov %s --check-prefixes=H,H-A,H-B
82 # Function summaries including branch probabilities.
83 RUN: llvm-cov gcov test.c -a -b -f | FileCheck %s --check-prefixes=OUT,OUTFILE,OUT-F,OUT-B,OUT-FB --match-full-lines --strict-whitespace
84 RUN: FileCheck %s --check-prefixes=C,C-A,C-B --match-full-lines --strict-whitespace < test.cpp.gcov
85 RUN: FileCheck %s --check-prefixes=H,H-A,H-B --match-full-lines --strict-whitespace < test.h.gcov
87 OUT-F:Function '_ZN1A1BEv'
88 OUT-F-NEXT:Lines executed:100.00% of 1
89 OUT-FB-NEXT:No branches
92 OUT-F-NEXT:Function '_Z7uselessv'
93 OUT-F-NEXT:Lines executed:0.00% of 1
94 OUT-FB-NEXT:No branches
97 OUT-F-NEXT:Function '_Z12more_uselessv'
98 OUT-F-NEXT:Lines executed:0.00% of 2
99 OUT-FB-NEXT:No branches
102 OUT-F-NEXT:Function '_Z3foov'
103 OUT-F-NEXT:Lines executed:100.00% of 3
104 OUT-FB-NEXT:No branches
107 OUT-F-NEXT:Function '_Z3barv'
108 OUT-F-NEXT:Lines executed:0.00% of 3
109 OUT-FB-NEXT:No branches
112 OUT-F-NEXT:Function '_Z6assignii'
113 OUT-F-NEXT:Lines executed:100.00% of 3
114 OUT-FB-NEXT:No branches
117 OUT-F-NEXT:Function '_Z15initialize_gridv'
118 OUT-F-NEXT:Lines executed:100.00% of 5
119 OUT-FB-NEXT:No branches
122 OUT-F-NEXT:Function 'main'
123 OUT-F-NEXT:Lines executed:92.00% of 25
124 OUT-FB-NEXT:No branches
127 OUT-F-NEXT:Function '_ZN1AC2Ev'
128 OUT-F-NEXT:Lines executed:100.00% of 1
129 OUT-FB-NEXT:No branches
133 OUT-NEXT:Lines executed:81.40% of 43
134 OUT-B-NEXT:Branches executed:100.00% of 15
135 OUT-B-NEXT:Taken at least once:86.67% of 15
137 OUTFILE-NEXT:Creating 'test.cpp.gcov'
139 OUT-NEXT:File 'test.h'
140 OUT-NEXT:Lines executed:100.00% of 1
141 OUT-B-NEXT:No branches
143 OUTFILE-NEXT:Creating 'test.h.gcov'
145 # Summarize unconditional branches too.
146 RUN: llvm-cov gcov test.c -a -b -u | FileCheck %s --check-prefixes=OUT,OUTFILE,OUT-B
147 RUN: FileCheck --input-file=test.cpp.gcov %s --check-prefixes=C,C-A,C-B,C-U
148 RUN: FileCheck --input-file=test.h.gcov %s --check-prefixes=H,H-A,H-B,H-U
150 # Absolute counts for branches.
151 RUN: llvm-cov gcov test.c -a -b -c -u
152 RUN: FileCheck --input-file=test.h.gcov %s --check-prefix=H-C
153 H-C: unconditional 0 taken 1
155 # Missing gcda file just gives 0 counts.
156 RUN: llvm-cov gcov test.c -gcda=no_such_gcda_file | FileCheck %s --check-prefix=NO-GCDA
157 RUN: diff -ub test_no_gcda.cpp.gcov test.cpp.gcov
158 RUN: diff -ub test_no_gcda.h.gcov test.h.gcov
159 NO-GCDA: File 'test.cpp'
160 NO-GCDA-NEXT: Lines executed:0.00% of 43
161 NO-GCDA-NEXT: Creating 'test.cpp.gcov'
163 NO-GCDA-NEXT: File 'test.h'
164 NO-GCDA-NEXT: Lines executed:0.00% of 1
165 NO-GCDA-NEXT: Creating 'test.h.gcov'
168 RUN: llvm-cov gcov test.c -gcno=test_read_fail.gcno
170 # Not a .gcda file. Error but keep the .gcov output.
171 RUN: echo invalid > not.gcda
172 RUN: llvm-cov gcov test.c -gcda=not.gcda 2> %t.err | FileCheck %s --check-prefix=NO-GCDA
173 RUN: FileCheck %s --check-prefix=NOT-GCDA < %t.err
174 NOT-GCDA: not.gcda:not a gcov data file
176 # Bad file checksum on gcda.
177 RUN: llvm-cov gcov test.c -gcda=test_file_checksum_fail.gcda 2> %t.err | FileCheck %s --check-prefix=NO-GCDA
179 # Bad function checksum on gcda
180 RUN: llvm-cov gcov test.c -gcda=test_func_checksum_fail.gcda 2> %t.err | FileCheck %s --check-prefix=NO-GCDA
182 # Has arcs from exit blocks
183 RUN-DISABLED: llvm-cov gcov test_exit_block_arcs.c 2>&1 | FileCheck %s -check-prefix=EXIT_BLOCK_ARCS
184 EXIT_BLOCK_ARCS: (main) has arcs from exit block.
187 C: -: 0:Source:test.cpp
188 C-NEXT: -: 0:Graph:test.gcno
189 C-NEXT: -: 0:Data:test.gcda
191 C-NEXT: -: 0:Programs:1
192 C-NEXT: -: 1:#include "test.h"
193 C-NEXT: -: 2:#include <cstdlib>
195 C-NEXT: -: 4:bool on = false;
196 C-NEXT: -: 5:int len = 42;
197 C-NEXT: -: 6:double grid[10][10] = {0};
198 C-NEXT: -: 7:const char * hello = "world";
199 C-NEXT: -: 8:const char * world = "hello";
201 C-B:function _ZN1A1BEv called 4294967296 returned 100% blocks executed 100%
202 C-NEXT:4294967296: 10:void A::B() {}
203 C-A:4294967296: 10-block 0
204 C-U:unconditional 0 taken 100%
205 C-A:4294967296: 10-block 1
206 C-U:unconditional 1 taken 100%
208 C-B:function _Z7uselessv called 0 returned 0% blocks executed 0%
209 C-NEXT: #####: 12:void useless() {}
210 C-A: $$$$$: 12-block 0
211 C-U:unconditional 0 never executed
212 C-A: $$$$$: 12-block 1
213 C-U:unconditional 1 never executed
215 C-B:function _Z12more_uselessv called 0 returned 0% blocks executed 0%
216 C-NEXT: #####: 14:double more_useless() {
217 C-NEXT: #####: 15: return 0;
218 C-A: $$$$$: 15-block 0
219 C-U:unconditional 0 never executed
220 C-A: $$$$$: 15-block 1
221 C-U:unconditional 1 never executed
224 C-B:function _Z3foov called 1 returned 100% blocks executed 100%
225 C-NEXT: 1: 18:int foo() {
226 C-NEXT: 1: 19: on = true;
228 C-U:unconditional 0 taken 100%
229 C-NEXT: 1: 20: return 3;
231 C-U:unconditional 0 taken 100%
234 C-B:function _Z3barv called 0 returned 0% blocks executed 0%
235 C-NEXT: #####: 23:int bar() {
236 C-NEXT: #####: 24: len--;
237 C-A: $$$$$: 24-block 0
238 C-U:unconditional 0 never executed
239 C-NEXT: #####: 25: return foo() + 45;
240 C-A: $$$$$: 25-block 0
241 C-U:unconditional 0 never executed
244 C-B:function _Z6assignii called 4 returned 100% blocks executed 100%
245 C-NEXT: 4: 28:void assign(int ii, int jj) {
247 C-U:unconditional 0 taken 100%
248 C-NEXT: 4: 29: grid[ii][jj] = (ii+1) * (jj+1);
251 C-U:unconditional 0 taken 100%
253 C-B:function _Z15initialize_gridv called 1 returned 100% blocks executed 100%
254 C-NEXT: 1: 32:void initialize_grid() {
255 C-NEXT: 3: 33: for (int ii = 0; ii < 2; ii++)
257 C-U:unconditional 0 taken 100%
259 C-U:unconditional 1 taken 100%
261 C-B:branch {{[02]}} taken 67%
262 C-B:branch {{[13]}} taken 33%
264 C-U:unconditional 4 taken 100%
265 C-NEXT: 6: 34: for (int jj = 0; jj < 2; jj++)
267 C-U:unconditional 0 taken 100%
269 C-B:branch {{[01]}} taken 67%
270 C-B:branch {{[12]}} taken 33%
272 C-U:unconditional 3 taken 100%
273 C-NEXT: 6: 35: assign(ii, jj);
275 C-U:unconditional 0 taken 100%
277 C-U:unconditional 1 taken 100%
280 C-U:unconditional 0 taken 100%
282 C-B:function main called 1 returned 100% blocks executed 94%
283 C-NEXT: 1: 38:int main() {
285 C-U:unconditional 0 taken 100%
286 C-NEXT: 1: 39: initialize_grid();
288 C-NEXT: 1: 41: int a = 2;
289 C-NEXT: 1: 42: on = rand() % 2;
290 C-NEXT: 1: 43: if (on) {
292 C-B:branch 0 taken 100%
293 C-B:branch 1 taken 0%
294 C-NEXT: 1: 44: foo();
296 C-NEXT: 1: 46: } else {
298 C-U:unconditional 0 taken 100%
299 C-NEXT: #####: 47: bar();
300 C-NEXT: #####: 48: a += rand();
301 C-A: $$$$$: 48-block 0
302 C-U:unconditional 0 never executed
305 C-NEXT: 11: 51: for (int ii = 0; ii < 10; ++ii) {
307 C-U:unconditional 0 taken 100%
309 C-B:branch {{[01]}} taken 91%
310 C-B:branch {{[12]}} taken 9%
312 C-U:unconditional 3 taken 100%
313 C-NEXT: 10: 52: switch (rand() % 5) {
315 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%
320 C-NEXT: -: 53: case 0:
321 C-NEXT: 2: 54: a += rand();
322 C-NEXT: 2: 55: break;
324 C-U:unconditional 0 taken 100%
325 C-NEXT: -: 56: case 1:
326 C-NEXT: -: 57: case 2:
327 C-NEXT: 4: 58: a += rand() / rand();
328 C-NEXT: 4: 59: break;
330 C-U:unconditional 0 taken 100%
331 C-NEXT: -: 60: case 3:
332 C-NEXT: 3: 61: a -= rand();
333 C-NEXT: 3: 62: break;
335 C-U:unconditional 0 taken 100%
336 C-NEXT: -: 63: default:
337 C-NEXT: 1: 64: a = -1;
340 C-U:unconditional 0 taken 100%
343 C-U:unconditional 0 taken 100%
345 C-NEXT: 1: 68: A thing;
346 C-NEXT:4294967297: 69: for (uint64_t ii = 0; ii < 4294967296; ++ii)
348 C-U:unconditional 0 taken 100%
349 C-A:4294967297: 69-block 1
350 C-B:branch {{[01]}} taken 99%
351 C-B:branch {{[12]}} taken 1%
352 C-A:4294967296: 69-block 2
353 C-U:unconditional 3 taken 100%
354 C-NEXT:4294967296: 70: thing.B();
355 C-A:4294967296: 70-block 0
356 C-U:unconditional 0 taken 100%
358 C-NEXT: 1: 72: return a + 8 + grid[2][3] + len;
360 C-U:unconditional 0 taken 100%
361 C-NEXT: -: 73: return more_useless();
364 H: -: 0:Source:test.h
365 H-NEXT: -: 0:Graph:test.gcno
366 H-NEXT: -: 0:Data:test.gcda
368 H-NEXT: -: 0:Programs:1
369 H-NEXT: -: 1:#include <stdint.h>
370 H-B:function _ZN1AC2Ev called 1 returned 100% blocks executed 100%
371 H-NEXT: 1: 2:struct A {
373 H-U:unconditional 0 taken 100%
374 H-NEXT: -: 3: virtual void B();