MATLAB: How to get coverage for all instances of a library block in a model

Simulink Coveragesimulink test

In my model, there are library blocks (e.g. libraryBlock) that are used multiple times (e.g. libraryBlock_1 and libraryBlock_2). To get coverage for the model, we use it on libraryBlock_1 and we get full coverage for that block. Although libraryBlock_2 is also using the same library block, it shows missing coverage.
Is there a way for coverage analysis to identify that these blocks are basically the same and consider full coverage for all of them as long one has full coverage?

Best Answer

Simulink library blocks receive the same coverage that they would receive if they were not linked to library objects. Each instance of a library block is treated separately when coverage data is collected for the model. This is done because model coverage calculates how much a model test case exercises simulation pathways through a model.

As mentioned in this documentation page,

https://www.mathworks.com/help/releases/R2019b/slcoverage/ug/model-objects-that-receive-coverage.html#btteiqs

If you feel that the coverage for a single instance of the library block (ie libraryBlock_1) should apply to all instances of the library block (such as libraryBlock_2), you can use Coverage Filtering to either exclude or justify those instances of the library block. This example takes you through the process of doing that:

https://www.mathworks.com/help/releases/R2019b/slcoverage/examples/creating-and-using-coverage-filters.html

If you are evaluating coverage results through the Simulink Test Manager, then this link will also be useful for filtering coverage results:

https://www.mathworks.com/help/releases/R2019b/sltest/ug/collect-model-coverage-in-tests.html