Skip to Main Content Skip to Search
Product Documentation

Creating Coverage Filter Rules for a Simulink Model

About the Example Model

In this example, when you simulate the slvnvdemo_covfilt model, the model does not record 100% coverage. In subsequent steps, you filter certain objects from recording coverage. These steps allow you to focus on specific parts of the model to test for coverage.

The slvnvdemo_covfilt model is configured to record and report coverage during simulation for the following coverage metrics:

Simulating the Example Model and Reviewing Coverage

To identify areas of your model that do not record 100% coverage, simulate the model and record coverage.

  1. Open the demo model:

    slvnvdemo_covfilt
  2. Select Simulation > Start.

When the simulation is complete, an HTML coverage report opens. This model does not record 100% coverage.

Filtering a Stateflow Transition

In the Mode Logic Stateflow chart, the [!on] transition is never false because it evaluates only when the [on] transition is false. If you do not collect coverage for the [!on] transition, the chart behavior does not change, so you should filter the [!on] transition.

  1. Open the Mode Logic chart.

  2. Right-click the [!on] transition and select Coverage > Exclude this transition.

    The Coverage Filter Viewer opens with the new filter rule listed.

  3. Click in the Rationale field and enter the reason for excluding this transition, for example, This transition is never evaluated.

  4. Save this rule to a filter file with the default name, slvnvdemo_covfilt_covfilter.cvf. Click Apply.

    If you are using this filter for the first time, the file is created in your MATLAB Current Folder. You can specify a different file name and location for your filter file.

  5. Attach this filter file to the slvnvdemo_covfilt model. Click Attach file to model and click Apply.

  6. Click OK to close the Coverage Filter Viewer.

  7. Simulate the model again and review the results in the coverage report.

    Under Filtered Objects, the report lists the [!on] transition as filtered from the coverage analysis.

    If you open the Mode Logic chart and click the transition, the Informer window displays filtering information and the Rationale text.

Filtering a Stateflow Temporal Event

Temporal events in Stateflow are a common cause for missing coverage in a chart, because they sometimes form an condition for coverage that can never be satisfied.

For example, in the Mode Logic chart, as you can see from the coverage report, the temporal event tick is never false.

As a result, you cannot record 100% condition and MCDC coverage for the transition after(4, tick).

To filter this temporal event, filter the transition after(4, tick).

  1. Open the Mode Logic chart.

  2. Right-click the after(4, tick) transition and select Coverage > Exclude temporal event 'tick'.

    The Coverage Filter Viewer opens with the new filter rule listed.

  3. Click in the Rationale field and enter text for excluding this transition, for example, tick is never false.

  4. Save this rule to the current filter. Click Apply.

  5. Simulate the model again and review the results.

    The Filtered Blocks section of the report lists the transition after(4, tick). Condition and MCDC coverage for the Mode Logic chart is not recorded.

Filtering Library Reference Blocks

The slvnvdemo_covfilt model contains two instances of a library-linked subsystem in the library slvnvdemo_covfilt_lib:

The library subsystem is a protection against division by zero and might not be relevant in the coverage report. Exclude it from coverage for this model.

  1. In the model window, right-click either of the protected division reference blocks.

    When you filter a library block, all instances of that block are filtered from coverage.

  2. Select Coverage > Exclude reference library: slvnvdemo_covfilt_lib/protected division.

    The Coverage Filter Viewer opens with the new filter rule listed.

  3. Click in the Rationale field for this new rule and enter text for excluding this transition, for example, Protection against division by zero.

  4. Save this rule to the current filter. Click Apply.

  5. Simulate the model again and review the results.

    The Filtered Blocks section of the report lists both protected division reference blocks. No coverage is recorded for the two protected division subsystems.

    In the model window, the blocks filtered from coverage are colored grey.

Filtering a Subsystem

The slvnvdemo_covfilt model uses a Constant block to drive the enable port for the Switchable config subsystem. Because the constant is always 0, this subsystem never executes.

Exclude the Switchable config subsystem from coverage.

  1. In the model window, right-click the Switchable config subsystem.

  2. Select Coverage > Exclude subsystem with all descendants.

  3. Click in the Rationale field for this new rule and enter text for excluding this transition, for example, Never executed.

  4. Save this rule to the current filter. Click Apply.

  5. Simulate the model again and review the results.

    The Filtered Blocks section of the report lists the Switchable config subsystem. No coverage is recorded for the subsystem.

Filtering a Specific Block

In the slvnvdemo_covfilt model, the rate signal can never be less than or equal to 0, which is the value of the Lower limit parameter of the Saturation block. This condition leads to missing coverage.

Exclude the Saturation block from coverage.

  1. In the model window, right-click the Saturation block.

  2. Select Coverage > Exclude this block.

  3. Click in the Rationale field for this new rule and enter text for excluding this transition, for example, Input never <= lower limit (0).

  4. Save this rule to the current filter. Click Apply.

  5. Simulate the model again and review the results.

    The Filtered Blocks section of the report lists the Saturation block. Coverage for that block is omitted from the report.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS