Main Content

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.

Test Sequence editor with has changed signal condition transitions

Temporal Operators

To create an expression that evaluates the simulation time, use temporal operators. Variables in signal conditions must be inputs, parameters, or constants in the Test Sequence block. You can use these temporal operators:

OperatorDescription
etThe elapsed time of the test step. You can specify the unit of time. If you do not specify a unit of time, the elapsed time is returned in seconds.
t

The elapsed time of the simulation. You can specify the unit of time. If you do not specify a unit of time, the elapsed time is returned in seconds.

after

Returns true if the specified time has elapsed since the beginning of the current test step.

before

Returns true until the specified time has elapsed from the beginning of the current test step.

duration

Returns the elapsed time for which the specified condition has been true. The elapsed time resets when the test step is re-entered or when the specified condition is no longer true.

Transition Operators

To create expressions that evaluate signal events, use transition operators. To evaluate signal events, the signals must be inputs in the Test Sequence or Test Assessment block.

OperatorDescription
hasChanged

Returns true if the specified signal changes in value since the beginning of the test step, and otherwise returns false.

hasChangedFrom

Returns true if the specified signal changes from the specified value to a different value, and otherwise returns false.

hasChangedTo

Returns true if the specified signal changes to the specified value, and otherwise returns false.

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:

  1. Receive the message from the input queue using receive.

  2. Forward the message using the command forward(M,M_out) where 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.

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

|

Topics