1 // Test visualization of general branch constructs in C.
3 // RUN: llvm-profdata merge %S/Inputs/branch-c-general.proftext -o %t.profdata
4 // RUN: llvm-cov show --show-branches=count %S/Inputs/branch-c-general.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs %S/Inputs/branch-c-general.c | FileCheck %s
5 // RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-c-general.o32l -instr-profile %t.profdata -show-functions -path-equivalence=/tmp,%S/Inputs %S/Inputs/branch-c-general.c | FileCheck %s -check-prefix=REPORT
7 // CHECK: simple_loops()
8 // CHECK: Branch (9:15): [True: 100, False: 1]
9 // CHECK: Branch (11:10): [True: 100, False: 1]
10 // CHECK: Branch (13:16): [True: 75, False: 1]
12 // CHECK: conditionals()
13 // CHECK: Branch (18:19): [True: 100, False: 1]
14 // CHECK: Branch (19:9): [True: 50, False: 50]
15 // CHECK: Branch (20:11): [True: 50, False: 0]
16 // CHECK: Branch (21:16): [True: 33, False: 17]
17 // CHECK: Branch (22:11): [True: 33, False: 0]
18 // CHECK: Branch (24:11): [True: 16, False: 1]
19 // CHECK: Branch (27:9): [Folded - Ignored]
20 // CHECK: Branch (27:14): [True: 99, False: 1]
21 // CHECK: Branch (28:9): [Folded - Ignored]
22 // CHECK: Branch (28:14): [True: 99, False: 1]
24 // CHECK: early_exits()
25 // CHECK: Branch (36:7): [True: 0, False: 1]
26 // CHECK: Branch (38:10): [True: 51, False: 0]
27 // CHECK: Branch (40:9): [True: 1, False: 50]
28 // CHECK: Branch (42:9): [True: 25, False: 25]
29 // CHECK: Branch (46:7): [True: 1, False: 0]
30 // CHECK: Branch (49:9): [True: 1, False: 25]
31 // CHECK: Branch (53:12): [True: 25, False: 0]
32 // CHECK: Branch (55:7): [True: 0, False: 0]
35 // CHECK: Branch (62:15): [True: 1, False: 0]
36 // CHECK: Branch (65:9): [True: 0, False: 0]
37 // CHECK: Branch (69:7): [True: 0, False: 1]
38 // CHECK: Branch (73:10): [True: 0, False: 1]
39 // CHECK: Branch (75:9): [True: 0, False: 1]
40 // CHECK: Branch (83:7): [True: 2, False: 1]
41 // CHECK: Branch (86:10): [True: 0, False: 1]
42 // CHECK: Branch (89:5): [True: 1, False: 2]
43 // CHECK: Branch (91:5): [True: 1, False: 2]
44 // CHECK: Branch (93:5): [True: 1, False: 2]
45 // CHECK: Branch (98:15): [True: 10, False: 1]
46 // CHECK: Branch (101:9): [True: 0, False: 0]
47 // CHECK: Branch (103:9): [True: 9, False: 1]
50 // CHECK: Branch (113:3): [True: 1, Folded]
51 // CHECK: Branch (117:63): [True: 15, False: 0]
52 // CHECK: Branch (119:5): [True: 1, False: 14]
53 // CHECK: Branch (120:11): [True: 0, False: 1]
54 // CHECK: Branch (122:5): [True: 2, False: 13]
55 // CHECK: Branch (123:11): [True: 2, False: 1]
56 // CHECK: Branch (125:5): [True: 3, False: 12]
57 // CHECK: Branch (126:11): [True: 3, False: 0]
58 // CHECK: Branch (128:5): [True: 4, False: 11]
59 // CHECK: Branch (129:11): [True: 4, False: 0]
60 // CHECK: Branch (131:7): [True: 4, Folded]
61 // CHECK: Branch (132:13): [True: 4, False: 0]
62 // CHECK: Branch (136:5): [True: 5, False: 10]
63 // CHECK: Branch (137:11): [True: 1, False: 4]
64 // CHECK: Branch (143:7): [True: 0, False: 0]
66 // CHECK: big_switch()
67 // CHECK: Branch (148:19): [True: 32, False: 1]
68 // CHECK: Branch (150:5): [True: 1, False: 31]
69 // CHECK: Branch (151:11): [True: 0, False: 1]
70 // CHECK: Branch (153:5): [True: 1, False: 31]
71 // CHECK: Branch (154:11): [True: 1, False: 1]
72 // CHECK: Branch (156:5): [True: 11, False: 21]
73 // CHECK: Branch (157:11): [True: 11, False: 0]
74 // CHECK: Branch (161:5): [True: 1, False: 31]
75 // CHECK: Branch (162:11): [True: 1, False: 0]
76 // CHECK: Branch (164:5): [True: 15, False: 17]
77 // CHECK: Branch (165:11): [True: 15, False: 0]
78 // CHECK: Branch (170:11): [True: 1, False: 0]
79 // CHECK: Branch (172:5): [True: 2, False: 30]
80 // CHECK: Branch (173:11): [True: 2, False: 0]
82 // CHECK: boolean_operators()
83 // CHECK: Branch (183:9): [True: 66, False: 34]
84 // CHECK: Branch (183:18): [True: 33, False: 1]
85 // CHECK: Branch (185:9): [True: 66, False: 34]
86 // CHECK: Branch (185:18): [True: 66, False: 0]
87 // CHECK: Branch (187:9): [True: 66, False: 34]
88 // CHECK: Branch (187:18): [True: 17, False: 17]
89 // CHECK: Branch (187:27): [True: 16, False: 1]
90 // CHECK: Branch (189:9): [True: 50, False: 50]
91 // CHECK: Branch (189:18): [True: 33, False: 17]
92 // CHECK: Branch (189:27): [True: 33, False: 0]
94 // CHECK: boolop_loops()
95 // CHECK: Branch (197:10): [True: 51, False: 0]
96 // CHECK: Branch (197:15): [True: 50, False: 1]
97 // CHECK: Branch (200:10): [True: 25, False: 26]
98 // CHECK: Branch (200:21): [True: 25, False: 1]
99 // CHECK: Branch (203:17): [True: 51, False: 0]
100 // CHECK: Branch (203:22): [True: 50, False: 1]
101 // CHECK: Branch (205:10): [True: 25, False: 26]
102 // CHECK: Branch (205:21): [True: 25, False: 1]
104 // CHECK: conditional_operator()
105 // CHECK: Branch (212:11): [True: 0, False: 1]
106 // CHECK: Branch (214:11): [True: 1, False: 0]
108 // CHECK: do_fallthrough()
109 // CHECK: Branch (219:19): [True: 10, False: 1]
110 // CHECK: Branch (227:14): [True: 2, False: 2]
112 // CHECK: static_func()
113 // CHECK: Branch (232:19): [True: 10, False: 1]
117 // REPORT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover
119 // REPORT-NEXT: simple_loops 8 0 100.00% 9 0 100.00% 6 0 100.00%
120 // REPORT-NEXT: conditionals 24 0 100.00% 15 0 100.00% 16 2 87.50%
121 // REPORT-NEXT: early_exits 20 4 80.00% 25 2 92.00% 16 6 62.50%
122 // REPORT-NEXT: jumps 39 12 69.23% 48 2 95.83% 26 9 65.38%
123 // REPORT-NEXT: switches 28 5 82.14% 38 4 89.47% 28 7 75.00%
124 // REPORT-NEXT: big_switch 25 1 96.00% 32 0 100.00% 30 6 80.00%
125 // REPORT-NEXT: boolean_operators 16 0 100.00% 13 0 100.00% 22 2 90.91%
126 // REPORT-NEXT: boolop_loops 19 0 100.00% 14 0 100.00% 16 2 87.50%
127 // REPORT-NEXT: conditional_operator 4 2 50.00% 8 0 100.00% 4 2 50.00%
128 // REPORT-NEXT: do_fallthrough 9 0 100.00% 12 0 100.00% 6 0 100.00%
129 // REPORT-NEXT: main 1 0 100.00% 16 0 100.00% 0 0 0.00%
130 // REPORT-NEXT: c-general.c:static_func 4 0 100.00% 4 0 100.00% 2 0 100.00%
132 // REPORT-NEXT: TOTAL 197 24 87.82% 234 8 96.58% 172 36 79.07%
134 // Test file-level report.
135 // RUN: llvm-profdata merge %S/Inputs/branch-c-general.proftext -o %t.profdata
136 // RUN: llvm-cov report %S/Inputs/branch-c-general.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs %S/Inputs/branch-c-general.c | FileCheck %s -check-prefix=FILEREPORT
137 // FILEREPORT: TOTAL{{.*}}172 36 79.07%
139 // Test color True/False output.
140 // RUN: llvm-cov show --use-color --show-branches=count %S/Inputs/branch-c-general.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs %S/Inputs/branch-c-general.c | FileCheck %s -check-prefix=USECOLOR
141 // USECOLOR: Branch ({{[0-9]+}}:7): {{.*}}: 0, {{.*}}0]
144 // RUN: llvm-cov show --show-branch-summary --show-branches=count %S/Inputs/branch-c-general.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs %S/Inputs/branch-c-general.c -format html -o %t.html.dir
145 // RUN: FileCheck -check-prefix=HTML -input-file=%t.html.dir/coverage/tmp/branch-c-general.c.html %s
146 // HTML-COUNT-89: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>
147 // HTML-NOT: Branch (<span class='line-number'><a name='L{{[0-9]+}}' href='#L{{[0-9]+}}'><span>
149 // RUN: FileCheck -check-prefix HTML-INDEX -input-file %t.html.dir/index.html %s
150 // HTML-INDEX-LABEL: <table>
151 // HTML-INDEX: <td class='column-entry-bold'>Filename</td>
152 // HTML-INDEX: <td class='column-entry-bold'>Function Coverage</td>
153 // HTML-INDEX: <td class='column-entry-bold'>Line Coverage</td>
154 // HTML-INDEX: <td class='column-entry-bold'>Region Coverage</td>
155 // HTML-INDEX: <td class='column-entry-bold'>Branch Coverage</td>
156 // HTML-INDEX: <a href='coverage{{.*}}branch-c-general.c.html'{{.*}}branch-c-general.c</a>
157 // HTML-INDEX: <td class='column-entry-green'>
158 // HTML-INDEX: 100.00% (12/12)
159 // HTML-INDEX: <td class='column-entry-yellow'>
160 // HTML-INDEX: 96.58% (226/234)
161 // HTML-INDEX: <td class='column-entry-yellow'>
162 // HTML-INDEX: 87.82% (173/197)
163 // HTML-INDEX: <td class='column-entry-red'>
164 // HTML-INDEX: 79.07% (136/172)
165 // HTML-INDEX: <tr class='light-row-bold'>
166 // HTML-INDEX: Totals