xref: /aosp_15_r20/external/llvm/test/tools/llvm-cov/llvm-cov.test (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker# Tests for compatibility between llvm-cov and gcov. These work by
2*9880d681SAndroid Build Coastguard Worker# comparing llvm-cov against reference outputs generated by gcov 4.2.
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Worker# Test fails on Windows where internal shell is used due to path separator
5*9880d681SAndroid Build Coastguard Worker# mismatches.
6*9880d681SAndroid Build Coastguard WorkerREQUIRES: shell
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard WorkerRUN: rm -rf %t
9*9880d681SAndroid Build Coastguard WorkerRUN: mkdir %t
10*9880d681SAndroid Build Coastguard WorkerRUN: cd %t
11*9880d681SAndroid Build Coastguard WorkerRUN: cp %p/Inputs/test* .
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Worker# Basic behaviour with no flags
14*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test.c | diff -u test_no_options.output -
15*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_no_options.cpp.gcov test.cpp.gcov
16*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_no_options.h.gcov test.h.gcov
17*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard Worker# Same, but specifying the object directory
19*9880d681SAndroid Build Coastguard WorkerRUN: mkdir -p %t/objdir
20*9880d681SAndroid Build Coastguard WorkerRUN: cp test.gcno test.gcda %t/objdir
21*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov -o objdir test.c | diff -u test_no_options.output -
22*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_objdir.cpp.gcov test.cpp.gcov
23*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_objdir.h.gcov test.h.gcov
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker# Specifying an object file
26*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov -o objdir/test.o test.c | diff -u test_no_options.output -
27*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_objdir.cpp.gcov test.cpp.gcov
28*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_objdir.h.gcov test.h.gcov
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Worker# Specifying an object file that could be ambiguous with a directory
31*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov -o objdir/test test.c | diff -u test_no_options.output -
32*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_objdir.cpp.gcov test.cpp.gcov
33*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_objdir.h.gcov test.h.gcov
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Worker# With gcov output disabled
36*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov -n test.c | diff -u test_no_output.output -
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard Worker# Missing source files. This test is fragile, as it depends on being
39*9880d681SAndroid Build Coastguard Worker# run before we copy some sources into place in the next test.
40*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test_paths.cpp 2>/dev/null | diff -u test_missing.output -
41*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_missing.cpp.gcov test.cpp.gcov
42*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_missing.h.gcov test.h.gcov
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker# Preserve paths. This mangles the output filenames.
45*9880d681SAndroid Build Coastguard WorkerRUN: mkdir -p %t/srcdir/nested_dir
46*9880d681SAndroid Build Coastguard WorkerRUN: cp test.cpp test.h %t/srcdir
47*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov -p test_paths.cpp | diff -u test_preserve_paths.output -
48*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_paths.cpp.gcov srcdir#nested_dir#^#test.cpp.gcov
49*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_paths.h.gcov srcdir#nested_dir#^#test.h.gcov
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Worker# Don't preserve paths. Same results as preserve paths, but no mangling.
52*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test_paths.cpp | diff -u test_no_preserve_paths.output -
53*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_paths.cpp.gcov test.cpp.gcov
54*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_paths.h.gcov test.h.gcov
55*9880d681SAndroid Build Coastguard Worker
56*9880d681SAndroid Build Coastguard Worker# Long file names.
57*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov -l test_paths.cpp | diff -u test_long_file_names.output -
58*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_paths.cpp.gcov test_paths.cpp##test.cpp.gcov
59*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_paths.h.gcov test_paths.cpp##test.h.gcov
60*9880d681SAndroid Build Coastguard Worker
61*9880d681SAndroid Build Coastguard Worker# Long file names and preserve paths.
62*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov -lp -gcno test_paths.gcno -gcda test_paths.gcda srcdir/../test_paths.cpp | diff -u test_long_paths.output -
63*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_paths.cpp.gcov srcdir#^#test_paths.cpp##srcdir#nested_dir#^#test.cpp.gcov
64*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_paths.h.gcov srcdir#^#test_paths.cpp##srcdir#nested_dir#^#test.h.gcov
65*9880d681SAndroid Build Coastguard Worker
66*9880d681SAndroid Build Coastguard Worker# Function summaries. This changes stdout, but not the gcov files.
67*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test.c -f | diff -u test_-f.output -
68*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_no_options.cpp.gcov test.cpp.gcov
69*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_no_options.h.gcov test.h.gcov
70*9880d681SAndroid Build Coastguard Worker
71*9880d681SAndroid Build Coastguard Worker# All blocks. This doesn't affect stdout, only the gcov files.
72*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test.c -a | diff -u test_no_options.output -
73*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_-a.cpp.gcov test.cpp.gcov
74*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_-a.h.gcov test.h.gcov
75*9880d681SAndroid Build Coastguard Worker
76*9880d681SAndroid Build Coastguard Worker# Branch probabilities.
77*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test.c -a -b | diff -u test_-b.output -
78*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_-a_-b.cpp.gcov test.cpp.gcov
79*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_-a_-b.h.gcov test.h.gcov
80*9880d681SAndroid Build Coastguard Worker
81*9880d681SAndroid Build Coastguard Worker# Function summaries including branch probabilities.
82*9880d681SAndroid Build Coastguard Worker
83*9880d681SAndroid Build Coastguard Worker# FIXME: We don't correctly handle calls when -b and -f are used
84*9880d681SAndroid Build Coastguard Worker# together, so our output differs from gcov. Remove the 'not' from
85*9880d681SAndroid Build Coastguard Worker# this test once this is fixed.
86*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test.c -a -b -f | not diff -u test_-b_-f.output - >/dev/null
87*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_-a_-b.cpp.gcov test.cpp.gcov
88*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_-a_-b.h.gcov test.h.gcov
89*9880d681SAndroid Build Coastguard Worker
90*9880d681SAndroid Build Coastguard Worker# Summarize unconditional branches too.
91*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test.c -a -b -u | diff -u test_-b.output -
92*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_-a_-b_-u.cpp.gcov test.cpp.gcov
93*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_-a_-b_-u.h.gcov test.h.gcov
94*9880d681SAndroid Build Coastguard Worker
95*9880d681SAndroid Build Coastguard Worker# Absolute counts for branches.
96*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test.c -a -b -c -u | diff -u test_-b.output -
97*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_-a_-b_-c_-u.cpp.gcov test.cpp.gcov
98*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_-a_-b_-c_-u.h.gcov test.h.gcov
99*9880d681SAndroid Build Coastguard Worker
100*9880d681SAndroid Build Coastguard Worker# Missing gcda file just gives 0 counts.
101*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test.c -gcda=no_such_gcda_file | diff -u test_no_gcda.output -
102*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_no_gcda.cpp.gcov test.cpp.gcov
103*9880d681SAndroid Build Coastguard WorkerRUN: diff -aub test_no_gcda.h.gcov test.h.gcov
104*9880d681SAndroid Build Coastguard Worker
105*9880d681SAndroid Build Coastguard Worker# Invalid gcno file.
106*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test.c -gcno=test_read_fail.gcno
107*9880d681SAndroid Build Coastguard Worker
108*9880d681SAndroid Build Coastguard Worker# Bad file checksum on gcda.
109*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test.c -gcda=test_file_checksum_fail.gcda
110*9880d681SAndroid Build Coastguard Worker
111*9880d681SAndroid Build Coastguard Worker# Bad function checksum on gcda
112*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test.c -gcda=test_func_checksum_fail.gcda
113*9880d681SAndroid Build Coastguard Worker
114*9880d681SAndroid Build Coastguard Worker# Has arcs from exit blocks
115*9880d681SAndroid Build Coastguard WorkerRUN: llvm-cov gcov test_exit_block_arcs.c 2>&1 | FileCheck %s -check-prefix=EXIT_BLOCK_ARCS
116*9880d681SAndroid Build Coastguard WorkerEXIT_BLOCK_ARCS: (main) has arcs from exit block.
117*9880d681SAndroid Build Coastguard Worker
118*9880d681SAndroid Build Coastguard WorkerXFAIL: powerpc64-, s390x, mips-, mips64-, sparc
119