LL| |#![feature(coverage_attribute)] | |
LL| |//@ edition: 2021 | |
LL| |//@ min-llvm-version: 19 | |
LL| |//@ compile-flags: -Zcoverage-options=mcdc | |
LL| |//@ llvm-cov-flags: --show-branches=count --show-mcdc | |
LL| | | |
LL| 4|fn nested_if_in_condition(a: bool, b: bool, c: bool) { | |
LL| 4| if a && if b || c { true } else { false } { | |
^3 ^2 ^2 ^1 | |
------------------ | |
| Branch (LL:8): [True: 3, False: 1] | |
| Branch (LL:13): [True: 2, False: 1] | |
| Branch (LL:16): [True: 1, False: 2] | |
| Branch (LL:21): [True: 1, False: 1] | |
------------------ | |
|---> MC/DC Decision Region (LL:8) to (LL:46) | |
| | |
| Number of Conditions: 2 | |
| Condition C1 --> (LL:8) | |
| Condition C2 --> (LL:13) | |
| | |
| 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% | |
| | |
|---> MC/DC Decision Region (LL:16) to (LL:22) | |
| | |
| Number of Conditions: 2 | |
| Condition C1 --> (LL:16) | |
| Condition C2 --> (LL:21) | |
| | |
| Executed MC/DC Test Vectors: | |
| | |
| C1, C2 Result | |
| 1 { F, F = F } | |
| 2 { F, T = T } | |
| 3 { T, - = T } | |
| | |
| C1-Pair: covered: (1,3) | |
| C2-Pair: covered: (1,2) | |
| MC/DC Coverage for Decision: 100.00% | |
| | |
------------------ | |
LL| 2| say("yes"); | |
LL| 2| } else { | |
LL| 2| say("no"); | |
LL| 2| } | |
LL| 4|} | |
LL| | | |
LL| 4|fn doubly_nested_if_in_condition(a: bool, b: bool, c: bool, d: bool) { | |
LL| 4| if a && if b || if c && d { true } else { false } { false } else { true } { | |
^3 ^2 ^1 ^1 ^1 ^2 ^1 | |
------------------ | |
| Branch (LL:8): [True: 3, False: 1] | |
| Branch (LL:13): [True: 1, False: 2] | |
| Branch (LL:16): [True: 1, False: 2] | |
| Branch (LL:21): [True: 1, False: 1] | |
| Branch (LL:24): [True: 1, False: 1] | |
| Branch (LL:29): [True: 1, False: 0] | |
------------------ | |
|---> MC/DC Decision Region (LL:8) to (LL:78) | |
| | |
| Number of Conditions: 2 | |
| Condition C1 --> (LL:8) | |
| Condition C2 --> (LL:13) | |
| | |
| 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% | |
| | |
|---> MC/DC Decision Region (LL:16) to (LL:54) | |
| | |
| Number of Conditions: 2 | |
| Condition C1 --> (LL:16) | |
| Condition C2 --> (LL:21) | |
| | |
| Executed MC/DC Test Vectors: | |
| | |
| C1, C2 Result | |
| 1 { F, F = F } | |
| 2 { F, T = T } | |
| 3 { T, - = T } | |
| | |
| C1-Pair: covered: (1,3) | |
| C2-Pair: covered: (1,2) | |
| MC/DC Coverage for Decision: 100.00% | |
| | |
|---> MC/DC Decision Region (LL:24) to (LL:30) | |
| | |
| Number of Conditions: 2 | |
| Condition C1 --> (LL:24) | |
| Condition C2 --> (LL:29) | |
| | |
| Executed MC/DC Test Vectors: | |
| | |
| C1, C2 Result | |
| 1 { F, - = F } | |
| 2 { T, T = T } | |
| | |
| C1-Pair: covered: (1,2) | |
| C2-Pair: not covered | |
| MC/DC Coverage for Decision: 50.00% | |
| | |
------------------ | |
LL| 1| say("yes"); | |
LL| 3| } else { | |
LL| 3| say("no"); | |
LL| 3| } | |
LL| 4|} | |
LL| | | |
LL| 3|fn nested_single_condition_decision(a: bool, b: bool) { | |
LL| 3| // Decision with only 1 decision should not be instrumented by MCDC because | |
LL| 3| // branch-coverage is equivalent to MCDC coverage in this case, and we don't | |
LL| 3| // want to waste bitmap space for this. | |
LL| 3| if a && if b { false } else { true } { | |
^2 ^1 ^1 | |
------------------ | |
| Branch (LL:8): [True: 2, False: 1] | |
| Branch (LL:13): [True: 1, False: 1] | |
| Branch (LL:16): [True: 1, False: 1] | |
------------------ | |
|---> MC/DC Decision Region (LL:8) to (LL:41) | |
| | |
| Number of Conditions: 2 | |
| Condition C1 --> (LL:8) | |
| Condition C2 --> (LL:13) | |
| | |
| 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| 1| say("yes"); | |
LL| 2| } else { | |
LL| 2| say("no"); | |
LL| 2| } | |
LL| 3|} | |
LL| | | |
LL| 7|fn nested_in_then_block_in_condition(a: bool, b: bool, c: bool, d: bool, e: bool) { | |
LL| 7| if a && if b || c { if d && e { true } else { false } } else { false } { | |
^6 ^5 ^5 ^2 ^1 ^4 ^1 | |
------------------ | |
| Branch (LL:8): [True: 6, False: 1] | |
| Branch (LL:13): [True: 1, False: 5] | |
| Branch (LL:16): [True: 1, False: 5] | |
| Branch (LL:21): [True: 4, False: 1] | |
| Branch (LL:28): [True: 2, False: 3] | |
| Branch (LL:33): [True: 1, False: 1] | |
------------------ | |
|---> MC/DC Decision Region (LL:8) to (LL:75) | |
| | |
| Number of Conditions: 2 | |
| Condition C1 --> (LL:8) | |
| Condition C2 --> (LL:13) | |
| | |
| 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% | |
| | |
|---> MC/DC Decision Region (LL:16) to (LL:22) | |
| | |
| Number of Conditions: 2 | |
| Condition C1 --> (LL:16) | |
| Condition C2 --> (LL:21) | |
| | |
| Executed MC/DC Test Vectors: | |
| | |
| C1, C2 Result | |
| 1 { F, F = F } | |
| 2 { F, T = T } | |
| 3 { T, - = T } | |
| | |
| C1-Pair: covered: (1,3) | |
| C2-Pair: covered: (1,2) | |
| MC/DC Coverage for Decision: 100.00% | |
| | |
|---> MC/DC Decision Region (LL:28) to (LL:34) | |
| | |
| Number of Conditions: 2 | |
| Condition C1 --> (LL:28) | |
| Condition C2 --> (LL:33) | |
| | |
| 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| 1| say("yes"); | |
LL| 6| } else { | |
LL| 6| say("no"); | |
LL| 6| } | |
LL| 7|} | |
LL| | | |
LL| |#[coverage(off)] | |
LL| |fn main() { | |
LL| | nested_if_in_condition(true, false, false); | |
LL| | nested_if_in_condition(true, true, true); | |
LL| | nested_if_in_condition(true, false, true); | |
LL| | nested_if_in_condition(false, true, true); | |
LL| | | |
LL| | doubly_nested_if_in_condition(true, false, false, true); | |
LL| | doubly_nested_if_in_condition(true, true, true, true); | |
LL| | doubly_nested_if_in_condition(true, false, true, true); | |
LL| | doubly_nested_if_in_condition(false, true, true, true); | |
LL| | | |
LL| | nested_single_condition_decision(true, true); | |
LL| | nested_single_condition_decision(true, false); | |
LL| | nested_single_condition_decision(false, false); | |
LL| | | |
LL| | nested_in_then_block_in_condition(false, false, false, false, false); | |
LL| | nested_in_then_block_in_condition(true, false, false, false, false); | |
LL| | nested_in_then_block_in_condition(true, true, false, false, false); | |
LL| | nested_in_then_block_in_condition(true, false, true, false, false); | |
LL| | nested_in_then_block_in_condition(true, false, true, true, false); | |
LL| | nested_in_then_block_in_condition(true, false, true, false, true); | |
LL| | nested_in_then_block_in_condition(true, false, true, true, true); | |
LL| |} | |
LL| | | |
LL| |#[coverage(off)] | |
LL| |fn say(message: &str) { | |
LL| | core::hint::black_box(message); | |
LL| |} | |