Skip to content

Commit 482d32e

Browse files
author
zhuyunxing
committed
coverage. Add mcdc test for nested if
1 parent 55279aa commit 482d32e

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

tests/coverage/mcdc_if.cov-map

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,51 @@ Number of file 0 mappings: 10
168168
- Code(Expression(5, Add)) at (prev + 3, 1) to (start + 0, 2)
169169
= ((c3 + c4) + (c2 + (c0 - c1)))
170170

171+
Function name: mcdc_if::mcdc_nested_if
172+
Raw bytes (124): 0x[01, 01, 0d, 01, 05, 02, 09, 05, 09, 1b, 15, 05, 09, 1b, 15, 05, 09, 11, 15, 02, 09, 2b, 32, 0d, 2f, 11, 15, 02, 09, 0e, 01, 3a, 01, 01, 09, 28, 00, 02, 01, 08, 00, 0e, 30, 05, 02, 01, 00, 02, 00, 08, 00, 09, 02, 00, 0d, 00, 0e, 30, 09, 32, 02, 00, 00, 00, 0d, 00, 0e, 1b, 01, 09, 01, 0d, 28, 01, 02, 01, 0c, 00, 12, 30, 16, 15, 01, 02, 00, 00, 0c, 00, 0d, 16, 00, 11, 00, 12, 30, 0d, 11, 02, 00, 00, 00, 11, 00, 12, 0d, 00, 13, 02, 0a, 2f, 02, 0a, 00, 0b, 32, 01, 0c, 02, 06, 27, 03, 01, 00, 02]
173+
Number of files: 1
174+
- file 0 => global file 1
175+
Number of expressions: 13
176+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
177+
- expression 1 operands: lhs = Expression(0, Sub), rhs = Counter(2)
178+
- expression 2 operands: lhs = Counter(1), rhs = Counter(2)
179+
- expression 3 operands: lhs = Expression(6, Add), rhs = Counter(5)
180+
- expression 4 operands: lhs = Counter(1), rhs = Counter(2)
181+
- expression 5 operands: lhs = Expression(6, Add), rhs = Counter(5)
182+
- expression 6 operands: lhs = Counter(1), rhs = Counter(2)
183+
- expression 7 operands: lhs = Counter(4), rhs = Counter(5)
184+
- expression 8 operands: lhs = Expression(0, Sub), rhs = Counter(2)
185+
- expression 9 operands: lhs = Expression(10, Add), rhs = Expression(12, Sub)
186+
- expression 10 operands: lhs = Counter(3), rhs = Expression(11, Add)
187+
- expression 11 operands: lhs = Counter(4), rhs = Counter(5)
188+
- expression 12 operands: lhs = Expression(0, Sub), rhs = Counter(2)
189+
Number of file 0 mappings: 14
190+
- Code(Counter(0)) at (prev + 58, 1) to (start + 1, 9)
191+
- MCDCDecision { bitmap_idx: 0, conditions_num: 2 } at (prev + 1, 8) to (start + 0, 14)
192+
- MCDCBranch { true: Counter(1), false: Expression(0, Sub), condition_id: 1, true_next_id: 0, false_next_id: 2 } at (prev + 0, 8) to (start + 0, 9)
193+
true = c1
194+
false = (c0 - c1)
195+
- Code(Expression(0, Sub)) at (prev + 0, 13) to (start + 0, 14)
196+
= (c0 - c1)
197+
- MCDCBranch { true: Counter(2), false: Expression(12, Sub), condition_id: 2, true_next_id: 0, false_next_id: 0 } at (prev + 0, 13) to (start + 0, 14)
198+
true = c2
199+
false = ((c0 - c1) - c2)
200+
- Code(Expression(6, Add)) at (prev + 1, 9) to (start + 1, 13)
201+
= (c1 + c2)
202+
- MCDCDecision { bitmap_idx: 1, conditions_num: 2 } at (prev + 1, 12) to (start + 0, 18)
203+
- MCDCBranch { true: Expression(5, Sub), false: Counter(5), condition_id: 1, true_next_id: 2, false_next_id: 0 } at (prev + 0, 12) to (start + 0, 13)
204+
true = ((c1 + c2) - c5)
205+
false = c5
206+
- Code(Expression(5, Sub)) at (prev + 0, 17) to (start + 0, 18)
207+
= ((c1 + c2) - c5)
208+
- MCDCBranch { true: Counter(3), false: Counter(4), condition_id: 2, true_next_id: 0, false_next_id: 0 } at (prev + 0, 17) to (start + 0, 18)
209+
true = c3
210+
false = c4
211+
- Code(Counter(3)) at (prev + 0, 19) to (start + 2, 10)
212+
- Code(Expression(11, Add)) at (prev + 2, 10) to (start + 0, 11)
213+
= (c4 + c5)
214+
- Code(Expression(12, Sub)) at (prev + 1, 12) to (start + 2, 6)
215+
= ((c0 - c1) - c2)
216+
- Code(Expression(9, Add)) at (prev + 3, 1) to (start + 0, 2)
217+
= ((c3 + (c4 + c5)) + ((c0 - c1) - c2))
218+

