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 bases on changes in the signal switch. See hasChanged.
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.
The elapsed time of the test step in
The elapsed time of the test sequence step in milliseconds:
The elapsed time of the simulation in
The elapsed time of the simulation in microseconds:
After 4 seconds:
Before 4 seconds:
duration(Phi>1,msec) > 550
Syntax in the table uses these arguments:
To create expressions that evaluate signal events, use transition operators. Common transition operators include:
Returns true if
Returns true if
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.
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.
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.
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
Forward the message using the command
M is the message input queue and
M_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.
Test Sequences Using Data
The DataSender block assigns a value to a data output
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
receive(M), removing the message from the queue.
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)