about summary refs log tree commit diff
path: root/tests/coverage/mcdc/nested_if.coverage
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-07-09 20:24:30 +0000
committerbors <bors@rust-lang.org>2024-07-09 20:24:30 +0000
commit6be96e3865c4e59028fd50396f7a46c3498ce91d (patch)
tree4b5980ba794c8661cd4d43ed378b2b787c2bd3a3 /tests/coverage/mcdc/nested_if.coverage
parent9dcaa7f92cf3ed0a9d2e93824025243533bb5541 (diff)
parent83fa6b726ad04d5b4e9769c39eae544131fee46c (diff)
downloadrust-6be96e3865c4e59028fd50396f7a46c3498ce91d.tar.gz
rust-6be96e3865c4e59028fd50396f7a46c3498ce91d.zip
Auto merge of #127234 - ZhuUx:inlined-expr, r=davidtwco,Zalathar
[Coverage][MCDC] Group mcdc tests and fix panic when generating mcdc code for inlined expressions.

### Changes

1. Group all mcdc tests to one directory.
2. Since mcdc instruments different mappings for boolean expressions with normal branch coverage as #125766 introduces, it would be better also trace branch coverage results in mcdc tests.
3. So far rustc does not call `CoverageInfoBuilderMethods::init_coverage` for inlined functions. As a result, it could panic if it tries to instrument mcdc statements for inlined functions due to uninitialized cond bitmaps. We can reproduce this issue by current nightly rustc and [the test](https://github.com/rust-lang/rust/pull/127234/files#diff-c81af6bf4869aa42f5c7334e3e86344475de362f673f54ce439ec75fcb5ac3e5) with flag `--release`. This patch fixes it.
Diffstat (limited to 'tests/coverage/mcdc/nested_if.coverage')
-rw-r--r--tests/coverage/mcdc/nested_if.coverage258
1 files changed, 258 insertions, 0 deletions
diff --git a/tests/coverage/mcdc/nested_if.coverage b/tests/coverage/mcdc/nested_if.coverage
new file mode 100644
index 00000000000..a273a713a8a
--- /dev/null
+++ b/tests/coverage/mcdc/nested_if.coverage
@@ -0,0 +1,258 @@
+   LL|       |#![feature(coverage_attribute)]
+   LL|       |//@ edition: 2021
+   LL|       |//@ min-llvm-version: 18
+   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 { T,  -  = T      }
+  |  3 { F,  T  = T      }
+  |
+  |  C1-Pair: covered: (1,2)
+  |  C2-Pair: covered: (1,3)
+  |  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 { T,  -  = T      }
+  |  3 { F,  T  = T      }
+  |
+  |  C1-Pair: covered: (1,2)
+  |  C2-Pair: covered: (1,3)
+  |  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 { T,  -  = T      }
+  |  3 { F,  T  = T      }
+  |
+  |  C1-Pair: covered: (1,2)
+  |  C2-Pair: covered: (1,3)
+  |  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|       |}
+