Main Content

Coverage for Models with Code Blocks and Simulink Blocks

This example shows how to record coverage for a model that contains a combination of code blocks and other Simulink® blocks.

The model is a cruise control system that consists of test cases and input signals from a Signal Editor block. The signals from the Signal Editor act as inputs to the Stateflow® chart ComputeTargetSpeed, which engages or disengages the cruise control system and sets the target speed, tspeed.

Configure Up the Model to Record Coverage

In the Simulink Editor, select Modeling > Model Settings. In the Code Generation pane, set the System target file in the Target selection menu to ert.tlc. In the Verification tab of the Code Generation pane, set the Code coverage for SIL or PIL parameter, to None (use Simulink Coverage).

Double click the RejectDoublePress block to open the S-Function Builder block. In the S-Function Builder tab, click the arrow beneath Build and select Enable support for coverage. To build the S-Function, click Build.

Note that to build the S-Function, you must have a compiler installed. For more information on supported compilers for various platforms, see Supported and Compatible Compilers.

Record Coverage

The Signal Editor block consists of eight signal groups with five signals each. In this example, you simulate all the signal groups and record coverage.

In the Simulink® toolstrip, click Simulation > Prepare > Multiple Simulations. In the Multiple Simulations pane, click the folder icon, then in the Select File to Open dialog, select slvnvdemo_doublepress_sfun_ds.mldatx. In the Simulation tab, click Run All (Coverage). At the end of the simulation, the Coverage Results Explorer opens, showing the results for the latest coverage analysis. The blocks in the model are highlighted in different colors corresponding to the level of coverage achieved by each block.

Review Results by Generating a Coverage Report

The Coverage Results Explorer offers several options for displaying and reporting coverage results. Select the Not_Engaged_with_Enable group in the Current Cumulative Data tab of the left pane. Click the Generate report link at the bottom of the Coverage Results Explorer to generate an HTML coverage report. The coverage report lists model coverage for Simulink model blocks and code coverage for code blocks. Scroll down to view the coverage metrics for the S-Function block in the coverage report. Click the Detailed Report link to open the code coverage report for the S-Function block. For more details on the code coverage report for S-Function blocks, see View Coverage Results for Custom C/C++ Code in S-Function Blocks.

Justify Missing Coverage

In this example, you justify coverage for one input signal group by creating a coverage filter. In the code coverage report for the S-Function block created in Review Results by Generating a Coverage Report, scroll down to Decision/Condition 2.1 !(CoastSetSwIn[0] && AccelResSwIn[0]). This condition is never False for the current test case.

Click the Justify or Exclude link under the detailed results for this condition. The Filter tab of the Coverage Results Explorer opens, and the rule filtering this transition is added. Change the Mode for this rule to Justified and enter a description for the Rationale, such as expression cannot be false. Click Apply to apply the changes.

After you click Apply, the Generate report link becomes available. Click the link to generate the report with the updated coverage filter. The new code coverage report for the RejectDoublePress S-Function block lists the excluded condition under Objects Filtered from Coverage Analysis. The detailed results for the condition !(CoastSetSwIn[0] && AccelResSwIn[0]) show that missing coverage for this condition has been justified. The justified objects are treated as satisfied when reporting coverage percentages and appear light blue in the Coverage Summary.

For more information on coverage filters, see Coverage Filtering.

See Also

| |