Skip to content

Commit

Permalink
coverage. Add tests for while-loops
Browse files Browse the repository at this point in the history
  • Loading branch information
RenjiSann committed Apr 8, 2024
1 parent db878c2 commit dedf131
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/coverage/mcdc_if.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,46 @@ Number of file 0 mappings: 13
- Code(Expression(9, Add)) at (prev + 3, 1) to (start + 0, 2)
= (c3 + (c2 + (c0 - c1)))

Function name: mcdc_if::mcdc_while
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, 5e, 01, 06, 12, 03, 08, 0b, 00, 16, 28, 00, 03, 00, 0b, 00, 34, 30, 0d, 3e, 01, 03, 02, 00, 0b, 00, 16, 0d, 00, 1a, 00, 25, 30, 05, 3a, 03, 00, 02, 00, 1a, 00, 25, 37, 00, 29, 00, 34, 30, 09, 32, 02, 00, 00, 00, 29, 00, 34, 2f, 01, 09, 00, 0f, 32, 02, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 16
- expression 0 operands: lhs = Counter(0), rhs = Expression(11, Add)
- expression 1 operands: lhs = Counter(1), rhs = Counter(2)
- expression 2 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 3 operands: lhs = Counter(3), rhs = Counter(1)
- expression 4 operands: lhs = Expression(14, Sub), rhs = Expression(15, Sub)
- expression 5 operands: lhs = Counter(3), rhs = Counter(1)
- expression 6 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 7 operands: lhs = Expression(13, Add), rhs = Counter(2)
- expression 8 operands: lhs = Expression(14, Sub), rhs = Expression(15, Sub)
- expression 9 operands: lhs = Counter(3), rhs = Counter(1)
- expression 10 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 11 operands: lhs = Counter(1), rhs = Counter(2)
- expression 12 operands: lhs = Expression(13, Add), rhs = Counter(2)
- expression 13 operands: lhs = Expression(14, Sub), rhs = Expression(15, Sub)
- expression 14 operands: lhs = Counter(3), rhs = Counter(1)
- expression 15 operands: lhs = Expression(0, Add), rhs = Counter(3)
Number of file 0 mappings: 10
- Code(Counter(0)) at (prev + 94, 1) to (start + 6, 18)
- Code(Expression(0, Add)) at (prev + 8, 11) to (start + 0, 22)
= (c0 + (c1 + c2))
- MCDCDecision { bitmap_idx: 0, conditions_num: 3 } at (prev + 0, 11) to (start + 0, 52)
- MCDCBranch { true: Counter(3), false: Expression(15, Sub), condition_id: 1, true_next_id: 3, false_next_id: 2 } at (prev + 0, 11) to (start + 0, 22)
true = c3
false = ((c0 + (c1 + c2)) - c3)
- Code(Counter(3)) at (prev + 0, 26) to (start + 0, 37)
- MCDCBranch { true: Counter(1), false: Expression(14, Sub), condition_id: 3, true_next_id: 0, false_next_id: 2 } at (prev + 0, 26) to (start + 0, 37)
true = c1
false = (c3 - c1)
- Code(Expression(13, Add)) at (prev + 0, 41) to (start + 0, 52)
= ((c3 - c1) + ((c0 + (c1 + c2)) - c3))
- MCDCBranch { true: Counter(2), false: Expression(12, Sub), condition_id: 2, true_next_id: 0, false_next_id: 0 } at (prev + 0, 41) to (start + 0, 52)
true = c2
false = (((c3 - c1) + ((c0 + (c1 + c2)) - c3)) - c2)
- Code(Expression(11, Add)) at (prev + 1, 9) to (start + 0, 15)
= (c1 + c2)
- Code(Expression(12, Sub)) at (prev + 2, 1) to (start + 0, 2)
= (((c3 - c1) + ((c0 + (c1 + c2)) - c3)) - c2)

38 changes: 38 additions & 0 deletions tests/coverage/mcdc_if.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,42 @@
LL| 4| }
LL| 4|}
LL| |
LL| |// Test that while control flow structures are correctly instrumented.
LL| 1|fn mcdc_while() {
LL| 1| let values = [
LL| 1| (false, true, true),
LL| 1| (true, false, true),
LL| 1| (true, false, false),
LL| 1| ];
LL| 1| let mut i = 0;
LL| |
LL| 3| while values[i].0 && values[i].1 || values[i].2 {
^2
------------------
|---> MC/DC Decision Region (LL:11) to (LL:52)
|
| Number of Conditions: 3
| Condition C1 --> (LL:11)
| Condition C2 --> (LL:26)
| Condition C3 --> (LL:41)
|
| Executed MC/DC Test Vectors:
|
| C1, C2, C3 Result
| 1 { T, F, F = F }
| 2 { F, -, T = T }
| 3 { T, F, T = T }
|
| C1-Pair: not covered
| C2-Pair: not covered
| C3-Pair: covered: (1,3)
| MC/DC Coverage for Decision: 33.33%
|
------------------
LL| 2| i += 1
LL| | }
LL| 1|}
LL| |
LL| |#[coverage(off)]
LL| |fn main() {
LL| | mcdc_check_neither(false, false);
Expand Down Expand Up @@ -330,6 +366,8 @@
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| | mcdc_while();
LL| |}
LL| |
LL| |#[coverage(off)]
Expand Down
16 changes: 16 additions & 0 deletions tests/coverage/mcdc_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ fn mcdc_nested_if_in_body_in_condition(a: bool, b: bool, c: bool, d: u32) {
}
}

// Test that while control flow structures are correctly instrumented.
fn mcdc_while() {
let values = [
(false, true, true),
(true, false, true),
(true, false, false),
];
let mut i = 0;

while values[i].0 && values[i].1 || values[i].2 {
i += 1
}
}

#[coverage(off)]
fn main() {
mcdc_check_neither(false, false);
Expand Down Expand Up @@ -129,6 +143,8 @@ fn main() {
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);

mcdc_while();
}

#[coverage(off)]
Expand Down

0 comments on commit dedf131

Please sign in to comment.