Main Content

Test Sequence Basics

A test sequence consists of test steps arranged in a hierarchy. You can use a test sequence to define test inputs and to define how a test will progress in response to the simulation. A test step contains actions that execute at the beginning of the step. A test step can contain transitions that define when the step stops executing, and which test step executes next. Actions and transitions use MATLAB® as the action language. You create test sequences by using the Test Sequence block and the Test Sequence Editor. See Use Stateflow Chart for Test Harness Inputs and Scheduling.

Test Sequence Hierarchy

Test sequences defined in Test Sequence blocks can have parent steps and substeps. Substeps can activate only if the parent step is active. A group of steps in the same hierarchy level shares a common transition type. When you create a test step, the step becomes a transition option for other steps in the same group.

Transition Types

Test sequences defined in Test Sequence blocks transition from one step to another in two ways:

  • Standard transition: You can define a sequence of actions that react to simulation conditions using a standard transition sequence. Standard transition sequences start with the first step and progress according to transition conditions and next steps.

    This test sequence sets the value of Boolean outputs RedButtonIn and GreenButtonIn, with transitions happening after each step has been active for 1 sec.

  • When decomposition: When decomposition sequences are analogous to switch statements in programming. Your sequence can act based on specific conditions occurring in your model. In a When decomposition sequence, steps activate based on a condition that you define after the step name. Transitions are not used between steps.

    This When decomposition contains three verify statements. Each verify statement is active when the signal gear is equal to a different value. For more information, see Assess a Model by Using When Decomposition.

Create a Basic Test Sequence

In this example, you use a Test Sequence block to create a simple test sequence for a transmission shift logic controller.

  1. Open the model. At the command line, enter

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

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

    • Under Sources and Sinks, select Test Sequence from the source drop-down menu.

    • Under Sources and Sinks, select Add separate assessment block.

    • Select Open harness after creation.

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

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

  6. Create the test sequence.

    1. Rename the first step Accelerate and add the step actions:

      speed = 10*ramp(et);
      throttle = 100;
    2. Right-click the Accelerate step and select Add step after. Rename this step Stop, and add the step actions:

      throttle = 0;
      speed = 0;
    3. Enter the transition condition for the Accelerate step. In this example, Accelerate transitions to Stop when the system is in fourth gear for 2 seconds. In the Transition column, enter:

      duration(gear == 4) >= Limit

      In the Next Step column, select Stop.

    4. Add a constant to define Limit. In the Symbols pane, hover over Constant and click the add data button. Enter Limit for the constant name.

    5. Hover over Limit and click the edit button. In the Constant value field, enter 2. Click OK.

Create Basic Test Assessments

  1. Continuing the example, in the test harness, double-click the Test Assessment block to open the editor. The editor displays a When decomposition sequence.

  2. Rename the first step Assessments.

  3. Add two steps to Assessments. Right-click the Assessments step and select Add sub-step. Do this a second time. There should be four steps under Assessments.

  4. Enter the names and actions for the four substeps.

    Check1st when gear == 1
    verify(speed < 45)
    Check2nd when gear == 2
    verify(speed < 75)
    Check3rd when gear == 3
    verify(speed < 105)

    The fourth step Else has no actions. Else handles simulation conditions outside of the preceding when conditions.

  5. Add a scope to the harness and connect the speed, throttle, and gear signals to the scope.

  6. Set the model simulation time to 15 seconds and simulate the test harness. View the signal data by opening the scope.

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

See Also

Related Topics