Model Coverage for Multiple Instances of a Referenced Model
About Coverage for Model Blocks
Model blocks do not receive coverage directly;
if you set the simulation mode of the Model block to Normal
, SIL
,
or PIL
, the Simulink®
Coverage™ software
records coverage for the model referenced from the Model block.
If the simulation mode for the Model block is anything
other than Normal
, SIL
,
or PIL
, the software does not record coverage
for the referenced model.
Your Simulink model can contain multiple Model blocks with the same simulation mode that reference the same model. When the software records coverage, each instance of the referenced model can be exercised with different inputs or parameters, possibly resulting additional coverage data for the referenced model.
The Simulink Coverage software records 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.
Record Coverage for Multiple Instances of a Referenced Model
To see how this works, simulate a model twice. The first time, you record coverage for
one Model block in Normal
simulation mode. The
second time, you record coverage for two Model blocks in
Normal
simulation mode. Both Model blocks
reference the same model.
Record Coverage for the First Instance of the Referenced Model
Record coverage for one Model block.
Open your top-level model. For this example, use the
sldemo_mdlref_datamngt
model in the Introduction to Managing Data with Model Reference example.openExample('sldemo_mdlref_datamngt')
This model contains three Model blocks that reference the
sldemo_mdlref_counter_datamngt
example model. The corners of each Model block indicate the value of their Simulation mode parameter:Counter1 — Simulation mode:
Normal
Counter2 — Simulation mode:
Accelerator
Counter3 — Simulation mode:
Accelerator
Configure your model to record coverage during simulation:
In the Simulink Editor, select Model Settings on the Modeling tab.
On the Coverage pane of the Configuration Parameters dialog box, select:
Enable coverage analysis
Referenced Models
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
. In this example, only the first Model block that referencessldemo_mdlref_counter_datamngt
is available for recording coverage.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 your model.
When the simulation is complete, the HTML coverage report opens. In this example, the coverage data for the referenced model,
sldemo_mdlref_counter_datamngt
, shows that the model achieved 69% coverage.Click the hyperlink in the report for the referenced model.
The detailed coverage report for the referenced model opens, and the referenced model appears with highlighting to show coverage results.
Note the following about the coverage for the Range Check subsystem in this example:
The Saturate Count block executed 100 times. This block has four Boolean decisions. Decision coverage was 50%, because two of the four decisions were never recorded:
The decision
input > lower limit
was neverfalse
.The decision
input >= upper limit
was nevertrue
.
The
DetectOverflow
function executed 50 times. This script has five decisions. TheDetectOverflow
script achieved 60% coverage because two of the five decisions were never recorded:The expression
count >= CounterParams.UpperLimit
was nevertrue
.The expression
count > CounterParams.LowerLimit
was 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 Function Block Parameters dialog box opens.
Set the Simulation mode parameter to
Normal
.Click OK to save your change and exit the Function Block Parameters dialog box.
The corners of the Model block change to indicate that the simulation mode for this block is
Normal
, as in the example below.To make sure that the software records coverage for both instances of this model:
In the Simulink Editor, select Model Settings on the Modeling tab.
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 both instances of the referenced model are selected. In this example, the list now looks like the following.
If you have multiple instances of a referenced model in
Normal
mode, you can choose to record coverage for all of them or none of them.Click OK to close the Select Models for Coverage Analysis dialog box.
Simulate your model again.
When the simulation is complete, open the HTML coverage report.
In this example, the referenced model achieved 85% coverage. Note the following about the coverage data for the Range Check subsystem:
The Saturate Count block executed 179 times. The simulation of the Counter2 block executed the Saturate Count block an additional 79 times, for a total of 179 executions.
The decision
input >= upper limit
wastrue
21 times during this simulation, compared to 0 during the first simulation. The fourth decisioninput > lower limit
was still neverfalse
. Three out of four decisions were recorded during simulation, so this block achieved 75% coverage.The
DetectOverflow
function executed 100 times. The simulation of the Counter2 block executed theDetectOverflow
function an additional 50 times.The
DetectOverflow
function has five decisions. The expressioncount >= CounterParams.UpperLimit
wastrue
21 times during this simulation, compared to 0 during the first simulation. The expressioncount > CounterParams.LowerLimit
was neverfalse
. Four out of five decisions were recorded during simulation, so theDetectOverflow
function achieved 80% coverage.