Main Content

slcoverage.MetricSelector Class

Namespace: slcoverage

Select metric criterion for coverage filter

Description

Use an object of the slcoverage.MetricSelector class to specify metric selection criteria for a coverage filter rule.

The slcoverage.MetricSelector class is a handle class.

Creation

Description

sel = slcoverage.MetricSelector(type,element,objIndex,outIndex) creates a metric selector object of type type for the specified model element element at the objective index objIndex and outcome index outIndex.

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.

Input Arguments

expand all

Metric selector type, specified as:

  • slcoverage.MetricSelectorType.ConditionOutcome objects select condition metric objective outcomes.

  • slcoverage.MetricSelectorType.DecisionOutcome objects select decision metric objective outcomes.

  • slcoverage.MetricSelectorType.MCDCOutcome objects select MCDC metric objective outcomes.

  • slcoverage.MetricSelectorType.RelationalBoundaryOutcome objects select outcome metrics related to relational boundary outcomes.

  • slcoverage.MetricSelectorType.SaturationOverflowOutcome objects select outcome metrics related to saturation on integer overflow outcomes.

Model element to select, specified as a handle or the Simulink identifier of the model element.

Example: 'slcoverage_lct_bus:18'

Index of the objective that you want to filter, specified as an integer.

Example: 1

Index of the outcome that you want to filter, specified as an integer.

Example: 2

Properties

expand all

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

Attributes:

GetAccess
public
SetAccess
protected

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

Attributes:

GetAccess
public
SetAccess
protected

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

Attributes:

GetAccess
public
SetAccess
protected

Index of the objective for this selector, returned as an integer.

Attributes:

GetAccess
public
SetAccess
protected

Index of the outcome for this selector, returned as an integer.

Attributes:

GetAccess
public
SetAccess
protected

Selector type, returned as ConditionOutcome, DecisionOutcome, MCDCOutcome, RelationalBoundaryOutcome, or SaturationOverflowOutcome.

Attributes:

GetAccess
public
SetAccess
protected

Methods

expand all

Examples

collapse all

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);

Use a 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 cvhtml.

covInitial = decisioninfo(covData,[modelName,'/Saturation']);
percentInitial = 100 * covInitial(1)/covInitial(2)
percentInitial =

    50

cvhtml('covReportInitial',covData);

Both decisioninfo and 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 getSimulinkBlockHandle.

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.

Because the 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 1,1.

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 addRule method.

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 cvdata object.

covFiltered = decisioninfo(covData,[modelName,'/Saturation']);
percentInitial = 100 * covFiltered(1)/covFiltered(2)
percentInitial =

    75

cvhtml('covReportFiltered',covData);

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 History

Introduced in R2017b

expand all