Documentation

slcoverage.BlockSelector class

Package: slcoverage

Select blocks for coverage filter

Description

Specify block selection criteria for a filter rule.

Construction

sel = slcoverage.BlockSelector(type,element) specifies the type of model elements to create the filter rule for and returns an slcoverage.BlockSelector object.

Input Arguments

expand all

Type of model element to select, specified as one of these values:

  • slcoverage.BlockSelectorType.BlockInstance — An instance of a block.

  • slcoverage.BlockSelectorType.BlockType — All blocks of the specified block type.

  • slcoverage.BlockSelectorType.Chart — A Stateflow® chart.

  • slcoverage.BlockSelectorType.MaskType — Blocks that use the specified mask type.

  • slcoverage.BlockSelectorType.State — A Stateflow state.

  • slcoverage.BlockSelectorType.StateAllContent — Stateflow state and its contents.

  • slcoverage.BlockSelectorType.StateflowFunction — A Stateflow function.

  • slcoverage.BlockSelectorType.Subsystem — A subsystem block.

  • slcoverage.BlockSelectorType.SubystemAllContent — A subsystem and its contents.

  • slcoverage.BlockSelectorType.TemporalEvent — A Stateflow temporal event.

  • slcoverage.BlockSelectorType.Transition — A Stateflow transition.

Example: slcoverage.BlockSelectorType.Transition

Model element to select, specified as a property name of the element, its handle, or its Simulink® identifier. Use a handle or ID for selector types that select an instance. Use a property name, such as the value of a block's 'BlockType' property, to select multiple model elements.

Example: 'sldemo_lct_bus:18', 'RelationalOperator'

Outputs

expand all

Selector object, returned as an slcoverage.BlockSelector object or array of slcoverage.BlockSelector objects.

Properties

expand all

This property is read-only.

Code used to create this selector object, returned as a character vector.

This property is read-only.

Description of the selector, returned as a character vector. Simulink Coverage™ creates the description based on how the selector is constructed.

This property is read-only.

Identifier of the model element, returned as character vector of the Simulink ID, model element property, or handle.

This property is read-only.

Selector type, returned as one of these slcoverage.BlockSelectorType values:

  • BlockInstance

  • BlockType

  • Chart

  • MaskType

  • State

  • StateAllContent

  • StateflowFunction

  • Subsystem

  • SubystemAllContent

  • TemporalEvent

  • Transition

Methods

allSelectorsSelectors for model element

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects (MATLAB).

Examples

expand all

Select multiple blocks to add a rule for and an instance of a block to add a rule for. The resulting filter has two rules. You can simulate your model for code coverage using the filter to see the effect.

Open the model. Specify coverage settings and turn on coverage recording.

modelName = 'sldemo_lct_bus';
open_system(modelName);
set_param(modelName,'CovMetricSettings','dcme','RecordCoverage','on');

Select blocks that have the same block type as the upper GE input block to add a filter rule for.

type = get_param('sldemo_lct_bus/slCounter/upper GE input','BlockType');
bl = slcoverage.BlockSelector(slcoverage.BlockSelectorType.BlockType,type);

Create a filter object, create a rule based on the selector, and add the rule to the filter.

filt = slcoverage.Filter;
rule = slcoverage.FilterRule(bl,'Tested elsewhere',slcoverage.FilterMode.Exclude);
filt.addRule(rule);

Select a block instance and add a rule for the block instance to the filter. This rule uses the default filter mode of Justify.

id = Simulink.ID.getSID('sldemo_lct_bus/slCounter/And');
bl = slcoverage.BlockSelector(slcoverage.BlockSelectorType.BlockInstance,id);
rule = slcoverage.FilterRule(bl,'Edge case');
filt.addRule(rule);

Save the filter as blfilter. Simulate the model for code coverage. Add the filter file as the value to the filter property of the resulting cvdata object. Then generate the coverage report.

filt.save('blfilter');
csim = cvsim(modelName);
csim.filter = 'blfilter';
cvhtml('cov',csim);

Examine the HTML report to see information about the blocks that you added rules for.

Introduced in R2017b

Was this topic helpful?