Main Content

Code Coverage for Models in Software-in-the-Loop (SIL) Mode and Processor-in-the-Loop (PIL) Mode

If you have Embedded Coder® and Simulink® Coverage™, you can analyze coverage for generated code during a software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation.

Enable SIL or PIL Code Coverage for a Model

To record SIL or PIL code coverage for a model:

  1. Ensure you have a supported compiler installed. For a list of supported compilers, see Supported and Compatible Compilers.

  2. In the Configuration Parameters dialog box, on the left pane, click Code Generation. From the list, select Verification.

  3. Under Code profiling, set Measure function execution times to Off.

  4. Under Code coverage for SIL or PIL, set Third-party tool to None (use Simulink Coverage).

  5. Enable coverage for a model in SIL or PIL mode or a reference model in SIL or PIL mode. For more information about enabling coverage, see Specify Coverage Options (Simulink Coverage).

  6. Run a SIL or PIL simulation.

    Note

    The Coverage (Run) button in the Coverage toolstrip forces a Normal mode simulation for the top-level model and does not yield SIL or PIL code coverage.

    To run a SIL or PIL simulation:

    1. In the Simulink window, click Apps and then click SIL/PIL Manager.

    2. In the SIL/PIL tab, click Automated Verification > SIL/PIL Simulation Only.

    3. Click Run SIL/PIL.

Review the Coverage Results for Models in SIL or PIL Mode

To view the code coverage information in the Code pane, click the menu icon to the right of the search box and select Show code coverage. If the option is disabled, then on the Coverage tab, click Coverage Highlighting. The code displays highlighting and annotations that show code coverage information. You can navigate from the code to the associated model blocks by using the links in the line numbers, code elements, and comments.

Code view showing generated code with coverage annotations. Labels point to coverage annotations and links to model elements.

If you point your cursor at a coverage annotation, a tooltip with additional information appears.

In R2023a: If coverage is missing, you can click the Not covered link in the tooltip to open the Filter Explorer pane of the Coverage Results Explorer with a new justification rule for the outcome you selected.

Code view showing generated code with the cursor pointed at an annotation. The annotation displays a summary of the coverage received for the decision. The false case is satisfied and the true case is not satisfied.

At the bottom of the Code view, Simulink Coverage shows a summary of the code coverage report. Point your cursor at one of the listed metrics to view a tooltip with additional information.

Code coverage summary section of the Code view. The cursor is pointed at condition 41%, the tooltip displays a message that says 5 out of 12 conditions covered.

Limitations

Coverage for models in SIL and PIL mode has these limitations:

  • The model must meet the requirements listed in Enable SIL or PIL Code Coverage for a Model.

  • Code coverage results must not include external C/C++ files in read-only folders.

  • The Coverage (Run) button in the Coverage toolstrip forces a Normal simulation and will not yield SIL or PIL code coverage.

  • Code coverage cannot be analyzed for processor-in-the-loop mode on Mac machines.

  • The Code pane does not support annotations or tooltips for Modified Condition Decision Coverage (MCDC) outcomes. As a result, you cannot justify these outcomes from the Code pane.

  • The Code pane does not support creating exclusion filter rules. To create exclusion filter rules, use the coverage report.

Related Topics