Keys
User Keys in PLT Test Plans are dynamic placeholders for storing and reusing values during test execution. These values can be set in the test plan, or extracted from command outputs.
Set Key
The define command can be used to assign assign a value to a key. These values are stored as strings and can be referenced in commands.
title: Define Keys Example
suite:
- ident: DEFINE-KEYS
steps:
# Define two keys with initial values
- command: define RETVAL 5
- command: define MSG "Hello!"
Commands
Extracting Keys
Most commands support extracting the test value result
in a key, by specifying name of the key
as the value of an extractKey:
field.
Example: Measurement
title: Measure Voltage and Store in Key
suite:
- ident: MEASURE-EXTRACT
steps:
- command: measure voltageDMM DATP01 3.25-3.35V
extractKey: VOLTAGE
In this case, the voltage measurement result is stored in the VOLTAGE
key.
Example: UART Interaction
title: Capture UART Data in Key
suite:
- ident: UART-EXTRACT
steps:
- command: uart UART0
send: "AT+ICCID\r\n"
expect: "+CCID:"
extract: "CCID: (\\d{20})\r\n"
extractKey: ICCID
In this example, the ICCID from the UART response is extracted and
stored in the ICCID
key.
Commands
Referencing Keys
Once set, keys can be referenced in other commands by using
%KEYNAME%
. This substitutes the key’s value as a string before
the command is executed.
Example: Using %KEYNAME%
in Commands
title: Use Key in String Substitution
suite:
- ident: USE-STRING-KEY
steps:
- command: define MSG "Hello!"
- command: operator %MSG%
- command: eval "%RETVAL% == '5'"
In this example:
The
%MSG%
key is replaced by"Hello!"
in the operator command.The eval command substitutes
%RETVAL%
with"5"
and performs a string comparison.
title: Keys as Signal Aliases
suite:
- ident: ICT-T0
title: Set variables
steps:
- command: define probe.VBUS DATP01
- ident: ICT-T1
title: Measure VBUS
steps:
- command: measure voltageDMM %probe.VBUS% 3.25-3.35V
All keys are included when making a webhook request.
title: Keys with Webhook
suite:
- ident: ICT-T0
title: Set variables
steps:
- command: define work_order 1011X02
- ident: ICT-T1
title: Invoke webhook with work_order key
steps:
- command: webhook request
Commands
Evaluating Keys
The eval command allows keys to be referenced
directly as their underlying object. This means keys are accessed as numbers,
strings, or measurements, depending on their content, without needing %
.
title: Use Key in Numeric Evaluation
suite:
- ident: USE-NUMERIC-KEY
steps:
- command: define RETVAL 5
- command: eval "numeric(RETVAL) > 3"
In this example:
The
RETVAL
key is set to the string"5"
, but inside the eval command, it is treated as a numeric value using thenumeric()
function.The eval command directly accesses the key without
%
, allowing the comparison as a number (5 > 3).
If %RETVAL%
were used, it would expand the key as a string, which would be
inappropriate for numeric comparisons.
Example: Using %KEYNAME%
in eval for String Substitution
title: Use Key for String Substitution in Eval
suite:
- ident: USE-STRING-EVAL
steps:
- command: define RETVAL 0
- command: eval "%RETVAL% == '0'"
Here, %RETVAL%
is substituted with the string "0"
, and the comparison is
performed between two strings.
title: Evaluate Expressions
suite:
- title: Eval
steps:
- command: define test "AC1D"
- command: eval "test != 'FOOBAR'"
- command: eval "test == 'AC1D'"
- command: define ONE 1
- command: eval "numeric(ONE)+2"
extractKey: SUM
- command: eval "SUM == 3"
Commands
Evaluating Measurements
Since measurement values stored in a key
include the unit, the numeric(..)
function can be
used within expressions to cast the measurement
result stored in a key, into a specific unit.
title: Evaluate Measurement
suite:
- title: Evaluate Measurement
steps:
- command: measure voltageDATP08 <4V
extractKey: VOLTAGE
- command: eval "(numeric(VOLTAGE, 'mV')) < 4000"
Commands