Recommit "rL366894: [yaml2obj] - Allow custom fields for the SHT_UNDEF sections."
[llvm-complete.git] / test / tools / llvm-cov / showLineExecutionCounts.cpp
blob51ac3ae1deee55e7abf600117fe2877a0e2c1aa7
1 // Basic handling of line counts.
2 // RUN: llvm-profdata merge %S/Inputs/lineExecutionCounts.proftext -o %t.profdata
4 // before any coverage // WHOLE-FILE: [[@LINE]]| |// before
5 // FILTER-NOT: [[@LINE-1]]| |// before
6 int main() { // TEXT: [[@LINE]]| 161|int main(
7 int x = 0; // TEXT: [[@LINE]]| 161| int x
8 // TEXT: [[@LINE]]| 161|
9 if (x) { // TEXT: [[@LINE]]| 161| if (x)
10 x = 0; // TEXT: [[@LINE]]| 0| x = 0
11 } else { // TEXT: [[@LINE]]| 161| } else
12 x = 1; // TEXT: [[@LINE]]| 161| x = 1
13 } // TEXT: [[@LINE]]| 161| }
14 // TEXT: [[@LINE]]| 161|
15 for (int i = 0; i < 100; ++i) { // TEXT: [[@LINE]]| 16.2k| for (
16 x = 1; // TEXT: [[@LINE]]| 16.1k| x = 1
17 } // TEXT: [[@LINE]]| 16.1k| }
18 // TEXT: [[@LINE]]| 161|
19 x = x < 10 ? x + 1 : x - 1; // TEXT: [[@LINE]]| 161| x =
20 x = x > 10 ? // TEXT: [[@LINE]]| 161| x =
21 x - 1: // TEXT: [[@LINE]]| 0| x
22 x + 1; // TEXT: [[@LINE]]| 161| x
23 // TEXT: [[@LINE]]| 161|
24 return 0; // TEXT: [[@LINE]]| 161| return
25 } // TEXT: [[@LINE]]| 161|}
26 // after coverage // WHOLE-FILE: [[@LINE]]| |// after
27 // FILTER-NOT: [[@LINE-1]]| |// after
29 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck -check-prefixes=TEXT,WHOLE-FILE %s
30 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -path-equivalence=/tmp,%S -name=main %s | FileCheck -check-prefixes=TEXT,FILTER %s
32 // Test -output-dir.
33 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -o %t.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S %s
34 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -output-dir %t.filtered.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S -name=main %s
35 // RUN: FileCheck -check-prefixes=TEXT,WHOLE-FILE -input-file %t.dir/coverage/tmp/showLineExecutionCounts.cpp.txt %s
36 // RUN: FileCheck -check-prefixes=TEXT,FILTER -input-file %t.filtered.dir/coverage/tmp/showLineExecutionCounts.cpp.txt %s
38 // RUN: llvm-cov export %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata 2>/dev/null -summary-only > %t.export-summary.json
39 // RUN: not grep '"name":"main"' %t.export-summary.json
41 // Test html output.
42 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.html.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S %s
43 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.html.filtered.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S -name=main %s
44 // RUN: FileCheck -check-prefixes=HTML,HTML-WHOLE-FILE -input-file %t.html.dir/coverage/tmp/showLineExecutionCounts.cpp.html %s
45 // RUN: FileCheck -check-prefixes=HTML,HTML-FILTER -input-file %t.html.filtered.dir/coverage/tmp/showLineExecutionCounts.cpp.html %s
47 // HTML-WHOLE-FILE: <td class='line-number'><a name='L4' href='#L4'><pre>4</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// before
48 // HTML-FILTER-NOT: <td class='line-number'><a name='L4' href='#L4'><pre>4</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// before
49 // HTML: <td class='line-number'><a name='L6' href='#L6'><pre>6</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>int main() {
50 // HTML-WHOLE-FILE: <td class='line-number'><a name='L26' href='#L26'><pre>26</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// after
51 // HTML-FILTER-NOT: <td class='line-number'><a name='L26' href='#L26'><pre>26</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// after
53 // Test index creation.
54 // RUN: FileCheck -check-prefix=TEXT-INDEX -input-file %t.dir/index.txt %s
55 // TEXT-INDEX: Filename
56 // TEXT-INDEX-NEXT: ---
57 // TEXT-INDEX-NEXT: {{.*}}showLineExecutionCounts.cpp
59 // RUN: FileCheck -check-prefix HTML-INDEX -input-file %t.html.dir/index.html %s
60 // HTML-INDEX-LABEL: <table>
61 // HTML-INDEX: <td class='column-entry-bold'>Filename</td>
62 // HTML-INDEX: <td class='column-entry-bold'>Function Coverage</td>
63 // HTML-INDEX: <td class='column-entry-bold'>Line Coverage</td>
64 // HTML-INDEX: <td class='column-entry-bold'>Region Coverage</td>
65 // HTML-INDEX: <a href='coverage{{.*}}showLineExecutionCounts.cpp.html'{{.*}}showLineExecutionCounts.cpp</a>
66 // HTML-INDEX: <td class='column-entry-green'>
67 // HTML-INDEX: 100.00% (1/1)
68 // HTML-INDEX: <td class='column-entry-yellow'>
69 // HTML-INDEX: 90.00% (18/20)
70 // HTML-INDEX: <td class='column-entry-red'>
71 // HTML-INDEX: 72.73% (8/11)
72 // HTML-INDEX: <tr class='light-row-bold'>
73 // HTML-INDEX: Totals