Skip to content

Commit 45ee9ea

Browse files
committed
!! (WIP) branch coverage test
1 parent 2c2f8bf commit 45ee9ea

File tree

3 files changed

+345
-0
lines changed

3 files changed

+345
-0
lines changed

tests/coverage/branch.cov-map

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
Function name: branch::if_and
2+
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]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 11
6+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
7+
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
8+
- expression 2 operands: lhs = Expression(10, Add), rhs = Counter(2)
9+
- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub)
10+
- expression 4 operands: lhs = Counter(3), rhs = Expression(9, Sub)
11+
- expression 5 operands: lhs = Expression(10, Add), rhs = Counter(2)
12+
- expression 6 operands: lhs = Counter(1), rhs = Expression(0, Sub)
13+
- expression 7 operands: lhs = Counter(4), rhs = Expression(8, Add)
14+
- expression 8 operands: lhs = Counter(3), rhs = Expression(9, Sub)
15+
- expression 9 operands: lhs = Expression(10, Add), rhs = Counter(2)
16+
- expression 10 operands: lhs = Counter(1), rhs = Expression(0, Sub)
17+
Number of file 0 mappings: 9
18+
- Code(Counter(0)) at (prev + 22, 1) to (start + 1, 35)
19+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 5) to (start + 0, 35)
20+
true = c1
21+
false = (c0 - c1)
22+
- Code(Expression(10, Add)) at (prev + 3, 9) to (start + 0, 10)
23+
= (c1 + (c0 - c1))
24+
- Branch { true: Counter(2), false: Expression(9, Sub) } at (prev + 0, 9) to (start + 0, 10)
25+
true = c2
26+
false = ((c1 + (c0 - c1)) - c2)
27+
- Code(Counter(2)) at (prev + 2, 9) to (start + 0, 10)
28+
- Branch { true: Counter(4), false: Counter(3) } at (prev + 0, 9) to (start + 0, 10)
29+
true = c4
30+
false = c3
31+
- Code(Counter(4)) at (prev + 1, 5) to (start + 2, 6)
32+
- Code(Expression(8, Add)) at (prev + 2, 12) to (start + 2, 6)
33+
= (c3 + ((c1 + (c0 - c1)) - c2))
34+
- Code(Expression(7, Add)) at (prev + 3, 1) to (start + 0, 2)
35+
= (c4 + (c3 + ((c1 + (c0 - c1)) - c2)))
36+
37+
Function name: branch::if_let
38+
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]
39+
Number of files: 1
40+
- file 0 => global file 1
41+
Number of expressions: 7
42+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
43+
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
44+
- expression 2 operands: lhs = Expression(6, Add), rhs = Counter(2)
45+
- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub)
46+
- expression 4 operands: lhs = Counter(2), rhs = Expression(5, Sub)
47+
- expression 5 operands: lhs = Expression(6, Add), rhs = Counter(2)
48+
- expression 6 operands: lhs = Counter(1), rhs = Expression(0, Sub)
49+
Number of file 0 mappings: 6
50+
- Code(Counter(0)) at (prev + 50, 1) to (start + 1, 35)
51+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 5) to (start + 0, 35)
52+
true = c1
53+
false = (c0 - c1)
54+
- Code(Expression(6, Add)) at (prev + 6, 9) to (start + 0, 13)
55+
= (c1 + (c0 - c1))
56+
- Code(Counter(2)) at (prev + 1, 5) to (start + 2, 6)
57+
- Code(Expression(5, Sub)) at (prev + 2, 12) to (start + 2, 6)
58+
= ((c1 + (c0 - c1)) - c2)
59+
- Code(Expression(4, Add)) at (prev + 3, 1) to (start + 0, 2)
60+
= (c2 + ((c1 + (c0 - c1)) - c2))
61+
62+
Function name: branch::if_not
63+
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]
64+
Number of files: 1
65+
- file 0 => global file 1
66+
Number of expressions: 9
67+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
68+
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
69+
- expression 2 operands: lhs = Expression(8, Add), rhs = Counter(2)
70+
- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub)
71+
- expression 4 operands: lhs = Expression(8, Add), rhs = Counter(2)
72+
- expression 5 operands: lhs = Counter(1), rhs = Expression(0, Sub)
73+
- expression 6 operands: lhs = Counter(2), rhs = Expression(7, Sub)
74+
- expression 7 operands: lhs = Expression(8, Add), rhs = Counter(2)
75+
- expression 8 operands: lhs = Counter(1), rhs = Expression(0, Sub)
76+
Number of file 0 mappings: 7
77+
- Code(Counter(0)) at (prev + 9, 1) to (start + 1, 35)
78+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 5) to (start + 0, 35)
79+
true = c1
80+
false = (c0 - c1)
81+
- Code(Expression(8, Add)) at (prev + 4, 9) to (start + 0, 13)
82+
= (c1 + (c0 - c1))
83+
- Branch { true: Counter(2), false: Expression(7, Sub) } at (prev + 0, 9) to (start + 0, 13)
84+
true = c2
85+
false = ((c1 + (c0 - c1)) - c2)
86+
- Code(Expression(7, Sub)) at (prev + 1, 5) to (start + 2, 6)
87+
= ((c1 + (c0 - c1)) - c2)
88+
- Code(Counter(2)) at (prev + 2, 12) to (start + 2, 6)
89+
- Code(Expression(6, Add)) at (prev + 3, 1) to (start + 0, 2)
90+
= (c2 + ((c1 + (c0 - c1)) - c2))
91+
92+
Function name: branch::if_or
93+
Raw bytes (75): 0x[01, 01, 0a, 01, 05, 05, 02, 17, 09, 05, 02, 17, 09, 05, 02, 09, 0d, 09, 0d, 27, 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, 27, 11, 00, 09, 00, 0a, 27, 01, 05, 02, 06, 11, 02, 0c, 02, 06, 23, 03, 01, 00, 02]
94+
Number of files: 1
95+
- file 0 => global file 1
96+
Number of expressions: 10
97+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
98+
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
99+
- expression 2 operands: lhs = Expression(5, Add), rhs = Counter(2)
100+
- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub)
101+
- expression 4 operands: lhs = Expression(5, Add), rhs = Counter(2)
102+
- expression 5 operands: lhs = Counter(1), rhs = Expression(0, Sub)
103+
- expression 6 operands: lhs = Counter(2), rhs = Counter(3)
104+
- expression 7 operands: lhs = Counter(2), rhs = Counter(3)
105+
- expression 8 operands: lhs = Expression(9, Add), rhs = Counter(4)
106+
- expression 9 operands: lhs = Counter(2), rhs = Counter(3)
107+
Number of file 0 mappings: 9
108+
- Code(Counter(0)) at (prev + 36, 1) to (start + 1, 35)
109+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 5) to (start + 0, 35)
110+
true = c1
111+
false = (c0 - c1)
112+
- Code(Expression(5, Add)) at (prev + 3, 9) to (start + 0, 10)
113+
= (c1 + (c0 - c1))
114+
- Branch { true: Counter(2), false: Expression(4, Sub) } at (prev + 0, 9) to (start + 0, 10)
115+
true = c2
116+
false = ((c1 + (c0 - c1)) - c2)
117+
- Code(Expression(4, Sub)) at (prev + 2, 9) to (start + 0, 10)
118+
= ((c1 + (c0 - c1)) - c2)
119+
- Branch { true: Expression(9, Add), false: Counter(4) } at (prev + 0, 9) to (start + 0, 10)
120+
true = (c2 + c3)
121+
false = c4
122+
- Code(Expression(9, Add)) at (prev + 1, 5) to (start + 2, 6)
123+
= (c2 + c3)
124+
- Code(Counter(4)) at (prev + 2, 12) to (start + 2, 6)
125+
- Code(Expression(8, Add)) at (prev + 3, 1) to (start + 0, 2)
126+
= ((c2 + c3) + c4)
127+

