Main Content

Transitions, Temporal Operators, and Messages in Test Sequence Blocks

Transition Between Steps Using Temporal or Signal Conditions

TheTest Sequenceblock 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. SeehasChanged.

Test Sequence editor with has changed signal condition transitions

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 theTest Sequenceblock.

Operator Syntax Description Example
et

et(TimeUnits)

The elapsed time of the test step inTimeUnits. OmittingTimeUnitsreturns the value in seconds.

The elapsed time of the test sequence step in milliseconds:

et(msec)
t

t(TimeUnits)

The elapsed time of the simulation inTimeUnits. OmittingTimeUnitsreturns the value in seconds.

The elapsed time of the simulation in microseconds:

t(usec)
after

after(n, TimeUnits)

Returnstrueifnspecified units of time inTimeUnitselapse since the beginning of the current test step.

After 4 seconds:

after(4,sec)
before

before(n, TimeUnits)

Returnstrueuntilnspecified units of time inTimeUnitselapse, beginning with the current test step.

Before 4 seconds:

before(4,sec)
duration

ElapsedTime = duration (Condition, TimeUnits)

ReturnsElapsedTimeinTimeUnitsfor whichConditionhas beentrue.ElapsedTimeis reset when the test step is re-entered or whenConditionis no longertrue.

Returntrueif the time in milliseconds sincePhi > 1is greater than 550:

duration(Phi>1,msec) > 550

Syntax in the table uses these arguments:

TimeUnits

Condition

Transition Operators

To create expressions that evaluate signal events, use transition operators. Common transition operators include:

Operator Syntax Description Example
hasChanged
hasChanged(u)

Returnstrueifu变化in value since the beginning of the test step, otherwise returnsfalse.

umust be an input data symbol.

Transition whenh变化:

hasChanged(h)
hasChangedFrom
hasChangedFrom(u,A)

Returns true ifu变化from the valueA, otherwise returns false.

umust be an input data symbol.

Transition whenh变化from1:

hasChangedFrom(h,1)
hasChangedTo
hasChangedTo(u,B)

Returns true ifu变化to the valueB, otherwise returns false.

umust be an input data symbol.

Transition whenh变化to0:

hasChangedTo(h,0)

使用消息测试序列

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, seeMessages(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 thereceivecommand before accessing message data or forwarding a message.

To create a message input, hover overInputin theSymbolssidebar, click the add message icon, and enter the message name.

receive(M)determines whether a message is present in the input queueM,从队列中删除消息。receive(M)returnstrueif a message is in the queue, andfalseif 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 theSymbolssidebar, click the edit icon next to the message input, and select theQueue type.

Send Messages

To send a message, create a message output and use thesendcommand. To create a message output, hover overOutputin theSymbolssidebar, click the add message icon, and enter the message name.

You can assign data to the message using the dot notationM.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 usingreceive.

  2. Forward the message using the commandforward(M,M_out)whereMis the message input queue andM_outis 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 outputM.

The DataReceiver block waits 3 seconds, then transitions to step S2. Step S2 transitions to step S3 using a condition comparingMto 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 outputM_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 queueMwithreceive(M), removing the message from the queue.receive(M)returnstruesince the message is present.M.data == 3.5compares 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

|

Related Topics