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
Plan-Wide Keys
Keys last for the whole test plan run. A key set in one suite or step, whether by
define or extractKey, can be used by every later step. Defining a key again replaces its value from then on.
Using Keys lets you collect a plan’s settings (file names, USB VID:PID values,
signal aliases, target names) in a first “Defines” suite. Later suites then
refer to them only as %KEY%. This allows you to define and change settings
in a single place.
title: "Update Test Agent"
suite:
- title: "Defines"
steps:
- command: define AGENT.vidpid "6666:8001"
- command: define BUNDLE.filename "update.raucb"
- title: "Setup Programming Session"
steps:
- command: usb detect
id: "%AGENT.vidpid%"
timeout: 300s
- command: agentCfg PROGSBC
id: "%AGENT.vidpid%"
retry: 3
with:
- "%BUNDLE.filename%"
- title: "Install Update"
steps:
- command: agentExec PROGSBC "rauc install /run/pltagent/mnt/%BUNDLE.filename%"
timeout: 120s
Notes:
6666:8001is the defaultVID:PIDfor an agentOS Test Agent (see agentOS). agentCfg also accepts the prefixed formvid:6666:8001, but usb detect expects the bareVID:PID. Store the bare form if both commands share the key.Dotted names such as
AGENT.vidpidare just a naming convention for grouping related keys. They have no special meaning.Every key goes into the test report and into webhook and serial-number requests. Don’t store secrets in keys.
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
RETVALkey 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