tests/coverage/branch.coverage

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |// edition: 2021
3+
LL| |// compile-flags: -Zunstable-options -Cinstrument-coverage=branch
4+
LL| |
5+
LL| |macro_rules! do_not_merge_with_signature {
6+
LL| | () => { if true {} else {} };
7+
LL| |}
8+
LL| |
9+
LL| 15|fn if_not(cond: bool) {
10+
LL| 15| do_not_merge_with_signature!();
11+
------------------
12+
| Branch (LL:5): [True: 15, False: 0]
13+
------------------
14+
LL| |
15+
LL| | if
16+
LL| | !
17+
LL| 15| cond
18+
------------------
19+
| Branch (LL:9): [True: 10, False: 5]
20+
------------------
21+
LL| 5| {
22+
LL| 5| println!("cond was false");
23+
LL| 10| } else {
24+
LL| 10| println!("cond was true");
25+
LL| 10| }
26+
LL| 15|}
27+
LL| |
28+
LL| 15|fn if_and(a: bool, b: bool) {
29+
LL| 15| do_not_merge_with_signature!();
30+
------------------
31+
| Branch (LL:5): [True: 15, False: 0]
32+
------------------
33+
LL| |
34+
LL| | if
35+
LL| 15| a
36+
------------------
37+
| Branch (LL:9): [True: 12, False: 3]
38+
------------------
39+
LL| | &&
40+
LL| 12| b
41+
------------------
42+
| Branch (LL:9): [True: 8, False: 4]
43+
------------------
44+
LL| 8| {
45+
LL| 8| println!("both");
46+
LL| 8| } else {
47+
LL| 7| println!("not both");
48+
LL| 7| }
49+
LL| 15|}
50+
LL| |
51+
LL| 15|fn if_or(a: bool, b: bool) {
52+
LL| 15| do_not_merge_with_signature!();
53+
------------------
54+
| Branch (LL:5): [True: 15, False: 0]
55+
------------------
56+
LL| |
57+
LL| | if
58+
LL| 15| a
59+
------------------
60+
| Branch (LL:9): [True: 12, False: 3]
61+
------------------
62+
LL| | ||
63+
LL| 3| b
64+
------------------
65+
| Branch (LL:9): [True: 14, False: 1]
66+
------------------
67+
LL| 14| {
68+
LL| 14| println!("either");
69+
LL| 14| } else {
70+
LL| 1| println!("neither");
71+
LL| 1| }
72+
LL| 15|}
73+
LL| |
74+
LL| 15|fn if_let(cond: bool) {
75+
LL| 15| do_not_merge_with_signature!();
76+
------------------
77+
| Branch (LL:5): [True: 15, False: 0]
78+
------------------
79+
LL| |
80+
LL| | if
81+
LL| | let
82+
LL| | true
83+
LL| | =
84+
LL| 15| cond
85+
LL| 10| {
86+
LL| 10| println!("true");
87+
LL| 10| } else {
88+
LL| 5| println!("false");
89+
LL| 5| }
90+
LL| 15|}
91+
LL| |
92+
LL| |#[coverage(off)]
93+
LL| |fn main() {
94+
LL| | let truthy = std::hint::black_box(true);
95+
LL| | let falsy = std::hint::black_box(false);
96+
LL| |
97+
LL| | for _ in 0..10 {
98+
LL| | if_not(truthy);
99+
LL| | if_let(truthy);
100+
LL| | }
101+
LL| | for _ in 0..5 {
102+
LL| | if_not(falsy);
103+
LL| | if_let(falsy);
104+
LL| | }
105+
LL| |
106+
LL| | for _ in 0..8 {
107+
LL| | if_and(truthy, truthy);
108+
LL| | if_or(truthy, truthy);
109+
LL| | }
110+
LL| | for _ in 0..4 {
111+
LL| | if_and(truthy, falsy);
112+
LL| | if_or(truthy, falsy);
113+
LL| | }
114+
LL| | for _ in 0..2 {
115+
LL| | if_and(falsy, truthy);
116+
LL| | if_or(falsy, truthy);
117+
LL| | }
118+
LL| | for _ in 0..1 {
119+
LL| | if_and(falsy, falsy);
120+
LL| | if_or(falsy, falsy);
121+
LL| | }
122+
LL| |}
123+

