Select metric criterion for coverage filter
Use an object of the
slcoverage.MetricSelector class to specify metric
selection criteria for a coverage filter rule.
slcoverage.MetricSelector class is a
creates a metric selector object of type
sel = slcoverage.MetricSelector(
type for the specified
element at the objective index
objIndex and outcome index
You can only create a justify rule for a metric selector. For more information about the difference between justification and exclusion, see Coverage Filtering.
For more information on the condition and decision coverage tables produced in the report, see Top-Level Model Coverage Report.
type — Metric selector type
Metric selector type, specified as:
slcoverage.MetricSelectorType.ConditionOutcomeobjects select condition metric objective outcomes.
slcoverage.MetricSelectorType.DecisionOutcomeobjects select decision metric objective outcomes.
slcoverage.MetricSelectorType.MCDCOutcomeobjects select MCDC metric objective outcomes.
slcoverage.MetricSelectorType.RelationalBoundaryOutcomeobjects select outcome metrics related to relational boundary outcomes.
slcoverage.MetricSelectorType.SaturationOverflowOutcomeobjects select outcome metrics related to saturation on integer overflow outcomes.
element — Model element to select
handle | Simulink® ID
Model element to select, specified as a handle or the Simulink identifier of the model element.
objIndex — Index of objective
Index of the objective that you want to filter, specified as an integer.
outIndex — Index of outcome
Index of the outcome that you want to filter, specified as an integer.
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.
ObjectiveIndex — Index of objective
Index of the objective for this selector, returned as an integer.
OutcomeIndex — Index of outcome
Index of the outcome for this selector, returned as an integer.
Type — Metric selector type
Selector type, returned as
Add Metric Selector Rule to a Filter
This example shows how to select a metric and add a rule that uses that metric. In this example, you create a rule to justify an unsatisfied decision for a Saturation block.
Open the Model and Enable Coverage Analysis
Load the model into memory.
modelName = 'slvnvdemo_covfilt'; load_system(modelName);
Simulink.SimulationInput object to configure coverage for the model.
covSet = Simulink.SimulationInput(modelName); covSet = covSet.setModelParameter('CovEnable','on'); covSet = covSet.setModelParameter('CovMetricStructuralLevel','MCDC'); covSet = covSet.setModelParameter('CovSFcnEnable','on'); covSet = covSet.setModelParameter('StopTime','20'); covSet = covSet.setModelParameter('CovSaveSingleToWorkspaceVar','on'); covSet = covSet.setModelParameter('CovSaveName','covData');
Simulate the model using the
SimulationInput object as the input.
simOut = sim(covSet);
View the coverage results before applying a filter. You can access the coverage using
decisioninfo, or you can view the HTML report using
covInitial = decisioninfo(covData,[modelName,'/Saturation']); percentInitial = 100 * covInitial(1)/covInitial(2)
percentInitial = 50
cvhtml show the same result of 50% decision coverage. If you don't intend your current tests to exercise this outcome, you can justify the outcome so it is no longer reported as missing coverage.
In this example, we justify the
false decision outcome of the
input > lower limit decision objective in the Saturation block.
Justify the Missing Condition Objective
MetricSelector objects accept the block path or the block handle as the second input. Get the block handle of the Saturation block by using
id = getSimulinkBlockHandle([modelName,'/Saturation']);
Because the objective being justified is a decision outcome, the first input to the metric selector constructor is
slcoverage.MetricSelectorType.DecisionOutcome. The second input is the block handle. The last two are the index of the objective to justify and the index of the outcome of that objective, respectively.
input > lower limit decision objective is the first objective for the Saturation block, its objective index is
1. Because the
false outcome of this objective is the first outcome, its outcome index is also
1. Therefore, the last two inputs are
metr = slcoverage.MetricSelector(slcoverage.MetricSelectorType.DecisionOutcome,id,1,1);
Create a filter and rule. In this case, we use the default filter mode of justify. Then add the rule to the filter using the
filt = slcoverage.Filter; rule = slcoverage.FilterRule(metr,'Expected result'); filt.addRule(rule);
Save the filter to a filter file using the
save method. Then apply the filter file to the
cvdata object by assigning the
filter property to the new filter file.
filt.save('metrfilter'); covData.filter = 'metrfilter';
Re-generate the coverage results for the Saturation block using the new filtered
covFiltered = decisioninfo(covData,[modelName,'/Saturation']); percentInitial = 100 * covFiltered(1)/covFiltered(2)
percentInitial = 75
In the HTML report, the missing decision outcome is highlighted to indicate that it is justified. Decision coverage for the Saturation block is now 75%.
Version HistoryIntroduced in R2017b
R2020b: Justify missing coverage outcomes for individual MCDC objectives
You can use
justify individual modified condition/decision coverage (MCDC) outcomes without
excluding the entire expression.