Skip to content

Commit 290a532

Browse files
committed
tests(coverage): Add tests for condition coverage
1 parent 350edd8 commit 290a532

File tree

3 files changed

+318
-0
lines changed

3 files changed

+318
-0
lines changed
+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
Function name: conditions::assign_3
2+
Raw bytes (73): 0x[01, 01, 09, 07, 0b, 05, 09, 0d, 11, 01, 05, 01, 05, 22, 11, 01, 05, 22, 11, 01, 05, 09, 01, 17, 01, 00, 28, 03, 01, 09, 00, 0a, 01, 00, 0d, 00, 0e, 20, 05, 22, 00, 0d, 00, 0e, 22, 00, 12, 00, 13, 20, 1e, 11, 00, 12, 00, 13, 1e, 00, 17, 00, 18, 20, 09, 0d, 00, 17, 00, 18, 03, 01, 05, 01, 02]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 9
6+
- expression 0 operands: lhs = Expression(1, Add), rhs = Expression(2, Add)
7+
- expression 1 operands: lhs = Counter(1), rhs = Counter(2)
8+
- expression 2 operands: lhs = Counter(3), rhs = Counter(4)
9+
- expression 3 operands: lhs = Counter(0), rhs = Counter(1)
10+
- expression 4 operands: lhs = Counter(0), rhs = Counter(1)
11+
- expression 5 operands: lhs = Expression(8, Sub), rhs = Counter(4)
12+
- expression 6 operands: lhs = Counter(0), rhs = Counter(1)
13+
- expression 7 operands: lhs = Expression(8, Sub), rhs = Counter(4)
14+
- expression 8 operands: lhs = Counter(0), rhs = Counter(1)
15+
Number of file 0 mappings: 9
16+
- Code(Counter(0)) at (prev + 23, 1) to (start + 0, 40)
17+
- Code(Expression(0, Add)) at (prev + 1, 9) to (start + 0, 10)
18+
= ((c1 + c2) + (c3 + c4))
19+
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 14)
20+
- Branch { true: Counter(1), false: Expression(8, Sub) } at (prev + 0, 13) to (start + 0, 14)
21+
true = c1
22+
false = (c0 - c1)
23+
- Code(Expression(8, Sub)) at (prev + 0, 18) to (start + 0, 19)
24+
= (c0 - c1)
25+
- Branch { true: Expression(7, Sub), false: Counter(4) } at (prev + 0, 18) to (start + 0, 19)
26+
true = ((c0 - c1) - c4)
27+
false = c4
28+
- Code(Expression(7, Sub)) at (prev + 0, 23) to (start + 0, 24)
29+
= ((c0 - c1) - c4)
30+
- Branch { true: Counter(2), false: Counter(3) } at (prev + 0, 23) to (start + 0, 24)
31+
true = c2
32+
false = c3
33+
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 1, 2)
34+
= ((c1 + c2) + (c3 + c4))
35+
36+
Function name: conditions::assign_3_bis
37+
Raw bytes (69): 0x[01, 01, 07, 07, 11, 09, 0d, 01, 05, 05, 09, 16, 1a, 05, 09, 01, 05, 09, 01, 1c, 01, 00, 2c, 03, 01, 09, 00, 0a, 01, 00, 0d, 00, 0e, 20, 05, 1a, 00, 0d, 00, 0e, 05, 00, 12, 00, 13, 20, 09, 16, 00, 12, 00, 13, 13, 00, 17, 00, 18, 20, 0d, 11, 00, 17, 00, 18, 03, 01, 05, 01, 02]
38+
Number of files: 1
39+
- file 0 => global file 1
40+
Number of expressions: 7
41+
- expression 0 operands: lhs = Expression(1, Add), rhs = Counter(4)
42+
- expression 1 operands: lhs = Counter(2), rhs = Counter(3)
43+
- expression 2 operands: lhs = Counter(0), rhs = Counter(1)
44+
- expression 3 operands: lhs = Counter(1), rhs = Counter(2)
45+
- expression 4 operands: lhs = Expression(5, Sub), rhs = Expression(6, Sub)
46+
- expression 5 operands: lhs = Counter(1), rhs = Counter(2)
47+
- expression 6 operands: lhs = Counter(0), rhs = Counter(1)
48+
Number of file 0 mappings: 9
49+
- Code(Counter(0)) at (prev + 28, 1) to (start + 0, 44)
50+
- Code(Expression(0, Add)) at (prev + 1, 9) to (start + 0, 10)
51+
= ((c2 + c3) + c4)
52+
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 14)
53+
- Branch { true: Counter(1), false: Expression(6, Sub) } at (prev + 0, 13) to (start + 0, 14)
54+
true = c1
55+
false = (c0 - c1)
56+
- Code(Counter(1)) at (prev + 0, 18) to (start + 0, 19)
57+
- Branch { true: Counter(2), false: Expression(5, Sub) } at (prev + 0, 18) to (start + 0, 19)
58+
true = c2
59+
false = (c1 - c2)
60+
- Code(Expression(4, Add)) at (prev + 0, 23) to (start + 0, 24)
61+
= ((c1 - c2) + (c0 - c1))
62+
- Branch { true: Counter(3), false: Counter(4) } at (prev + 0, 23) to (start + 0, 24)
63+
true = c3
64+
false = c4
65+
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 1, 2)
66+
= ((c2 + c3) + c4)
67+
68+
Function name: conditions::assign_and
69+
Raw bytes (51): 0x[01, 01, 04, 09, 07, 0d, 0e, 01, 05, 01, 05, 07, 01, 0d, 01, 00, 21, 03, 01, 09, 00, 0a, 01, 00, 0d, 00, 0e, 20, 05, 0e, 00, 0d, 00, 0e, 05, 00, 12, 00, 13, 20, 09, 0d, 00, 12, 00, 13, 03, 01, 05, 01, 02]
70+
Number of files: 1
71+
- file 0 => global file 1
72+
Number of expressions: 4
73+
- expression 0 operands: lhs = Counter(2), rhs = Expression(1, Add)
74+
- expression 1 operands: lhs = Counter(3), rhs = Expression(3, Sub)
75+
- expression 2 operands: lhs = Counter(0), rhs = Counter(1)
76+
- expression 3 operands: lhs = Counter(0), rhs = Counter(1)
77+
Number of file 0 mappings: 7
78+
- Code(Counter(0)) at (prev + 13, 1) to (start + 0, 33)
79+
- Code(Expression(0, Add)) at (prev + 1, 9) to (start + 0, 10)
80+
= (c2 + (c3 + (c0 - c1)))
81+
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 14)
82+
- Branch { true: Counter(1), false: Expression(3, Sub) } at (prev + 0, 13) to (start + 0, 14)
83+
true = c1
84+
false = (c0 - c1)
85+
- Code(Counter(1)) at (prev + 0, 18) to (start + 0, 19)
86+
- Branch { true: Counter(2), false: Counter(3) } at (prev + 0, 18) to (start + 0, 19)
87+
true = c2
88+
false = c3
89+
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 1, 2)
90+
= (c2 + (c3 + (c0 - c1)))
91+
92+
Function name: conditions::assign_or
93+
Raw bytes (51): 0x[01, 01, 04, 07, 0d, 05, 09, 01, 05, 01, 05, 07, 01, 12, 01, 00, 20, 03, 01, 09, 00, 0a, 01, 00, 0d, 00, 0e, 20, 05, 0e, 00, 0d, 00, 0e, 0e, 00, 12, 00, 13, 20, 09, 0d, 00, 12, 00, 13, 03, 01, 05, 01, 02]
94+
Number of files: 1
95+
- file 0 => global file 1
96+
Number of expressions: 4
97+
- expression 0 operands: lhs = Expression(1, Add), rhs = Counter(3)
98+
- expression 1 operands: lhs = Counter(1), rhs = Counter(2)
99+
- expression 2 operands: lhs = Counter(0), rhs = Counter(1)
100+
- expression 3 operands: lhs = Counter(0), rhs = Counter(1)
101+
Number of file 0 mappings: 7
102+
- Code(Counter(0)) at (prev + 18, 1) to (start + 0, 32)
103+
- Code(Expression(0, Add)) at (prev + 1, 9) to (start + 0, 10)
104+
= ((c1 + c2) + c3)
105+
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 14)
106+
- Branch { true: Counter(1), false: Expression(3, Sub) } at (prev + 0, 13) to (start + 0, 14)
107+
true = c1
108+
false = (c0 - c1)
109+
- Code(Expression(3, Sub)) at (prev + 0, 18) to (start + 0, 19)
110+
= (c0 - c1)
111+
- Branch { true: Counter(2), false: Counter(3) } at (prev + 0, 18) to (start + 0, 19)
112+
true = c2
113+
false = c3
114+
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 1, 2)
115+
= ((c1 + c2) + c3)
116+
117+
Function name: conditions::foo
118+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 21, 01, 02, 02]
119+
Number of files: 1
120+
- file 0 => global file 1
121+
Number of expressions: 0
122+
Number of file 0 mappings: 1
123+
- Code(Counter(0)) at (prev + 33, 1) to (start + 2, 2)
124+
125+
Function name: conditions::func_call
126+
Raw bytes (39): 0x[01, 01, 03, 01, 05, 09, 0b, 0d, 02, 05, 01, 25, 01, 01, 0a, 20, 05, 02, 01, 09, 00, 0a, 05, 00, 0e, 00, 0f, 20, 09, 0d, 00, 0e, 00, 0f, 07, 01, 01, 00, 02]
127+
Number of files: 1
128+
- file 0 => global file 1
129+
Number of expressions: 3
130+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
131+
- expression 1 operands: lhs = Counter(2), rhs = Expression(2, Add)
132+
- expression 2 operands: lhs = Counter(3), rhs = Expression(0, Sub)
133+
Number of file 0 mappings: 5
134+
- Code(Counter(0)) at (prev + 37, 1) to (start + 1, 10)
135+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 9) to (start + 0, 10)
136+
true = c1
137+
false = (c0 - c1)
138+
- Code(Counter(1)) at (prev + 0, 14) to (start + 0, 15)
139+
- Branch { true: Counter(2), false: Counter(3) } at (prev + 0, 14) to (start + 0, 15)
140+
true = c2
141+
false = c3
142+
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2)
143+
= (c2 + (c3 + (c0 - c1)))
144+
145+
Function name: conditions::simple_assign
146+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 08, 01, 03, 02]
147+
Number of files: 1
148+
- file 0 => global file 1
149+
Number of expressions: 0
150+
Number of file 0 mappings: 1
151+
- Code(Counter(0)) at (prev + 8, 1) to (start + 3, 2)
152+
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2021
3+
LL| |//@ compile-flags: -Zcoverage-options=condition
4+
LL| |//@ llvm-cov-flags: --show-branches=count
5+
LL| |
6+
LL| |use core::hint::black_box;
7+
LL| |
8+
LL| 2|fn simple_assign(a: bool) {
9+
LL| 2| let x = a;
10+
LL| 2| black_box(x);
11+
LL| 2|}
12+
LL| |
13+
LL| 3|fn assign_and(a: bool, b: bool) {
14+
LL| 3| let x = a && b;
15+
^2
16+
------------------
17+
| Branch (LL:13): [True: 2, False: 1]
18+
| Branch (LL:18): [True: 1, False: 1]
19+
------------------
20+
LL| 3| black_box(x);
21+
LL| 3|}
22+
LL| |
23+
LL| 3|fn assign_or(a: bool, b: bool) {
24+
LL| 3| let x = a || b;
25+
^1
26+
------------------
27+
| Branch (LL:13): [True: 2, False: 1]
28+
| Branch (LL:18): [True: 0, False: 1]
29+
------------------
30+
LL| 3| black_box(x);
31+
LL| 3|}
32+
LL| |
33+
LL| 4|fn assign_3(a: bool, b: bool, c: bool) {
34+
LL| 4| let x = a || b && c;
35+
^2 ^1
36+
------------------
37+
| Branch (LL:13): [True: 2, False: 2]
38+
| Branch (LL:18): [True: 1, False: 1]
39+
| Branch (LL:23): [True: 1, False: 0]
40+
------------------
41+
LL| 4| black_box(x);
42+
LL| 4|}
43+
LL| |
44+
LL| 4|fn assign_3_bis(a: bool, b: bool, c: bool) {
45+
LL| 4| let x = a && b || c;
46+
^2 ^3
47+
------------------
48+
| Branch (LL:13): [True: 2, False: 2]
49+
| Branch (LL:18): [True: 1, False: 1]
50+
| Branch (LL:23): [True: 2, False: 1]
51+
------------------
52+
LL| 4| black_box(x);
53+
LL| 4|}
54+
LL| |
55+
LL| 3|fn foo(a: bool) -> bool {
56+
LL| 3| black_box(a)
57+
LL| 3|}
58+
LL| |
59+
LL| 3|fn func_call(a: bool, b: bool) {
60+
LL| 3| foo(a && b);
61+
^2
62+
------------------
63+
| Branch (LL:9): [True: 2, False: 1]
64+
| Branch (LL:14): [True: 1, False: 1]
65+
------------------
66+
LL| 3|}
67+
LL| |
68+
LL| |
69+
LL| |
70+
LL| |#[coverage(off)]
71+
LL| |fn main() {
72+
LL| | simple_assign(true);
73+
LL| | simple_assign(false);
74+
LL| |
75+
LL| | assign_and(true, false);
76+
LL| | assign_and(true, true);
77+
LL| | assign_and(false, false);
78+
LL| |
79+
LL| | assign_or(true, false);
80+
LL| | assign_or(true, true);
81+
LL| | assign_or(false, false);
82+
LL| |
83+
LL| | assign_3(true, false, false);
84+
LL| | assign_3(true, true, false);
85+
LL| | assign_3(false, false, true);
86+
LL| | assign_3(false, true, true);
87+
LL| |
88+
LL| | assign_3_bis(true, false, false);
89+
LL| | assign_3_bis(true, true, false);
90+
LL| | assign_3_bis(false, false, true);
91+
LL| | assign_3_bis(false, true, true);
92+
LL| |
93+
LL| | func_call(true, false);
94+
LL| | func_call(true, true);
95+
LL| | func_call(false, false);
96+
LL| |}
97+

