Creating and Using Coverage Filters

This example shows how to use Simulink® Verification and Validation™ model coverage filters to exclude model items from coverage recording and justify missing coverage in reports.

Coverage Filters

In the verification process, a model can contain several constructs that prevent full model coverage, such as a subsystem that contains some driver for a controller that is not tested and is not relevant to the validation process. Filtering these constructs from coverage recording and reporting allows you to focus on other aspects of missing coverage that can and should be tested.

Coverage filters are stored in .cvf files. Filter files can span multiple models. Each filter consists of rules that define model objects that will be excluded or justified in the coverage results. You can filter any model object that receives coverage or contains other items, such as a subsystem.

Coverage filters can be created and applied either before or after simulating a model. Both workflows are described in this example.

Open Model

This example makes use of the model slvnvdemo_covfilt. The model shows some common patterns that might need to be filtered from coverage recording and reporting.

Open the model to begin.

Filter a Specific Block before Simulation

In the slvnvdemo_covfilt model, the Saturation block has a lower limit of 0 and an upper limit of 200. The input to this block is the rate signal, which can never be less than or equal to 0. This will lead to missing coverage, as the lower limit of the Saturation block is not fully exercised. As such, exclude the Saturation block from coverage.

In the Simulink Editor, right-click the Saturation block and select Coverage > Exclude this block.

The list of current filter rules shows in the Coverage Results Explorer. Click in the Rationale field for this new rule and enter text describing why this block is excluded, such as "Input never <= lower limit (0)". Click Apply when finished.

Filter Based on Library Reference

The library block slvnvdemo_covfilt_lib/protected division is a protection against division by zero and might be irrelevant in the coverage report. The right-click context menu on this block provides options for filtering the specific instance of the library or all references to this library. Select Exclude referenced library: slvnvdemo_covfilt_lib/protected division.

Under the Filter tab of the Coverage Results Explorer, enter the Rationale for this rule, such as "division by zero protection". Click Apply when finished.

Filter an Event in Stateflow®

Generally, filter rules eliminate an entire block or Stateflow® object from coverage recording. Stateflow® events are an exception where you can eliminate coverage for part of the transition and record coverage for the remainder of the transition.

In this example, there is a transition that defines the temporal event tick that is never false, preventing full condition and MCDC coverage.

To exclude temporal event tick, select Coverage > Exclude temporal event 'tick' in the right-click context menu of this transition.

Under the Filter tab of the Coverage Results Explorer, enter the Rationale for this rule, such as "tick". Click Apply when finished.

Simulate and Review Filtered Coverage Results

Simulate the model. The Coverage Results Explorer will open when the simulation completes. Click the Generate report link to create and open a coverage report for this run.

The coverage report shows a section titled Options Filtered from Coverage Analysis listing each of the excluded elements and their corresponding rationales. The coverage results exclude these elements.

Filter a Subsystem after Simulation

In certain cases, you may have an expectation that certain items in a model will not acheive full coverage. You therefore filter these items before simulating for coverage, as was done in the previous sections of this example. You can also create and apply a filter to coverage results after simulation. This allows you to review coverage results, create or adjust a filter as desired, and generate a new coverage report using this filter without having to rerun the simulation.

Consider, for example, the subsystem Switchable config. Using constant values to drive subsystem enable ports for changing model configurations is a common pattern in designs; however, the enable logic and subsystem contents might lead to missing coverage. This configuration is not used in this model, so add the Switchable config subsystem to the coverage filter.

In the Simulink Editor, right-click the Switchable config subsystem and select Coverage > Exclude subsystem with all descendants.

Under the Filter tab of the Coverage Results Explorer, enter the Rationale for this rule, such as "unused config". Click Apply when finished.

Filter a Stateflow® Transition from the Coverage Report

In the coverage report, navigate to the detailed results for Stateflow® Transition "[!on]" from Junction #0 to "off" under the chart Mode Logic. This transition is never false because it only evaluates when Transition "[on]" from Junction #0 to "on" is false.

As an alternative to navigating back to the model and filtering this transition via the right-click context menu, you can filter this item directly from the report.

Click the Justify or Exclude link under the detailed results for this transition.

The Filter tab of the Coverage Results Explorer opens, and the rule filtering this transition is added.

Change the filtering Mode for this rule to Justified and enter a description for the Rationale, such as "expression can't be false". Click Apply when finished.

Generate Updated Coverage Report

After clicking Apply, the Generate report link shows at the bottom of the dialog. Click this link to regenerate the report with the updated coverage filter.

The new coverage report lists all of the excluded elements under Objects Filtered from Coverage Analysis, including the subsystem Switchable config which was filtered after simulation. Also, note that the detailed results for Transition "[!on]" from Junction #0 to "off" show that missing coverage for this transition has been justified. The justified objectives are treated as satisfied when reporting coverage percentages.

Clean Up

To complete the example, close the model.

Was this topic helpful?