Skip to content

Commit db878c2

Browse files
committed
coverage. Add tests for unsupported nested control structures
1 parent 4723dd0 commit db878c2

File tree

3 files changed

+198
-0
lines changed

3 files changed

+198
-0
lines changed

tests/coverage/mcdc_if.cov-map

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,90 @@ Number of file 0 mappings: 14
216216
- Code(Expression(9, Add)) at (prev + 3, 1) to (start + 0, 2)
217217
= ((c3 + (c4 + c5)) + ((c0 - c1) - c2))
218218

219+
Function name: mcdc_if::mcdc_nested_if_in_body_in_condition
220+
Raw bytes (110): 0x[01, 01, 0a, 01, 05, 05, 11, 05, 11, 1a, 15, 05, 11, 1a, 15, 05, 11, 09, 02, 0d, 27, 09, 02, 0e, 01, 55, 01, 01, 09, 28, 00, 02, 01, 08, 00, 3c, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 20, 0d, 09, 00, 0d, 00, 3c, 05, 00, 10, 00, 11, 30, 11, 1a, 02, 00, 00, 00, 10, 00, 11, 11, 00, 14, 00, 15, 1a, 00, 22, 00, 23, 20, 15, 16, 00, 22, 00, 23, 15, 00, 26, 00, 27, 16, 00, 31, 00, 32, 0d, 00, 3d, 02, 06, 27, 02, 0c, 02, 06, 23, 03, 01, 00, 02]
221+
Number of files: 1
222+
- file 0 => global file 1
223+
Number of expressions: 10
224+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
225+
- expression 1 operands: lhs = Counter(1), rhs = Counter(4)
226+
- expression 2 operands: lhs = Counter(1), rhs = Counter(4)
227+
- expression 3 operands: lhs = Expression(6, Sub), rhs = Counter(5)
228+
- expression 4 operands: lhs = Counter(1), rhs = Counter(4)
229+
- expression 5 operands: lhs = Expression(6, Sub), rhs = Counter(5)
230+
- expression 6 operands: lhs = Counter(1), rhs = Counter(4)
231+
- expression 7 operands: lhs = Counter(2), rhs = Expression(0, Sub)
232+
- expression 8 operands: lhs = Counter(3), rhs = Expression(9, Add)
233+
- expression 9 operands: lhs = Counter(2), rhs = Expression(0, Sub)
234+
Number of file 0 mappings: 14
235+
- Code(Counter(0)) at (prev + 85, 1) to (start + 1, 9)
236+
- MCDCDecision { bitmap_idx: 0, conditions_num: 2 } at (prev + 1, 8) to (start + 0, 60)
237+
- MCDCBranch { true: Counter(1), false: Expression(0, Sub), condition_id: 1, true_next_id: 2, false_next_id: 0 } at (prev + 0, 8) to (start + 0, 9)
238+
true = c1
239+
false = (c0 - c1)
240+
- Branch { true: Counter(3), false: Counter(2) } at (prev + 0, 13) to (start + 0, 60)
241+
true = c3
242+
false = c2
243+
- Code(Counter(1)) at (prev + 0, 16) to (start + 0, 17)
244+
- MCDCBranch { true: Counter(4), false: Expression(6, Sub), condition_id: 2, true_next_id: 0, false_next_id: 0 } at (prev + 0, 16) to (start + 0, 17)
245+
true = c4
246+
false = (c1 - c4)
247+
- Code(Counter(4)) at (prev + 0, 20) to (start + 0, 21)
248+
- Code(Expression(6, Sub)) at (prev + 0, 34) to (start + 0, 35)
249+
= (c1 - c4)
250+
- Branch { true: Counter(5), false: Expression(5, Sub) } at (prev + 0, 34) to (start + 0, 35)
251+
true = c5
252+
false = ((c1 - c4) - c5)
253+
- Code(Counter(5)) at (prev + 0, 38) to (start + 0, 39)
254+
- Code(Expression(5, Sub)) at (prev + 0, 49) to (start + 0, 50)
255+
= ((c1 - c4) - c5)
256+
- Code(Counter(3)) at (prev + 0, 61) to (start + 2, 6)
257+
- Code(Expression(9, Add)) at (prev + 2, 12) to (start + 2, 6)
258+
= (c2 + (c0 - c1))
259+
- Code(Expression(8, Add)) at (prev + 3, 1) to (start + 0, 2)
260+
= (c3 + (c2 + (c0 - c1)))
261+
262+
Function name: mcdc_if::mcdc_nested_if_in_condition
263+
Raw bytes (110): 0x[01, 01, 0b, 01, 05, 05, 11, 05, 11, 1e, 15, 05, 11, 11, 15, 1e, 15, 05, 11, 09, 02, 0d, 2b, 09, 02, 0d, 01, 4d, 01, 01, 09, 28, 00, 03, 01, 08, 00, 2e, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 20, 0d, 09, 00, 0d, 00, 2e, 05, 00, 10, 00, 11, 30, 11, 1e, 02, 00, 03, 00, 10, 00, 11, 1e, 00, 15, 00, 16, 30, 15, 1a, 03, 00, 00, 00, 15, 00, 16, 17, 00, 19, 00, 1e, 1a, 00, 28, 00, 2c, 0d, 00, 2f, 02, 06, 2b, 02, 0c, 02, 06, 27, 03, 01, 00, 02]
264+
Number of files: 1
265+
- file 0 => global file 1
266+
Number of expressions: 11
267+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
268+
- expression 1 operands: lhs = Counter(1), rhs = Counter(4)
269+
- expression 2 operands: lhs = Counter(1), rhs = Counter(4)
270+
- expression 3 operands: lhs = Expression(7, Sub), rhs = Counter(5)
271+
- expression 4 operands: lhs = Counter(1), rhs = Counter(4)
272+
- expression 5 operands: lhs = Counter(4), rhs = Counter(5)
273+
- expression 6 operands: lhs = Expression(7, Sub), rhs = Counter(5)
274+
- expression 7 operands: lhs = Counter(1), rhs = Counter(4)
275+
- expression 8 operands: lhs = Counter(2), rhs = Expression(0, Sub)
276+
- expression 9 operands: lhs = Counter(3), rhs = Expression(10, Add)
277+
- expression 10 operands: lhs = Counter(2), rhs = Expression(0, Sub)
278+
Number of file 0 mappings: 13
279+
- Code(Counter(0)) at (prev + 77, 1) to (start + 1, 9)
280+
- MCDCDecision { bitmap_idx: 0, conditions_num: 3 } at (prev + 1, 8) to (start + 0, 46)
281+
- MCDCBranch { true: Counter(1), false: Expression(0, Sub), condition_id: 1, true_next_id: 2, false_next_id: 0 } at (prev + 0, 8) to (start + 0, 9)
282+
true = c1
283+
false = (c0 - c1)
284+
- Branch { true: Counter(3), false: Counter(2) } at (prev + 0, 13) to (start + 0, 46)
285+
true = c3
286+
false = c2
287+
- Code(Counter(1)) at (prev + 0, 16) to (start + 0, 17)
288+
- MCDCBranch { true: Counter(4), false: Expression(7, Sub), condition_id: 2, true_next_id: 0, false_next_id: 3 } at (prev + 0, 16) to (start + 0, 17)
289+
true = c4
290+
false = (c1 - c4)
291+
- Code(Expression(7, Sub)) at (prev + 0, 21) to (start + 0, 22)
292+
= (c1 - c4)
293+
- MCDCBranch { true: Counter(5), false: Expression(6, Sub), condition_id: 3, true_next_id: 0, false_next_id: 0 } at (prev + 0, 21) to (start + 0, 22)
294+
true = c5
295+
false = ((c1 - c4) - c5)
296+
- Code(Expression(5, Add)) at (prev + 0, 25) to (start + 0, 30)
297+
= (c4 + c5)
298+
- Code(Expression(6, Sub)) at (prev + 0, 40) to (start + 0, 44)
299+
= ((c1 - c4) - c5)
300+
- Code(Counter(3)) at (prev + 0, 47) to (start + 2, 6)
301+
- Code(Expression(10, Add)) at (prev + 2, 12) to (start + 2, 6)
302+
= (c2 + (c0 - c1))
303+
- Code(Expression(9, Add)) at (prev + 3, 1) to (start + 0, 2)
304+
= (c3 + (c2 + (c0 - c1)))
305+

