Skip to content

Commit 96a71d8

Browse files
committed
!! (WIP) branch coverage test
1 parent fb6dd05 commit 96a71d8

File tree

3 files changed

+308
-0
lines changed

3 files changed

+308
-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, 0d, 01, 01, 23, 2b, 03, 08, 00, 09, 20, 09, 26, 00, 08, 00, 09, 09, 00, 0d, 00, 0e, 20, 11, 0d, 00, 0d, 00, 0e, 11, 00, 0f, 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 + 13, 1) to (start + 1, 35)
22+
- Code(Expression(10, Add)) at (prev + 3, 8) to (start + 0, 9)
23+
= (c1 + (c0 - c1))
24+
- Branch { true: Counter(2), false: Expression(9, Sub) } at (prev + 0, 8) to (start + 0, 9)
25+
true = c2
26+
false = ((c1 + (c0 - c1)) - c2)
27+
- Code(Counter(2)) at (prev + 0, 13) to (start + 0, 14)
28+
- Branch { true: Counter(4), false: Counter(3) } at (prev + 0, 13) to (start + 0, 14)
29+
true = c4
30+
false = c3
31+
- Code(Counter(4)) at (prev + 0, 15) 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, 21, 01, 01, 23, 1b, 03, 13, 00, 17, 09, 00, 18, 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 + 33, 1) to (start + 1, 35)
54+
- Code(Expression(6, Add)) at (prev + 3, 19) to (start + 0, 23)
55+
= (c1 + (c0 - c1))
56+
- Code(Counter(2)) at (prev + 0, 24) 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, 03, 09, 00, 0d, 20, 09, 1e, 00, 09, 00, 0d, 1e, 00, 0e, 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 + 3, 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 + 0, 14) 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, 17, 01, 01, 23, 17, 03, 08, 00, 09, 20, 09, 12, 00, 08, 00, 09, 12, 00, 0d, 00, 0e, 20, 27, 11, 00, 0d, 00, 0e, 27, 00, 0f, 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 + 23, 1) to (start + 1, 35)
112+
- Code(Expression(5, Add)) at (prev + 3, 8) to (start + 0, 9)
113+
= (c1 + (c0 - c1))
114+
- Branch { true: Counter(2), false: Expression(4, Sub) } at (prev + 0, 8) to (start + 0, 9)
115+
true = c2
116+
false = ((c1 + (c0 - c1)) - c2)
117+
- Code(Expression(4, Sub)) at (prev + 0, 13) to (start + 0, 14)
118+
= ((c1 + (c0 - c1)) - c2)
119+
- Branch { true: Expression(9, Add), false: Counter(4) } at (prev + 0, 13) to (start + 0, 14)
120+
true = (c2 + c3)
121+
false = c4
122+
- Code(Expression(9, Add)) at (prev + 0, 15) 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

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

tests/coverage/branch.rs

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 !cond {
13+
println!("cond was false");
14+
} else {
15+
println!("cond was true");
16+
}
17+
}
18+
19+
fn if_and(a: bool, b: bool) {
20+
do_not_merge_with_signature!();
21+
22+
if a && b {
23+
println!("both");
24+
} else {
25+
println!("not both");
26+
}
27+
}
28+
29+
fn if_or(a: bool, b: bool) {
30+
do_not_merge_with_signature!();
31+
32+
if a || b {
33+
println!("either");
34+
} else {
35+
println!("neither");
36+
}
37+
}
38+
39+
fn if_let(cond: bool) {
40+
do_not_merge_with_signature!();
41+
42+
if let true = cond {
43+
println!("true");
44+
} else {
45+
println!("false");
46+
}
47+
}
48+
49+
#[coverage(off)]
50+
fn main() {
51+
let truthy = std::hint::black_box(true);
52+
let falsy = std::hint::black_box(false);
53+
54+
for _ in 0..10 {
55+
if_not(truthy);
56+
if_let(truthy);
57+
}
58+
for _ in 0..5 {
59+
if_not(falsy);
60+
if_let(falsy);
61+
}
62+
63+
for _ in 0..8 {
64+
if_and(truthy, truthy);
65+
if_or(truthy, truthy);
66+
}
67+
for _ in 0..4 {
68+
if_and(truthy, falsy);
69+
if_or(truthy, falsy);
70+
}
71+
for _ in 0..2 {
72+
if_and(falsy, truthy);
73+
if_or(falsy, truthy);
74+
}
75+
for _ in 0..1 {
76+
if_and(falsy, falsy);
77+
if_or(falsy, falsy);
78+
}
79+
}

0 commit comments

Comments
 (0)