rust/tests/coverage/mcdc_non_control_flow.coverage

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

99 lines
3.2 KiB
Plaintext
Raw Normal View History

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| |// 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
LL| 3| black_box(x);
LL| 3|}
LL| |
LL| 3|fn assign_or(a: bool, b: bool) {
LL| 3| let x = a || b;
^1
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
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
------------------
|---> 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| 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
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
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| |}