Skip to content

Commit

Permalink
!! (WIP) branch coverage test
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Nov 28, 2023
1 parent c14bc9b commit 1f08442
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 0 deletions.
126 changes: 126 additions & 0 deletions tests/coverage/branch.cov-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
Function name: branch::if_and
Raw bytes (77): 0x[01, 01, 0b, 01, 05, 05, 02, 2b, 09, 05, 02, 0d, 26, 2b, 09, 05, 02, 11, 23, 0d, 26, 2b, 09, 05, 02, 09, 01, 16, 01, 01, 23, 20, 05, 02, 01, 05, 00, 23, 2b, 03, 09, 00, 0a, 20, 09, 26, 00, 09, 00, 0a, 09, 02, 09, 00, 0a, 20, 11, 0d, 00, 09, 00, 0a, 11, 01, 05, 02, 06, 23, 02, 0c, 02, 06, 1f, 03, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 11
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
- expression 2 operands: lhs = Expression(10, Add), rhs = Counter(2)
- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub)
- expression 4 operands: lhs = Counter(3), rhs = Expression(9, Sub)
- expression 5 operands: lhs = Expression(10, Add), rhs = Counter(2)
- expression 6 operands: lhs = Counter(1), rhs = Expression(0, Sub)
- expression 7 operands: lhs = Counter(4), rhs = Expression(8, Add)
- expression 8 operands: lhs = Counter(3), rhs = Expression(9, Sub)
- expression 9 operands: lhs = Expression(10, Add), rhs = Counter(2)
- expression 10 operands: lhs = Counter(1), rhs = Expression(0, Sub)
Number of file 0 mappings: 9
- Code(Counter(0)) at (prev + 22, 1) to (start + 1, 35)
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 5) to (start + 0, 35)
true = c1
false = (c0 - c1)
- Code(Expression(10, Add)) at (prev + 3, 9) to (start + 0, 10)
= (c1 + (c0 - c1))
- Branch { true: Counter(2), false: Expression(9, Sub) } at (prev + 0, 9) to (start + 0, 10)
true = c2
false = ((c1 + (c0 - c1)) - c2)
- Code(Counter(2)) at (prev + 2, 9) to (start + 0, 10)
- Branch { true: Counter(4), false: Counter(3) } at (prev + 0, 9) to (start + 0, 10)
true = c4
false = c3
- Code(Counter(4)) at (prev + 1, 5) to (start + 2, 6)
- Code(Expression(8, Add)) at (prev + 2, 12) to (start + 2, 6)
= (c3 + ((c1 + (c0 - c1)) - c2))
- Code(Expression(7, Add)) at (prev + 3, 1) to (start + 0, 2)
= (c4 + (c3 + ((c1 + (c0 - c1)) - c2)))

Function name: branch::if_let
Raw bytes (50): 0x[01, 01, 07, 01, 05, 05, 02, 1b, 09, 05, 02, 09, 16, 1b, 09, 05, 02, 06, 01, 32, 01, 01, 23, 20, 05, 02, 01, 05, 00, 23, 1b, 06, 09, 00, 0d, 09, 01, 05, 02, 06, 16, 02, 0c, 02, 06, 13, 03, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 7
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
- expression 2 operands: lhs = Expression(6, Add), rhs = Counter(2)
- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub)
- expression 4 operands: lhs = Counter(2), rhs = Expression(5, Sub)
- expression 5 operands: lhs = Expression(6, Add), rhs = Counter(2)
- expression 6 operands: lhs = Counter(1), rhs = Expression(0, Sub)
Number of file 0 mappings: 6
- Code(Counter(0)) at (prev + 50, 1) to (start + 1, 35)
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 5) to (start + 0, 35)
true = c1
false = (c0 - c1)
- Code(Expression(6, Add)) at (prev + 6, 9) to (start + 0, 13)
= (c1 + (c0 - c1))
- Code(Counter(2)) at (prev + 1, 5) to (start + 2, 6)
- Code(Expression(5, Sub)) at (prev + 2, 12) to (start + 2, 6)
= ((c1 + (c0 - c1)) - c2)
- Code(Expression(4, Add)) at (prev + 3, 1) to (start + 0, 2)
= (c2 + ((c1 + (c0 - c1)) - c2))