tests/coverage/mcdc_if.coverage

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,72 @@
225225
LL| 0| }
226226
LL| 3|}
227227
LL| |
228+
LL| |// The 2 following tests check for a currently unsupported behavior :
229+
LL| |// The nesting of if-expressions inside decisions.
230+
LL| |// The current implementation assumes that decisions in the function are
231+
LL| |// evaluated one after another, but when nesting if-exprs like so,
232+
LL| |// sub-expressions are evaluated within the evaluation of their parent, which
233+
LL| |// overwrites the condition bitmap.
234+
LL| |
235+
LL| 5|fn mcdc_nested_if_in_condition(a: bool, b: bool, c: bool) {
236+
LL| 5| if a && if b || c { false } else { true } {
237+
^4 ^2 ^3 ^1
238+
------------------
239+
|---> MC/DC Decision Region (LL:8) to (LL:46)
240+
|
241+
| Number of Conditions: 3
242+
| Condition C1 --> (LL:8)
243+
| Condition C2 --> (LL:16)
244+
| Condition C3 --> (LL:21)
245+
|
246+
| Executed MC/DC Test Vectors:
247+
|
248+
| C1, C2, C3 Result
249+
| 1 { F, -, - = F }
250+
| 2 { T, F, F = F }
251+
| 3 { T, T, - = T }
252+
| 4 { T, F, T = T }
253+
|
254+
| C1-Pair: covered: (1,3)
255+
| C2-Pair: covered: (2,3)
256+
| C3-Pair: covered: (2,4)
257+
| MC/DC Coverage for Decision: 100.00%
258+
|
259+
------------------
260+
LL| 1| println!("Success");
261+
LL| 4| } else {
262+
LL| 4| println!("Failed");
263+
LL| 4| }
264+
LL| 5|}
265+
LL| |
266+
LL| 4|fn mcdc_nested_if_in_body_in_condition(a: bool, b: bool, c: bool, d: u32) {
267+
LL| 4| if a && if b { 0 } else { if c { 0 } else { d } } == 15 {
268+
^3 ^2 ^1 ^1 ^0
269+
------------------
270+
|---> MC/DC Decision Region (LL:8) to (LL:60)
271+
|
272+
| Number of Conditions: 2
273+
| Condition C1 --> (LL:8)
274+
| Condition C2 --> (LL:16)
275+
|
276+
| Executed MC/DC Test Vectors:
277+
|
278+
| C1, C2 Result
279+
| 1 { F, - = F }
280+
| 2 { T, F = F }
281+
| 3 { T, T = T }
282+
|
283+
| C1-Pair: covered: (1,3)
284+
| C2-Pair: covered: (2,3)
285+
| MC/DC Coverage for Decision: 100.00%
286+
|
287+
------------------
288+
LL| 0| println!("Success");
289+
LL| 4| } else {
290+
LL| 4| println!("Failed");
291+
LL| 4| }
292+
LL| 4|}
293+
LL| |
228294
LL| |#[coverage(off)]
229295
LL| |fn main() {
230296
LL| | mcdc_check_neither(false, false);
@@ -253,6 +319,17 @@
253319
LL| | mcdc_nested_if(true, false, true);
254320
LL| | mcdc_nested_if(true, true, true);
255321
LL| | mcdc_nested_if(true, true, false);
322+
LL| |
323+
LL| | mcdc_nested_if_in_condition(true, true, true);
324+
LL| | mcdc_nested_if_in_condition(false, true, true);
325+
LL| | mcdc_nested_if_in_condition(true, false, true);
326+
LL| | mcdc_nested_if_in_condition(true, true, false);
327+
LL| | mcdc_nested_if_in_condition(true, false, false);
328+
LL| |
329+
LL| | mcdc_nested_if_in_body_in_condition(true, true, true, 15);
330+
LL| | mcdc_nested_if_in_body_in_condition(true, false, true, 15);
331+
LL| | mcdc_nested_if_in_body_in_condition(true, true, false, 15);
332+
LL| | mcdc_nested_if_in_body_in_condition(false, false, true, 15);
256333
LL| |}
257334
LL| |
258335
LL| |#[coverage(off)]

