Model Coverage for Multiple Instances of a Referenced Model
Model blocks themselves receive only block execution coverage. If you set
the simulation mode of the Model block to Normal ,
software-in-the-loop (SIL), or
processor-in-the-loop (PIL), Simulink®
Coverage™ analyzes coverage for the model referenced by the Model
block.
Your Simulink model can contain multiple Model blocks with the same simulation mode that reference the same model. When you analyze coverage, you can specify different inputs or parameters for each instance of the referenced model. You can use this approach to satisfy additional coverage objectives for the referenced model.
Simulink Coverage analyzes coverage for all instances of the referenced model with the same simulation mode and combines the coverage data for that referenced model in the final results.
To see how coverage treats multiple instances of a referenced model, simulate a model
twice. The first time, you record coverage for one Model block in
Normal simulation mode. The second time, record coverage for
two Model blocks in Normal simulation mode. Both
Model blocks reference the same model. In both simulations, you only see
coverage results for the instances of the model reference that are in normal simulation
mode, because you cannot collect coverage for multiple simulation modes in one
simulation.
Record Coverage for the First Instance of the Referenced Model
Record coverage for one Model block.
Open your top-level model. For example, this model contains three Model blocks that reference the
sldemo_mdlref_counter_datamngtmodel.
The corners of each Model block indicate the value of their Simulation mode parameter:
Counter1 — Simulation mode:
NormalCounter2 — Simulation mode:
AcceleratorCounter3 — Simulation mode:
Accelerator
Configure your model to record coverage during simulation:
In the Simulink Editor, on the Modeling tab, select Model Settings.
In the Configuration Parameters dialog box, in the left pane, click Coverage.
In the Coverage pane, select Enable coverage analysis and then select the Referenced Models radio button.
Click Select Models. In the Select Models for Coverage Analysis dialog box, you can select only those referenced models whose simulation mode is
Normal,SIL, orPIL. The dialog box displays the model once for each simulation mode. In this example, you can only select the first Model block that referencessldemo_mdlref_counter_datamngtbecause that represents the instance of the model that uses normal simulation mode.
Click OK to exit the Select Models for Coverage Analysis dialog box.
Click OK to save your coverage settings and exit the Configuration Parameters dialog box.
Simulate the model by clicking the Run (Coverage) button.
When the simulation completes, the Coverage Details pane opens and displays the coverage report. For this case, the coverage data for the referenced model,
sldemo_mdlref_counter_datamngt, shows that the model achieved 85% coverage.To view the contents of a referenced model, click the arrow in the bottom-left corner of the Model block. The Coverage Details pane shows the coverage report for the referenced model and highlights the blocks to show the coverage results.

In this example, for the
Range Checksubsystem:The Saturate Count block executes 50 times. This block has four decision outcomes. Decision coverage is 50%, because two of the four decision outcomes are not satisfied:
The decision
input >= lower limitis neverfalse.The decision
input > upper limitis nevertrue.

The
DetectOverflowfunction executes 50 times. This script has five decisions. TheDetectOverflowscript achieves 60% coverage because two of the five decision outcomes are not satisfied. The expressioncount >= CounterParams.UpperLimitis nevertrue, and the expressioncount > CounterParams.LowerLimitis neverfalse.
Record Coverage for the Second Instance of the Referenced Model
Record coverage for two Model blocks. Set the simulation mode of a second Model block
to Normal and simulate the model. In this example, the
Counter2 block adds to the coverage for the model referenced from
both Model blocks.
In the Simulink Editor for your top-level model, right-click a second Model block and select Block Parameters (ModelReference).
The Block Parameters dialog box opens.
Set the Simulation mode parameter to
Normal.Click OK to save your change and exit the Block Parameters dialog box.
The corners of the Model block change to indicate that the simulation mode for this block is
Normal.
To record coverage for both instances of this model:
On the Modeling tab, select Model Settings.
On the Coverage pane, select Enable coverage analysis.
Select Referenced Models and click Select Models.
In the Select Models for Coverage Analysis dialog box, verify that the referenced model is selected. In this example, the list now looks like the following.

Click OK to close the Select Models for Coverage Analysis dialog box.
Simulate the model again.
When the simulation completes, the Coverage Details pane updates the coverage report with the additional coverage data.
The referenced model achieves 85% coverage. Inside the
Range Checksubsystem:The Saturate Count block executes 100 times. The simulation of the
Counter2model block causes an additional 50 executions of the Saturate Count block.The decision
input > upper limitistrue18 times during this simulation, compared to 0 during the first simulation. The fourth decisioninput > lower limitis still neverfalse. Three out of four decisions are recorded during simulation, so this block achieves 75% decision coverage.
The
DetectOverflowfunction executes 100 times. The simulation of theCounter2block executes theDetectOverflowfunction an additional 50 times.The
DetectOverflowfunction has five decisions. The expressioncount >= CounterParams.UpperLimitistrue21 times during this simulation, compared to 0 during the first simulation. The expressioncount > CounterParams.LowerLimitis neverfalse. Four out of five decisions are satisfied during simulation, so theDetectOverflowfunction achieves 80% decision coverage.