Function name: branch::if_not
Raw bytes (61): 0x[01, 01, 09, 01, 05, 05, 02, 23, 09, 05, 02, 23, 09, 05, 02, 09, 1e, 23, 09, 05, 02, 07, 01, 09, 01, 01, 23, 20, 05, 02, 01, 05, 00, 23, 23, 04, 09, 00, 0d, 20, 09, 1e, 00, 09, 00, 0d, 1e, 01, 05, 02, 06, 09, 02, 0c, 02, 06, 1b, 03, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 9
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
- expression 2 operands: lhs = Expression(8, Add), rhs = Counter(2)
- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub)
- expression 4 operands: lhs = Expression(8, Add), rhs = Counter(2)
- expression 5 operands: lhs = Counter(1), rhs = Expression(0, Sub)
- expression 6 operands: lhs = Counter(2), rhs = Expression(7, Sub)
- expression 7 operands: lhs = Expression(8, Add), rhs = Counter(2)
- expression 8 operands: lhs = Counter(1), rhs = Expression(0, Sub)
Number of file 0 mappings: 7
- Code(Counter(0)) at (prev + 9, 1) to (start + 1, 35)
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 5) to (start + 0, 35)
true = c1
false = (c0 - c1)
- Code(Expression(8, Add)) at (prev + 4, 9) to (start + 0, 13)
= (c1 + (c0 - c1))
- Branch { true: Counter(2), false: Expression(7, Sub) } at (prev + 0, 9) to (start + 0, 13)
true = c2
false = ((c1 + (c0 - c1)) - c2)
- Code(Expression(7, Sub)) at (prev + 1, 5) to (start + 2, 6)
= ((c1 + (c0 - c1)) - c2)
- Code(Counter(2)) at (prev + 2, 12) to (start + 2, 6)
- Code(Expression(6, Add)) at (prev + 3, 1) to (start + 0, 2)
= (c2 + ((c1 + (c0 - c1)) - c2))

Function name: branch::if_or
Raw bytes (73): 0x[01, 01, 09, 01, 05, 05, 02, 17, 09, 05, 02, 17, 09, 05, 02, 09, 0d, 23, 11, 09, 0d, 09, 01, 24, 01, 01, 23, 20, 05, 02, 01, 05, 00, 23, 17, 03, 09, 00, 0a, 20, 09, 12, 00, 09, 00, 0a, 12, 02, 09, 00, 0a, 20, 0d, 11, 00, 09, 00, 0a, 23, 01, 05, 02, 06, 11, 02, 0c, 02, 06, 1f, 03, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 9
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
- expression 2 operands: lhs = Expression(5, Add), rhs = Counter(2)
- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub)
- expression 4 operands: lhs = Expression(5, Add), rhs = Counter(2)
- expression 5 operands: lhs = Counter(1), rhs = Expression(0, Sub)
- expression 6 operands: lhs = Counter(2), rhs = Counter(3)
- expression 7 operands: lhs = Expression(8, Add), rhs = Counter(4)
- expression 8 operands: lhs = Counter(2), rhs = Counter(3)
Number of file 0 mappings: 9
- Code(Counter(0)) at (prev + 36, 1) to (start + 1, 35)
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 5) to (start + 0, 35)
true = c1
false = (c0 - c1)
- Code(Expression(5, Add)) at (prev + 3, 9) to (start + 0, 10)
= (c1 + (c0 - c1))
- Branch { true: Counter(2), false: Expression(4, Sub) } at (prev + 0, 9) to (start + 0, 10)
true = c2
false = ((c1 + (c0 - c1)) - c2)
- Code(Expression(4, Sub)) at (prev + 2, 9) to (start + 0, 10)
= ((c1 + (c0 - c1)) - c2)
- Branch { true: Counter(3), false: Counter(4) } at (prev + 0, 9) to (start + 0, 10)
true = c3
false = c4
- Code(Expression(8, Add)) at (prev + 1, 5) to (start + 2, 6)
= (c2 + c3)
- Code(Counter(4)) at (prev + 2, 12) to (start + 2, 6)
- Code(Expression(7, Add)) at (prev + 3, 1) to (start + 0, 2)
= ((c2 + c3) + c4)

