Skip to content

Commit 8b74525

Browse files
committed
coverage. Add test cases for while-loops instrumentation
1 parent 4723dd0 commit 8b74525

File tree

3 files changed

+286
-0
lines changed

3 files changed

+286
-0
lines changed

tests/coverage/mcdc_while.cov-map

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

tests/coverage/mcdc_while.coverage

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2021
3+
LL| |//@ min-llvm-version: 18
4+
LL| |//@ compile-flags: -Zcoverage-options=mcdc
5+
LL| |//@ llvm-cov-flags: --show-mcdc
6+
LL| |
7+
LL| 1|fn mcdc_while_33_percent() {
8+
LL| 1| let values = [(false, true, true), (true, false, true), (true, false, false)];
9+
LL| 1| let mut i = 0;
10+
LL| |
11+
LL| 3| while (values[i].0 && values[i].1) || values[i].2 {
12+
^2
13+
------------------
14+
|---> MC/DC Decision Region (LL:11) to (LL:54)
15+
|
16+
| Number of Conditions: 3
17+
| Condition C1 --> (LL:12)
18+
| Condition C2 --> (LL:27)
19+
| Condition C3 --> (LL:43)
20+
|
21+
| Executed MC/DC Test Vectors:
22+
|
23+
| C1, C2, C3 Result
24+
| 1 { T, F, F = F }
25+
| 2 { F, -, T = T }
26+
| 3 { T, F, T = T }
27+
|
28+
| C1-Pair: not covered
29+
| C2-Pair: not covered
30+
| C3-Pair: covered: (1,3)
31+
| MC/DC Coverage for Decision: 33.33%
32+
|
33+
------------------
34+
LL| 2| i += 1
35+
LL| | }
36+
LL| 1|}
37+
LL| |
38+
LL| 1|fn mcdc_while_66_percent() {
39+
LL| 1| let values =
40+
LL| 1| [(false, true, true), (true, false, true), (true, true, true), (false, false, false)];
41+
LL| 1| let mut i = 0;
42+
LL| |
43+
LL| 4| while (values[i].0 && values[i].1) || values[i].2 {
44+
^2 ^3
45+
------------------
46+
|---> MC/DC Decision Region (LL:11) to (LL:54)
47+
|
48+
| Number of Conditions: 3
49+
| Condition C1 --> (LL:12)
50+
| Condition C2 --> (LL:27)
51+
| Condition C3 --> (LL:43)
52+
|
53+
| Executed MC/DC Test Vectors:
54+
|
55+
| C1, C2, C3 Result
56+
| 1 { F, -, F = F }
57+
| 2 { F, -, T = T }
58+
| 3 { T, F, T = T }
59+
| 4 { T, T, - = T }
60+
|
61+
| C1-Pair: covered: (1,4)
62+
| C2-Pair: not covered
63+
| C3-Pair: covered: (1,2)
64+
| MC/DC Coverage for Decision: 66.67%
65+
|
66+
------------------
67+
LL| 3| i += 1
68+
LL| | }
69+
LL| 1|}
70+
LL| |
71+
LL| 2|fn mcdc_while_100_percent(values: &[(bool, bool, bool)]) {
72+
LL| 2| let mut i = 0;
73+
LL| |
74+
LL| 4| while (values[i].0 && values[i].1) || values[i].2 {
75+
^2 ^3
76+
------------------
77+
|---> MC/DC Decision Region (LL:11) to (LL:54)
78+
|
79+
| Number of Conditions: 3
80+
| Condition C1 --> (LL:12)
81+
| Condition C2 --> (LL:27)
82+
| Condition C3 --> (LL:43)
83+
|
84+
| Executed MC/DC Test Vectors:
85+
|
86+
| C1, C2, C3 Result
87+
| 1 { F, -, F = F }
88+
| 2 { T, F, F = F }
89+
| 3 { F, -, T = T }
90+
| 4 { T, T, - = T }
91+
|
92+
| C1-Pair: covered: (1,4)
93+
| C2-Pair: covered: (2,4)
94+
| C3-Pair: covered: (1,3)
95+
| MC/DC Coverage for Decision: 100.00%
96+
|
97+
------------------
98+
LL| 2| i += 1
99+
LL| | }
100+
LL| 2|}
101+
LL| |
102+
LL| |#[coverage(off)]
103+
LL| |fn main() {
104+
LL| | mcdc_while_33_percent();
105+
LL| |
106+
LL| | mcdc_while_66_percent();
107+
LL| |
108+
LL| | let values_1 = [(true, true, true), (true, false, false)];
109+
LL| | let values_2 = [(false, true, true), (false, false, false)];
110+
LL| | mcdc_while_100_percent(&values_1);
111+
LL| | mcdc_while_100_percent(&values_2);
112+
LL| |}
113+

tests/coverage/mcdc_while.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#![feature(coverage_attribute)]
2+
//@ edition: 2021
3+
//@ min-llvm-version: 18
4+
//@ compile-flags: -Zcoverage-options=mcdc
5+
//@ llvm-cov-flags: --show-mcdc
6+
7+
fn mcdc_while_33_percent() {
8+
let values = [(false, true, true), (true, false, true), (true, false, false)];
9+
let mut i = 0;
10+
11+
while (values[i].0 && values[i].1) || values[i].2 {
12+
i += 1
13+
}
14+
}
15+
16+
fn mcdc_while_66_percent() {
17+
let values =
18+
[(false, true, true), (true, false, true), (true, true, true), (false, false, false)];
19+
let mut i = 0;
20+
21+
while (values[i].0 && values[i].1) || values[i].2 {
22+
i += 1
23+
}
24+
}
25+
26+
fn mcdc_while_100_percent(values: &[(bool, bool, bool)]) {
27+
let mut i = 0;
28+
29+
while (values[i].0 && values[i].1) || values[i].2 {
30+
i += 1
31+
}
32+
}
33+
34+
#[coverage(off)]
35+
fn main() {
36+
mcdc_while_33_percent();
37+
38+
mcdc_while_66_percent();
39+
40+
let values_1 = [(true, true, true), (true, false, false)];
41+
let values_2 = [(false, true, true), (false, false, false)];
42+
mcdc_while_100_percent(&values_1);
43+
mcdc_while_100_percent(&values_2);
44+
}

0 commit comments

Comments
 (0)