Skip to content

Commit 31831e4

Browse files
committed
tests(coverage): Add mcdc_non_control_flow tests
1 parent ab9a52a commit 31831e4

File tree

3 files changed

+292
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)