123 changes: 123 additions & 0 deletions tests/coverage/branch.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
LL| |#![feature(coverage_attribute)]
LL| |// edition: 2021
LL| |// compile-flags: -Zunstable-options -Cinstrument-coverage=branch
LL| |
LL| |macro_rules! do_not_merge_with_signature {
LL| | () => { if true {} else {} };
LL| |}
LL| |
LL| 15|fn if_not(cond: bool) {
LL| 15| do_not_merge_with_signature!();
------------------
| Branch (LL:5): [True: 15, False: 0]
------------------
LL| |
LL| | if
LL| | !
LL| 15| cond
------------------
| Branch (LL:9): [True: 10, False: 5]
------------------
LL| 5| {
LL| 5| println!("cond was false");
LL| 10| } else {
LL| 10| println!("cond was true");
LL| 10| }
LL| 15|}
LL| |
LL| 15|fn if_and(a: bool, b: bool) {
LL| 15| do_not_merge_with_signature!();
------------------
| Branch (LL:5): [True: 15, False: 0]
------------------
LL| |
LL| | if
LL| 15| a
------------------
| Branch (LL:9): [True: 12, False: 3]
------------------
LL| | &&
LL| 12| b
------------------
| Branch (LL:9): [True: 8, False: 4]
------------------
LL| 8| {
LL| 8| println!("both");
LL| 8| } else {
LL| 7| println!("not both");
LL| 7| }
LL| 15|}
LL| |
LL| 15|fn if_or(a: bool, b: bool) {
LL| 15| do_not_merge_with_signature!();
------------------
| Branch (LL:5): [True: 15, False: 0]
------------------
LL| |
LL| | if
LL| 15| a
------------------
| Branch (LL:9): [True: 12, False: 3]
------------------
LL| | ||
LL| 3| b
------------------
| Branch (LL:9): [True: 2, False: 1]
------------------
LL| 14| {
LL| 14| println!("either");
LL| 14| } else {
LL| 1| println!("neither");
LL| 1| }
LL| 15|}
LL| |
LL| 15|fn if_let(cond: bool) {
LL| 15| do_not_merge_with_signature!();
------------------
| Branch (LL:5): [True: 15, False: 0]
------------------
LL| |
LL| | if
LL| | let
LL| | true
LL| | =
LL| 15| cond
LL| 10| {
LL| 10| println!("true");
LL| 10| } else {
LL| 5| println!("false");
LL| 5| }
LL| 15|}
LL| |
LL| |#[coverage(off)]
LL| |fn main() {
LL| | let truthy = std::hint::black_box(true);
LL| | let falsy = std::hint::black_box(false);
LL| |
LL| | for _ in 0..10 {
LL| | if_not(truthy);
LL| | if_let(truthy);
LL| | }
LL| | for _ in 0..5 {
LL| | if_not(falsy);
LL| | if_let(falsy);
LL| | }
LL| |
LL| | for _ in 0..8 {
LL| | if_and(truthy, truthy);
LL| | if_or(truthy, truthy);
LL| | }
LL| | for _ in 0..4 {
LL| | if_and(truthy, falsy);
LL| | if_or(truthy, falsy);
LL| | }
LL| | for _ in 0..2 {
LL| | if_and(falsy, truthy);
LL| | if_or(falsy, truthy);
LL| | }
LL| | for _ in 0..1 {
LL| | if_and(falsy, falsy);
LL| | if_or(falsy, falsy);
LL| | }
LL| |}

95 changes: 95 additions & 0 deletions tests/coverage/branch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#![feature(coverage_attribute)]
// edition: 2021
// compile-flags: -Zunstable-options -Cinstrument-coverage=branch

macro_rules! do_not_merge_with_signature {
() => { if true {} else {} };
}

fn if_not(cond: bool) {
do_not_merge_with_signature!();

if
!
cond
{
println!("cond was false");
} else {
println!("cond was true");
}
}

fn if_and(a: bool, b: bool) {
do_not_merge_with_signature!();

if
a
&&
b
{
println!("both");
} else {
println!("not both");
}
}

fn if_or(a: bool, b: bool) {
do_not_merge_with_signature!();

if
a
||
b
{
println!("either");
} else {
println!("neither");
}
}

fn if_let(cond: bool) {
do_not_merge_with_signature!();

if
let
true
=
cond
{
println!("true");
} else {
println!("false");
}
}

#[coverage(off)]
fn main() {
let truthy = std::hint::black_box(true);
let falsy = std::hint::black_box(false);

for _ in 0..10 {
if_not(truthy);
if_let(truthy);
}
for _ in 0..5 {
if_not(falsy);
if_let(falsy);
}

for _ in 0..8 {
if_and(truthy, truthy);
if_or(truthy, truthy);
}
for _ in 0..4 {
if_and(truthy, falsy);
if_or(truthy, falsy);
}
for _ in 0..2 {
if_and(falsy, truthy);
if_or(falsy, truthy);
}
for _ in 0..1 {
if_and(falsy, falsy);
if_or(falsy, falsy);
}
}

0 comments on commit 1f08442

Please sign in to comment.