coverage: Add CLI support for -Zcoverage-options=condition
This commit is contained in:
parent
caa187f3bc
commit
fa563c1384
6 changed files with 34 additions and 6 deletions
compiler/rustc_session/src
src/doc/unstable-book/src/compiler-flags
tests/ui/instrument-coverage
|
@ -159,7 +159,23 @@ pub enum CoverageLevel {
|
||||||
Block,
|
Block,
|
||||||
/// Also instrument branch points (includes block coverage).
|
/// Also instrument branch points (includes block coverage).
|
||||||
Branch,
|
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.
|
/// differ in some corner cases.
|
||||||
Mcdc,
|
Mcdc,
|
||||||
}
|
}
|
||||||
|
|
|
@ -395,7 +395,7 @@ mod desc {
|
||||||
pub const parse_optimization_fuel: &str = "crate=integer";
|
pub const parse_optimization_fuel: &str = "crate=integer";
|
||||||
pub const parse_dump_mono_stats: &str = "`markdown` (default) or `json`";
|
pub const parse_dump_mono_stats: &str = "`markdown` (default) or `json`";
|
||||||
pub const parse_instrument_coverage: &str = parse_bool;
|
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_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_unpretty: &str = "`string` or `string=string`";
|
||||||
pub const parse_treat_err_as_bug: &str = "either no value or a non-negative number";
|
pub const parse_treat_err_as_bug: &str = "either no value or a non-negative number";
|
||||||
|
@ -961,6 +961,7 @@ mod parse {
|
||||||
match option {
|
match option {
|
||||||
"block" => slot.level = CoverageLevel::Block,
|
"block" => slot.level = CoverageLevel::Block,
|
||||||
"branch" => slot.level = CoverageLevel::Branch,
|
"branch" => slot.level = CoverageLevel::Branch,
|
||||||
|
"condition" => slot.level = CoverageLevel::Condition,
|
||||||
"mcdc" => slot.level = CoverageLevel::Mcdc,
|
"mcdc" => slot.level = CoverageLevel::Mcdc,
|
||||||
_ => return false,
|
_ => return false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -353,6 +353,11 @@ impl Session {
|
||||||
&& self.opts.unstable_opts.coverage_options.level >= CoverageLevel::Branch
|
&& 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 {
|
pub fn instrument_coverage_mcdc(&self) -> bool {
|
||||||
self.instrument_coverage()
|
self.instrument_coverage()
|
||||||
&& self.opts.unstable_opts.coverage_options.level >= CoverageLevel::Mcdc
|
&& 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:
|
Multiple options can be passed, separated by commas. Valid options are:
|
||||||
|
|
||||||
- `block`, `branch`, `mcdc`:
|
- `block`, `branch`, `condition`, `mcdc`:
|
||||||
Sets the level of coverage instrumentation.
|
Sets the level of coverage instrumentation.
|
||||||
Setting the level will override any previously-specified level.
|
Setting the level will override any previously-specified level.
|
||||||
- `block` (default):
|
- `block` (default):
|
||||||
Blocks in the control-flow graph will be instrumented for coverage.
|
Blocks in the control-flow graph will be instrumented for coverage.
|
||||||
- `branch`:
|
- `branch`:
|
||||||
In addition to block coverage, also enables branch coverage instrumentation.
|
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`:
|
- `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.)
|
(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
|
//@ needs-profiler-support
|
||||||
//@ revisions: block branch mcdc bad
|
//@ revisions: block branch condition mcdc bad
|
||||||
//@ compile-flags -Cinstrument-coverage
|
//@ compile-flags -Cinstrument-coverage
|
||||||
|
|
||||||
//@ [block] check-pass
|
//@ [block] check-pass
|
||||||
|
@ -8,6 +8,9 @@
|
||||||
//@ [branch] check-pass
|
//@ [branch] check-pass
|
||||||
//@ [branch] compile-flags: -Zcoverage-options=branch
|
//@ [branch] compile-flags: -Zcoverage-options=branch
|
||||||
|
|
||||||
|
//@ [condition] check-pass
|
||||||
|
//@ [condition] compile-flags: -Zcoverage-options=condition
|
||||||
|
|
||||||
//@ [mcdc] check-pass
|
//@ [mcdc] check-pass
|
||||||
//@ [mcdc] compile-flags: -Zcoverage-options=mcdc
|
//@ [mcdc] compile-flags: -Zcoverage-options=mcdc
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue