Skip to content

Commit

Permalink
coverage: Enable branch coverage in the branch coverage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Mar 10, 2024
1 parent 4451445 commit d40cf6d
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 105 deletions.
27 changes: 18 additions & 9 deletions tests/coverage/branch_generics.cov-map
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
Function name: branch_generics::print_size::<()>
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 06, 01, 01, 24, 05, 01, 25, 02, 06, 02, 02, 0c, 02, 06, 07, 03, 01, 00, 02]
Raw bytes (35): 0x[01, 01, 02, 01, 05, 05, 02, 05, 01, 06, 01, 01, 24, 20, 05, 02, 01, 08, 00, 24, 05, 00, 25, 02, 06, 02, 02, 0c, 02, 06, 07, 03, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 2
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
Number of file 0 mappings: 4
Number of file 0 mappings: 5
- Code(Counter(0)) at (prev + 6, 1) to (start + 1, 36)
- Code(Counter(1)) at (prev + 1, 37) to (start + 2, 6)
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 8) to (start + 0, 36)
true = c1
false = (c0 - c1)
- Code(Counter(1)) at (prev + 0, 37) to (start + 2, 6)
- Code(Expression(0, Sub)) at (prev + 2, 12) to (start + 2, 6)
= (c0 - c1)
- Code(Expression(1, Add)) at (prev + 3, 1) to (start + 0, 2)
= (c1 + (c0 - c1))

Function name: branch_generics::print_size::<u32>
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 06, 01, 01, 24, 05, 01, 25, 02, 06, 02, 02, 0c, 02, 06, 07, 03, 01, 00, 02]
Raw bytes (35): 0x[01, 01, 02, 01, 05, 05, 02, 05, 01, 06, 01, 01, 24, 20, 05, 02, 01, 08, 00, 24, 05, 00, 25, 02, 06, 02, 02, 0c, 02, 06, 07, 03, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 2
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
Number of file 0 mappings: 4
Number of file 0 mappings: 5
- Code(Counter(0)) at (prev + 6, 1) to (start + 1, 36)
- Code(Counter(1)) at (prev + 1, 37) to (start + 2, 6)
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 8) to (start + 0, 36)
true = c1
false = (c0 - c1)
- Code(Counter(1)) at (prev + 0, 37) to (start + 2, 6)
- Code(Expression(0, Sub)) at (prev + 2, 12) to (start + 2, 6)
= (c0 - c1)
- Code(Expression(1, Add)) at (prev + 3, 1) to (start + 0, 2)
= (c1 + (c0 - c1))

Function name: branch_generics::print_size::<u64>
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 06, 01, 01, 24, 05, 01, 25, 02, 06, 02, 02, 0c, 02, 06, 07, 03, 01, 00, 02]
Raw bytes (35): 0x[01, 01, 02, 01, 05, 05, 02, 05, 01, 06, 01, 01, 24, 20, 05, 02, 01, 08, 00, 24, 05, 00, 25, 02, 06, 02, 02, 0c, 02, 06, 07, 03, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 2
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
Number of file 0 mappings: 4
Number of file 0 mappings: 5
- Code(Counter(0)) at (prev + 6, 1) to (start + 1, 36)
- Code(Counter(1)) at (prev + 1, 37) to (start + 2, 6)
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 8) to (start + 0, 36)
true = c1
false = (c0 - c1)
- Code(Counter(1)) at (prev + 0, 37) to (start + 2, 6)
- Code(Expression(0, Sub)) at (prev + 2, 12) to (start + 2, 6)
= (c0 - c1)
- Code(Expression(1, Add)) at (prev + 3, 1) to (start + 0, 2)
Expand Down
16 changes: 15 additions & 1 deletion tests/coverage/branch_generics.coverage
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |
LL| |//@ compile-flags: -Zunstable-options -Cinstrument-coverage=branch
LL| |//@ llvm-cov-flags: --show-branches=count
LL| |
LL| 3|fn print_size<T>() {
LL| 3| if std::mem::size_of::<T>() > 4 {
------------------
| Branch (LL:8): [True: 0, False: 1]
| Branch (LL:8): [True: 0, False: 1]
| Branch (LL:8): [True: 1, False: 0]
------------------
LL| 1| println!("size > 4");
LL| 2| } else {
LL| 2| println!("size <= 4");
Expand All @@ -14,6 +19,9 @@
| branch_generics::print_size::<()>:
| LL| 1|fn print_size<T>() {
| LL| 1| if std::mem::size_of::<T>() > 4 {
| ------------------
| | Branch (LL:8): [True: 0, False: 1]
| ------------------
| LL| 0| println!("size > 4");
| LL| 1| } else {
| LL| 1| println!("size <= 4");
Expand All @@ -23,6 +31,9 @@
| branch_generics::print_size::<u32>:
| LL| 1|fn print_size<T>() {
| LL| 1| if std::mem::size_of::<T>() > 4 {
| ------------------
| | Branch (LL:8): [True: 0, False: 1]
| ------------------
| LL| 0| println!("size > 4");
| LL| 1| } else {
| LL| 1| println!("size <= 4");
Expand All @@ -32,6 +43,9 @@
| branch_generics::print_size::<u64>:
| LL| 1|fn print_size<T>() {
| LL| 1| if std::mem::size_of::<T>() > 4 {
| ------------------
| | Branch (LL:8): [True: 1, False: 0]
| ------------------
| LL| 1| println!("size > 4");
| LL| 1| } else {
| LL| 0| println!("size <= 4");
Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/branch_generics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(coverage_attribute)]
//@ edition: 2021

//@ compile-flags: -Zunstable-options -Cinstrument-coverage=branch
//@ llvm-cov-flags: --show-branches=count

fn print_size<T>() {
Expand Down
Loading

0 comments on commit d40cf6d

Please sign in to comment.