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.
The 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 Editor 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
sldvdemo_autotrans
from this example:openExample('sldv/UsingExistingCoverageDataSubsystemAnalysisExample')
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
ShiftLogic
and 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:
Enable Save last run in workspace variable
In the cvdata object name field, enter
covdata_original_controller
to specify a unique name for the coverage data workspace variable.Select Generate report automatically after analysis.
Click OK.
Start the simulation of the
sldvdemo_autotrans
model 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
covdata_original_controller
, acvtest
object that contains the coverage data.Save the coverage data in a file on the MATLAB path:
cvsave('existingcov',covdata_original_controller);
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
Test generation
. Under Model coverage objectives, selectMCDC
.Under the Design Verifier node, select Test Generation. Under Add tests for the missing coverage, select Extend using existing coverage data.
In the Coverage data field, enter the name of the file containing the coverage data that you recorded during simulation:
existingcov.cvt
Click Apply to save these settings. Click OK.
Right the
ShiftLogic
block and select Generate Tests for Subsystem under Design Verifier pane.The analysis extracts the Stateflow chart into a new model named
ShiftLogic
. The analysis analyzes the new model, ignoring the coverage objectives previously satisfied and recorded in theexistingcov.cvt
file.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: 97% (30/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
existingcov.cvt
file.The Simulink Design Verifier report indicates that two coverage objectives in the Stateflow chart ShiftLogic are proven unsatisfiable. The implicit event
tick
is neverfalse
because the ShiftLogic chart is updated at every time step. The analysis cannot satisfy condition or MCDC coverage for either instance of the temporal eventafter(TWAIT, tick)
.after(TWAIT, tick)
is semantically equivalent toEvent == 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
tick
is alwaystrue
, so it only tests thetemporalCount(tick) >= TWAIT
part ofafter(TWAIT, tick)
. The analysis is able to find test objectives that satisfy condition and MCDC coverage forafter(TWAIT, tick)
.