Achieve Missing Coverage in Closed-Loop Simulation Model
If you have a subsystem or a Stateflow® chart that does not achieve 100% coverage, and you do not want to convert the subsystem or chart to a Model block, follow this example to achieve full coverage.
The example uses a closed-loop controller model. A closed-loop controller passes instructions to the controlled system and receives information from the environment as the control instructions are executed. The controller can adapt and change its instructions as it receives this information.
sldvdemo_autotrans model is a closed-loop
simulation model. The ShiftLogic Stateflow chart represents the
controller part of this model. Test cases designed in the ManeuversGUI Signal
Builder block drive the closed-loop simulation.
Record Coverage Data for the Model
To simulate the model, recording condition, decision, and MCDC coverage for the ShiftLogic controller:
Open the example model:
On the Apps tab, click the arrow on the right of the Apps section.
Under Model Verification, Validation, and Test, click Coverage Analyzer.
On the Coverage tab, click Settings.
On the Coverage pane in the Configuration Parameters dialog box. set the following options:
Select Enable coverage analysis.
Select Subsystem and click Select Subsystem.
In the Subsystem Selection dialog box, select
ShiftLogicand click OK.
Under Coverage metrics, select
Modified Condition Decision Coverage (MCDC).
Clear the Other metrics if they are selected.
In the Coverage > Results pane of the Configuration Parameters dialog box, set the following options:
In the cvdata object name field, enter
covdata_original_controllerto specify a unique name for the coverage data workspace variable.
Select Generate report automatically after analysis.
Start the simulation of the
sldvdemo_autotransmodel to record the coverage data.
After the simulation, the coverage report opens. The report indicates that the following coverage is achieved for the ShiftLogic Stateflow chart:
Decision: 87% (27/31)
Condition: 67% (8/12)
MCDC: 33% (2/6) conditions reversed the outcome
The simulation saves the coverage data in the MATLAB® workspace variable
cvtestobject that contains the coverage data.
Save the coverage data in a file on the MATLAB path:
Find Test Cases for Missing Coverage
To find the missing coverage for the ShiftLogic chart, run a subsystem analysis on that block. Use this technique to focus your analysis on an individual part of the model.
To achieve 100% coverage for the ShiftLogic controller, run a test-generation analysis that uses the existing coverage data.
Right-click the ShiftLogic block and select Design Verifier > Options.
In the Configuration Parameters dialog box, under the Select tree, choose the Design Verifier node. Under Analysis options in the Mode field, select
Under the Design Verifier node, select Test Generation. Under Existing coverage data, select Ignore objectives satisfied in existing coverage data.
In the Coverage data file field, enter the name of the file containing the coverage data that you recorded during simulation:
Click Apply to save these settings.
Under the Select tree, click Design Verifier.
On the main Design Verifier pane, click Generate Tests.
The analysis extracts the Stateflow chart into a new model named
ShiftLogic0. The analysis analyzes the new model, ignoring the coverage objectives previously satisfied and recorded in the
When the test-generation analysis is complete, in the Simulink® Design Verifier™ log window, select Simulate tests and produce a model coverage report.
The report indicates that the following coverage is achieved for the ShiftLogic chart in simulation with the test cases generated by Simulink Design Verifier:
Decision: 84% (26/31)
Condition: 83% (10/12)
MCDC: 67% (4/6) conditions reversed the outcome
The Simulink Design Verifier report lists six test cases for the extracted model that satisfy the objectives not covered in the
The Simulink Design Verifier report indicates that two coverage objectives in the Stateflow chart ShiftLogic are proven unsatisfiable. The implicit event
falsebecause the ShiftLogic chart is updated at every time step. The analysis cannot satisfy condition or MCDC coverage for either instance of the temporal event
after(TWAIT, tick)is semantically equivalent to
Event == tick && temporalCount(tick) >= TWAIT
If you move
after(TWAIT, tick)into the condition, as in
[after(TWAIT, tick) && speed < down_th]
Simulink Design Verifier determines that
true, so it only tests the
temporalCount(tick) >= TWAITpart of
after(TWAIT, tick). The analysis is able to find test objectives that satisfy condition and MCDC coverage for