Skip to content

Commit

Permalink
coverage. Add tests for unsupported nested control structures
Browse files Browse the repository at this point in the history
  • Loading branch information
RenjiSann committed Apr 8, 2024
1 parent 4723dd0 commit db878c2
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 0 deletions.
87 changes: 87 additions & 0 deletions tests/coverage/mcdc_if.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,90 @@ Number of file 0 mappings: 14
- Code(Expression(9, Add)) at (prev + 3, 1) to (start + 0, 2)
= ((c3 + (c4 + c5)) + ((c0 - c1) - c2))

Function name: mcdc_if::mcdc_nested_if_in_body_in_condition
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]
Number of files: 1
- file 0 => global file 1
Number of expressions: 10
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Counter(1), rhs = Counter(4)
- expression 2 operands: lhs = Counter(1), rhs = Counter(4)
- expression 3 operands: lhs = Expression(6, Sub), rhs = Counter(5)
- expression 4 operands: lhs = Counter(1), rhs = Counter(4)
- expression 5 operands: lhs = Expression(6, Sub), rhs = Counter(5)
- expression 6 operands: lhs = Counter(1), rhs = Counter(4)
- expression 7 operands: lhs = Counter(2), rhs = Expression(0, Sub)
- expression 8 operands: lhs = Counter(3), rhs = Expression(9, Add)
- expression 9 operands: lhs = Counter(2), rhs = Expression(0, Sub)
Number of file 0 mappings: 14
- Code(Counter(0)) at (prev + 85, 1) to (start + 1, 9)
- MCDCDecision { bitmap_idx: 0, conditions_num: 2 } at (prev + 1, 8) to (start + 0, 60)
- 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)
true = c1
false = (c0 - c1)
- Branch { true: Counter(3), false: Counter(2) } at (prev + 0, 13) to (start + 0, 60)
true = c3
false = c2
- Code(Counter(1)) at (prev + 0, 16) to (start + 0, 17)
- 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)
true = c4
false = (c1 - c4)
- Code(Counter(4)) at (prev + 0, 20) to (start + 0, 21)
- Code(Expression(6, Sub)) at (prev + 0, 34) to (start + 0, 35)
= (c1 - c4)
- Branch { true: Counter(5), false: Expression(5, Sub) } at (prev + 0, 34) to (start + 0, 35)
true = c5
false = ((c1 - c4) - c5)
- Code(Counter(5)) at (prev + 0, 38) to (start + 0, 39)
- Code(Expression(5, Sub)) at (prev + 0, 49) to (start + 0, 50)
= ((c1 - c4) - c5)
- Code(Counter(3)) at (prev + 0, 61) to (start + 2, 6)
- Code(Expression(9, Add)) at (prev + 2, 12) to (start + 2, 6)
= (c2 + (c0 - c1))
- Code(Expression(8, Add)) at (prev + 3, 1) to (start + 0, 2)
= (c3 + (c2 + (c0 - c1)))

Function name: mcdc_if::mcdc_nested_if_in_condition
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]
Number of files: 1
- file 0 => global file 1
Number of expressions: 11
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Counter(1), rhs = Counter(4)
- expression 2 operands: lhs = Counter(1), rhs = Counter(4)
- expression 3 operands: lhs = Expression(7, Sub), rhs = Counter(5)
- expression 4 operands: lhs = Counter(1), rhs = Counter(4)
- expression 5 operands: lhs = Counter(4), rhs = Counter(5)
- expression 6 operands: lhs = Expression(7, Sub), rhs = Counter(5)
- expression 7 operands: lhs = Counter(1), rhs = Counter(4)
- expression 8 operands: lhs = Counter(2), rhs = Expression(0, Sub)
- expression 9 operands: lhs = Counter(3), rhs = Expression(10, Add)
- expression 10 operands: lhs = Counter(2), rhs = Expression(0, Sub)
Number of file 0 mappings: 13
- Code(Counter(0)) at (prev + 77, 1) to (start + 1, 9)
- MCDCDecision { bitmap_idx: 0, conditions_num: 3 } at (prev + 1, 8) to (start + 0, 46)
- 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)
true = c1
false = (c0 - c1)
- Branch { true: Counter(3), false: Counter(2) } at (prev + 0, 13) to (start + 0, 46)
true = c3
false = c2
- Code(Counter(1)) at (prev + 0, 16) to (start + 0, 17)
- 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)
true = c4
false = (c1 - c4)
- Code(Expression(7, Sub)) at (prev + 0, 21) to (start + 0, 22)
= (c1 - c4)
- 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)
true = c5
false = ((c1 - c4) - c5)
- Code(Expression(5, Add)) at (prev + 0, 25) to (start + 0, 30)
= (c4 + c5)
- Code(Expression(6, Sub)) at (prev + 0, 40) to (start + 0, 44)
= ((c1 - c4) - c5)
- Code(Counter(3)) at (prev + 0, 47) to (start + 2, 6)
- Code(Expression(10, Add)) at (prev + 2, 12) to (start + 2, 6)
= (c2 + (c0 - c1))
- Code(Expression(9, Add)) at (prev + 3, 1) to (start + 0, 2)
= (c3 + (c2 + (c0 - c1)))

