Main Content

Author a Test Sequence and Test Assessment

This example shows how to use a Test Sequence block and Test Assessment block to create a test harness for a transmission shift logic controller. The Test Sequence block varies the speed input to the controller and the Test Assessment block verifies that the speed is appropriate for the gear position. For more information, see Test Sequence Basics.

Create a Test Sequence

1. Open the model.

open_system("sf_car")

sf_car model

2. Right-click the shift_logic subsystem and select Test Harness > Create for ‘shift_logic’.

3. In the Create Test Harness dialog box, under Sources and Sinks:

  • Set the source drop-down menu to Test Sequence.

  • Select Add separate assessment block.

  • Select Open harness after creation.

The Sources and Sinks section of the Create Test Harness dialog box.

For more information, see Create a Test Harness.

4. Click OK. The test harness for the shift_logic subsystem opens.

The shift_logic test harness

5. Double-click the Test Sequence block. The Test Sequence Editor opens.

The Test Sequence Editor. The block has one step titled Run.

6. Change the name of the first step from Run to Accelerate, and add the step actions that specify the initial throttle setting and how the speed increases:

speed = 10*ramp(et);

throttle = 100;

The ramp function returns the value of a ramp signal of slope 1 at time et, which is the elapsed time of the step. For this example, the speed at a particular time after the beginning of the step is 10 times the value of the ramp at that time. See Test Sequence Editor for more information.

7. Right-click the Accelerate step and select Add step after. Change the name of this step from step_1 to Stop, and add the step actions that stop the test when the throttle and speed are equal to 0:

throttle = 0;

speed = 0;

8. In the Symbols pane, point to Constant and click the add data button . Enter Limit for the constant name and click Add data.

9. Point to Limit and click the edit button editicon.png. In the Constant value field, enter 2. Click OK.

The Data Limit dialog box

10. Right-click the Transition column in the first step, select Add transition. Enter the transition condition for the Accelerate step. In this example, Accelerate transitions to Stop when the system is in fourth gear for at least two seconds. In the Transition column, enter:

duration(gear == 4) >= Limit

11. In the Next Step column, select Stop.

The Test Sequence Editor. There is an Accelerate step and a Stop step.

12. Save the changes and close the Test Sequence Editor.

Create a Test Assessment

Next, add verifications to the Test Assessment block.

1. Double-click the Test Assessment block to open the editor. The editor displays a default When decomposition sequence in the Step column. For more information, see Activate verify Statements by Using Signal Conditions.

The Test Sequence Editor. There are two substeps in one step.

2. Change the name of the first step from Run to Assessments.

3. Change the names and add actions for four substeps:

  • Rename step_1_1 to Check1st. Define the when condition as gear == 1 and add a verify statement that evaluates whether the speed is less than 45.

  • Rename step_1_2 to Check2nd. Define the when condition as gear == 2 and add a verify statement that evaluates whether the speed is less than 75.

  • Right-click the Check2nd step and click Add step after. Rename the step Check3rd. Define the when condition as gear == 3 and add a verify statement that evaluates whether the speed is less than 105.

  • Right click the Check3rd step and click Add step after. Rename the step else. This step handles simulation conditions outside of the preceding when conditions. In this step, you do not specify any actions.

The Test Sequence Editor. There is one step named Assessments with four substeps.

4. Save the changes and close the Test Sequence Editor.

5. In the test harness, add a Scope block and connect the speed, throttle, and gear signals to the scope.

The shift_logic test harness with a Scope block.

6. Open the Scope block. In View > Layout, select a three-column, one-row layout.

7. In the Simulink model, in the Simulation tab, set Stop Time to 15 and click Run. View the signal data in the Scope block. The speed plot shows how the speed increases to a maximum value of 105. The throttle plot shows that the throttle value is held at 100 throughout the test. The gear plot shows that the gear shifts to the next-higher gear at the appropriate speed. After the gear has been equal to 4 for 2 seconds, the speed and throttle go to zero and the gear decreases.

The Scope block with the three subplots. The plots display the speed, throttle, and gear signals.

8. View the results of the verify statements in the Simulation Data Inspector.

  • In the Simulink model, in the Simulation tab, click Data Inspector.

  • Click the Visualizations and layouts button VisualizationAndLayoutIcon.png and, under Grid, set Rows to 3 and Columns to 1.

  • Select one plot, then select an assessment from the left pane. Repeat for each of the other plots and assessments.

The Simulation Data Inspector. A plot is displayed for each verify statement which show pass and untested results.

When the model runs, the Test Assessment block verifies that the speed is in the correct range for each gear position. A pass indicates that the speed is in the correct range. Each verify statement is for a specific gear, so the speed is untested when the controller is in a different gear than the one being tested. There are two pass regions for the Check1st test assessment because the gear position goes back to first in the second step of the test sequence.

See Also

|

Related Topics