263 lines
7.4 KiB
Plaintext
263 lines
7.4 KiB
Plaintext
LL| |#![feature(coverage_attribute)]
|
|
LL| |//@ edition: 2021
|
|
LL| |//@ min-llvm-version: 18
|
|
LL| |//@ compile-flags: -Zcoverage-options=mcdc
|
|
LL| |//@ llvm-cov-flags: --show-mcdc
|
|
LL| |
|
|
LL| 2|fn mcdc_check_neither(a: bool, b: bool) {
|
|
LL| 2| if a && b {
|
|
^0
|
|
------------------
|
|
|---> MC/DC Decision Region (LL:8) to (LL:14)
|
|
|
|
|
| Number of Conditions: 2
|
|
| Condition C1 --> (LL:8)
|
|
| Condition C2 --> (LL:13)
|
|
|
|
|
| Executed MC/DC Test Vectors:
|
|
|
|
|
| C1, C2 Result
|
|
| 1 { F, - = F }
|
|
|
|
|
| C1-Pair: not covered
|
|
| C2-Pair: not covered
|
|
| MC/DC Coverage for Decision: 0.00%
|
|
|
|
|
------------------
|
|
LL| 0| say("a and b");
|
|
LL| 2| } else {
|
|
LL| 2| say("not both");
|
|
LL| 2| }
|
|
LL| 2|}
|
|
LL| |
|
|
LL| 2|fn mcdc_check_a(a: bool, b: bool) {
|
|
LL| 2| if a && b {
|
|
^1
|
|
------------------
|
|
|---> MC/DC Decision Region (LL:8) to (LL:14)
|
|
|
|
|
| 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, T = T }
|
|
|
|
|
| C1-Pair: covered: (1,2)
|
|
| C2-Pair: not covered
|
|
| MC/DC Coverage for Decision: 50.00%
|
|
|
|
|
------------------
|
|
LL| 1| say("a and b");
|
|
LL| 1| } else {
|
|
LL| 1| say("not both");
|
|
LL| 1| }
|
|
LL| 2|}
|
|
LL| |
|
|
LL| 2|fn mcdc_check_b(a: bool, b: bool) {
|
|
LL| 2| if a && b {
|
|
------------------
|
|
|---> MC/DC Decision Region (LL:8) to (LL:14)
|
|
|
|
|
| Number of Conditions: 2
|
|
| Condition C1 --> (LL:8)
|
|
| Condition C2 --> (LL:13)
|
|
|
|
|
| Executed MC/DC Test Vectors:
|
|
|
|
|
| C1, C2 Result
|
|
| 1 { T, F = F }
|
|
| 2 { T, T = T }
|
|
|
|
|
| C1-Pair: not covered
|
|
| C2-Pair: covered: (1,2)
|
|
| MC/DC Coverage for Decision: 50.00%
|
|
|
|
|
------------------
|
|
LL| 1| say("a and b");
|
|
LL| 1| } else {
|
|
LL| 1| say("not both");
|
|
LL| 1| }
|
|
LL| 2|}
|
|
LL| |
|
|
LL| 3|fn mcdc_check_both(a: bool, b: bool) {
|
|
LL| 3| if a && b {
|
|
^2
|
|
------------------
|
|
|---> MC/DC Decision Region (LL:8) to (LL:14)
|
|
|
|
|
| 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("a and b");
|
|
LL| 2| } else {
|
|
LL| 2| say("not both");
|
|
LL| 2| }
|
|
LL| 3|}
|
|
LL| |
|
|
LL| 4|fn mcdc_check_tree_decision(a: bool, b: bool, c: bool) {
|
|
LL| 4| // This expression is intentionally written in a way
|
|
LL| 4| // where 100% branch coverage indicates 100% mcdc coverage.
|
|
LL| 4| if a && (b || c) {
|
|
^3 ^2
|
|
------------------
|
|
|---> MC/DC Decision Region (LL:8) to (LL:21)
|
|
|
|
|
| Number of Conditions: 3
|
|
| Condition C1 --> (LL:8)
|
|
| Condition C2 --> (LL:14)
|
|
| Condition C3 --> (LL:19)
|
|
|
|
|
| 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| 2| say("pass");
|
|
LL| 2| } else {
|
|
LL| 2| say("reject");
|
|
LL| 2| }
|
|
LL| 4|}
|
|
LL| |
|
|
LL| 4|fn mcdc_check_not_tree_decision(a: bool, b: bool, c: bool) {
|
|
LL| 4| // Contradict to `mcdc_check_tree_decision`,
|
|
LL| 4| // 100% branch coverage of this expression does not mean indicates 100% mcdc coverage.
|
|
LL| 4| if (a || b) && c {
|
|
^1
|
|
------------------
|
|
|---> MC/DC Decision Region (LL:8) to (LL:21)
|
|
|
|
|
| Number of Conditions: 3
|
|
| Condition C1 --> (LL:9)
|
|
| Condition C2 --> (LL:14)
|
|
| Condition C3 --> (LL:20)
|
|
|
|
|
| Executed MC/DC Test Vectors:
|
|
|
|
|
| C1, C2, C3 Result
|
|
| 1 { T, -, F = F }
|
|
| 2 { T, -, T = T }
|
|
| 3 { F, T, T = T }
|
|
|
|
|
| C1-Pair: not covered
|
|
| C2-Pair: not covered
|
|
| C3-Pair: covered: (1,2)
|
|
| MC/DC Coverage for Decision: 33.33%
|
|
|
|
|
------------------
|
|
LL| 2| say("pass");
|
|
LL| 2| } else {
|
|
LL| 2| say("reject");
|
|
LL| 2| }
|
|
LL| 4|}
|
|
LL| |
|
|
LL| 3|fn mcdc_nested_if(a: bool, b: bool, c: bool) {
|
|
LL| 3| if a || b {
|
|
^0
|
|
------------------
|
|
|---> MC/DC Decision Region (LL:8) to (LL:14)
|
|
|
|
|
| Number of Conditions: 2
|
|
| Condition C1 --> (LL:8)
|
|
| Condition C2 --> (LL:13)
|
|
|
|
|
| Executed MC/DC Test Vectors:
|
|
|
|
|
| C1, C2 Result
|
|
| 1 { T, - = T }
|
|
|
|
|
| C1-Pair: not covered
|
|
| C2-Pair: not covered
|
|
| MC/DC Coverage for Decision: 0.00%
|
|
|
|
|
------------------
|
|
LL| 3| say("a or b");
|
|
LL| 3| if b && c {
|
|
^2
|
|
------------------
|
|
|---> MC/DC Decision Region (LL:12) to (LL:18)
|
|
|
|
|
| Number of Conditions: 2
|
|
| Condition C1 --> (LL:12)
|
|
| Condition C2 --> (LL:17)
|
|
|
|
|
| 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("b and c");
|
|
LL| 2| }
|
|
LL| 0| } else {
|
|
LL| 0| say("neither a nor b");
|
|
LL| 0| }
|
|
LL| 3|}
|
|
LL| |
|
|
LL| |#[coverage(off)]
|
|
LL| |fn main() {
|
|
LL| | mcdc_check_neither(false, false);
|
|
LL| | mcdc_check_neither(false, true);
|
|
LL| |
|
|
LL| | mcdc_check_a(true, true);
|
|
LL| | mcdc_check_a(false, true);
|
|
LL| |
|
|
LL| | mcdc_check_b(true, true);
|
|
LL| | mcdc_check_b(true, false);
|
|
LL| |
|
|
LL| | mcdc_check_both(false, true);
|
|
LL| | mcdc_check_both(true, true);
|
|
LL| | mcdc_check_both(true, false);
|
|
LL| |
|
|
LL| | mcdc_check_tree_decision(false, true, true);
|
|
LL| | mcdc_check_tree_decision(true, true, false);
|
|
LL| | mcdc_check_tree_decision(true, false, false);
|
|
LL| | mcdc_check_tree_decision(true, false, true);
|
|
LL| |
|
|
LL| | mcdc_check_not_tree_decision(false, true, true);
|
|
LL| | mcdc_check_not_tree_decision(true, true, false);
|
|
LL| | mcdc_check_not_tree_decision(true, false, false);
|
|
LL| | mcdc_check_not_tree_decision(true, false, true);
|
|
LL| |
|
|
LL| | mcdc_nested_if(true, false, true);
|
|
LL| | mcdc_nested_if(true, true, true);
|
|
LL| | mcdc_nested_if(true, true, false);
|
|
LL| |}
|
|
LL| |
|
|
LL| |#[coverage(off)]
|
|
LL| |fn say(message: &str) {
|
|
LL| | core::hint::black_box(message);
|
|
LL| |}
|
|
|