Coverage filter set
Create a coverage filter object to add filter rules to.
filt = slcoverage.Filter()
adds the filter rules in
filt = slcoverage.Filter(
filterFile to the filter.
filterFile— Filter file
Filter file (
.cvf file), specified as a character
vector of the path name to the file. You do not need to include the
|addRule||Add coverage filtering rule to filter|
|removeRule||Remove rule from filter rule set|
|rules||Rules for filter|
Handle. To learn how handle classes affect copy operations, see Copying Objects (MATLAB).
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
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
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 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')