Main Content

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.

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

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

  3. Configure your model to record coverage during simulation:

    1. In the Simulink Editor, select Model Settings on the Modeling tab.

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

      • Enable coverage analysis

      • Referenced Models

    3. 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, or PIL. In this example, only the first Model block that references sldemo_mdlref_counter_datamngt is 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. Click OK to exit the Select Models for Coverage Analysis dialog box.

  4. Click OK to 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 decision input > lower limit was never false.

      • The decision input >= upper limit was never true.

      Coverage results for the Saturate Count block report that the block receives 50% decision coverage (2 out of 4 decision outcomes satisfied).

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

      • The expression count >= CounterParams.UpperLimit was never true.

      • The expression count > CounterParams.LowerLimit was never false.

      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 to Normal and 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 select Block Parameters (ModelReference).

    The Function Block Parameters dialog box opens.

  2. Set the Simulation mode parameter to Normal.

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

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

    1. In the Simulink Editor, select Model Settings on the Modeling tab.

    2. On the Coverage pane, select Enable coverage analysis.

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

      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 in Normal mode, you can choose to record coverage for all of them or none of them.

    4. Click OK to 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 decision input >= upper limit was true 21 times during this simulation, compared to 0 during the first simulation. The fourth decision input > lower limit was still never false. Three out of four decisions were recorded during simulation, so this block achieved 75% coverage.

      Coverage results for the Saturate Count block report that the block receives 75% decision coverage (3 out of 4 decision outcomes satisfied).

    • The DetectOverflow function executed 100 times. The simulation of the Counter2 block executed the DetectOverflow function an additional 50 times.

      The DetectOverflow function has five decisions. The expression count >= CounterParams.UpperLimit was true 21 times during this simulation, compared to 0 during the first simulation. The expression count > CounterParams.LowerLimit was never false. Four out of five decisions were recorded during simulation, so the DetectOverflow function achieved 80% coverage.

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