Why does adding/removing a scope block from my Simulink model affect code coverage results in R2021a?

Commenting and uncommenting scope blocks seems to affect code coverage results. Why is this happening?

 Accepted Answer

In Simulink, when one switch block is upstream from another switch block, Simulink performs Conditional Branch Optimization. See the following link:
If there exists a scope block between the two switch blocks, this interferes with the optimization. However, when the scope block is commented/removed, the optimization occurs as it normally would, reducing coverage results. At the bottom of the documentation page linked, there is a section titled "Address Incomplete Coverage" which has a few different approaches you can take to resolve the issue.  To disable this optimization, change the setting "ConditionallyExecuteInputs."
Alternatively, you might try to add additional tests to fully satisfy coverage even when this optimization is "on," and the scope blocks have been removed.  Keep in mind that, since these branches can be optimized out, the model is in a state such that these input branches don't have any downstream effect on the output.  Therefore, there are some coverage outcomes for some blocks which their tests currently hit, but they never hit at a time when they really matter (i.e. when they would affect the output of the model). 

More Answers (0)

Categories

Find more on Verification, Validation, and Test in Help Center and File Exchange

Products

Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!