Skip to content

Commit 2198ae1

Browse files
committed
tests(coverage): Add condition coverage tests
1 parent ae1a797 commit 2198ae1

File tree

3 files changed

+289
-0
lines changed

3 files changed

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

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)