Skip to content

Commit 4f91110

Browse files
committed
!! (WIP) branch coverage test
1 parent 1acbfc3 commit 4f91110

File tree

3 files changed

+342
-0
lines changed

3 files changed

+342
-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, 20, 05, 02, 06, 10, 00, 14, 01, 10, 01, 01, 23, 2b, 04, 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+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 6, 16) to (start + 0, 20)
19+
true = c1
20+
false = (c0 - c1)
21+
- Code(Counter(0)) at (prev + 16, 1) to (start + 1, 35)
22+
- Code(Expression(10, Add)) at (prev + 4, 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, 20, 05, 02, 06, 10, 00, 14, 01, 2c, 01, 01, 23, 1b, 07, 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+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 6, 16) to (start + 0, 20)
51+
true = c1
52+
false = (c0 - c1)
53+
- Code(Counter(0)) at (prev + 44, 1) to (start + 1, 35)
54+
- Code(Expression(6, Add)) at (prev + 7, 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, 20, 05, 02, 06, 10, 00, 14, 01, 03, 01, 01, 23, 23, 05, 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+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 6, 16) to (start + 0, 20)
78+
true = c1
79+
false = (c0 - c1)
80+
- Code(Counter(0)) at (prev + 3, 1) to (start + 1, 35)
81+
- Code(Expression(8, Add)) at (prev + 5, 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, 20, 05, 02, 06, 10, 00, 14, 01, 1e, 01, 01, 23, 17, 04, 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+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 6, 16) to (start + 0, 20)
109+
true = c1
110+
false = (c0 - c1)
111+
- Code(Counter(0)) at (prev + 30, 1) to (start + 1, 35)
112+
- Code(Expression(5, Add)) at (prev + 4, 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

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
------------------
8+
| Branch (LL:16): [True: 15, False: 0]
9+
------------------
10+
| Branch (LL:16): [True: 15, False: 0]
11+
------------------
12+
| Branch (LL:16): [True: 15, False: 0]
13+
------------------
14+
| Branch (LL:16): [True: 15, False: 0]
15+
------------------
16+
LL| |}
17+
LL| |
18+
LL| 15|fn if_not(cond: bool) {
19+
LL| 15| do_not_merge_with_signature!();
20+
LL| |
21+
LL| | if
22+
LL| | !
23+
LL| 15| cond
24+
------------------
25+
| Branch (LL:9): [True: 10, False: 5]
26+
------------------
27+
LL| 5| {
28+
LL| 5| println!("cond was false");
29+
LL| 10| } else {
30+
LL| 10| println!("cond was true");
31+
LL| 10| }
32+
LL| 15|}
33+
LL| |
34+
LL| 15|fn if_and(a: bool, b: bool) {
35+
LL| 15| do_not_merge_with_signature!();
36+
LL| |
37+
LL| | if
38+
LL| 15| a
39+
------------------
40+
| Branch (LL:9): [True: 12, False: 3]
41+
------------------
42+
LL| | &&
43+
LL| 12| b
44+
------------------
45+
| Branch (LL:9): [True: 8, False: 4]
46+
------------------
47+
LL| 8| {
48+
LL| 8| println!("both");
49+
LL| 8| } else {
50+
LL| 7| println!("not both");
51+
LL| 7| }
52+
LL| 15|}
53+
LL| |
54+
LL| 15|fn if_or(a: bool, b: bool) {
55+
LL| 15| do_not_merge_with_signature!();
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+
LL| |
77+
LL| | if
78+
LL| | let
79+
LL| | true
80+
LL| | =
81+
LL| 15| cond
82+
LL| 10| {
83+
LL| 10| println!("true");
84+
LL| 10| } else {
85+
LL| 5| println!("false");
86+
LL| 5| }
87+
LL| 15|}
88+
LL| |
89+
LL| |#[coverage(off)]
90+
LL| |fn main() {
91+
LL| | let truthy = std::hint::black_box(true);
92+
LL| | let falsy = std::hint::black_box(false);
93+
LL| |
94+
LL| | for _ in 0..10 {
95+
LL| | if_not(truthy);
96+
LL| | if_let(truthy);
97+
LL| | }
98+
LL| | for _ in 0..5 {
99+
LL| | if_not(falsy);
100+
LL| | if_let(falsy);
101+
LL| | }
102+
LL| |
103+
LL| | for _ in 0..8 {
104+
LL| | if_and(truthy, truthy);
105+
LL| | if_or(truthy, truthy);
106+
LL| | }
107+
LL| | for _ in 0..4 {
108+
LL| | if_and(truthy, falsy);
109+
LL| | if_or(truthy, falsy);
110+
LL| | }
111+
LL| | for _ in 0..2 {
112+
LL| | if_and(falsy, truthy);
113+
LL| | if_or(falsy, truthy);
114+
LL| | }
115+
LL| | for _ in 0..1 {
116+
LL| | if_and(falsy, falsy);
117+
LL| | if_or(falsy, falsy);
118+
LL| | }
119+
LL| |}
120+

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)