Main Content

Use Justification Rules to Filter Code Coverage Outcomes

This example shows how to filter code coverage outcomes in the coverage report after collecting coverage for a model in software-in-the-loop (SIL) or processor-in-the-loop (PIL) mode.

Generate Code Coverage Data

First, put the model into SIL/PIL mode. In the Simulink® window, click Apps and, under Code Verification, Validation, and Test, click SIL/PIL Manager. On the SIL/PIL tab, change Automated Verification to SIL/PIL Simulation Only.

In this example model, coverage is enabled by default. If you are using your own model, enable coverage in the Configuration Parameters window. For more information about coverage settings, see Specify Coverage Options.

Simulate the model and collect coverage by clicking Run SIL/PIL. When you simulate the model, a docked pane opens next to the Simulink® model. Click the Coverage Details tab to see the code coverage report.

### Starting build procedure for: slvnvdemo_counter
### Successful completion of build procedure for: slvnvdemo_counter

Build Summary

Top model targets built:

Model              Action                        Rebuild Reason                                    
slvnvdemo_counter  Code generated and compiled.  Code generation information file does not exist.  

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 29.3s
### Preparing to start SIL simulation ...
Building with 'gcc'.
MEX completed successfully.
### Updating code generation report with SIL files ...
### Starting SIL simulation for component: slvnvdemo_counter
### Application stopped
### Stopping SIL simulation for component: slvnvdemo_counter
### Completed code coverage analysis

Justify Missing Code Coverage Using Coverage Filters

If your model has unreachable logic that is intentional, such as defensive model design or exception handling, you can justify this missing coverage using coverage filters.

The Summary section of the code coverage report links to each source file and function. In this example, click slvnvdemo_counter_step. The code coverage report jumps to the function named slvnvdemo_counter_step. In section 2.1, you can see that both conditions inside the decision (!(slvnvdemo_counter_U.upper >=z rtb_input)) | (!rtb_inputGElower) are false for all time steps.

To justify a missing coverage outcome, in the Conditions analyzed table, next to the condition slvnvdemo_counter_U.upper >= rtb_input, click the Add justification rule icon. The Coverage Results Explorer opens and creates a filter rule to justify the false outcome of the condition slvnvdemo_counter_U.upper >= rtb_input.

In the Filter Editor pane, set the Name field to myCodeCovFilter. You can set the Description field to any descriptive text. The Filter Rules section has two tabs, Model and Code. In this case, the filter appears on the Code tab because you are filtering from the code coverage report. You can double-click the Rationale field to add a reason, for example "Expected result."

Near the top of the Filter Editor, under the Filename field, click Save as. In the Save filter window, name the filter file myCodeCovFilter. Note that the filter name and the filter file name do not have to be the same.

When you save the filter, the code coverage report updates and displays the justified outcome.

Justify the false case of the second condition by clicking the Add justification rule filter next to rtb_inputGElower and following the steps listed above. This second rule is added to the same filter file that you created for the first rule.

You can create a new code coverage report after applying coverage filters by clicking Current Cumulative Data (H) in the left pane of the Coverage Results Explorer, and then clicking Generate report at the bottom of the Coverage Data pane. This link creates a standalone report which you can use for archiving or sharing reports.

The summary section of the code coverage report reflects the improved condition coverage due to the filter rules.

Additionally, the code coverage report now shows a section titled Objects Filtered from Coverage Analysis that displays the filter rules and rationales.

Related Topics