Documentation Center

  • Trial Software
  • Product Updates

Filter Model Objects to Refine Coverage Results

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:

  • Decision coverage

  • Condition coverage

  • Modified condition/decision coverage (MCDC)

Simulate Example Model and Review Coverage

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

  1. Open the example model:

    slvnvdemo_covfiltslvnvdemo_covfilt
  2. Select Simulation > Run.

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

Filter 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.

Filter a Stateflow Event

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, the temporal event tick is never false, as you can see from the coverage report.

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

To filter the temporal event tick from coverage analysis for this model:

  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 explanatory text, for example, tick is never false.

  4. Select Attach file to model and click Apply to save this rule to the current filter.

    Click OK to close the Coverage Filter Viewer.

  5. Simulate the model again and review the results.

    The Objects filtered from coverage analysis section of the report lists the conditions of the event tick that are excluded, along with the corresponding Rationale text you entered in the Coverage Filter Viewer.

    With the tick event filtered from coverage analysis, there is no longer a subcondition on the decision for the after(4, tick) transition. There are only two possible decision outcomes for the after(4, tick) transition.

Filter Library Reference Blocks

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

  • protected division

  • protected division1

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 Simulink® Editor, 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 Simulink Editor, the blocks filtered from coverage are colored grey.

Filter 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 Simulink Editor, 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.

Filter 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 Simulink Editor, 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.

Was this topic helpful?