Model Coverage for Multiple Instances of a Referenced Model
About Coverage for Model Blocks
Modelblocks do not receive coverage directly; if you set the simulation mode of theModelblock toNormal
,SIL
, orPIL
,金宝app®Coverage™software records coverage for the model referenced from theModelblock. If the simulation mode for theModelblock is anything other thanNormal
,SIL
, orPIL
,software does not record coverage for the referenced model.
你Simulink model can contain multipleModelblocks 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.
TheSimulink Coveragesoftware 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 oneModelblock inNormal
simulation mode. The second time, you record coverage for twoModelblocks inNormal
simulation mode. BothModelblocks 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 theIntroduction to Managing Data with Model Referenceexample.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 theirSimulation modeparameter:Counter1 — Simulation mode:
Normal
Counter2 — Simulation mode:
Accelerator
Counter3 — Simulation mode:
Accelerator
Configure your model to record coverage during simulation:
In the Simulink Editor, selectModel Settingson theModelingtab.
On theCoveragepane of the Configuration Parameters dialog box, select:
Enable coverage analysis
Referenced Models
ClickSelect 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.ClickOKto exit the Select Models for Coverage Analysis dialog box.
ClickOKto 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 toNormal
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 selectBlock Parameters (ModelReference).
The Function Block Parameters dialog box opens.
Set theSimulation modeparameter to
Normal
.ClickOKto 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, selectModel Settingson theModelingtab.
On theCoveragepane, selectEnable coverage analysis.
SelectReferenced Modelsand clickSelect Models.
In theSelect Models for Coverage Analysisdialog 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.ClickOKto 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.