Main Content

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 inNormalsimulation mode. The second time, you record coverage for twoModelblocks inNormalsimulation mode. BothModelblocks reference the same model.

Record Coverage for the First Instance of the Referenced Model

Record coverage for one Model block.

  1. Open your top-level model. For this example, use thesldemo_mdlref_datamngtmodel in theIntroduction to Managing Data with Model Referenceexample.

    openExample('sldemo_mdlref_datamngt')

  2. This model contains three Model blocks that reference thesldemo_mdlref_counter_datamngtexample 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

  3. Configure your model to record coverage during simulation:

    1. In the Simulink Editor, selectModel Settingson theModelingtab.

    2. On theCoveragepane of the Configuration Parameters dialog box, select:

      • Enable coverage analysis

      • Referenced Models

    3. ClickSelect Models. In the Select Models for Coverage Analysis dialog box, you can select only those referenced models whose simulation mode isNormal,SIL, orPIL. In this example, only the first Model block that referencessldemo_mdlref_counter_datamngtis available for recording coverage.

      Model reference selection dialog shows three models referenced by the top model. One of the referenced models has a check box to select, and the other two do not.

    4. ClickOKto exit the Select Models for Coverage Analysis dialog box.

  4. ClickOKto save your coverage settings and exit the Configuration Parameters dialog box.

  5. 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.

  6. 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 decisioninput > lower limitwas neverfalse.

      • The decisioninput >= upper limitwas nevertrue.

      报道结果饱和数块回购rt that the block receives 50% decision coverage (2 out of 4 decision outcomes satisfied).

    • TheDetectOverflowfunction executed 50 times. This script has five decisions. TheDetectOverflowscript achieved 60% coverage because two of the five decisions were never recorded:

      • The expressioncount >= CounterParams.UpperLimitwas nevertrue.

      • The expressioncount > CounterParams.LowerLimitwas neverfalse.

      Coverage results for the MATLAB function DetectOverflow report that the function receives 60% decision coverage (3 out of 5 decision outcomes satisfied).

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 toNormaland simulate the model. In this example, the Counter2 block adds to the coverage for the model referenced from both Model blocks.

  1. 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.

  2. Set theSimulation modeparameter toNormal.

  3. 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 isNormal, as in the example below.

  4. To make sure that the software records coverage for both instances of this model:

    1. In the Simulink Editor, selectModel Settingson theModelingtab.

    2. On theCoveragepane, selectEnable coverage analysis.

    3. 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.

      Model reference selection dialog shows three models referenced by the top model. Two of the referenced models have a check box to select, and the other one does not.

      If you have multiple instances of a referenced model inNormalmode, you can choose to record coverage for all of them or none of them.

    4. ClickOKto close the Select Models for Coverage Analysis dialog box.

  5. Simulate your model again.

  6. 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 decisioninput >= upper limitwastrue21 times during this simulation, compared to 0 during the first simulation. The fourth decisioninput > lower limitwas still neverfalse. Three out of four decisions were recorded during simulation, so this block achieved 75% coverage.

      报道结果饱和数块回购rt that the block receives 75% decision coverage (3 out of 4 decision outcomes satisfied).

    • TheDetectOverflowfunction executed 100 times. The simulation of the Counter2 block executed theDetectOverflowfunction an additional 50 times.

      TheDetectOverflowfunction has five decisions. The expressioncount >= CounterParams.UpperLimitwastrue21 times during this simulation, compared to 0 during the first simulation. The expressioncount > CounterParams.LowerLimitwas neverfalse. Four out of five decisions were recorded during simulation, so theDetectOverflowfunction achieved 80% coverage.

      Coverage results for the DetectOverflow function report that the function receives 80% decision coverage (4 out of 5 decision outcomes satisfied).