Main Content

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

  1. Open the example model:

    openExample('sldv/UsingExistingCoverageDataSubsystemAnalysisExample',...
    'supportingFile','sldvdemo_autotrans')
  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. 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.

  5. Under Coverage metrics, select Modified Condition Decision Coverage (MCDC).

  6. Clear the Other metrics if they are selected.

  7. In the Coverage > Results pane of the Configuration Parameters dialog box, set the following options:

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

  8. Click OK.

  9. 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, a cvtest object that contains the coverage data.

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

  1. Right-click the ShiftLogic block and select Design Verifier > Options.

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

  3. Under the Design Verifier node, select Test Generation. Under Existing coverage data, select Ignore objectives satisfied in existing coverage data.

  4. In the Coverage data file field, enter the name of the file containing the coverage data that you recorded during simulation:

    existingcov.cvt
  5. Click Apply to save these settings.

  6. Under the Select tree, click Design Verifier.

  7. 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 existingcov.cvt file.

  8. 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 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 never false because 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).

    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 tick is always true, so it only tests the temporalCount(tick) >= TWAIT part of after(TWAIT, tick). The analysis is able to find test objectives that satisfy condition and MCDC coverage for after(TWAIT, tick).

Related Topics