mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
coverage: Add CLI support for -Zcoverage-options=condition
This commit is contained in:
parent
caa187f3bc
commit
fa563c1384
@ -159,7 +159,23 @@ pub enum CoverageLevel {
|
||||
Block,
|
||||
/// Also instrument branch points (includes block coverage).
|
||||
Branch,
|
||||
/// Instrument for MC/DC. Mostly a superset of branch coverage, but might
|
||||
/// Same as branch coverage, but also adds branch instrumentation for
|
||||
/// certain boolean expressions that are not directly used for branching.
|
||||
///
|
||||
/// For example, in the following code, `b` does not directly participate
|
||||
/// in a branch, but condition coverage will instrument it as its own
|
||||
/// artificial branch:
|
||||
/// ```
|
||||
/// # let (a, b) = (false, true);
|
||||
/// let x = a && b;
|
||||
/// // ^ last operand
|
||||
/// ```
|
||||
///
|
||||
/// This level is mainly intended to be a stepping-stone towards full MC/DC
|
||||
/// instrumentation, so it might be removed in the future when MC/DC is
|
||||
/// sufficiently complete, or if it is making MC/DC changes difficult.
|
||||
Condition,
|
||||
/// Instrument for MC/DC. Mostly a superset of condition coverage, but might
|
||||
/// differ in some corner cases.
|
||||
Mcdc,
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ mod desc {
|
||||
pub const parse_optimization_fuel: &str = "crate=integer";
|
||||
pub const parse_dump_mono_stats: &str = "`markdown` (default) or `json`";
|
||||
pub const parse_instrument_coverage: &str = parse_bool;
|
||||
pub const parse_coverage_options: &str = "`block` | `branch` | `mcdc`";
|
||||
pub const parse_coverage_options: &str = "`block` | `branch` | `condition` | `mcdc`";
|
||||
pub const parse_instrument_xray: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), or a comma separated list of settings: `always` or `never` (mutually exclusive), `ignore-loops`, `instruction-threshold=N`, `skip-entry`, `skip-exit`";
|
||||
pub const parse_unpretty: &str = "`string` or `string=string`";
|
||||
pub const parse_treat_err_as_bug: &str = "either no value or a non-negative number";
|
||||
@ -961,6 +961,7 @@ mod parse {
|
||||
match option {
|
||||
"block" => slot.level = CoverageLevel::Block,
|
||||
"branch" => slot.level = CoverageLevel::Branch,
|
||||
"condition" => slot.level = CoverageLevel::Condition,
|
||||
"mcdc" => slot.level = CoverageLevel::Mcdc,
|
||||
_ => return false,
|
||||
}
|
||||
|
@ -353,6 +353,11 @@ impl Session {
|
||||
&& self.opts.unstable_opts.coverage_options.level >= CoverageLevel::Branch
|
||||
}
|
||||
|
||||
pub fn instrument_coverage_condition(&self) -> bool {
|
||||
self.instrument_coverage()
|
||||
&& self.opts.unstable_opts.coverage_options.level >= CoverageLevel::Condition
|
||||
}
|
||||
|
||||
pub fn instrument_coverage_mcdc(&self) -> bool {
|
||||
self.instrument_coverage()
|
||||
&& self.opts.unstable_opts.coverage_options.level >= CoverageLevel::Mcdc
|
||||
|
@ -5,13 +5,16 @@ This option controls details of the coverage instrumentation performed by
|
||||
|
||||
Multiple options can be passed, separated by commas. Valid options are:
|
||||
|
||||
- `block`, `branch`, `mcdc`:
|
||||
- `block`, `branch`, `condition`, `mcdc`:
|
||||
Sets the level of coverage instrumentation.
|
||||
Setting the level will override any previously-specified level.
|
||||
- `block` (default):
|
||||
Blocks in the control-flow graph will be instrumented for coverage.
|
||||
- `branch`:
|
||||
In addition to block coverage, also enables branch coverage instrumentation.
|
||||
- `condition`:
|
||||
In addition to branch coverage, also instruments some boolean expressions
|
||||
as branches, even if they are not directly used as branch conditions.
|
||||
- `mcdc`:
|
||||
In addition to block and branch coverage, also enables MC/DC instrumentation.
|
||||
In addition to condition coverage, also enables MC/DC instrumentation.
|
||||
(Branch coverage instrumentation may differ in some cases.)
|
||||
|
@ -1,2 +1,2 @@
|
||||
error: incorrect value `bad` for unstable option `coverage-options` - `block` | `branch` | `mcdc` was expected
|
||||
error: incorrect value `bad` for unstable option `coverage-options` - `block` | `branch` | `condition` | `mcdc` was expected
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
//@ needs-profiler-support
|
||||
//@ revisions: block branch mcdc bad
|
||||
//@ revisions: block branch condition mcdc bad
|
||||
//@ compile-flags -Cinstrument-coverage
|
||||
|
||||
//@ [block] check-pass
|
||||
@ -8,6 +8,9 @@
|
||||
//@ [branch] check-pass
|
||||
//@ [branch] compile-flags: -Zcoverage-options=branch
|
||||
|
||||
//@ [condition] check-pass
|
||||
//@ [condition] compile-flags: -Zcoverage-options=condition
|
||||
|
||||
//@ [mcdc] check-pass
|
||||
//@ [mcdc] compile-flags: -Zcoverage-options=mcdc
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user