Generate Test Cases for a Simplified Cruise Control Model
With Simulink® Design Verifier™, you can generate test cases for model coverage and custom objectives. You can also measure coverage of existing requirements-based test cases and extend these test cases to increase coverage or achieve full coverage.
This tutorial explains a simplified cruise control model that controls the throttle speed. You generate test cases that satisfy condition and decision model coverage objectives and then, simulate these test cases to generate the model coverage report.
Analyze a Simple Cruise Control Model
Consider a simplified cruise control model that adjusts the throttle to maintain a steady speed as set by the set speed.
This cruise control model meets these requirements:
The control system is activated when the
true. This condition is defined by the AND block.
When the system is activated, the Switch block passes
set speedto the PI controller. The PI controller calculates the
throttleby integrating the error term defined by the difference
set speed - current speed.
Throttlecontinues to increase or decrease until
set speedis higher or lower than
When the system is not activated, the Discrete-Time Integrator block resets. The error term is
zero, which means the
throttleis in reset position.
When you perform test generation analysis, Simulink Design Verifier generates test cases for the model coverage objectives associated with each model item in the model. The table lists the condition and decision coverage objectives for the associated Model blocks. For more information on model coverage objectives, see Model Coverage Objectives for Test Generation and Model Objects That Receive Coverage (Simulink Coverage).
|Block||Model Coverage Objective||Generated Test Case Description|
Each input value is set to true or false independently.
|Input is set to true or false independently.|
|Test case demonstrates that the Switch passes both the input signals to output.|
Generate Test Cases for Coverage Analysis
The analysis results give detailed descriptions of the coverage objectives for each model item and generated test cases for all satisfied objectives. You simulate the generated test cases to measure model coverage.
Step 1: Generate Test Cases
Open the model sldvexSimpleCruiseControl.
On the Design Verifier tab, in the Mode section, select Test Generation.
To generate test cases, click Generate Tests.
The Results Summary window displays the results. The result indicates that all
Step 2: Review the Analysis Results
On the Design Verifier tab, in the Review Results gallery, click Highlight in Model. The model objectives that the software found to be satisfied are highlighted in green.
Click the Switch block. The Results window displays the summary of the satisfied decision objectives.
The summary shows that all the objectives of the Switch block are satisfied.
To view the HTML report, in the Review Results gallery, click HTML Report.
The test objective status section includes detailed descriptions of satisfied objectives for each model item and generated test case.
Step 3: Simulate Test Cases for Model Coverage Analysis
To view the test case for a model coverage objective, in the Results window, click View test case. The harness model and the Signal Builder block opens.
To simulate the test case, in the Signal Builder block, click the button.
The software simulates the test case and highlights the harness model. To view the coverage of the model items, point the cursor to each model object in the harness model.