Main Content

slcoverage.MetricSelector class

Package:slcoverage

Select metric criterion for coverage filter

Description

Use an object of theslcoverage.MetricSelectorclass to specify metric selection criteria for a coverage filter rule.

Theslcoverage.MetricSelectorclass is ahandleclass.

Creation

Description

sel= slcoverage.MetricSelector(type,element,objIndex,outIndex)creates a metric selector object of typetypefor the specified model elementelementat the objective indexobjIndexand outcome indexoutIndex.

You can only create a justify rule for a metric selector. For more information about the difference between justification and exclusion, seeCoverage Filtering.

For more information on the condition and decision coverage tables produced in the report, seeTop-Level Model Coverage Report.

Input Arguments

expand all

Metric selector type, specified as:

  • slcoverage.MetricSelectorType.ConditionOutcomeobjects select condition metric objective outcomes.

  • slcoverage.MetricSelectorType.DecisionOutcome对象选择决定度量客观结果。

  • 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.

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 asConditionOutcome,DecisionOutcome,MCDCOutcome,RelationalBoundaryOutcome, orSaturationOverflowOutcome.

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 aSimulink.SimulationInputobject 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 theSimulationInputobject as the input.

simOut = sim(covSet);

View the coverage results before applying a filter. You can access the coverage usingdecisioninfo, or you can view the HTML report usingcvhtml.

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

Bothdecisioninfoandcvhtml显示相同的结果覆盖50%的决定。如果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 thefalsedecision outcome of theinput > lower limitdecision objective in the Saturation block.

Justify the Missing Condition Objective

MetricSelectorobjects accept the block path or the block handle as the second input. Get the block handle of the Saturation block by usinggetSimulinkBlockHandle.

id = getSimulinkBlockHandle([modelName,'/Saturation']);

Because the objective being justified is a decision outcome, the first input to the metric selector constructor isslcoverage.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 theinput > lower limitdecision objective is the first objective for the Saturation block, its objective index is1. Because thefalseoutcome of this objective is the first outcome, its outcome index is also1. Therefore, the last two inputs are1,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 theaddRulemethod.

filt = slcoverage.Filter; rule = slcoverage.FilterRule(metr,'Expected result'); filt.addRule(rule);

Save the filter to a filter file using thesavemethod. Then apply the filter file to thecvdataobject by assigning thefilterproperty to the new filter file.

filt.save('metrfilter'); covData.filter ='metrfilter';

Re-generate the coverage results for the Saturation block using the new filteredcvdataobject.

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