Documentation

Syntax for Test Sequences and Assessments

This topic describes syntax used in Test Sequence and Test Assessment block actions, transitions, and assessments. You can also work with Test Sequence blocks using the test sequence API, which provides functions to create, read, edit, and delete test sequence steps, transitions, and data symbols. See the functions listed in the Test Sequence Programming section on the Test Sequences and Assessments page.

Within test step actions, transitions, and assessments, Test Sequence and Test Assessment blocks use MATLAB® as the action language. In addition to the MATLAB language, the block includes keywords and operators to create action, transition, and assessment statements. For example:

  • Output a square wave with a period of 10 sec:

    square(et/10)
  • Transition when h changes to 0:

    hasChangedTo(h,0)
  • Verify that x is greater than y:

    verify(x > y)

Assessment Statements

To verify simulation, stop simulation, and return verification results, use assessment statements.

KeywordStatement SyntaxDescriptionExample
verify

verify(expression)

verify(expression, errorMessage)

verify(expression, identifier, errorMessage)

Assesses a logical expression. Optional arguments label results in the Test Manager and diagnostic viewer.

verify(x > y,...
'SimulinkTest:greaterThan',...
'x and y values are %d, %d',x,y)
assert

assert(expression)

assert(expression, errorMessage)

Evaluates a logical expression. Failure stops simulation and returns an error. Optional arguments return an error message.

assert(h == 0 && k == 0,...
'h and k must initialize to 0')

Syntax in the table uses these arguments:

 expression

 identifier

 errorMessage

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.

OperatorSyntaxDescriptionExample
et

et(TimeUnits)

The elapsed time of the test step in TimeUnits. Omitting TimeUnits returns 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 in TimeUnits. Omitting TimeUnits returns the value in seconds.

The elapsed time of the simulation in microseconds:

t(usec)
after

after(n, TimeUnits)

Returns true if n specified units of time in TimeUnits elapse since the beginning of the current test step.

After 4 seconds:

after(4,sec)
before

before(n, TimeUnits)

Returns true until n specified units of time in TimeUnits elapse, beginning with the current test step.

Before 4 seconds:

before(4,sec)
duration

ElapsedTime = duration (Condition, TimeUnits)

Returns ElapsedTime in TimeUnits for which Condition has been true. ElapsedTime is reset when the test step is re-entered or when Condition is no longer true.

Return true if the time in milliseconds since Phi > 1 is 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:

OperatorSyntaxDescriptionExample
hasChanged
hasChanged(u)

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

u must be an input data symbol.

Transition when h changes:

hasChanged(h)
hasChangedFrom
hasChangedFrom(u,A)

Returns true if u changes from the value A, otherwise returns false.

u must be an input data symbol.

Transition when h changes from 1:

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

Returns true if u changes to the value B, otherwise returns false.

u must be an input data symbol.

Transition when h changes to 0:

hasChangedTo(h,0)

Output Functions

Generate test signals using output functions. Some output functions use the temporal operator et, which is the elapsed time of the test step in seconds.

Note

Function outputs are not constrained to provide a defined pattern. Scaling, rounding, and other approximations of argument values can affect function outputs.

Common output functions include:

FunctionSyntaxDescriptionExample
squaresquare(x)

Represents a square wave output with a period of 1 and range –1 to 1.

Within the interval 0 <= x < 1, square(x) returns the value 1 for 0 <= x < 0.5and –1 for 0.5 <= x < 1.

Output a square wave with a period of 10 sec:

square(et/10)
sawtoothsawtooth(x)

Represents a sawtooth wave output with a period of 1 and range –1 to 1.

Within the interval 0 <= x < 1, sawtooth(x) increases.

Output a sawtooth wave with a period of 10 sec:

sawtooth(et/10)
triangletriangle(x)

Represents a triangle wave output with a period of 1 and range –1 to 1.

Within the interval 0 <= x < 0.5, triangle(x) increases.

Output a triangle wave with a period of 10 sec:

triangle(et/10)
rampramp(x)

Represents a ramp signal of slope 1, returning the value of the ramp at time x.

ramp(et) effectively returns the elapsed time of the test step.

Ramp one unit for every 5 seconds of test step elapsed time:

ramp(et/5)
heavisideheaviside(x)

Represents a heaviside step signal, returning 0 for x < 0 and 1 for x >= 0.

Output a heaviside signal after 5 seconds:

heaviside(et-5)
latchlatch(x)

Saves the value of x at the first time latch(x) evaluates in a test step, and subsequently returns the saved value of x. Resets the saved value of x when the step exits. Reevaluates latch(x) when the step is next active.

Latch b to the value of torque:

b = latch(torque)
sinsin(x)

Returns the sine of x, where x is in radians.

A sine wave with a period of 10 sec:

sin(et*2*pi/10)
coscos(x)

Returns the cosine of x, where x is in radians.

A cosine wave with a period of 10 sec:

cos(et*2*pi/10)
randrand

Uniformly distributed pseudorandom number.

Generate values from the uniform distribution on the interval [a, b].

a + (b-a)*rand
randnrandn

Normally distributed pseudorandom number.

Generate values from a normal distribution with mean 1 and standard deviation 2.

1 + 2*randn(100,1)
expexp(x)

Returns the natural exponential function, ex.

An exponential signal progressing at one tenth of the test step elapsed time:

exp(et/10)

Logical Operators

You can use logical connectives in actions, transitions, and assessments. In these examples, p and q represent Boolean signals or logical expressions.

OperationSyntaxDescriptionExample

Negation

~p

not p

verify(~p)

Conjunction

p && q

p and q

verify(p && q)

Disjunction

p || q

p or q

verify(p || q)

Implication

~p || q

if p, q. Logically equivalent to implication pq.

verify(~p || q)

Biconditional

(p && q) || (~p && ~q)

p and q, or not p and not q. Logically equivalent to biconditional pq.

verify((p && q) || (~p && ~q))

Relational Operators

You can use relational operators in actions, transitions, and assessments. In these examples, x and y represent numeric-type variables.

Using == or ~= operators in a verify statement returns a warning when comparing floating-point data. Consider the precision limitations associated with floating-point numbers when implementing verify statements. See Floating-Point Numbers (MATLAB). If you use floating-point data, consider defining a tolerance for the assessment. For example, instead of verify(x == 5), verify x within a tolerance of 0.001:

verify(abs(x-5) < 0.001)

Operator and SyntaxDescriptionExample
x > yGreater thanverify(x > y)
x < yLess thanverify(x < y)
x >= yGreater than or equal toverify(x >= y)
x <= yLess than or equal toverify(x <= y)
x == yEqual toverify(x == y)
x ~= yNot equal toverify(x ~= y)

Related Topics

Was this topic helpful?