Main Content

slcoverage.Filter class

Package: slcoverage

Coverage filter set

Description

Use an object of the slcoverage.Filter class to filter out unsatisfied coverage objectives by creating rules using the slcoverage.FilterRule class.

The slcoverage.Filter class is a handle class.

Creation

Description

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

filt = slcoverage.Filter(filterFile) creates an slcoverage.Filter object that contains the filter rules saved in filterFile.

Input Arguments

expand all

Filter file in CVF format, specified as a character array of the path name to the file, or a cell array of character arrays. You do not need to include the file extension.

Example: 'myfilt', 'filters\myfilt', {'myfilt1', 'myfilt2'}

Methods

expand all

Examples

collapse all

This example shows how to add a rule to a coverage filter file.

Create a filter object and use the BlockSelector class to create a BlockSelector object for the Saturation block in the slvnvdemo_covfilt model.

filt = slcoverage.Filter;
blockSel = slcoverage.BlockSelector(slcoverage.BlockSelectorType.BlockInstance,...
           'slvnvdemo_covfilt/Saturation');

Create a rule to filter the Saturation block using slcoverage.FilterRule with the selector as the first input and the rationale as the second input.

rule = slcoverage.FilterRule(blockSel,'Edge case');

Use the addRule method of the slcoverage.Filter class to add the rule to the filter object.

addRule(filt,rule);

Save the filter with the new rule to a filter file using the save method of the slcoverage.Filter class.

save(filt,'myFilterFile')

This example shows how to create a filter object and add a rule to exclude a subsystem from coverage analysis.

Open the slvnvdemo_covfilt model. Use a SimulationInput object to enable coverage recording and specify coverage settings.

modelName = 'slvnvdemo_covfilt';
load_system(modelName)
simIn = Simulink.SimulationInput(modelName);
simIn = setModelParameter(simIn,'CovEnable','on');
simIn = setModelParameter(simIn,'CovMetricStructuralLevel','MCDC');
simIn = setModelParameter(simIn,'CovSaveSingleToWorkspaceVar','on');
simIn = setModelParameter(simIn,'CovSaveName','covData');

Simulate the model. The coverage data is stored in the value supplied for the CovSaveName property.

simOut = sim(simIn);
covData = simOut.covData;

You can filter a block by using the slcoverage.BlockSelector class. To exclude the Switchable config subsystem, use slcoverage.BlockSelectorType.SubsystemAllContent as the first input.

subsysSel = slcoverage.BlockSelector(...
                      slcoverage.BlockSelectorType.SubsystemAllContent,...
                      'slvnvdemo_covfilt/Switchable config');

Create the filter rule by passing the selector, rationale, and the exclude filter mode as inputs.

rule = slcoverage.FilterRule(subsysSel,...
                    'Unused configuration',...
                    slcoverage.FilterMode.Exclude);

Create an slcoverage.Filter object and then add the rule to it.

filt = slcoverage.Filter;
addRule(filt,rule);

Save the filter to a file called blockFilter.cvf. To create a report that uses this coverage filter, add the filter file as the value to the filter property of covData, and create a report called coverageData.html using covData.

save(filt,'blockFilter')
covData.filter = 'blockFilter';
cvhtml('coverageData',covData)

If you have multiple filter files that each contain their own set of rules, you can apply them to a coverage result set by creating a cell array of the filter file names or path names. In this example, you apply two filter files to a single cvdata object and then view the report to see that the filters are applied.

Load the slvnvdemo_covfilt model into memory.

modelName = 'slvnvdemo_covfilt';
load_system(modelName)

Set the coverage settings by using a Simulink.SimulationInput object and simulate the model using sim.

simIn = Simulink.SimulationInput(modelName);
simIn = setModelParameter(simIn,'CovEnable','on');
simIn = setModelParameter(simIn,'CovMetricStructuralLevel','MCDC');
simIn = setModelParameter(simIn,'CovSaveSingleToWorkspaceVar','on');
simIn = setModelParameter(simIn,'CovSaveName','covData');
simOut = sim(simIn);

Apply the two filters to the cvdata object by assigning them to the filter property as a cell array.

covData.filter = {'filter_1','filter_2'};
cvhtml('twoFiltersCovData',covData);

You can see the applied coverage filters in the Objects Filtered from Coverage Analysis section of the coverage report.

Introduced in R2017b