Software-in-the-Loop Code Coverage
This example shows how to collect code coverage metrics from a model reference using software-in-the-loop (SIL) mode.
Generate Code Coverage Results
slvnvdemo_counter_harness is a harness model that uses a Signal Editor block to specify inputs for a model reference to the
The model is configured for coverage, but the simulation mode is set to
Normal. In normal simulation mode, you can only collect model coverage data. To collect software-in-the-loop coverage, use one of the following methods:
From a model reference, set the simulation mode for the referenced model in the block parameters of the Model block. Click the Model block
slvnvdemo_counter, then click the Model Block tab. Set Simulation Mode, to
Software-in-the-Loop (SIL). The corners of the block icon turn black and (SIL) appears under the model name on the block.
In the Apps tab, click Coverage Analyzer. Then, on the Coverage tab, click Analyze Coverage. Simulink Coverage® collects coverage for the generated code of the referenced subsystems that use SIL simulation mode.
Use the SIL/PIL Manager app to run the simulation. Use this approach when you want to collect coverage on the top model and the referenced models, or when the Scope of coverage analysis is set to
Entire System. On the Apps tab. On the Apps tab, click SIL/PIL Manager. Click Run Verification. Simulink Coverage® collects coverage for the generated code of the SIL/PIL simulation. Note that if you want to collect coverage on the top model, the Analyze Coverage button always runs a normal mode simulation and does not generate code coverage results.
For more information about configuring a model for coverage, see Specify Coverage Options.
View the Coverage Results in Coverage Details
When the simulation finishes, Simulink® opens the Code and Coverage Details panes. You can view only one of these panes at a time. The Code pane opens by default and contains the details of the code generated from your model. At the bottom of the Code pane, click the Coverage Details tab.
The pane displays the message
Coverage was not recorded for
slvnvdemo_counter_harness. This message appears because the model is configured to collect coverage for the model reference
slvnvdemo_counter and not the top model,
slvnvdemo_counter_harness. Double click the model block
slvnvdemo_counter to see coverage results for this model reference.
Scroll to the top of the Coverage Details pane to see that this is the SIL mode coverage summary.
Click Details to view the Details section of the coverage report. This section lists the code coverage organized by the source files, the functions called by those files, and the individual coverage objective outcomes that make up the functions.
In the model, click on the Switch block called
limit to see the Details By Model Object section of the report, which lists the expressions and functions for each model object. For example, the Switch block
limit receives decision and statement code coverage on lines 48, 50, and 53 of the function
slvnvdemo_counter.c and the covered expression is
View the Coverage Results in Code View
You can also see coverage results in the code view created by Embedded Coder®. At the bottom of the Coverage Details pane, click Code.
Each line of code has an annotation that indicates whether it has full coverage. For example, line 40 has the following annotations:
^Sbeneath the statement
rtb_inputGElower, colored in green, indicates that the line executed and receives full statement coverage.
^tfbeneath the condition
rtb_input >= *rtu_lower, colored in green, indicates that both the true and false cases of the condition executed and the condition has full condition coverage.
For more information about code view annotations, see Code Coverage for Models in Software-in-the-Loop (SIL) Mode and Processor-in-the-Loop (PIL) Mode (Embedded Coder).
Create and View a Standalone Coverage Report
To create a standalone code coverage report, in the Coverage tab, click Generate Report. The code coverage report contains a section that displays the generated code.
Each code statement and logic block contains a comment or set of comments that describe the source block from which the code was generated. Each comment also contains a link that brings you back to the model and to aid in model-to-code mapping.