Extend Test Cases for Closed-Loop System
Suppose that you have a model with a closed-loop controller in a model referenced by a Model block. You do not record 100% coverage for the referenced model. Extending existing test cases can help you achieve 100% coverage. The Simulink® Design Verifier™ software adds time steps to the existing test cases when analyzing the controller implemented by the referenced model. The test cases that result from the analysis realistically reflect the continuous time behavior expected in the closed-loop controller.
A closed-loop controller passes instructions to the controlled system and receives information from the environment as the control instructions execute. The controller can adapt and change its instructions as it receives this information.
Log Starting Test Case
This example uses the example model sldemo_mdlref_basic
. The
CounterA Model block references the model
sldemo_mdlref_counter
. When you simulate the parent model,
sldemo_mdlref_basic
, and collect coverage, you record only
75% coverage for sldemo_mdlref_counter
. Log the data from the
simulation and extend those test cases to achieve 100% coverage for the referenced
model.
Open the example model
sldemo_mdlref_basic
.openExample('sldemo_mdlref_basic');
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.
In the Coverage pane of the Configuration Parameters, select Enable coverage analysis.
Select Referenced Models.
Note that the analysis records coverage only for referenced models with Simulation mode set to
Normal
,SIL
, orPIL
. Insldemo_mdlref_basic
, the CounterC Model block has Simulation mode set toAccelerator
, so you cannot record coverage for it.Under Coverage metrics, set the structural coverage level to Modified Condition Decision Coverage (MCDC) to record decision, condition, and modified condition/decision coverage.
Click OK.
Click Analyze Coverage.
To open the coverage report, in the Review Results section, click Generate Report.
When the simulation completes, the generated coverage report opens in a browser window. The report shows the following coverage results for the referenced model:
Decision: 25% (1/4) decision outcomes
Condition: 50% (4/8) condition outcomes
MCDC: 0% (0/2) conditions reversed the outcome
Execution: 86% (6/7) objective outcomes
The coverage results are also highlighted in the referenced model,
sldemo_mdlref_counter
. You can select individual model objects to view specific coverage results in the Coverage dialog box, as shown in the following screenshot.To log the input signals for the CounterA Model block in
sldemo_mdlref_basic
during simulation, at the MATLAB® command prompt, enter the following code:logged_data = sldvlogsignals('sldemo_mdlref_basic/CounterA');
Save the logged data in a MAT-file named
existingtestcase.mat
:save('existingtestcase.mat', 'logged_data');
When you analyze the model referenced in CounterA (
sldemo_mdlref_counter
) to extend existing test cases, you specify this MAT-file.
Extend Existing Test Cases
Analyze the sldemo_mdfref_counter
model, specifying that the
analysis extend the test cases already satisfied:
To open the
sldemo_mdfref_counter
model, in thesldemo_mdlref_basic
model, right-click the model and selectOpen as Top Model
.On the Design Verifier tab, click Test Generation Settings.
In the Configuration Parameters dialog box, on the Test Generation pane, in the Model coverage objectives box, select
MCDC
.Under Advanced parameters, select Add tests for the missing coverage.
Select the Extend using existing data check box.
In Test Data field, specify the name of the
MAT
-file that contains the logged data, in this case,existingtestcase.mat
Click OK.
Click Generate Tests.
The analysis first loads the objectives satisfied by the logged test cases. Then it adds extra time steps to those test cases and tries to satisfy any missing objectives. When the analysis completes, the Simulink Design Verifier log window opens and indicates that all
16
objectives are satisfied.To view the analysis results on the model, in the Simulink Design Verifier log window, select Highlight analysis results on model.
The Simulink Design Verifier results are highlighted in the referenced model,
sldemo_mdlref_counter
. You can select individual model objects to view specific analysis results in the Simulink Design Verifier Results dialog box, as shown in the following screenshot.To verify the results of the analysis and review the generated test cases, in the Simulink Design Verifier log window, select Detailed analysis report.
To collect model coverage using the extended test suite, in the Simulink Design Verifier log window, select Simulate tests and produce a model coverage report.
When the simulation completes, the generated coverage report opens in a browser window. The report now shows the following coverage results for the referenced model
sldemo_mdlref_counter
:Decision: 100% (4/4) decision outcomes
Condition: 100% (8/8) condition outcomes
MCDC: 100% (2/2) conditions reversed the outcome
Execution: 100% (7/7) objective outcomes
Related Examples
- Component-Based Modeling with Model Reference
- Generate Tests for Model Block Component by Using Default Simulation