rust/tests/coverage/mcdc/non_control_flow.coverage

227 lines
6.6 KiB
Plaintext

LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ min-llvm-version: 18
LL| |//@ ignore-llvm-version: 19 - 99
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| |}