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 Component-Based Modeling with Model Reference example model
model. 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
Open the Component-Based Modeling with Model Reference 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.
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
sldemo_mdlref_basic, the CounterC Model block has Simulation mode set to
Accelerator, 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 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:
Condition: 50% (2/4) condition outcomes
Decision: 25% (1/4) decision outcomes
MCDC: 0% (0/2) conditions reversed the outcome
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_basicduring 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
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
sldemo_mdfref_counter model, specifying that the
analysis extend the test cases already satisfied:
To open the
sldemo_mdfref_countermodel, in the
sldemo_mdlref_basicmodel, double-click the CounterA Model block.
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
Under Advanced parameters, select Add tests for the missing coverage.
Select the Extend using existing data check box.
In Coverage Data field, specify the name of the
MAT-file that contains the logged data, in this case,
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
12objectives 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 Generate 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
Condition: 100% (4/4) condition outcomes
Decision: 100% (4/4) decision outcomes
MCDC: 100% (2/2) conditions reversed the outcome