Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/branch-macros.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@




#define COND1 (a == b)
#define COND2 (a != b)
#define COND3 (COND1 && COND2)
#define COND4 (COND3 ? COND2 : COND1) // BRCOV: | Branch ([[@LINE]]:15): [True: 1, False: [[#min(C,2)]]]
#define MACRO1 COND3
#define MACRO2 MACRO1
#define MACRO3 MACRO2

#include <stdlib.h>

// CHECK: |{{ +}}[[#min(C,3)]]|bool func(
bool func(int a, int b) {
bool c = COND1 && COND2; // BRCOV: | | | Branch ([[@LINE-12]]:15): [True: 1, False: [[#min(C,2)]]]
// BRCOV: | | | Branch ([[@LINE-12]]:15): [True: 0, False: 1]
bool d = COND3; // BRCOV: | | | | | Branch ([[@LINE-14]]:15): [True: 1, False: [[#min(C,2)]]]
// BRCOV: | | | | | Branch ([[@LINE-14]]:15): [True: 0, False: 1]
bool e = MACRO1; // BRCOV: | | | | | | | Branch ([[@LINE-16]]:15): [True: 1, False: [[#min(C,2)]]]
// BRCOV: | | | | | | | Branch ([[@LINE-16]]:15): [True: 0, False: 1]
bool f = MACRO2; // BRCOV: | | | | | | | | | Branch ([[@LINE-18]]:15): [True: 1, False: [[#min(C,2)]]]
// BRCOV: | | | | | | | | | Branch ([[@LINE-18]]:15): [True: 0, False: 1]
bool g = MACRO3; // BRCOV: | | | | | | | | | | | Branch ([[@LINE-20]]:15): [True: 1, False: [[#min(C,2)]]]
// BRCOV: | | | | | | | | | | | Branch ([[@LINE-20]]:15): [True: 0, False: 1]
return c && d && e && f && g;
// BRCOV: | Branch ([[@LINE-1]]:10): [True: 0, False: [[#min(C,3)]]]
// BRCOV: | Branch ([[@LINE-2]]:15): [True: 0, False: 0]
// BRCOV: | Branch ([[@LINE-3]]:20): [True: 0, False: 0]
// BRCOV: | Branch ([[@LINE-4]]:25): [True: 0, False: 0]
// BRCOV: | Branch ([[@LINE-5]]:30): [True: 0, False: 0]
}


bool func2(int a, int b) {
bool h = MACRO3 || COND4; // BRCOV: | | | | | | | | | | | Branch ([[@LINE-32]]:15): [True: 1, False: [[#min(C,2)]]]
// BRCOV: | | | | | | | | | | | Branch ([[@LINE-32]]:15): [True: 0, False: 1]
// BRCOV: | | | | | | | Branch ([[@LINE-34]]:15): [True: 1, False: [[#min(C,2)]]]
// BRCOV: | | | | | | | Branch ([[@LINE-34]]:15): [True: 0, False: 1]
// BRCOV: | | | Branch ([[@LINE-33]]:15): [True: 1, False: [[#min(C,2)]]]
return h;
}