tests/coverage/branch/conditions.rs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#![feature(coverage_attribute)]
2+
//@ edition: 2021
3+
//@ compile-flags: -Zcoverage-options=condition
4+
//@ llvm-cov-flags: --show-branches=count
5+
6+
use core::hint::black_box;
7+
8+
fn simple_assign(a: bool) {
9+
let x = a;
10+
black_box(x);
11+
}
12+
13+
fn assign_and(a: bool, b: bool) {
14+
let x = a && b;
15+
black_box(x);
16+
}
17+
18+
fn assign_or(a: bool, b: bool) {
19+
let x = a || b;
20+
black_box(x);
21+
}
22+
23+
fn assign_3(a: bool, b: bool, c: bool) {
24+
let x = a || b && c;
25+
black_box(x);
26+
}
27+
28+
fn assign_3_bis(a: bool, b: bool, c: bool) {
29+
let x = a && b || c;
30+
black_box(x);
31+
}
32+
33+
fn foo(a: bool) -> bool {
34+
black_box(a)
35+
}
36+
37+
fn func_call(a: bool, b: bool) {
38+
foo(a && b);
39+
}
40+
41+
42+
43+
#[coverage(off)]
44+
fn main() {
45+
simple_assign(true);
46+
simple_assign(false);
47+
48+
assign_and(true, false);
49+
assign_and(true, true);
50+
assign_and(false, false);
51+
52+
assign_or(true, false);
53+
assign_or(true, true);
54+
assign_or(false, false);
55+
56+
assign_3(true, false, false);
57+
assign_3(true, true, false);
58+
assign_3(false, false, true);
59+
assign_3(false, true, true);
60+
61+
assign_3_bis(true, false, false);
62+
assign_3_bis(true, true, false);
63+
assign_3_bis(false, false, true);
64+
assign_3_bis(false, true, true);
65+
66+
func_call(true, false);
67+
func_call(true, true);
68+
func_call(false, false);
69+
}

0 commit comments

Comments
 (0)