77 changes: 77 additions & 0 deletions tests/coverage/mcdc_if.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,72 @@
LL| 0| }
LL| 3|}
LL| |
LL| |// The 2 following tests check for a currently unsupported behavior :
LL| |// The nesting of if-expressions inside decisions.
LL| |// The current implementation assumes that decisions in the function are
LL| |// evaluated one after another, but when nesting if-exprs like so,
LL| |// sub-expressions are evaluated within the evaluation of their parent, which
LL| |// overwrites the condition bitmap.
LL| |
LL| 5|fn mcdc_nested_if_in_condition(a: bool, b: bool, c: bool) {
LL| 5| if a && if b || c { false } else { true } {
^4 ^2 ^3 ^1
------------------
|---> MC/DC Decision Region (LL:8) to (LL:46)
|
| Number of Conditions: 3
| Condition C1 --> (LL:8)
| Condition C2 --> (LL:16)
| Condition C3 --> (LL:21)
|
| Executed MC/DC Test Vectors:
|
| C1, C2, C3 Result
| 1 { F, -, - = F }
| 2 { T, F, F = F }
| 3 { T, T, - = T }
| 4 { T, F, T = T }
|
| C1-Pair: covered: (1,3)
| C2-Pair: covered: (2,3)
| C3-Pair: covered: (2,4)
| MC/DC Coverage for Decision: 100.00%
|
------------------
LL| 1| println!("Success");
LL| 4| } else {
LL| 4| println!("Failed");
LL| 4| }
LL| 5|}
LL| |
LL| 4|fn mcdc_nested_if_in_body_in_condition(a: bool, b: bool, c: bool, d: u32) {
LL| 4| if a && if b { 0 } else { if c { 0 } else { d } } == 15 {
^3 ^2 ^1 ^1 ^0
------------------
|---> MC/DC Decision Region (LL:8) to (LL:60)
|
| Number of Conditions: 2
| Condition C1 --> (LL:8)
| Condition C2 --> (LL:16)
|
| Executed MC/DC Test Vectors:
|
| C1, C2 Result
| 1 { F, - = F }
| 2 { T, F = F }
| 3 { T, T = T }
|
| C1-Pair: covered: (1,3)
| C2-Pair: covered: (2,3)
| MC/DC Coverage for Decision: 100.00%
|
------------------
LL| 0| println!("Success");
LL| 4| } else {
LL| 4| println!("Failed");
LL| 4| }
LL| 4|}
LL| |
LL| |#[coverage(off)]
LL| |fn main() {
LL| | mcdc_check_neither(false, false);
Expand Down Expand Up @@ -253,6 +319,17 @@
LL| | mcdc_nested_if(true, false, true);
LL| | mcdc_nested_if(true, true, true);
LL| | mcdc_nested_if(true, true, false);
LL| |
LL| | mcdc_nested_if_in_condition(true, true, true);
LL| | mcdc_nested_if_in_condition(false, true, true);
LL| | mcdc_nested_if_in_condition(true, false, true);
LL| | mcdc_nested_if_in_condition(true, true, false);
LL| | mcdc_nested_if_in_condition(true, false, false);
LL| |
LL| | mcdc_nested_if_in_body_in_condition(true, true, true, 15);
LL| | mcdc_nested_if_in_body_in_condition(true, false, true, 15);
LL| | mcdc_nested_if_in_body_in_condition(true, true, false, 15);
LL| | mcdc_nested_if_in_body_in_condition(false, false, true, 15);
LL| |}
LL| |
LL| |#[coverage(off)]
Expand Down
34 changes: 34 additions & 0 deletions tests/coverage/mcdc_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ fn mcdc_nested_if(a: bool, b: bool, c: bool) {
}
}

// The 2 following tests check for a currently unsupported behavior :
// The nesting of if-expressions inside decisions.
// The current implementation assumes that decisions in the function are
// evaluated one after another, but when nesting if-exprs like so,
// sub-expressions are evaluated within the evaluation of their parent, which
// overwrites the condition bitmap.

fn mcdc_nested_if_in_condition(a: bool, b: bool, c: bool) {
if a && if b || c { false } else { true } {
println!("Success");
} else {
println!("Failed");
}
}

fn mcdc_nested_if_in_body_in_condition(a: bool, b: bool, c: bool, d: u32) {
if a && if b { 0 } else { if c { 0 } else { d } } == 15 {
println!("Success");
} else {
println!("Failed");
}
}

#[coverage(off)]
fn main() {
mcdc_check_neither(false, false);
Expand Down Expand Up @@ -95,6 +118,17 @@ fn main() {
mcdc_nested_if(true, false, true);
mcdc_nested_if(true, true, true);
mcdc_nested_if(true, true, false);

mcdc_nested_if_in_condition(true, true, true);
mcdc_nested_if_in_condition(false, true, true);
mcdc_nested_if_in_condition(true, false, true);
mcdc_nested_if_in_condition(true, true, false);
mcdc_nested_if_in_condition(true, false, false);

mcdc_nested_if_in_body_in_condition(true, true, true, 15);
mcdc_nested_if_in_body_in_condition(true, false, true, 15);
mcdc_nested_if_in_body_in_condition(true, true, false, 15);
mcdc_nested_if_in_body_in_condition(false, false, true, 15);
}

#[coverage(off)]
Expand Down

0 comments on commit db878c2

Please sign in to comment.