int main(int argc, char *argv[])
{
func(atoi(argv[1]), atoi(argv[2]));
func2(atoi(argv[1]), atoi(argv[2]));
(void)0;
return 0;
}
30 changes: 30 additions & 0 deletions llvm/test/tools/llvm-cov/Inputs/showLineExecutionCounts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// HTML-WHOLE-FILE: <td class='line-number'><a name='L[[@LINE+2]]' href='#L[[@LINE+2]]'><pre>[[@LINE+2]]</pre></a></td><td class='skipped-line'></td><td class='code'><pre>// before
// HTML-FILTER-NOT: <td class='line-number'><a name='L[[@LINE+1]]' href='#L[[@LINE+1]]'><pre>[[@LINE+1]]</pre></a></td><td class='skipped-line'></td><td class='code'><pre>// before
// before any coverage // WHOLE-FILE: [[@LINE]]| |// before
// FILTER-NOT: [[@LINE-1]]| |// before
// HTML: <td class='line-number'><a name='L[[@LINE+1]]' href='#L[[@LINE+1]]'><pre>[[@LINE+1]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>int main() {
int main() { // TEXT: [[@LINE]]| [[#C161:min(C,161)]]|int main(
int x = 0; // TEXT: [[@LINE]]| [[#C161]]| int x

if (x) { // TEXT: [[@LINE]]| [[#C161]]| if (x)
x = 0; // TEXT: [[@LINE]]| 0| x = 0
} else { // TEXT: [[@LINE]]| [[#C161]]| } else
x = 1; // TEXT: [[@LINE]]| [[#C161]]| x = 1
} // TEXT: [[@LINE]]| [[#C161]]| }

for (int i = 0; i < 100; ++i) { // TEXT: [[@LINE]]| [[C16K2]]| for (
x = 1; // TEXT: [[@LINE]]| [[C16K1]]| x = 1
} // TEXT: [[@LINE]]| [[C16K1]]| }

x = x < 10 ? x + 1 : x - 1; // TEXT: [[@LINE]]| [[#C161]]| x =
x = x > 10 ? // TEXT: [[@LINE]]| [[#C161]]| x =
x - 1: // TEXT: [[@LINE]]| 0| x
x + 1; // TEXT: [[@LINE]]| [[#C161]]| x

return 0; // TEXT: [[@LINE]]| [[#C161]]| return
} // TEXT: [[@LINE]]| [[#C161]]|}
// after coverage // WHOLE-FILE: [[@LINE]]| |// after
// FILTER-NOT: [[@LINE-1]]| |// after
// HTML-BINARY-NOT: <td class='covered-line'><pre>16
// HTML-WHOLE-FILE: <td class='line-number'><a name='L[[@LINE-3]]' href='#L[[@LINE-3]]'><pre>[[@LINE-3]]</pre></a></td><td class='skipped-line'></td><td class='code'><pre>// after
// HTML-FILTER-NOT: <td class='line-number'><a name='L[[@LINE-4]]' href='#L[[@LINE-4]]'><pre>[[@LINE-4]]</pre></a></td><td class='skipped-line'></td><td class='code'><pre>// after
60 changes: 0 additions & 60 deletions llvm/test/tools/llvm-cov/branch-macros.cpp

This file was deleted.

12 changes: 12 additions & 0 deletions llvm/test/tools/llvm-cov/branch-macros.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: llvm-profdata merge %S/Inputs/branch-macros.proftext -o %t.profdata
// RUN: llvm-cov show --show-expansions --show-branches=count %S/Inputs/branch-macros.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck %S/Inputs/branch-macros.cpp -check-prefixes=CHECK,BRCOV -D#C=999
// RUN: llvm-cov show --binary-counters=true --show-expansions --show-branches=count %S/Inputs/branch-macros.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck %S/Inputs/branch-macros.cpp -check-prefixes=CHECK,BRCOV -D#C=1
// RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-macros.o32l -instr-profile %t.profdata -show-functions -path-equivalence=/tmp,%S/Inputs %S/Inputs/branch-macros.cpp | FileCheck %s -check-prefix=REPORT

// REPORT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover
// REPORT-NEXT: ---
// REPORT-NEXT: _Z4funcii 28 4 85.71% 18 0 100.00% 30 14 53.33%
// REPORT-NEXT: _Z5func2ii 13 1 92.31% 8 0 100.00% 10 2 80.00%
// REPORT-NEXT: main 1 0 100.00% 6 0 100.00% 0 0 0.00%
// REPORT-NEXT: ---
// REPORT-NEXT: TOTAL 42 5 88.10% 32 0 100.00% 40 16 60.00%
73 changes: 0 additions & 73 deletions llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp

This file was deleted.

46 changes: 46 additions & 0 deletions llvm/test/tools/llvm-cov/showLineExecutionCounts.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Basic handling of line counts.
// RUN: rm -rf %t.dir
// RUN: llvm-profdata merge %S/Inputs/lineExecutionCounts.proftext -o %t.profdata

// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck -check-prefixes=TEXT,WHOLE-FILE -D#C=999 -DC16K2=16.2k -DC16K1=16.1k %S/Inputs/showLineExecutionCounts.cpp
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -binary-counters=true -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck -check-prefixes=TEXT,WHOLE-FILE -D#C=1 -DC16K2=1 -DC16K1=1 %S/Inputs/showLineExecutionCounts.cpp
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -name=main | FileCheck -check-prefixes=TEXT,FILTER -D#C=999 -DC16K2=16.2k -DC16K1=16.1k %S/Inputs/showLineExecutionCounts.cpp

// Test -output-dir.
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -o %t.dir/show -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -output-dir %t.dir/show.filtered -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -name=main
// RUN: FileCheck -check-prefixes=TEXT,WHOLE-FILE -D#C=999 -DC16K2=16.2k -DC16K1=16.1k -input-file %t.dir/show/coverage/tmp/showLineExecutionCounts.cpp.txt %S/Inputs/showLineExecutionCounts.cpp
// RUN: FileCheck -check-prefixes=TEXT,FILTER -D#C=999 -DC16K2=16.2k -DC16K1=16.1k -input-file %t.dir/show.filtered/coverage/tmp/showLineExecutionCounts.cpp.txt %S/Inputs/showLineExecutionCounts.cpp
//
// RUN: llvm-cov export %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata 2>/dev/null -summary-only > %t.export-summary.json
// RUN: not grep '"name":"main"' %t.export-summary.json
//
// Test html output.
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.dir/html -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.dir/html.binary -binary-counters=true -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just -binary-counters. =true is a weird syntax that most command line parsing libraries don't allow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've dropped =true. I like it, though.

// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.dir/html.filtered -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -name=main
// RUN: FileCheck -check-prefixes=HTML,HTML-WHOLE-FILE -input-file %t.dir/html/coverage/tmp/showLineExecutionCounts.cpp.html %S/Inputs/showLineExecutionCounts.cpp
// RUN: FileCheck -check-prefixes=HTML-BINARY,HTML-WHOLE-FILE -input-file %t.dir/html.binary/coverage/tmp/showLineExecutionCounts.cpp.html %S/Inputs/showLineExecutionCounts.cpp
// RUN: FileCheck -check-prefixes=HTML,HTML-FILTER -input-file %t.dir/html.filtered/coverage/tmp/showLineExecutionCounts.cpp.html %S/Inputs/showLineExecutionCounts.cpp
//
// Test index creation.
// RUN: FileCheck -check-prefix=TEXT-INDEX -input-file %t.dir/show/index.txt %s
// TEXT-INDEX: Filename
// TEXT-INDEX-NEXT: ---
// TEXT-INDEX-NEXT: {{.*}}showLineExecutionCounts.cpp
//
// RUN: FileCheck -check-prefix HTML-INDEX -input-file %t.dir/html/index.html %s
// HTML-INDEX-LABEL: <table>
// HTML-INDEX: <td class='column-entry-bold'>Filename</td>
// HTML-INDEX: <td class='column-entry-bold'>Function Coverage</td>
// HTML-INDEX: <td class='column-entry-bold'>Line Coverage</td>
// HTML-INDEX: <td class='column-entry-bold'>Region Coverage</td>
// HTML-INDEX: <a href='coverage{{.*}}showLineExecutionCounts.cpp.html'{{.*}}showLineExecutionCounts.cpp</a>
// HTML-INDEX: <td class='column-entry-green'>
// HTML-INDEX: 100.00% (1/1)
// HTML-INDEX: <td class='column-entry-yellow'>
// HTML-INDEX: 90.00% (18/20)
// HTML-INDEX: <td class='column-entry-red'>
// HTML-INDEX: 72.73% (8/11)
// HTML-INDEX: <tr class='light-row-bold'>
// HTML-INDEX: Totals
Loading
Loading