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 13, 2024
1 parent 1f6a5ee commit fbc0067
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 116 deletions.
27 changes: 18 additions & 9 deletions tests/coverage/branch_generics.cov-map
@@ -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
@@ -1,10 +1,15 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |
LL| |//@ compile-flags: -Zcoverage-options=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
@@ -1,6 +1,6 @@
#![feature(coverage_attribute)]
//@ edition: 2021

//@ compile-flags: -Zcoverage-options=branch
//@ llvm-cov-flags: --show-branches=count

fn print_size<T>() {
Expand Down
26 changes: 17 additions & 9 deletions tests/coverage/branch_guard.cov-map
@@ -1,24 +1,32 @@
Function name: branch_guard::branch_match_guard
Raw bytes (67): 0x[01, 01, 04, 05, 09, 0b, 15, 0f, 11, 03, 0d, 0b, 01, 0c, 01, 01, 10, 1d, 03, 0b, 00, 0c, 15, 01, 14, 02, 0a, 0d, 03, 0e, 00, 0f, 19, 00, 14, 00, 19, 0d, 00, 1d, 02, 0a, 11, 03, 0e, 00, 0f, 1d, 00, 14, 00, 19, 11, 00, 1d, 02, 0a, 03, 03, 0e, 02, 0a, 07, 04, 01, 00, 02]
Raw bytes (85): 0x[01, 01, 06, 19, 0d, 05, 09, 0f, 15, 13, 11, 17, 0d, 05, 09, 0d, 01, 0c, 01, 01, 10, 1d, 03, 0b, 00, 0c, 15, 01, 14, 02, 0a, 0d, 03, 0e, 00, 0f, 19, 00, 14, 00, 19, 20, 0d, 02, 00, 14, 00, 1e, 0d, 00, 1d, 02, 0a, 11, 03, 0e, 00, 0f, 1d, 00, 14, 00, 19, 20, 11, 09, 00, 14, 00, 1e, 11, 00, 1d, 02, 0a, 17, 03, 0e, 02, 0a, 0b, 04, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 4
- expression 0 operands: lhs = Counter(1), rhs = Counter(2)
- expression 1 operands: lhs = Expression(2, Add), rhs = Counter(5)
- expression 2 operands: lhs = Expression(3, Add), rhs = Counter(4)
- expression 3 operands: lhs = Expression(0, Add), rhs = Counter(3)
Number of file 0 mappings: 11
Number of expressions: 6
- expression 0 operands: lhs = Counter(6), rhs = Counter(3)
- expression 1 operands: lhs = Counter(1), rhs = Counter(2)
- expression 2 operands: lhs = Expression(3, Add), rhs = Counter(5)
- expression 3 operands: lhs = Expression(4, Add), rhs = Counter(4)
- expression 4 operands: lhs = Expression(5, Add), rhs = Counter(3)
- expression 5 operands: lhs = Counter(1), rhs = Counter(2)
Number of file 0 mappings: 13
- Code(Counter(0)) at (prev + 12, 1) to (start + 1, 16)
- Code(Counter(7)) at (prev + 3, 11) to (start + 0, 12)
- Code(Counter(5)) at (prev + 1, 20) to (start + 2, 10)
- Code(Counter(3)) at (prev + 3, 14) to (start + 0, 15)
- Code(Counter(6)) at (prev + 0, 20) to (start + 0, 25)
- Branch { true: Counter(3), false: Expression(0, Sub) } at (prev + 0, 20) to (start + 0, 30)
true = c3
false = (c6 - c3)
- Code(Counter(3)) at (prev + 0, 29) to (start + 2, 10)
- Code(Counter(4)) at (prev + 3, 14) to (start + 0, 15)
- Code(Counter(7)) at (prev + 0, 20) to (start + 0, 25)
- Branch { true: Counter(4), false: Counter(2) } at (prev + 0, 20) to (start + 0, 30)
true = c4
false = c2
- Code(Counter(4)) at (prev + 0, 29) to (start + 2, 10)
- Code(Expression(0, Add)) at (prev + 3, 14) to (start + 2, 10)
- Code(Expression(5, Add)) at (prev + 3, 14) to (start + 2, 10)
= (c1 + c2)
- Code(Expression(1, Add)) at (prev + 4, 1) to (start + 0, 2)
- Code(Expression(2, Add)) at (prev + 4, 1) to (start + 0, 2)
= ((((c1 + c2) + c3) + c4) + c5)

8 changes: 7 additions & 1 deletion tests/coverage/branch_guard.coverage
@@ -1,6 +1,6 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |
LL| |//@ compile-flags: -Zcoverage-options=branch
LL| |//@ llvm-cov-flags: --show-branches=count
LL| |
LL| |macro_rules! no_merge {
Expand All @@ -18,9 +18,15 @@
LL| 1| }
LL| 3| Some(x) if x % 2 == 0 => {
^2
------------------
| Branch (LL:20): [True: 2, False: 1]
------------------
LL| 2| println!("is nonzero and even");
LL| 2| }
LL| 1| Some(x) if x % 3 == 0 => {
------------------
| Branch (LL:20): [True: 1, False: 0]
------------------
LL| 1| println!("is nonzero and odd, but divisible by 3");
LL| 1| }
LL| 0| _ => {
Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/branch_guard.rs
@@ -1,6 +1,6 @@
#![feature(coverage_attribute)]
//@ edition: 2021

//@ compile-flags: -Zcoverage-options=branch
//@ llvm-cov-flags: --show-branches=count

macro_rules! no_merge {
Expand Down

0 comments on commit fbc0067

Please sign in to comment.