Documentation

slcoverage.MetricSelector class

Package: slcoverage

Select metric criterion for coverage filter

Description

Specify metric selection criteria for a filter rule.

Construction

sel = slcoverage.MetricSelector(type,element,objIndex,outIndex)specifies the model element and the block metrics to create the rule for. Specify whether the type of selector is a condition or decision outcome. Then select the object and outcome index combination to specify the metric that you want to write the filter rule for.

You can create only a justify rule for a metric selector. You cannot create an exclude rule.

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 selects outcome metrics related to block inputs.

  • slcoverage.MetricSelectorType.DecisionOutcome selects outcome metrics related to block outputs.

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

Example: 'sldemo_lct_bus:18'

Matrix position of objective to select, specified as an integer that corresponds to the row of the coverage table.

Example: 1

Matrix position of the outcome to select, specified as an integer that corresponds to the column of the coverage table.

Example: 2

Properties

expand all

This property is read-only.

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

This property is read-only.

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

This property is read-only.

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

This property is read-only.

Matrix position of objective for this selector, returned as an integer.

This property is read-only.

Matrix position of outcome for this selector, returned as an integer.

This property is read-only.

Selector type, returned as ConditionOutcome or DecisionOutcome.

Outputs

expand all

Selector object, returned as an slcoverage.MetricSelector object or array of slcoverage.MetricSelector objects.

Methods

allSelectorsSelectors for model element

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects (MATLAB).

Examples

expand all

Select a metric, create a rule for it, and add the rule to a filter. Then you can simulate the model for code coverage using the filter to see the effect.

In this example, you create a rule to justify the untested condition for the And block.

Open the model. Specify coverage settings and turn on coverage recording.

modelName = 'sldemo_lct_bus';
open_system(modelName);
set_param(modelName,'CovMetricSettings','dcme','RecordCoverage','on');

Get the identifier for the And block. Create the metric selector for the block. For this example, filter the second condition (input port 2) False outcome, whose index, then, is 2,2. Use the ConditionOutcome selector type and the index 2,2.

id = Simulink.ID.getSID('sldemo_lct_bus/slCounter/And');
metr = slcoverage.MetricSelector(slcoverage.MetricSelectorType.ConditionOutcome,id,2,2);

Create a filter object and create a rule using the default filter mode of justify. Add the rule to the filter.

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

Save the filter as metrfilter. 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('metrfilter');
csim = cvsim(modelName);
csim.filter = 'metrfilter';
cvhtml('cov',csim);

Examine the HTML report and view the condition table for the And block. The report now shows 100% coverage for the condition and that the untested condition was justified.

Introduced in R2017b

Was this topic helpful?