tests/coverage/branch.rs

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#![feature(coverage_attribute)]
2+
// edition: 2021
3+
// compile-flags: -Zunstable-options -Cinstrument-coverage=branch
4+
5+
macro_rules! do_not_merge_with_signature {
6+
() => { if true {} else {} };
7+
}
8+
9+
fn if_not(cond: bool) {
10+
do_not_merge_with_signature!();
11+
12+
if
13+
!
14+
cond
15+
{
16+
println!("cond was false");
17+
} else {
18+
println!("cond was true");
19+
}
20+
}
21+
22+
fn if_and(a: bool, b: bool) {
23+
do_not_merge_with_signature!();
24+
25+
if
26+
a
27+
&&
28+
b
29+
{
30+
println!("both");
31+
} else {
32+
println!("not both");
33+
}
34+
}
35+
36+
fn if_or(a: bool, b: bool) {
37+
do_not_merge_with_signature!();
38+
39+
if
40+
a
41+
||
42+
b
43+
{
44+
println!("either");
45+
} else {
46+
println!("neither");
47+
}
48+
}
49+
50+
fn if_let(cond: bool) {
51+
do_not_merge_with_signature!();
52+
53+
if
54+
let
55+
true
56+
=
57+
cond
58+
{
59+
println!("true");
60+
} else {
61+
println!("false");
62+
}
63+
}
64+
65+
#[coverage(off)]
66+
fn main() {
67+
let truthy = std::hint::black_box(true);
68+
let falsy = std::hint::black_box(false);
69+
70+
for _ in 0..10 {
71+
if_not(truthy);
72+
if_let(truthy);
73+
}
74+
for _ in 0..5 {
75+
if_not(falsy);
76+
if_let(falsy);
77+
}
78+
79+
for _ in 0..8 {
80+
if_and(truthy, truthy);
81+
if_or(truthy, truthy);
82+
}
83+
for _ in 0..4 {
84+
if_and(truthy, falsy);
85+
if_or(truthy, falsy);
86+
}
87+
for _ in 0..2 {
88+
if_and(falsy, truthy);
89+
if_or(falsy, truthy);
90+
}
91+
for _ in 0..1 {
92+
if_and(falsy, falsy);
93+
if_or(falsy, falsy);
94+
}
95+
}

0 commit comments

Comments
 (0)