Main Content

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.

  1. Open your top-level model. For example, this model contains three Model blocks that reference the sldemo_mdlref_counter_datamngt 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

  2. Configure your model to record coverage during simulation:

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

    2. In the Configuration Parameters dialog box, in the left pane, click Coverage.

    3. In the Coverage pane, select Enable coverage analysis and then select the Referenced Models radio button.

    4. 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. The dialog box displays the model once for each simulation mode. In this example, you can only select the first Model block that references sldemo_mdlref_counter_datamngt because that represents the instance of the model that uses normal simulation mode.

      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.

    5. Click OK to exit the Select Models for Coverage Analysis dialog box.

  3. Click OK to save your coverage settings and exit the Configuration Parameters dialog box.

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

  5. 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 Check subsystem:

    • 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 limit is never false.

      • The decision input > upper limit is 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 executes 50 times. This script has five decisions. The DetectOverflow script achieves 60% coverage because two of the five decision outcomes are not satisfied. The expression count >= CounterParams.UpperLimit is never true, and the expression count > CounterParams.LowerLimit is never false.

      Coverage results for the MATLAB function DetectOverflow report that the function receives 80% decision coverage (4 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 Block Parameters dialog box opens.

  2. Set the Simulation mode parameter to Normal.

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

  4. To record coverage for both instances of this model:

    1. On the Modeling tab, select Model Settings.

    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 the referenced model is selected. In this example, the list now looks like the following.

      Model reference selection dialog shows three entries. The first line is the top model which is not selected for coverage analysis. The second selection is the referenced model in normal mode and the third entry is the referenced model in accelerator mode.

    4. Click OK to close the Select Models for Coverage Analysis dialog box.

  5. Simulate the model again.

  6. 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 Check subsystem:

    • The Saturate Count block executes 100 times. The simulation of the Counter2 model block causes an additional 50 executions of the Saturate Count block.

      The decision input > upper limit is true 18 times during this simulation, compared to 0 during the first simulation. The fourth decision input > lower limit is still never false. Three out of four decisions are recorded during simulation, so this block achieves 75% decision 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 executes 100 times. The simulation of the Counter2 block executes the DetectOverflow function an additional 50 times.

      The DetectOverflow function has five decisions. The expression count >= CounterParams.UpperLimit is true 21 times during this simulation, compared to 0 during the first simulation. The expression count > CounterParams.LowerLimit is never false. Four out of five decisions are satisfied during simulation, so the DetectOverflow function achieves 80% decision coverage.

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

See Also

Related Topics