Get selectors of all types
slcoverage.Selector class with the
allSelectors method to return all
types of the selectors for a model object.
slcoverage.Selector class is a
ConstructorCode — Code used to create this selector object
Code used to create this selector object, returned as a character vector.
Description — Description of the selector
Description of the selector, returned as a character vector. Simulink® Coverage™ creates the description based on the selector.
Id — Element identifier
Simulink ID (default) | handle
Identifier of the model element, returned as character vector of the Simulink ID or a handle.
Type — Selector type
selector type value
Selector type, returned as a selector type of the corresponding selector.
Get All Selectors
This example shows how to get all the selectors for an And block and then add a rule to justify or exclude a selector. Metric selectors can only be justified.
Load the model and set coverage settings
modelName = 'slvnvdemo_covfilt'; load_system(modelName); set_param(modelName,'CovEnable','on','CovMetricStructuralLevel','MCDC');
First, get the block handle for the And block.
id = getSimulinkBlockHandle([modelName,'/Saturation']);
Get the selectors using the block handle.
sel = slcoverage.Selector.allSelectors(id)
sel = 1x10 heterogeneous Selector (BlockSelector, MetricSelector) array with properties: Description Type Id ConstructorCode
The block has ten selectors. You can index into each one to see their contents. In this example, you want to justify the sixth selector.
ans = MetricSelector with properties: ObjectiveIndex: 2 OutcomeIndex: 2 Description: 'T outcome of input > upper limit in Saturate block "Saturation"' Type: DecisionOutcome Id: 'slvnvdemo_covfilt:5' ConstructorCode: 'slcoverage.MetricSelector(slcoverage.MetricSelectorType.DecisionOutcome, 'slvnvdemo_covfilt:5', 2, 2)'
Create a justify rule, then create a filter object and add the rule to it.
rule = slcoverage.FilterRule(sel(6),'Expected result'); filt = slcoverage.Filter; filt.addRule(rule);
Save the filter and generate a coverage report.
filt.save('metrfilter'); csim = cvsim(modelName); csim.filter = 'metrfilter'; cvhtml('cov',csim,'-sRT=0');