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 block and the . see .
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.
test sequence scenarios
in a test sequence block, you can define multiple test sequences, which are called test sequence scenarios. by using scenarios, you can define distinct test sequences without having multiple test sequence blocks in your test harness. you can run test sequence scenarios in these ways:
activate a single scenario from the test sequence editor and run the model
activate a single scenario using api commands and run the model
control the active scenario with a workspace variable and run the model
use a custom test script to loop through scenarios when running the model
define iterations in the test manager to run more than one scenario in a single test case
for more information and examples of using test sequence scenarios, see use test sequence scenarios in the test sequence editor and test manager and .
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. for a list of transitions, see .
this test sequence sets the value of boolean outputs
redbuttonin
andgreenbuttonin
, 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 awhen
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. eachverify
statement is active when the signalgear
is equal to a different value. for more information, see .
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.
open the model. at the command line, enter
openexample('transmissiondownshifttestsequence')
right-click the
shift_controller
subsystem and select test harness > create for ‘shift_controller’.in the create test harness dialog box, under sources and sinks:
select
test sequence
from the source drop-down menu.select add separate assessment block.
select open harness after creation.
click ok. the test harness for the
shift_controller
subsystem opens.double-click the test sequence block. the test sequence editor opens.
create the test sequence.
rename the first step
accelerate
and add the step actions:speed = 10*ramp(et); throttle = 100;
right-click the
accelerate
step and select add step after. rename this stepstop
, and add the step actions:throttle = 0; speed = 0;
enter the transition condition for the
accelerate
step. in this example,accelerate
transitions tostop
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
.add a constant to define
limit
. in the symbols pane, hover over constant and click the add data button. enterlimit
for the constant name.hover over
limit
and click the edit button. in the constant value field, enter2
. click ok.
create basic test assessments
continuing the example, in the test harness, double-click the test assessment block to open the editor. the editor displays a when decomposition sequence.
rename the first step
assessments
.add two steps to
assessments
. right-click theassessments
step and select add sub-step. do this a second time. there should be four steps underassessments
.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)
else
the fourth step
else
has no actions.else
handles simulation conditions outside of the precedingwhen
conditions.add a scope to the harness and connect the
speed
,throttle
, andgear
signals to the scope.set the model simulation time to 15 seconds and simulate the test harness. view the signal data by opening the scope.
view the results of the
verify
statements in the simulation data inspector.