-
Notifications
You must be signed in to change notification settings - Fork 15.3k
llvm-cov: Introduce --binary-counters
#120841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
805e9a9
llvm-cov: Introduce `--binary-counters`
chapuni 47550d1
threads.c => threads.test (following #113114)
chapuni f4dc4eb
s/Count1/BinaryCount/
chapuni 822620b
Update desc
chapuni 658bd48
Merge branch 'main' into users/chapuni/cov/binary
chapuni 714690d
Update desc
chapuni b11ff81
Strip `=true` on `--binary-counters`
chapuni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
30
llvm/test/tools/llvm-cov/Inputs/showLineExecutionCounts.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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% |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| // 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 | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just
-binary-counters.=trueis a weird syntax that most command line parsing libraries don't allow.There was a problem hiding this comment.
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.