Skip to content
/ rust Public
forked from rust-lang/rust

Commit c858b97

Browse files
committed
coverage. Add test for while-loops instrumentation
1 parent db878c2 commit c858b97

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

tests/coverage/mcdc_if.cov-map

+43
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,46 @@ Number of file 0 mappings: 13
303303
- Code(Expression(9, Add)) at (prev + 3, 1) to (start + 0, 2)
304304
= (c3 + (c2 + (c0 - c1)))
305305

306+
Function name: mcdc_if::mcdc_while
307+
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]
308+
Number of files: 1
309+
- file 0 => global file 1
310+
Number of expressions: 16
311+
- expression 0 operands: lhs = Counter(0), rhs = Expression(11, Add)
312+
- expression 1 operands: lhs = Counter(1), rhs = Counter(2)
313+
- expression 2 operands: lhs = Expression(0, Add), rhs = Counter(3)
314+
- expression 3 operands: lhs = Counter(3), rhs = Counter(1)
315+
- expression 4 operands: lhs = Expression(14, Sub), rhs = Expression(15, Sub)
316+
- expression 5 operands: lhs = Counter(3), rhs = Counter(1)
317+
- expression 6 operands: lhs = Expression(0, Add), rhs = Counter(3)
318+
- expression 7 operands: lhs = Expression(13, Add), rhs = Counter(2)
319+
- expression 8 operands: lhs = Expression(14, Sub), rhs = Expression(15, Sub)
320+
- expression 9 operands: lhs = Counter(3), rhs = Counter(1)
321+
- expression 10 operands: lhs = Expression(0, Add), rhs = Counter(3)
322+
- expression 11 operands: lhs = Counter(1), rhs = Counter(2)
323+
- expression 12 operands: lhs = Expression(13, Add), rhs = Counter(2)
324+
- expression 13 operands: lhs = Expression(14, Sub), rhs = Expression(15, Sub)
325+
- expression 14 operands: lhs = Counter(3), rhs = Counter(1)
326+
- expression 15 operands: lhs = Expression(0, Add), rhs = Counter(3)
327+
Number of file 0 mappings: 10
328+
- Code(Counter(0)) at (prev + 94, 1) to (start + 6, 18)
329+
- Code(Expression(0, Add)) at (prev + 8, 11) to (start + 0, 22)
330+
= (c0 + (c1 + c2))
331+
- MCDCDecision { bitmap_idx: 0, conditions_num: 3 } at (prev + 0, 11) to (start + 0, 52)
332+
- 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)
333+
true = c3
334+
false = ((c0 + (c1 + c2)) - c3)
335+
- Code(Counter(3)) at (prev + 0, 26) to (start + 0, 37)
336+
- 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)
337+
true = c1
338+
false = (c3 - c1)
339+
- Code(Expression(13, Add)) at (prev + 0, 41) to (start + 0, 52)
340+
= ((c3 - c1) + ((c0 + (c1 + c2)) - c3))
341+
- 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)
342+
true = c2
343+
false = (((c3 - c1) + ((c0 + (c1 + c2)) - c3)) - c2)
344+
- Code(Expression(11, Add)) at (prev + 1, 9) to (start + 0, 15)
345+
= (c1 + c2)
346+
- Code(Expression(12, Sub)) at (prev + 2, 1) to (start + 0, 2)
347+
= (((c3 - c1) + ((c0 + (c1 + c2)) - c3)) - c2)
348+

tests/coverage/mcdc_if.coverage

+38
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,42 @@
291291
LL| 4| }
292292
LL| 4|}
293293
LL| |
294+
LL| |// Test that while control flow structures are correctly instrumented.
295+
LL| 1|fn mcdc_while() {
296+
LL| 1| let values = [
297+
LL| 1| (false, true, true),
298+
LL| 1| (true, false, true),
299+
LL| 1| (true, false, false),
300+
LL| 1| ];
301+
LL| 1| let mut i = 0;
302+
LL| |
303+
LL| 3| while values[i].0 && values[i].1 || values[i].2 {
304+
^2
305+
------------------
306+
|---> MC/DC Decision Region (LL:11) to (LL:52)
307+
|
308+
| Number of Conditions: 3
309+
| Condition C1 --> (LL:11)
310+
| Condition C2 --> (LL:26)
311+
| Condition C3 --> (LL:41)
312+
|
313+
| Executed MC/DC Test Vectors:
314+
|
315+
| C1, C2, C3 Result
316+
| 1 { T, F, F = F }
317+
| 2 { F, -, T = T }
318+
| 3 { T, F, T = T }
319+
|
320+
| C1-Pair: not covered
321+
| C2-Pair: not covered
322+
| C3-Pair: covered: (1,3)
323+
| MC/DC Coverage for Decision: 33.33%
324+
|
325+
------------------
326+
LL| 2| i += 1
327+
LL| | }
328+
LL| 1|}
329+
LL| |
294330
LL| |#[coverage(off)]
295331
LL| |fn main() {
296332
LL| | mcdc_check_neither(false, false);
@@ -330,6 +366,8 @@
330366
LL| | mcdc_nested_if_in_body_in_condition(true, false, true, 15);
331367
LL| | mcdc_nested_if_in_body_in_condition(true, true, false, 15);
332368
LL| | mcdc_nested_if_in_body_in_condition(false, false, true, 15);
369+
LL| |
370+
LL| | mcdc_while();
333371
LL| |}
334372
LL| |
335373
LL| |#[coverage(off)]

tests/coverage/mcdc_if.rs

+16
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ fn mcdc_nested_if_in_body_in_condition(a: bool, b: bool, c: bool, d: u32) {
9090
}
9191
}
9292

93+
// Test that while control flow structures are correctly instrumented.
94+
fn mcdc_while() {
95+
let values = [
96+
(false, true, true),
97+
(true, false, true),
98+
(true, false, false),
99+
];
100+
let mut i = 0;
101+
102+
while values[i].0 && values[i].1 || values[i].2 {
103+
i += 1
104+
}
105+
}
106+
93107
#[coverage(off)]
94108
fn main() {
95109
mcdc_check_neither(false, false);
@@ -129,6 +143,8 @@ fn main() {
129143
mcdc_nested_if_in_body_in_condition(true, false, true, 15);
130144
mcdc_nested_if_in_body_in_condition(true, true, false, 15);
131145
mcdc_nested_if_in_body_in_condition(false, false, true, 15);
146+
147+
mcdc_while();
132148
}
133149

134150
#[coverage(off)]

0 commit comments

Comments
 (0)