tests/coverage/mcdc_if.coverage

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,55 @@
175175
LL| 2| }
176176
LL| 4|}
177177
LL| |
178+
LL| 3|fn mcdc_nested_if(a: bool, b: bool, c: bool) {
179+
LL| 3| if a || b {
180+
^0
181+
------------------
182+
|---> MC/DC Decision Region (59:8) to (59:14)
183+
|
184+
| Number of Conditions: 2
185+
| Condition C1 --> (59:8)
186+
| Condition C2 --> (59:13)
187+
|
188+
| Executed MC/DC Test Vectors:
189+
|
190+
| C1, C2 Result
191+
| 1 { T, - = T }
192+
|
193+
| C1-Pair: not covered
194+
| C2-Pair: not covered
195+
| MC/DC Coverage for Decision: 0.00%
196+
|
197+
------------------
198+
LL| 3| say("a or b");
199+
LL| 3| if b && c {
200+
^2
201+
------------------
202+
|---> MC/DC Decision Region (61:12) to (61:18)
203+
|
204+
| Number of Conditions: 2
205+
| Condition C1 --> (61:12)
206+
| Condition C2 --> (61:17)
207+
|
208+
| Executed MC/DC Test Vectors:
209+
|
210+
| C1, C2 Result
211+
| 1 { F, - = F }
212+
| 2 { T, F = F }
213+
| 3 { T, T = T }
214+
|
215+
| C1-Pair: covered: (1,3)
216+
| C2-Pair: covered: (2,3)
217+
| MC/DC Coverage for Decision: 100.00%
218+
|
219+
------------------
220+
LL| 1| say("b and c");
221+
LL| 2| }
222+
LL| 0| } else {
223+
LL| 0| say("neither a nor b");
224+
LL| 0| }
225+
LL| 3|}
226+
LL| |
178227
LL| |#[coverage(off)]
179228
LL| |fn main() {
180229
LL| | mcdc_check_neither(false, false);
@@ -199,6 +248,10 @@
199248
LL| | mcdc_check_not_tree_decision(true, true, false);
200249
LL| | mcdc_check_not_tree_decision(true, false, false);
201250
LL| | mcdc_check_not_tree_decision(true, false, true);
251+
LL| |
252+
LL| | mcdc_nested_if(true, false, true);
253+
LL| | mcdc_nested_if(true, true, true);
254+
LL| | mcdc_nested_if(true, true, false);
202255
LL| |}
203256
LL| |
204257
LL| |#[coverage(off)]

tests/coverage/mcdc_if.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ fn mcdc_check_not_tree_decision(a: bool, b: bool, c: bool) {
5555
}
5656
}
5757

58+
fn mcdc_nested_if(a: bool, b: bool, c: bool) {
59+
if a || b {
60+
say("a or b");
61+
if b && c {
62+
say("b and c");
63+
}
64+
} else {
65+
say("neither a nor b");
66+
}
67+
}
68+
5869
#[coverage(off)]
5970
fn main() {
6071
mcdc_check_neither(false, false);
@@ -79,6 +90,10 @@ fn main() {
7990
mcdc_check_not_tree_decision(true, true, false);
8091
mcdc_check_not_tree_decision(true, false, false);
8192
mcdc_check_not_tree_decision(true, false, true);
93+
94+
mcdc_nested_if(true, false, true);
95+
mcdc_nested_if(true, true, true);
96+
mcdc_nested_if(true, true, false);
8297
}
8398

8499
#[coverage(off)]

0 commit comments

Comments
 (0)