tests/coverage/mcdc_if.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ fn mcdc_nested_if(a: bool, b: bool, c: bool) {
6767
}
6868
}
6969

70+
// The 2 following tests check for a currently unsupported behavior :
71+
// The nesting of if-expressions inside decisions.
72+
// The current implementation assumes that decisions in the function are
73+
// evaluated one after another, but when nesting if-exprs like so,
74+
// sub-expressions are evaluated within the evaluation of their parent, which
75+
// overwrites the condition bitmap.
76+
77+
fn mcdc_nested_if_in_condition(a: bool, b: bool, c: bool) {
78+
if a && if b || c { false } else { true } {
79+
println!("Success");
80+
} else {
81+
println!("Failed");
82+
}
83+
}
84+
85+
fn mcdc_nested_if_in_body_in_condition(a: bool, b: bool, c: bool, d: u32) {
86+
if a && if b { 0 } else { if c { 0 } else { d } } == 15 {
87+
println!("Success");
88+
} else {
89+
println!("Failed");
90+
}
91+
}
92+
7093
#[coverage(off)]
7194
fn main() {
7295
mcdc_check_neither(false, false);
@@ -95,6 +118,17 @@ fn main() {
95118
mcdc_nested_if(true, false, true);
96119
mcdc_nested_if(true, true, true);
97120
mcdc_nested_if(true, true, false);
121+
122+
mcdc_nested_if_in_condition(true, true, true);
123+
mcdc_nested_if_in_condition(false, true, true);
124+
mcdc_nested_if_in_condition(true, false, true);
125+
mcdc_nested_if_in_condition(true, true, false);
126+
mcdc_nested_if_in_condition(true, false, false);
127+
128+
mcdc_nested_if_in_body_in_condition(true, true, true, 15);
129+
mcdc_nested_if_in_body_in_condition(true, false, true, 15);
130+
mcdc_nested_if_in_body_in_condition(true, true, false, 15);
131+
mcdc_nested_if_in_body_in_condition(false, false, true, 15);
98132
}
99133

100134
#[coverage(off)]

0 commit comments

Comments
 (0)