Using Simulink |
 |
Model Coverage Tool
The Model Coverage Tool determines the extent to which a model test case exercises simulation pathways through a model. The percentage of pathways that a test case exercises is called its model coverage. Model coverage is a measure of how thoroughly a test tests a model. The Model Coverage Tool therefore helps you to validate your model tests.
Note
You must have the Simulink Performance Tools option installed on your system to use the Model Coverage Tool.
|
How the Model Coverage Tool Works
The Model Coverage Tool works by analyzing the execution of blocks that directly or indirectly determine simulation pathways through your model. If a model includes Stateflow charts, the tool also analyzes the states and transitions of those charts. During a simulation run, the tool records the behavior of the covered blocks, states, and transitions. At the end of the simulation, the tool reports the extent to which the run exercised potential simulation pathways through each covered block.
Coverage Analysis
The tool performs any or all of the following types of coverage analysis, depending on which coverage options you select:
- Cyclomatic complexity is a measure of the structural complexity of a model. It approximates the McCabe complexity measure for code generated from the model. In general, the McCabe complexity measure is slightly higher because of error checks that the model coverage analysis does not consider.
The Model Coverage Tool uses the following formula to compute the cyclomatic complexity of an object (block, chart, state, etc.):
- where
N
is the number of decision points that the object represents and o
n is the number of outcomes for the n
th decision point. The tool adds 1 to the complexity number computed by this formula for atomic subsystems and Stateflow charts.
- Examines items that represent decision points in a model, such as the Switch blocks and Stateflow states. For each item, decision coverage determines the percentage of the total number of simulation paths through the item that the simulation actually traversed.
- Examines blocks that output the logical combination of their inputs, e.g., the Logic block, and Stateflow transitions. A test case achieves full coverage if it causes each input to each instance of a logic block in the model and each condition on a transition to be true at least once during the simulation and false at least once during the simulation. Condition coverage analysis reports for each block in the model whether the test case fully covered the block.
- Modified condition/decision coverage (MC/DC)
- Examines blocks that output the logical combination of their inputs (e.g., the Logic block) and Stateflow transitions to determine the extent to which the test case tests the independence of logical block inputs and transition conditions. A test case achieves full coverage for a block if, for every input, there is a pair of simulation times when changing that input alone causes a change in the block's output. A test case achieves full coverage for a transition if, for each condition on the transition, there is at least one time when a change in the condition triggers the transition.
- Lookup table (LUT) coverage
- Examines blocks, such as the 1D Look-Up block, that output the result of looking up one or more inputs in a table of inputs and outputs, interpolating between or extrapolating from table entries as necessary. Lookup table coverage records the frequency that table lookups use each interpolation interval. A test case achieves full coverage if it executes each interpolation and extrapolation interval at least once. For each LUT block in the model, the coverage report displays a colored map of the lookup table indicating where each interpolation was performed.
Covered Blocks
The following table lists the types of Simulink blocks analyzed by the tool and the kind of coverage analysis performed for each block.
Block
|
Decision
|
Condition
|
MC/DC
|
LUT
|
1D Look-Up
|
|
|
|

|
2D Look-Up
|
|
|
|

|
Abs
|

|
|
|
|
Combin. Logic
|

|

|
|
|
Discrete-Time Integrator (when saturation limits are enabled)
|

|
|
|
|
Fcn (Boolean operators only)
|
|

|
|
|
For
|

|
|
|
|
If
|

|
|
|
|
Logic
|
|

|

|
|
MinMax
|

|
|
|
|
Multiport Switch
|

|
|
|
|
Rate Limiter
|
 (relative to slew rates)
|
|
|
|
Relay
|

|
|
|
|
Saturation
|

|
|
|
|
Subsystem
|

|

|

|
|
Switch
|

|
|
|
|
SwitchCase
|

|
|
|
|
While
|

|
|
|
|
The tool also provides decision coverage for Stateflow states and events, state temporal logic decisions, and decision, condition, and MCDC coverage for Stateflow transitions.
Using the Model Coverage Tool
To develop effective tests with the Model Coverage Tool:
- Develop one or more test cases for your model (see Creating and Running Test Cases).
- Run the test cases to verify that the model behavior is correct.
- Analyze the coverage reports produced by Simulink.
- Using the information in the coverage reports, modify the test cases to increase their coverage or add new test cases that cover areas not covered by the current set of test cases.
- Repeat the preceding steps until you are satisfied with the coverage of your test set.
Note
Simulink comes with an online demonstration of the use of the Model Coverage Tool to validate model tests. To run the demo, enter simcovdemo at the MATLAB command prompt.
|
| Profiler | | Creating and Running Test Cases |  |