Main Content

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 sldemo_mdlref_basic 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 model.

  1. Open the example model:

  2. On the Apps tab, click the arrow on the right of the Apps section.

    Under Model Verification, Validation, and Test, click Coverage Analyzer.

  3. On the Coverage tab, click Settings.

  4. In the Coverage pane of the Configuration Parameters, select Enable coverage analysis.

  5. Select Referenced Models.

    Note that the analysis records coverage only for referenced models with Simulation mode set to Normal, SIL, or PIL. In sldemo_mdlref_basic, the CounterC Model block has Simulation mode set to Accelerator, so you cannot record coverage for it.

  6. Under Coverage metrics, set the structural coverage level to Modified Condition Decision Coverage (MCDC) to record decision, condition, and modified condition/decision coverage.

  7. Click OK.

  8. 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.

  9. 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');
  10. 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:

  1. To open the sldemo_mdfref_counter model, in the sldemo_mdlref_basic model, double-click the CounterA Model block.

  2. On the Design Verifier tab, click Test Generation Settings.

  3. In the Configuration Parameters dialog box, on the Test Generation pane, in the Model coverage objectives box, select MCDC.

  4. Under Existing test cases, select Extend existing test cases.

  5. In the Data file field, specify the name of the MAT-file that contains the logged data, in this case, existingtestcase.mat.

  6. Clear Ignore objectives satisfied by existing test cases.

    When you clear this option, the software includes the test cases recorded in the file existingtestcase.mat in the final test suite.

  7. Click OK.

  8. 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 12 objectives are satisfied.

  9. 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.

  10. 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.

  11. 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:

    • Condition: 100% (4/4) condition outcomes

    • Decision: 100% (4/4) decision outcomes

    • MCDC: 100% (2/2) conditions reversed the outcome

Related Topics