slcoverage.Filter class

Package: slcoverage

Coverage filter set

Description

Create a coverage filter object to add filter rules to.

Construction

filt = slcoverage.Filter() creates an slcoverage.Filter object.

filt = slcoverage.Filter(filterFile) adds the filter rules in filterFile to the filter.

Input Arguments

expand all

Filter file (.cvf file), specified as a character vector of the path name to the file. You do not need to include the extension.

Example: 'myfilt', 'filters/myfilt'

Methods

addRuleAdd coverage filtering rule to filter
removeRuleRemove rule from filter rule set
rulesRules for filter

Copy Semantics

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

Examples

collapse all

Create a filter object and add a rule to it. In this example, you add a rule to exclude some blocks from coverage testing.

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

Select blocks with block type 'RelationalOperator' to add a filter rule for.

bl = slcoverage.BlockSelector(slcoverage.BlockSelectorType.BlockType,'RelationalOperator');

Create a filter object, create a rule, and add the rule to the filter.

filt = slcoverage.Filter;
rule = slcoverage.FilterRule(bl,'Tested elsewhere',slcoverage.FilterMode.Exclude);
filt.addRule(rule);

After you create a filter and add one or more rules to it, save the filter to a file. Simulate the model for code coverage. Add the filter file as the value to the filter property of the resulting cvdata object.

filt.save('blfilter');
csim = cvsim(modelName);
csim.filter = 'blfilter';
cvhtml('cov',csim);

Examine the HTML report and notice the rules that were added for the blocks. The coverage report shows the excluded blocks and the rationale.

This example assumes that you have two existing filter files, myfilt1.cvf and myfilt2.cvf. Simulate the model for coverage. Add the filter files to the filter property of the resulting cvdata object.

csim = cvsim(modelName);
csim.filter = {'myfilt1', 'myfilt2'};
cvhtml('cov',csim);

This example assumes that you have an existing filter file myfilt.cvf that you want to add a rule to. Create a filter object that uses that file. Add a rule to the filter object and then save the file again.

filt = slcoverage.Filter('myfilt');
bl = slcoverage.BlockSelector(slcoverage.BlockSelectorType.BlockInstance,'sldemo_lct_bus:23');

rule = slcoverage.FilterRule(bl,'Edge case');
filt.addRule(rule);
filt.save('myfilt')
Introduced in R2017b