1 // Basic handling of line counts.
2 // RUN: llvm-profdata merge %S/Inputs/lineExecutionCounts.proftext -o %t.profdata
3 
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]]|     0|  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
28 
29 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -filename-equivalence %s | FileCheck -check-prefixes=TEXT,WHOLE-FILE %s
30 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -filename-equivalence -name=main %s | FileCheck -check-prefixes=TEXT,FILTER %s
31 
32 // Test -output-dir.
33 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -o %t.dir -instr-profile %t.profdata -filename-equivalence %s
34 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -output-dir %t.dir -instr-profile %t.profdata -filename-equivalence -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.dir/functions.txt %s
37 //
38 // RUN: llvm-cov export %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -name=main 2>/dev/null > %t.export.json
39 // RUN: FileCheck -input-file %t.export.json %S/Inputs/lineExecutionCounts.json
40 // RUN: cat %t.export.json | %python -c "import json, sys; json.loads(sys.stdin.read())"
41 //
42 // Test html output.
43 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.html.dir -instr-profile %t.profdata -filename-equivalence %s
44 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.html.dir -instr-profile %t.profdata -filename-equivalence -name=main %s
45 // RUN: FileCheck -check-prefixes=HTML,HTML-WHOLE-FILE -input-file %t.html.dir/coverage/tmp/showLineExecutionCounts.cpp.html %s
46 // RUN: FileCheck -check-prefixes=HTML,HTML-FILTER -input-file %t.html.dir/functions.html %s
47 //
48 // HTML-WHOLE-FILE: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// before
49 // HTML-FILTER-NOT: <td class='line-number'><a name='L[[@LINE-45]]' href='#L[[@LINE-45]]'><pre>[[@LINE-45]]</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// before
50 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>int main() {
51 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>  int x = 0
52 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>
53 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre>  if (x) {
54 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre>
55 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre><span class='red'>  }</span>
56 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>    x = 1;
57 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>  }
58 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>
59 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>16.2k</pre></td><td class='code'><pre>  for (int i = 0; i &lt; 100; ++i)
60 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>16.1k</pre></td><td class='code'><pre>    x = 1;
61 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>16.1k</pre></td><td class='code'><pre>  }
62 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>
63 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>  x = x &lt; 10
64 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>  x = x &gt; 10
65 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre>        x - 1:
66 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>        x + 1;
67 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>
68 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>  return 0;
69 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>}
70 // HTML-WHOLE-FILE: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// after
71 // HTML-FILTER-NOT: <td class='line-number'><a name='L[[@LINE-45]]' href='#L[[@LINE-45]]'><pre>[[@LINE-45]]</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// after
72 //
73 // Test index creation.
74 // RUN: FileCheck -check-prefix=TEXT-INDEX -input-file %t.dir/index.txt %s
75 // TEXT-INDEX: Filename
76 // TEXT-INDEX-NEXT: ---
77 // TEXT-INDEX-NEXT: {{.*}}showLineExecutionCounts.cpp
78 //
79 // RUN: FileCheck -check-prefix HTML-INDEX -input-file %t.html.dir/index.html %s
80 // HTML-INDEX-LABEL: <table>
81 // HTML-INDEX: <td class='column-entry-left'>Filename</td>
82 // HTML-INDEX: <td class='column-entry'>Function Coverage</td>
83 // HTML-INDEX: <td class='column-entry'>Instantiation Coverage</td>
84 // HTML-INDEX: <td class='column-entry'>Line Coverage</td>
85 // HTML-INDEX: <td class='column-entry'>Region Coverage</td>
86 // HTML-INDEX: <a href='coverage{{.*}}showLineExecutionCounts.cpp.html'{{.*}}showLineExecutionCounts.cpp</a>
87 // HTML-INDEX: <td class='column-entry-green'>
88 // HTML-INDEX: 100.00% (1/1)
89 // HTML-INDEX: <td class='column-entry-green'>
90 // HTML-INDEX: 100.00% (1/1)
91 // HTML-INDEX: <td class='column-entry-yellow'>
92 // HTML-INDEX: 80.00% (16/20)
93 // HTML-INDEX: <td class='column-entry-red'>
94 // HTML-INDEX: 70.00% (7/10)
95 // HTML-INDEX: TOTALS
96