about summary refs log tree commit diff
path: root/tests/coverage/mcdc/non_control_flow.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/non_control_flow.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/non_control_flow.coverage')
-rw-r--r--tests/coverage/mcdc/non_control_flow.coverage225
1 files changed, 225 insertions, 0 deletions
diff --git a/tests/coverage/mcdc/non_control_flow.coverage b/tests/coverage/mcdc/non_control_flow.coverage
new file mode 100644
index 00000000000..6ae796e8ed2
--- /dev/null
+++ b/tests/coverage/mcdc/non_control_flow.coverage
@@ -0,0 +1,225 @@
+   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|       |// This test ensures that boolean expressions that are not inside control flow
+   LL|       |// decisions are correctly instrumented.
+   LL|       |
+   LL|       |use core::hint::black_box;
+   LL|       |
+   LL|      3|fn assign_and(a: bool, b: bool) {
+   LL|      3|    let x = a && b;
+                               ^2
+  ------------------
+  |  Branch (LL:13): [True: 2, False: 1]
+  |  Branch (LL:18): [True: 1, False: 1]
+  ------------------
+  |---> MC/DC Decision Region (LL:13) to (LL:19)
+  |
+  |  Number of Conditions: 2
+  |     Condition C1 --> (LL:13)
+  |     Condition C2 --> (LL:18)
+  |
+  |  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|      3|    black_box(x);
+   LL|      3|}
+   LL|       |
+   LL|      3|fn assign_or(a: bool, b: bool) {
+   LL|      3|    let x = a || b;
+                               ^1
+  ------------------
+  |  Branch (LL:13): [True: 2, False: 1]
+  |  Branch (LL:18): [True: 0, False: 1]
+  ------------------
+  |---> MC/DC Decision Region (LL:13) to (LL:19)
+  |
+  |  Number of Conditions: 2
+  |     Condition C1 --> (LL:13)
+  |     Condition C2 --> (LL:18)
+  |
+  |  Executed MC/DC Test Vectors:
+  |
+  |     C1, C2    Result
+  |  1 { F,  F  = F      }
+  |  2 { T,  -  = T      }
+  |
+  |  C1-Pair: covered: (1,2)
+  |  C2-Pair: not covered
+  |  MC/DC Coverage for Decision: 50.00%
+  |
+  ------------------
+   LL|      3|    black_box(x);
+   LL|      3|}
+   LL|       |
+   LL|      4|fn assign_3(a: bool, b: bool, c: bool) {
+   LL|      4|    let x = a || b && c;
+                               ^2   ^1
+  ------------------
+  |  Branch (LL:13): [True: 2, False: 2]
+  |  Branch (LL:18): [True: 1, False: 1]
+  |  Branch (LL:23): [True: 1, False: 0]
+  ------------------
+  |---> MC/DC Decision Region (LL:13) to (LL:24)
+  |
+  |  Number of Conditions: 3
+  |     Condition C1 --> (LL:13)
+  |     Condition C2 --> (LL:18)
+  |     Condition C3 --> (LL:23)
+  |
+  |  Executed MC/DC Test Vectors:
+  |
+  |     C1, C2, C3    Result
+  |  1 { F,  F,  -  = F      }
+  |  2 { T,  -,  -  = T      }
+  |  3 { F,  T,  T  = T      }
+  |
+  |  C1-Pair: covered: (1,2)
+  |  C2-Pair: covered: (1,3)
+  |  C3-Pair: not covered
+  |  MC/DC Coverage for Decision: 66.67%
+  |
+  ------------------
+   LL|      4|    black_box(x);
+   LL|      4|}
+   LL|       |
+   LL|      4|fn assign_3_bis(a: bool, b: bool, c: bool) {
+   LL|      4|    let x = a && b || c;
+                               ^2   ^3
+  ------------------
+  |  Branch (LL:13): [True: 2, False: 2]
+  |  Branch (LL:18): [True: 1, False: 1]
+  |  Branch (LL:23): [True: 2, False: 1]
+  ------------------
+  |---> MC/DC Decision Region (LL:13) to (LL:24)
+  |
+  |  Number of Conditions: 3
+  |     Condition C1 --> (LL:13)
+  |     Condition C2 --> (LL:18)
+  |     Condition C3 --> (LL:23)
+  |
+  |  Executed MC/DC Test Vectors:
+  |
+  |     C1, C2, C3    Result
+  |  1 { T,  F,  F  = F      }
+  |  2 { F,  -,  T  = T      }
+  |  3 { T,  T,  -  = T      }
+  |
+  |  C1-Pair: not covered
+  |  C2-Pair: covered: (1,3)
+  |  C3-Pair: not covered
+  |  MC/DC Coverage for Decision: 33.33%
+  |
+  ------------------
+   LL|      4|    black_box(x);
+   LL|      4|}
+   LL|       |
+   LL|      3|fn right_comb_tree(a: bool, b: bool, c: bool, d: bool, e: bool) {
+   LL|      3|    let x = a && (b && (c && (d && (e))));
+                                ^2    ^1    ^1   ^1
+  ------------------
+  |  Branch (LL:13): [True: 2, False: 1]
+  |  Branch (LL:19): [True: 1, False: 1]
+  |  Branch (LL:25): [True: 1, False: 0]
+  |  Branch (LL:31): [True: 1, False: 0]
+  |  Branch (LL:36): [True: 1, False: 0]
+  ------------------
+  |---> MC/DC Decision Region (LL:13) to (LL:42)
+  |
+  |  Number of Conditions: 5
+  |     Condition C1 --> (LL:13)
+  |     Condition C2 --> (LL:19)
+  |     Condition C3 --> (LL:25)
+  |     Condition C4 --> (LL:31)
+  |     Condition C5 --> (LL:36)
+  |
+  |  Executed MC/DC Test Vectors:
+  |
+  |     C1, C2, C3, C4, C5    Result
+  |  1 { F,  -,  -,  -,  -  = F      }
+  |  2 { T,  F,  -,  -,  -  = F      }
+  |  3 { T,  T,  T,  T,  T  = T      }
+  |
+  |  C1-Pair: covered: (1,3)
+  |  C2-Pair: covered: (2,3)
+  |  C3-Pair: not covered
+  |  C4-Pair: not covered
+  |  C5-Pair: not covered
+  |  MC/DC Coverage for Decision: 40.00%
+  |
+  ------------------
+   LL|      3|    black_box(x);
+   LL|      3|}
+   LL|       |
+   LL|      3|fn foo(a: bool) -> bool {
+   LL|      3|    black_box(a)
+   LL|      3|}
+   LL|       |
+   LL|      3|fn func_call(a: bool, b: bool) {
+   LL|      3|    foo(a && b);
+                           ^2
+  ------------------
+  |  Branch (LL:9): [True: 2, False: 1]
+  |  Branch (LL:14): [True: 1, False: 1]
+  ------------------
+  |---> MC/DC Decision Region (LL:9) to (LL:15)
+  |
+  |  Number of Conditions: 2
+  |     Condition C1 --> (LL:9)
+  |     Condition C2 --> (LL:14)
+  |
+  |  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|      3|}
+   LL|       |
+   LL|       |#[coverage(off)]
+   LL|       |fn main() {
+   LL|       |    assign_and(true, false);
+   LL|       |    assign_and(true, true);
+   LL|       |    assign_and(false, false);
+   LL|       |
+   LL|       |    assign_or(true, false);
+   LL|       |    assign_or(true, true);
+   LL|       |    assign_or(false, false);
+   LL|       |
+   LL|       |    assign_3(true, false, false);
+   LL|       |    assign_3(true, true, false);
+   LL|       |    assign_3(false, false, true);
+   LL|       |    assign_3(false, true, true);
+   LL|       |
+   LL|       |    assign_3_bis(true, false, false);
+   LL|       |    assign_3_bis(true, true, false);
+   LL|       |    assign_3_bis(false, false, true);
+   LL|       |    assign_3_bis(false, true, true);
+   LL|       |
+   LL|       |    right_comb_tree(false, false, false, true, true);
+   LL|       |    right_comb_tree(true, false, false, true, true);
+   LL|       |    right_comb_tree(true, true, true, true, true);
+   LL|       |
+   LL|       |    func_call(true, false);
+   LL|       |    func_call(true, true);
+   LL|       |    func_call(false, false);
+   LL|       |}
+