Main Content

Model Coverage for Variant Blocks

Simulink® Coverage™ can analyze and report coverage data for models containing variant blocks, such as Variant Source or Variant Subsystem blocks. When you simulate a model containing one or more variant blocks with coverage enabled, Simulink Coverage reports the coverage results depending on the type of variant block and the Variant activation time parameter.

For Variant Source and Variant Sink blocks, Simulink Coverage analyzes the upstream and downstream blocks of the variant choices, respectively. The Variant Source and Variant Sink block itself does not receive coverage. For Variant Subsystem and Variant Model blocks, Simulink Coverage analyzes the contents of the subsystem or model blocks for the selected metrics.

Update-Time and Compile-Time Variants

If you set the Variant activation time parameter of a variant block to update diagram, update diagram analyze all choices, or code compile, Simulink Coverage reports coverage only for the variant choice that is active during the simulation.

Tip

You cannot aggregate coverage for simulations with different active variant choices for update-time or compile-time variants. If you want to test all possible variant choices, consider setting Variant activation time to startup.

For example, suppose you have a model that contains a Variant Subsystem block with two variant choices. The Variant activation time parameter of the Variant Subsystem block is set to update diagram.

Simulink model containing a variant subsystem. A graphic shows that the variant subsystem expands into two variant choices.

If Subsystem1 is active for the simulation, you receive coverage results for Subsystem1 and not Subsystem2.

In the coverage results, Subsystem1 is red, which indicates that it received incomplete coverage, and Subsystem2 is grey which indicates that it was not analyzed. Additionally, the coverage report summary omits the variant choices that were not active.

Coverage report summary showing Subsystem 1 has 50% decision and 100% block execution coverage. Subsystem 2 is omitted from the summary.

When you set the Variant activation time parameter of a variant block to update diagram, update diagram analyze all choices, or code compile, changing the active variant is a structural change to the model. Because the coverage data for a model is only valid as long as the model is not changed or closed, you cannot aggregate coverage for the same model simulated with different active variants. If you want to test multiple active variants and aggregate coverage for them, change the Variant activation time parameter to startup.

Startup Variants

If you set the Variant activation time parameter of a variant block to startup, Simulink Coverage reports coverage for all variant choices, even if they are not active during the simulation. You can also aggregate coverage for simulations with different active variant choices.

For example, if you modify the model in the previous example and set the Variant activation time to startup and Subsystem1 is active for the simulation, you get the same coverage for Subsystem1 as the case with the update time variant. However, Simulink Coverage also reports on the inactive variant, Subsystem2.

In the coverage results, Subsystem1 and Subsystem2 are both red which indicates incomplete coverage. The coverage report summary includes all variant choices.

Coverage report summary showing the top model has 30% decision coverage, the variant subsystem has 25% decision coverage, the variant child Subsystem 1 has 50% decision coverage, and the variant child Subsystem 2 has 0% decision coverage.

The inactive variants receive 0% coverage because they were not executed during the simulation. To increase the reported coverage for Variant_Subsystem, you can simulate the model again with Subsystem2 as the active variant and then aggregate the coverage results.

Aggregated Tests and Summary sections of the coverage report. Coverage results from two simulations aggregated together show the top model has 60% decision coverage, the variant subsystem has 50% decision coverage, the variant child Subsystem 1 has 50% decision coverage, and the variant child Subsystem 2 has 50% decision coverage.

If you want to use startup variant blocks, but you do not want to see inactive variants reported with 0% coverage, you can create exclusion filter rules. For more information about creating coverage filter rules, see Create, Edit, and View Coverage Filter Rules.

Related Topics

See Also

| |