slcoverage.BlockSelector Class
Namespace: slcoverage
Select blocks for coverage filter
Description
Specify block selection criteria for a filter rule.
The slcoverage.BlockSelector
class is a handle
class.
Creation
Description
Input Arguments
type
— Block selector type
slcoverage.BlockSelectorType
value
Type of model element to select, specified as one of these values:
slcoverage.BlockSelectorType.BlockInstance
— An instance of a block or an external MATLAB function called by a MATLAB function 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.SubsystemAllContent
— A subsystem and its contents.slcoverage.BlockSelectorType.TemporalEvent
— A Stateflow temporal event.slcoverage.BlockSelectorType.Transition
— A Stateflow transition.
Example: slcoverage.BlockSelectorType.Transition
element
— Model element to select
property name | handle | Simulink® ID
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: 'slcoverage_lct_bus:18'
,
'RelationalOperator'
Attributes:
- SetAccess
protected
Data Types: char
| string
| handle
| integer
Properties
ConstructorCode
— Code used to create this selector object
character array
Code used to create this selector object, returned as a character vector.
Attributes:
GetAccess | public |
SetAccess | protected |
Description
— Description of the selector
character vector
Description of the selector, returned as a character vector. Simulink Coverage™ creates the description based on the selector.
Attributes:
GetAccess | public |
SetAccess | protected |
Id
— Model element identifier
Simulink ID (default) | property | handle
Model element identifier, specified as the property name of the element, the handle to
an element, or the Simulink identifier of the element. Use a handle or ID for selector types that
select an instance. Use a property name, such as the value of the
'BlockType'
property of a block, to select multiple model
elements.
Attributes
SetAccess | protected |
Data Types: char
| string
| handle
| integer
Type
— Block selector type
slcoverage.BlockSelectorType
value
Selector type, returned as one of these
slcoverage.BlockSelectorType
values:
slcoverage.BlockSelectorType.BlockInstance
— An instance of a block or an external MATLAB function called by a MATLAB function 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.SubsystemAllContent
— A subsystem and its contents.slcoverage.BlockSelectorType.TemporalEvent
— A Stateflow temporal event.slcoverage.BlockSelectorType.Transition
— A Stateflow transition.
Attributes:
GetAccess | public |
SetAccess | protected |
Methods
Public Methods
allSelectors | Selectors for model or code element |
Examples
Add Block Selector Rules to a Filter
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 = 'slcoverage_lct_bus'; open_system(modelName); set_param(modelName,'CovMetricStructuralLevel','MCDC','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('slcoverage_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('slcoverage_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.
Get a Selector for a MATLAB Function
This example shows how to get a selector for a MATLAB® function using the slcoverage.BlockSelector
class.
The example model slvnvdemo_eml_model_coverage_demo
contains a series of MATLAB function blocks. One of the MATLAB function blocks calls an external function called slcoverageExternalFile.m
.
Start by loading the model and generating coverage results.
modelName = 'slvnvdemo_eml_model_coverage_demo';
load_system(modelName)
covData = cvsim(modelName);
Since the model uses an external function, the coverage results are returned in a cv.cvdatagroup
object. Use the cv.cvdatagroup.get
class method to extract the cvdata
object that contains the results for the slcoverageExternalFile
function.
functionCov = get(covData,'slcoverageExternalFile');
To exclude the entire function from the coverage report, use an exclusion filter. First, use the slcoverage.BlockSelector
class to create a selector for the external MATLAB function slcoverageExternalFile.m
. The correct BlockSelectorType
enumeration to use for this is BlockInstance
.
sel = slcoverage.BlockSelector(... slcoverage.BlockSelectorType.BlockInstance,... 'slcoverageExternalFile.m');
Create an empty slcoverage.Filter
object.
filt = slcoverage.Filter;
Create the exclusion filter rule using the slcoverage.FilterRule
class. Use the selector you created, the rationale for filtering the function, and the filter type of slcoverage.FilterMode.Exclude
.
rule = slcoverage.FilterRule(sel,'Exclude function demo',... slcoverage.FilterMode.Exclude);
Add the filter rule to the filter object, name the filter, and save it to a file.
addRule(filt,rule); setFilterName(filt,'mfileFilter'); setFilterDescription(filt,'Demo exclusion filter for external m-file'); save(filt,'externalFileFilter')
Apply the filter file to the cvdata object which contains coverage results for the function slcoverageExternalFile.m
.
functionCov.filter = 'externalFileFilter';
Create the coverage report and observe that the function slcoverageExternalFile
now has no coverage data reported in the summary, and if you click on the function name to open the function report, you see slcoverageExternalFile
listed under Objects Filtered from Coverage Analysis.
cvhtml('covReport',covData);
Version History
Introduced in R2017b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)