Transitions, Temporal Operators, and Messages in Test Sequence Blocks
Transition Between Steps Using Temporal or Signal Conditions
The Test Sequence block uses MATLAB® as the action language. You can transition between test steps by evaluating the component under test. You can use conditional logic, temporal operators, and event operators.
Consider a simple test sequence that outputs a sine wave at three frequencies. The Test Sequence block steps through several actions based on changes in the signal switch. See hasChanged.
Temporal Operators
To create an expression that evaluates the simulation time, use temporal operators. Variables used in signal conditions must be inputs, parameters, or constants in the Test Sequence block.
Operator | Syntax | Description | Example |
---|---|---|---|
et |
| The elapsed time of the test step in | The elapsed time of the test sequence step in milliseconds: et(msec) |
t |
| The elapsed time of the simulation in | The elapsed time of the simulation in microseconds: t(usec) |
after |
| Returns | After 4 seconds: after(4,sec) |
before |
| Returns | Before 4 seconds: before(4,sec) |
duration |
| Returns | Return duration(Phi>1,msec) > 550 |
Syntax in the table uses these arguments:
Transition Operators
To create expressions that evaluate signal events, use transition operators. Common transition operators include:
Operator | Syntax | Description | Example |
---|---|---|---|
hasChanged | hasChanged(u) | Returns
| Transition when hasChanged(h) |
hasChangedFrom | hasChangedFrom(u,A) | Returns true if
| Transition when hasChangedFrom(h,1) |
hasChangedTo | hasChangedTo(u,B) | Returns true if
| Transition when hasChangedTo(h,0) |
Use Messages in Test Sequences
Messages carry data between Test Sequence blocks and other blocks such as Stateflow® charts. Messages can be used to model asynchronous events. A message is queued until you evaluate it, which removes it from the queue. You can use messages and message data inside a test sequence. The message remains valid until you forward it, or the time step ends. For more information, see Messages (Stateflow) in the Stateflow® documentation.
Receive Messages and Access Message Data
If your Test Sequence block has a message input, you can use queued messages in test sequence actions or transitions. Use the receive
command before accessing message data or forwarding a message.
To create a message input, hover over Input in the Symbols sidebar, click the add message icon, and enter the message name.
receive(M)
determines whether a message is present in the input queue M
, and removes the message from the queue. receive(M)
returns true
if a message is in the queue, and false
if not. Once the message is received, you can access the message data using the dot notation, M.data
, or forward the message. The message is valid until it is forwarded or the current time step ends.
The order of message removal depends on the queue type. Set the queue type using the message properties dialog box. In the Symbols sidebar, click the edit icon next to the message input, and select the Queue type.
Send Messages
To send a message, create a message output and use the send
command. To create a message output, hover over Output in the Symbols sidebar, click the add message icon, and enter the message name.
You can assign data to the message using the dot notation M.data
, where M is the message output of the Test Sequence block. send(M)
sends the message.
Forward Messages
You can forward a message from an input message queue to an output port. To forward a message:
Receive the message from the input queue using
receive
.Forward the message using the command
forward(M,M_out)
whereM
is the message input queue andM_out
is the message output.
Compare Test Sequences Using Data and Messages
This example demonstrates message inputs and outputs, sending, and receiving a message. The model compares two pairs of test sequences. Each pair is comprised of a sending and receiving test sequence block. The first pair sends and receives data, and the second sends and receives a message.
Set the model name variable.
model = 'sltest_testsequence_data_vs_message';
Open the model.
open_system(model)
Test Sequences Using Data
The DataSender block assigns a value to a data output M
.
The DataReceiver block waits 3 seconds, then transitions to step S2. Step S2 transitions to step S3 using a condition comparing M
to the expected value, and does the same for S3 to S4.
Test Sequences Using Messages
The MessageSender block assigns a value to the message data of a message output M_out
, then sends the message to the MessageReceiver block.
The MessageReceiver block waits 3 seconds, then transitions to step S2. Step S2's transition evaluates the queue M
with receive(M)
, removing the message from the queue. receive(M)
returns true
since the message is present. M.data == 3.5
compares the message data to the expected value. The statement is true, and the sequence transitions to step S3.
When step S3's transition condition evaluates, no messages are present in the queue. Therefore, S3 does not transition to S4.
Run the test and observe the output comparing the different behaviors of the test sequence pairs.
open_system([model '/Scope'])
sim(model)
close_system(model,0) clear(model)
See Also
Test Sequence | Test Sequence and Assessment Syntax