Skip to content

CI Test Runner (labwired test)

LabWired provides a CI-friendly runner mode driven by a YAML test script:

labwired test --script test.yaml

Every v1.0 script selects exactly one run shape: a single machine, an environment world, or a portable Flex project. The inputs forms are mutually exclusive.

Single-machine script

Use inputs.firmware (and optionally inputs.system) to run one machine. A per-machine system.yaml is the same system manifest consumed by the Playground; CI does not use a separate board-description format.

labwired test --firmware path/to/fw.elf --system system.yaml --script test.yaml
schema_version: "1.0"
inputs:
  firmware: "relative/or/absolute/path/to/fw.elf"
  chip: "stm32f103"
limits:
  max_steps: 100000
assertions:
  - uart_contains: "Hello"

inputs.chip names one of the chips bundled with the CLI, for firmware with nothing wired to it. This is the whole configuration — there is no manifest to write and no chip descriptor to copy into your repository, so your test tracks our silicon model instead of freezing a copy of it. Run labwired chips for the available names.

Firmware with external devices or board I/O uses inputs.system instead, pointing at a manifest:

inputs:
  firmware: "path/to/fw.elf"
  system: "path/to/system.yaml"

A manifest's chip: field takes the same two forms: a built-in name, or a path to your own descriptor for silicon we do not ship. Setting both inputs.chip and inputs.system is an error.

--firmware and --system are single-machine overrides only. They are not valid with an environment script.

Environment/world script

Use inputs.env to select an environment manifest. The manifest owns the world topology: every node supplies its id, the shared-with-Playground system.yaml, and its firmware ELF. Connectivity belongs only in explicit interconnects; it is never implied by CLI overrides.

# test.yaml
schema_version: "1.0"
inputs:
  env: "two-node-env.yaml"
limits:
  max_steps: 100000
  max_cycles: 123456     # optional
  max_uart_bytes: 4096   # optional
  wall_time_ms: 5000     # optional
  stop_when_assertions_pass: true          # optional; default false
  stop_when_assertions_pass_settle_steps: 1000  # optional; default 100000
  stop_when_assertions_pass_min_steps: 1000     # optional; default 0
assertions:
  - memory_value:
      node: alpha
      address: 0x20000000
      expected_value: 0
      size: 8
      mask: 0xff
# two-node-env.yaml
schema_version: "1.0"
name: "two-node-smoke"
nodes:
  - id: alpha
    system: "systems/alpha.yaml"
    firmware: "firmware/alpha.elf"
  - id: beta
    system: "systems/beta.yaml"
    firmware: "firmware/beta.elf"
interconnects:
  - type: can_bus
    nodes: [alpha, beta]
    config:
      peripheral: can1

An environment assertion must be a node-qualified memory_value assertion. v0.19 environment worlds are Cortex-M-only: each resolved node chip must resolve to arch: arm and explicitly declare core: cortex-m*. Its firmware must be an EM_ARM ELF with a valid Cortex-M Thumb reset vector at flash.base + reset_vector_offset: the initial stack pointer must land in RAM and the Thumb-bit reset handler must land in flash. A node outside that contract is rejected as a configuration error before a Cortex-M machine is constructed.

nodes[].config_overrides must be omitted. Every explicit occurrence, including {} and null, is rejected in environment schema 1.0.

Interconnect membership and config are validated before the world starts. Each config mapping is closed and type-checked:

  • uart_cross_link requires exactly two unique, known nodes. Its only optional keys are non-empty strings node_a_uart and node_b_uart (each defaults to uart2).
  • can_bus requires at least two unique, known nodes. Its only key is required non-empty string config.peripheral.
  • egress requires exactly one known node. Its only keys are optional non-empty strings uart (default usart2), transport (tcp, mqtt, or http), encoding (raw, ndjson-trace, or frames-json), required non-empty string url, MQTT-only required non-empty string topic, and positive integer buffer_max. topic is invalid for TCP and HTTP.

Environment scripts do not accept single-machine firmware/system overrides or topology-affecting CLI options.

stop_when_assertions_pass is opt-in for an environment world and has the same durable completion contract as a single-machine run. Once every node-qualified memory_value assertion passes at or after stop_when_assertions_pass_min_steps, it must remain true for stop_when_assertions_pass_settle_steps world rounds (default 100000). A regression restarts that window. A runtime failure or a same-round wall_time_ms, max_cycles, or max_uart_bytes limit wins over completion. max_steps remains the outer execution bound, so completion on its final allowed world round reports assertions_passed; otherwise the result has stop_reason: assertions_passed. The three fields are respectively a boolean and non-negative integers; explicit YAML null is rejected.

Portable Flex script

Use inputs.flex to run portable firmware against a Flex manifest. The firmware is a WebAssembly module that imports labwired.read(i32) -> f64, labwired.write(i32, f64) and labwired.advance_ns(i32), labwired.i2c_transfer if the manifest has an I2C bus, and labwired.console_write if the manifest has a console. The runner calls one export once (entry), or runs a sequence of calls and test-bench stimuli on one firmware instance. This path does not emulate a target CPU, and it never falls back to one. A script that needs target instructions, MMIO or interrupts names inputs.system or inputs.chip instead; a script that names both is rejected.

# test-bright.yaml
schema_version: "1.0"
inputs:
  flex: system.yaml        # Flex manifest (ports, models, assumptions)
  firmware: firmware.wasm  # portable firmware module
entry:
  export: run              # default: run
  args:                    # in the export's parameter order
    - { port: lux }        # the id of a named manifest port (i32)
    - { port: sensor_v }
    - { port: user_led_drive }
    - { port: user_led_state }
    - { number: 100 }      # a plain number, exact in the parameter's type
limits:
  max_steps: 100000        # WebAssembly fuel for the firmware call
  max_time_ns: 10000000    # virtual-time ceiling
assertions:
  - entry_result: { equals: 2974 }                        # the export's i32 result
  - port_value: { port: sensor_v, min: 2.396, max: 2.398 } # final read-port value
  - digital_edges: { port: user_led_state, count: 2 }     # exact captured edges
  - digital_edges: { port: user_led_state, times_ns: [4001000, 4002000] }
  - digital_edges: { port: user_led_state, count: 1, from_ns: 4001500, to_ns: 4002000 }
  - analog_sample: { port: sensor_v, at_ns: 350000, min: 2.033, max: 2.034 }
  - analog_window: { port: sensor_v, from_ns: 2000000, min: 2.395, max: 2.398 }
  - analog_crossings: { port: sensor_v, level: 2.001, direction: rising, times_ns: [350000] }
  - final_time_ns: { equals: 4002000 }
Assertion Reads Passes when
entry_result The i32 result of a firmware call It equals equals.
port_value A read port after the last step It is equals, or inside min..max.
digital_edges One logic-analyzer channel: port (a Boolean port) or signal (a traced model signal with no port). from_ns and to_ns limit it to the edges with from_ns <= time <= to_ns; the default is the whole run. The edge count matches, every edge time matches times_ns in order, or both.
analog_sample One oscilloscope channel: port (a numeric read port) or channel (a channel name with no port) The last sample at or before at_ns is equals, or inside min..max, in the channel's unit.
analog_window Every value of one oscilloscope channel with from_ns <= time <= to_ns, and the value the channel holds at from_ns. The default is the whole run. The lowest value is at or above min and the highest is at or below max.
analog_crossings The times one oscilloscope channel crosses level in one direction: rising (from below to at or above) or falling (from above to at or below). from_ns and to_ns limit it as for digital_edges. The crossing count matches, every crossing time matches times_ns in order, or both.
final_time_ns The virtual time at the end of the run It is equals, or inside min..max.
console_contains The text the firmware wrote to the manifest console in the whole run The text contains the string. observed is the byte offset of the first match.
device_state One key of what a device holds at the end of the run: the meta of its artifact, as in result.json's devices (a display's text, a strip's lit_pixels or frame_history, a 1-Wire part's registers). device is a sink, bus device or model id. The value is equals; or a string contains contains, or a list holds it as an element or inside one string element; or a number is inside min..max. observed_value is the value read.
i2c_transfers The number of labwired.i2c_transfer calls on one bus in the whole run. address limits it to one 7-bit address. ack: true counts the transfers a device acknowledged, ack: false those no device answered. The count is equals, or inside min..max.

A port or channel that the instrument does not have is a config_error before the firmware runs. An at_ns or a to_ns after the end of the run was not observed: the assertion fails with observed: null. result.json gives each digital_edges assertion its edge times, each analog_crossings assertion its crossing times, and each analog_sample assertion the time of the sample it read, in observed_times_ns. For an analog_window, observed is the lowest value, observed_max is the highest, and observed_times_ns holds the times of the two. A value held from before the window has the time from_ns.

A crossing has the time of the first sample at or past the level. The runner does not interpolate between samples, so the time is a multiple of the model step_ns. A channel that starts at or past the level has not crossed it.

The runner counts the edges of each digital_edges assertion when the logic analyzer records them. The count and the times_ns comparison are exact for a run of any length. The capture itself keeps the newest 65,536 edges of all channels: after a longer run, flex-trace.json and --vcd hold those edges, and traces.digital_dropped in result.json is the number of older edges they do not hold. observed_times_ns lists at most the first 4,096 edge times of a window, or one more than times_ns expects if that is larger; observed_times_truncated: true marks a shortened list.

The analog assertions use the same method. The runner reads each sample when the oscilloscope records it, so analog_sample, analog_window and analog_crossings are exact for a run of any length. The oscilloscope capture keeps the newest 20,000 samples (or the model's trace_samples); traces.analog_dropped is the number of older samples that flex-trace.json and --analog-trace do not hold. flex-trace.json also holds analog_series, the run-long change-point series of every channel that the detailed path writes to result.json: a point is written when a value leaves the series deadband (the larger of 0.5 % of the held value and 0.001 in the channel unit; 1e-5 for A, 1 for rpm), up to 65,536 points per channel. When the capture dropped samples, traces.analog_series_points and traces.analog_series_dropped tell whether that series still holds the whole run. The browser runtime gives the same series from analog_series().

A sequence replaces entry when the firmware has more than one entry point, for example setup and loop, or when the environment changes during the run. The firmware keeps its memory between steps. The limits apply to the whole sequence.

# test-heat-cycle.yaml
sequence:
  - call: { export: setup, args: [{ port: temperature_mv }, { port: fan_drive }] }
  - call: { export: loop, repeat: 2 }          # two calls in a row
  - set: { port: temperature_c, value: 50 }    # the test bench writes a write port
  - call: { export: loop, repeat: 2 }
assertions:
  - entry_result: { equals: 0, step: 1 }       # last result of sequence step 1
  - entry_result: { equals: 1 }                # default: the last call step

Each step is resolved against the firmware and the manifest before step 0 runs: an unknown export, a wrong argument count, or a set on a read port is a config_error. A set does not advance time; the models see the value at the next firmware advance_ns. result.json lists each step with the number of completed calls, the last result, and the virtual time at its end (time_ns: null for a step the run did not reach). A call step that a limit or an error interrupted has no result for entry_result.

Stop reason Status Exit code Meaning
completed pass or fail 0 or 1 Every call returned. The assertions decide.
max_steps fail 1 The firmware used all its fuel.
max_time_ns fail 1 The firmware asked to advance past the ceiling.
model_error error 3 A port or model rejected a host call, for example an input outside a modeled range.
firmware_trap error 3 The firmware module trapped.
config_error error 2 The script, manifest or module was rejected before the firmware ran.

--output-dir receives result.json, junit.xml and flex-trace.json, and console.log when the manifest has a console. result.json carries the final value of each read port, each assertion with its observed value, and run_report: the execution path (flex_portable_wasm), target_cpu_emulated: false, the manifest SHA-256, the named ports, the model configuration, and the manifest's assumptions and unsupported_checks. config.firmware_sha256 pins the firmware bytes. flex-trace.json holds the logic-analyzer edges and oscilloscope samples in nanoseconds with their port names. --vcd writes the digital edges and --analog-trace writes the analog samples (.csv or .vcd), both in nanoseconds. Options that need a target machine, such as --system, --breakpoint, --max-cycles and --trace, are rejected with a configuration error.

A pass shows that this firmware module satisfied the assertions against the declared model. It is not evidence for original target firmware, MCU instruction or peripheral fidelity, full-board coverage, or chip parity.

I2C devices from the catalog

A Flex manifest can declare I2C buses. Each device is a catalog I2C device model, the same model that external_devices attaches to an MCU's I2C controller on the detailed path. The firmware is the only controller of the bus.

# system.yaml
ports:
  - { name: ambient_c, signal: environment.temperature, access: write, kind: number, unit: "°C", initial: 25 }
i2c_buses:
  - name: sensor_i2c
    frequency_hz: 100000
    devices:
      - id: source-u4-bme280
        type: bme280                      # catalog device type
        config: { i2c_address: 0x76 }     # the device's external_devices config
        inputs:                           # device input channel -> signal
          temperature: environment.temperature

The firmware imports one more function:

labwired.i2c_transfer(bus: i32, address: i32,
                      write_ptr: i32, write_len: i32,
                      read_ptr: i32, read_len: i32) -> i32
  • The call writes write_len bytes to the 7-bit address, reads read_len bytes after a repeated START, and sends a STOP. Either length can be 0. Both lengths 0 is an address probe.
  • The result is 0 when a device acknowledged the address and 1 when no device answered. A refused address is a result, not an error.
  • The byte ranges are in the firmware's exported memory. Each range is at most 4,096 bytes.
  • The call takes virtual time: one SCL period for each bit, for START and for STOP, at the bus frequency_hz. This time counts against max_time_ns, and an until_ns can suspend the firmware inside a transfer.
  • A script passes the bus to the firmware with a { bus: sensor_i2c } call argument. The value is the bus id (i32).

A device input channel takes its value from a signal: a write port, or a model output. The signal must have the unit that the channel declares (°C for the BME280 temperature channel); there is no unit conversion. A set on that port changes the device at once. A value outside the channel's range stops the run with model_error.

result.json gives the number of transfers in traces.i2c_transfers, and run_report.i2c_buses lists each bus with its devices, their addresses, and not_modeled. flex-trace.json gets an i2c record: each transfer with its start time, duration, address, ack, and the bytes written and read. The record keeps the newest 4,096 transfers; the i2c_transfers counts are exact for a run of any length.

This path exchanges whole bytes with the device model. It does not model the SCL and SDA waveforms, pull-ups, bus capacitance, clock stretching, a second controller, or device pin outputs such as an interrupt line. An unknown bus name, an unknown device type, an unknown input channel, a unit mismatch, or two devices with one address on a bus is a config_error.

Console output

A Flex manifest can declare one console: the place where target firmware prints, for example a UART or a USB serial port.

# system.yaml
console:
  name: usb_serial

The firmware imports one more function:

labwired.console_write(ptr: i32, len: i32)
  • The call appends len bytes of the firmware's exported memory to the console. A write is at most 1 MiB.
  • The call takes no virtual time. Each write keeps the virtual time of the call.
  • A console_write with no console in the manifest stops the run with model_error. A console_contains assertion with no console is a config_error.

result.json and flex-trace.json get a console record: text (the bytes as UTF-8), bytes, dropped_bytes, and writes, each with its time_ns, offset and len in the text. --output-dir also receives console.log, the text alone. The console keeps the first 1 MiB of a run; later bytes count in dropped_bytes, and console_contains does not see them. run_report.console gives the name and not_modeled: the baud rate and transfer time, UART framing and the TX pin, USB enumeration and host polling, and input to the firmware.

Part packs and listen-only devices

A Flex manifest carries parts:, the same labwired.part/v1 documents a system manifest carries (part packs). A bus device type, a co-simulation model's config.device_type or a sink type that names a pack is modelled from the pack, before the catalog; replacing a catalog part needs overrides:. A generated part model (an i2c_device, spi_device, display, analog_source, gpio_device, onewire_device or led_strip pack) runs with no engine code. Packs are inline: a Flex manifest has no path: entries.

# system.yaml
parts:
  - schema: labwired.part/v1
    type: "gen:relay-module"
    behavior:
      primitive: gpio_device
      pins: { IN: in_pin }
      outputs: [COIL]
      rules:
        - on: { pins: [IN] }
          do: [{ pin: COIL, level: "!pin(IN)" }]
cosim_models:
  - id: relay
    adapter: behavior
    step_ns: 1000
    inputs: { IN: mcu.d5 }
    outputs: { COIL: relay.coil }
    config: { device_type: "gen:relay-module" }
sinks:
  - { id: ring, type: neopixel, config: { num_pixels: 8 }, pins: { DIN: mcu.d6 } }
  - { id: display, type: tm1637-7seg, pins: { CLK: mcu.d2, DIO: mcu.d3 } }

sinks: are parts that only receive pin levels: a single-wire led_strip (WS2812) or a gpio_device that drives nothing (TM1637). Every pin of the part is bound to a Boolean signal. A sink takes each edge at the exact virtual time the signal changed, so an NRZ bit stream timed in nanoseconds decodes without a model step per nanosecond. It publishes no signal; what it holds is its device state. A strip sink keeps every changed frame in frame_history (cycle is the nanosecond it completed; at most 1024 frames, the oldest dropped and counted in frame_history_dropped).

result.json lists devices: each sink, bus device and model that publishes state, with its id, kind and state. run_report lists sinks and the part_packs types. A device_state assertion naming a device or key that does not exist is a config_error.

The same script in the browser

The browser package (labwired-wasm) runs a Flex script with the runner that labwired test uses. The page gives the three texts the script names; there are no paths in the browser.

const run = WasmFlexTestRun.run('test-heat-cycle.yaml', scriptYaml, manifestYaml, firmwareBytes);
const result = JSON.parse(run.result_json());   // the content of result.json
const runtime = run.take_runtime();              // a WasmFlexRuntime
const edges = runtime.digital_trace_snapshot(0); // logic analyzer
const samples = runtime.analog_trace_snapshot(0); // oscilloscope
const transfers = runtime.i2c_trace_snapshot(0);  // I2C transfer record
const console = runtime.console_capture();        // console text, or undefined
  • result_json() is the text of result.json. It differs from the CLI file only in config.script, config.flex and config.firmware: the browser keeps the names as the script writes them.
  • take_runtime() gives the runtime of the run to the existing instrument methods. It is an error after a config_error, because no runtime exists.
  • A script that does not parse or validate throws. Every later failure is a result with a stop_reason, as in the table above.
  • sequence, until_ns, resume, all assertions and both limits work as in the CLI. The firmware module runs in the wasmi interpreter on both hosts, so steps_executed is the same number.
  • The call returns when the script ends. Call it from a worker if the script is long.

scripts/test_browser_flex_scripts.mjs runs each test-*.yaml of the Flex fixtures in Chromium and in the CLI and compares the result text and both instrument captures. crates/wasm/tests/fixtures/browser-flex-scripts.json is the receipt of that run; a unit test of labwired-wasm fails when a script is missing from it or when the runner gives a different result text.

Exit Codes

Code Meaning Notes
0 Pass All assertions passed, and any non-success stop reason was explicitly asserted (if applicable).
1 Assertion failure Includes failed assertions, and hitting wall_time_ms / max_uart_bytes / no_progress_steps without asserting the matching expected_stop_reason.
2 Config/script error Invalid YAML, unknown fields, unsupported schema_version, missing/invalid inputs/limits, or a safety guard (e.g. max-steps cap).
3 Simulation/runtime error Runtime failure (e.g. memory_violation, decode_error) unless an expected_stop_reason assertion matches the stop reason.

Exit-code precedence: 1) Any failed assertion ⇒ 1 (even if a runtime error also occurred) 2) wall_time / max_uart_bytes / no_progress stop without matching expected_stop_reason ⇒ 1 3) Runtime error stop without matching expected_stop_reason ⇒ 3 4) Otherwise ⇒ 0

Script Schema (v1.0)

schema_version: "1.0"
inputs:
  firmware: "relative/or/absolute/path/to/fw.elf"
  system: "optional/path/to/system.yaml"
limits:
  max_steps: 100000
  max_cycles: 123456     # optional
  max_uart_bytes: 4096   # optional
  no_progress_steps: 500 # optional (PC unchanged for N steps)
  wall_time_ms: 5000   # optional
assertions:
  - uart_contains: "Hello"
  - uart_regex: "^Hello.*$"
  - rtt_contains: "Boot complete"
  - fidelity_clean: true
  - peripheral_log: {peripheral: i2c1, log: bus_trace, contains: "addr 0x48 W ack"}
  - expected_stop_reason: max_steps

Notes: - Unknown fields are rejected (script parse/validation returns exit code 2). - Relative inputs.firmware / inputs.system paths are resolved relative to the directory containing the script file (not the current working directory). - Relative inputs.env is resolved relative to the test script; each node's system and firmware paths are resolved relative to the environment manifest. - For a single-machine script, CLI flags override script inputs: - --firmware overrides inputs.firmware - --system overrides inputs.system - For an environment script, inputs.env is the only topology input; --firmware and --system are rejected. - CLI flags override script limits: - --max-steps overrides limits.max_steps - --max-cycles overrides limits.max_cycles - --max-uart-bytes overrides limits.max_uart_bytes - --detect-stuck (alias: --no-progress) overrides limits.no_progress_steps - --breakpoint <addr> (repeatable) stops the run when PC matches and sets stop_reason: halt.

rtt_contains matches only the dedicated SEGGER RTT stream (see SEGGER RTT logging); its presence enables RTT capture automatically. Environment/world scripts reject it at validation.

fidelity_clean: true passes only when the run hit no fidelity gap: no access to unmapped MMIO and no undecoded instruction. These are the unmapped_mmio and undecoded_instruction entries of the fidelity section in result.json. Approximations such as derived_device_time are not gaps. fidelity_clean: false passes only when the run hit at least one gap. The check reads the report when the run ends, before other assertions read memory. Use it in place of the LABWIRED_STRICT_FIDELITY environment variable, which aborts the process at the first gap with no result.json.

peripheral_log checks a named log that a peripheral model records during the run. A line matches when it contains contains; the assertion passes when at least min_count lines match (default 1). A model can store consecutive identical events as one line with a repeat count: the line ends in x{count} (for example seq 2 cmd 0x05 addr 0x00000000 size 1 x5000). Such a line counts as count matches, and contains matches the text before the x{count}. The check runs once, when the run ends. It does not hold a stop_when_assertions_pass run open.

assertions:
  - peripheral_log: {peripheral: usb1, log: host, contains: "device 1fc9:0135"}
  - peripheral_log: {peripheral: flexio2, log: wire, contains: "pin 2 ", min_count: 960}

peripheral is a peripheral name or the external_devices: id of an attached device (a device that records logs, such as the NAU88L21 codec):

assertions:
  - peripheral_log: {peripheral: codec, log: writes, contains: "write 0x001c = 0x000e"}

A peripheral, device or log name that does not exist is a config error (exit code 2), found before the run starts. The error lists the logs the peripheral has. A device has no bus_trace of its own: its traffic is in the bus_trace of the controller it hangs off. Logs today:

Log Peripheral One line per Example line
bus_trace every peripheral bus-trace event with this peripheral's name addr 0x54 W nack, data 0x0f ack, mosi 0x9f miso 0xef, tx 0x41
host i.MX RT USB OTG (imxrt_usb) fact or transfer the simulated USB host saw device 1fc9:0135 class 00/00/00 usb 0200 ep0 64, address 5, interface 3 alt 0 class 03/00/00 endpoints 2, endpoint 0x81 attr 0x03 max 64, string 2 "Product", control 00 09 0001 0000 0000 ok, in 1 01 02, out 2 64, note ...
ip i.MX RT FlexSPI (imxrt_flexspi) run of identical IP commands seq 1 cmd 0x9f addr 0x00000000 size 3, seq 2 cmd 0x05 addr 0x00000000 size 1 x5000
wire i.MX RT FlexIO (imxrt_flexio) word shifted out on a pin pin 2 width 1 bits 8 beats 0xc0 cycle 1234
writes NAU88L21 codec (nau88l21, attached device) register write write 0x001c = 0x000e, write 0x0000 = 0x0000 (reset)
reads NAU88L21 codec (nau88l21, attached device) register word read read 0x0058 = 0x1a20
regs NAU88L21 codec (nau88l21, attached device) register, value at the end of the run 0x001c = 0x000e
state NAU88L21 codec (nau88l21, attached device) decoded audio interface setting dai slave i2s 32-bit, adcout driven, enable dac_l dac_r adc_l adc_r
text multiplexed segment display (segment-display-mux, external device) change of the text a human sees "P3C" at cycle 3200000000
frames multiplexed segment display (segment-display-mux, external device) change of the visible segment masks, one per digit 0x0629 0x0000 0x0000 at cycle 3200000000
frames multiplexed LED matrix (led-matrix-mux, external device) change of the picture, 0–9 per pixel, one group per row 09090 99999 99999 09990 00900 at cycle 3200000

The bus trace is a ring of 4096 events shared by all buses. A long run can drop early events. When a bus_trace check fails, the message tells how many events the ring dropped. A device log is kept by the device model and is not in the ring. A model adds a log by overriding Peripheral::logs in labwired-core. An external device is named by its external_devices id and has no bus_trace log: a device on GPIO pads (a BusResidentDevice) adds a log by overriding BusResidentDevice::logs, an attached I2C device by overriding I2cDevice::logs. When a check fails, the message shows the last lines of the log.

The single-machine example above permits the documented single-machine assertions. Environment scripts are stricter: they require at least one node-qualified memory_value assertion and support max_steps, max_cycles, max_uart_bytes, wall_time_ms, stop_when_assertions_pass, stop_when_assertions_pass_settle_steps, and stop_when_assertions_pass_min_steps limits. They reject limits.no_progress_steps and single-machine-only controls such as --breakpoint.

Deprecated Legacy Schema (v1)

For backward compatibility, schema_version: 1 is still accepted, but is deprecated and will be removed in a future release.

Legacy shape:

schema_version: 1
firmware: "optional/path/to/fw.elf"   # optional (can be provided by --firmware)
system: "optional/path/to/system.yaml"
max_steps: 100000
wall_time_ms: 5000   # optional
assertions: []

Stop Reasons

expected_stop_reason supports: - max_steps - max_cycles - max_uart_bytes - no_progress - wall_time - assertions_passed - memory_violation - decode_error - halt - exception - config_error (runner failed before simulation started; e.g. script parse/validation error)

Semantics: - If the simulator hits wall_time_ms, the run is treated as an assertion failure (exit code 1) unless an expected_stop_reason assertion matches wall_time. - If the simulator hits max_uart_bytes or no_progress_steps, the run is treated as an assertion failure (exit code 1) unless an expected_stop_reason assertion matches (max_uart_bytes / no_progress). - If the simulator hits max_steps or max_cycles, the run is considered a normal stop (exit code 0) as long as assertions pass. - max_cycles, after_cycles triggers and a stimulus's reported at_cycle all count machine cycles (Machine::total_cycles): one per retired instruction on Cortex-M, RISC-V and Xtensa, and the core's datasheet cycles (1–4 per instruction) on the ATmega328P. A limit or trigger lands on its cycle or at the first instruction boundary after it. The top-level cycles field in result.json is a performance counter and may differ. - If opt-in assertion completion reaches its durable settling window, the run stops with assertions_passed and passes. - If the simulator hits a runtime error stop reason (e.g. memory_violation), the run is treated as a runtime error (exit code 3) unless an expected_stop_reason assertion matches the stop reason.

result.json uses: - result_schema_version: the result-union discriminator: "1.0" for a single machine or "1.0-environment" for an environment world - run_type: "environment": present only on the environment arm - stop_reason: the terminal reason the simulator stopped - stop_reason_details: which stop condition triggered (+ the limit/observed value when applicable) - limits: the resolved limits used for the run (after applying any CLI overrides) - status: one of pass, fail, error

Artifacts

Use --output-dir to write artifacts:

labwired test --script test.yaml --output-dir out/artifacts

Artifacts: - out/artifacts/result.json: machine-readable summary - out/artifacts/snapshot.json: a CPU snapshot for a single machine, or an environment snapshot with a nodes array for a world (also written for config errors) - out/artifacts/uart.log: captured UART TX bytes; world output is grouped by node - out/artifacts/rtt.log: captured SEGGER RTT bytes (empty unless RTT was enabled) - out/artifacts/junit.xml: JUnit XML report (one testcase for run + one per assertion)

Alternatively, you can write JUnit XML to a specific path:

labwired test --script test.yaml --junit out/junit.xml

Path Resolution Rules

  • --script: if relative, resolved relative to the current working directory.
  • Script-relative paths:
  • inputs.firmware, inputs.system (v1.0)
  • inputs.env (environment v1.0)
  • firmware, system (legacy v1) are resolved relative to the directory containing the script file.
  • Environment-manifest-relative paths: each nodes[].system and nodes[].firmware value is resolved relative to the environment manifest.
  • System manifest-relative paths: system.yaml may reference chip: ...; this chip path is resolved relative to the directory containing the system manifest file.
  • --output-dir / --junit: if relative, resolved relative to the current working directory.

result.json Contract

The runner writes result.json only when --output-dir is provided, including config/script errors that exit with code 2. Its top-level shape is a discriminated union. Consumers must branch on result_schema_version—and, for worlds, run_type—rather than assuming one firmware identity.

JSON Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "LabWired CI runner result.json",
  "$defs": {
    "common": {
      "type": "object",
      "required": [
        "status",
        "steps_executed",
        "cycles",
        "instructions",
        "stop_reason",
        "stop_reason_details",
        "limits",
        "assertions"
      ],
      "properties": {
        "status": { "enum": ["pass", "fail", "error"] },
        "steps_executed": { "type": "integer", "minimum": 0 },
        "cycles": { "type": "integer", "minimum": 0 },
        "instructions": { "type": "integer", "minimum": 0 },
        "stop_reason": {
          "enum": [
            "config_error",
            "max_steps",
            "max_cycles",
            "max_uart_bytes",
            "no_progress",
            "wall_time",
            "assertions_passed",
            "memory_violation",
            "decode_error",
            "halt",
            "exception"
          ]
        },
        "stop_reason_details": { "type": "object" },
        "limits": { "type": "object" },
        "message": { "type": ["string", "null"] },
        "assertions": { "type": "array" },
        "fidelity": { "type": "array" }
      }
    },
    "environment_node": {
      "type": "object",
      "required": ["id", "system", "firmware", "system_hash", "firmware_hash"],
      "properties": {
        "id": { "type": "string" },
        "system": { "type": "string" },
        "firmware": { "type": "string" },
        "system_hash": { "type": "string" },
        "firmware_hash": { "type": "string" }
      }
    }
  },
  "oneOf": [
    {
      "title": "single-machine result",
      "allOf": [
        { "$ref": "#/$defs/common" },
        {
          "type": "object",
          "required": ["result_schema_version", "firmware_hash", "config"],
          "properties": {
            "result_schema_version": { "const": "1.0" },
            "firmware_hash": {
              "type": "string",
              "description": "SHA-256 of the firmware ELF bytes."
            },
            "config": {
              "type": "object",
              "required": ["firmware", "system", "script"],
              "properties": {
                "firmware": { "type": "string" },
                "system": { "type": ["string", "null"] },
                "script": { "type": "string" }
              }
            }
          }
        }
      ]
    },
    {
      "title": "environment/world result",
      "allOf": [
        { "$ref": "#/$defs/common" },
        {
          "type": "object",
          "required": ["result_schema_version", "run_type", "config"],
          "not": { "required": ["firmware_hash"] },
          "properties": {
            "result_schema_version": { "const": "1.0-environment" },
            "run_type": { "const": "environment" },
            "config": {
              "type": "object",
              "required": ["script", "environment", "world_firmware_hash", "nodes"],
              "properties": {
                "script": { "type": "string" },
                "environment": { "type": "string" },
                "world_firmware_hash": { "type": "string" },
                "nodes": {
                  "type": "array",
                  "items": { "$ref": "#/$defs/environment_node" }
                }
              }
            }
          }
        }
      ]
    }
  ]
}

The single-machine arm has the top-level firmware_hash and a config.firmware/system/script provenance object. The environment arm has no top-level firmware_hash: it identifies the world with config.world_firmware_hash and records each node's id, system, firmware, system_hash, and firmware_hash. A world config error still uses the environment arm; its nodes list can be empty when the manifest could not be resolved. That includes explicit config_overrides (including {} and null), a chip without an explicit Cortex-M core, an ARM ELF without a valid Thumb reset vector, and unknown, mistyped, or invalid interconnect configuration; these produce status: "error" with stop_reason: "config_error" without changing the result-union arm.

uart_lines (optional)

A single-machine run whose firmware printed anything over the UART capture also carries uart_lines: every line of uart.log, in order, stamped on the engine-cycle axis, so a check can ask what a pin did when a line printed.

"uart_lines": {
  "lines": [
    { "text": "READY", "cycle_lo": 8158720, "cycle": 8178134, "end_cycle": 8179210 }
  ],
  "dropped_lines": 0
}

text is the line without its \r\n. Its first byte appeared after cycle_lo and by cycle; the window is the observation step the byte landed in (up to one execution batch), so read cycle as "certainly printed by" and cycle_lo as "certainly not before". end_cycle is when the newline had appeared; the last line has none when the run stopped mid-line. Lines past 20,000 are counted in dropped_lines, and text past 512 bytes is cut and flagged text_truncated: true. Silent runs omit the block, and older consumers can ignore it.

Deterministic reruns: trace hashing

--trace (global, also -t) makes test write trace.json into --output-dir: one JSON object per traced instruction, each stamped with its virtual cycle; --trace-max <N> caps how many are kept. The trace is a function of the firmware, config and emulator build only — no wall clock, no host entropy — so runs of the same script are byte-identical. The shipped harness crates/cli/tests/determinism.rs pins that: five runs must produce equal result.json, the same trace SHA-256 and the same stdout SHA-256, then three more must keep them stable under --log-timestamps virtual.

The CI recipe is a checksum pair. On the committed UART fixture, with a script whose inputs are absolute (the script lives outside the repo, so relative inputs would resolve against its own directory):

# /tmp/ci-docs/script.yaml
schema_version: "1.0"
inputs:
  firmware: "/path/to/repo/tests/fixtures/uart-ok-thumbv7m.elf"
  system: "/path/to/repo/configs/systems/ci-fixture-uart1.yaml"
limits:
  max_steps: 1000
assertions: []
cargo build -p labwired-cli

./target/debug/labwired test --script /tmp/ci-docs/script.yaml --trace --output-dir /tmp/ci-docs/det-a
./target/debug/labwired test --script /tmp/ci-docs/script.yaml --trace --output-dir /tmp/ci-docs/det-b
sha256sum /tmp/ci-docs/det-a/trace.json /tmp/ci-docs/det-b/trace.json
40909dab280765cc06c7bb6d0edd12ae3bec1c2fe5882605d972ea5f9ea6b0dc  /tmp/ci-docs/det-a/trace.json
40909dab280765cc06c7bb6d0edd12ae3bec1c2fe5882605d972ea5f9ea6b0dc  /tmp/ci-docs/det-b/trace.json

The same two runs hash stdout — the fixture's OK echo — to a12b7cb43c9d9134b5bb1b35e9096b66775d9e92e7611d1cc92b02edd6782a87. Judge determinism on the files, not the log: stderr carries wall-clock timestamps and the verdict's elapsed time (PASS … · 0.01s). That is the D3 round receipt as well: 10 idle and 10 loaded runs of this fixture shared one trace hash (40909dab…) and one stdout hash (a12b7cb4…). Gate on the trace hash to prove the simulator itself is reproducible; diff two trace.json files to find the first instruction where behavior changed.

Replaying a failed run (CAN)

A can-bridge can record every frame a run exchanges and replay the recording later on the virtual time axis, which turns an intermittent bench or field failure into a committed regression. The committed H563 UDS fixture (examples/h563-can-replay/) is the receipt:

cargo run -p labwired-cli -- test \
  --script examples/h563-can-replay/record.yaml \
  --no-uart-stdout --output-dir /tmp/ci-docs/rec
cargo run -p labwired-cli -- test \
  --script examples/h563-can-replay/replay.yaml \
  --no-uart-stdout --output-dir /tmp/ci-docs/rep
PASS  3/3 checks · record · 2000000 steps · 2.10s
PASS  2/2 checks · replay · 2000000 steps · 2.20s

The record run's bridge writes can-bus.jsonl (native replay format) and can-bus.candump.log into its --output-dir; the replay run injects the recorded tester requests at their recorded cycles and compares every answer the ECU transmits. Its verdict is in result.json:

jq '.can_bridges[0].replay' /tmp/ci-docs/rep/result.json
{
  "expected_tx": 22,
  "matched_tx": 22,
  "max_cycle_skew": 0,
  "observed_tx": 22,
  "rx_injected": 14,
  "rx_rejected": 0,
  "rx_total": 14,
  "verdict": "match"
}

max_cycle_skew: 0 means every answer landed on exactly the recorded cycle. Workflow: record on failure (or in a nightly job), commit the recording beside the replay system manifest, point the bridge's recording_path: at it, and replay in CI — a replay runs on virtual time, which does not move while paused, so it is identical every run, and a can_bridge assertion can require replay: match with max_dropped: 0. Bridge schema, pause modes and formats: examples/h563-can-replay/README.md.

CI artifacts and stdout rules

CI log viewers are the wrong place for firmware console output: a talkative firmware can drown the runner's verdict, and raw control bytes can scramble annotations. --no-uart-stdout disables only the stdout echo — UART bytes are still captured for uart_contains assertions and still written to uart.log:

$ ./target/debug/labwired test --script /tmp/ci-docs/script.yaml --no-uart-stdout \
    --output-dir /tmp/ci-docs/art > /tmp/ci-docs/art.stdout 2>/dev/null
$ wc -c < /tmp/ci-docs/art.stdout
0
$ cat /tmp/ci-docs/art/uart.log
OK

(Without the flag the same run writes the fixture's OK to stdout — 3 bytes.)

--output-dir is the artifact root. The audited file set is in the CLI Reference: result.json, snapshot.json, uart.log, rtt.log, semihosting.log, itm.log, and junit.xml, plus trace.json when --trace is set and the coverage, run-manifest and fault artifacts when those flags are requested. junit.xml (also mirrorable with --junit <PATH>) is the file CI UIs consume — GitLab's reports: junit, Azure's PublishTestResults@2, or any JUnit viewer; platform wiring is in CI integration. Keep the whole directory as the job's artifact, retained on failure.

CI release runners

Use the pinned v0.23.0 release runner in CI. It runs the same labwired test command described above and writes the same artifact contract.

GitHub Actions

Use the public Core action and pin the Core CLI with its version input. Its only inputs are required script, optional version (default v0.23.0), output-dir, and args:

- id: labwired
  name: Run LabWired tests
  uses: w1ne/labwired-core/.github/actions/labwired-test@64ed5d9723e2d9f5f4a851a81a3468025671d94e
  with:
    version: v0.23.0
    script: examples/ci/dummy-max-steps.yaml
    output-dir: out/artifacts
    args: --no-uart-stdout

- name: Link the automatic LabWired artifact
  if: always()
  run: echo "${{ steps.labwired.outputs.artifact-url }}" >> "$GITHUB_STEP_SUMMARY"

The Core action is an immutable action-source pin to 64ed5d9723e2d9f5f4a851a81a3468025671d94e; version: v0.23.0 independently pins the immutable Core CLI release. It downloads that public release archive with curl, creates output-dir/junit.xml plus Markdown and HTML reports, appends the Markdown report to the job summary, and always uploads the entire output directory—even after a failed test. Its status, summary-md, report-html, artifact-url, and exit-code outputs are available through the labwired step ID.

Docker and GitLab runners

The GHCR image has labwired as its entrypoint. For Docker, pass test directly after the pinned image name. Docker and the Action accept the same test YAML: use either a single-machine script or an inputs.env world script.

docker run --rm --user "$(id -u):$(id -g)" -v "$PWD:/workspace" -w /workspace \
  ghcr.io/w1ne/labwired:v0.23.0 \
  test --script examples/ci/dummy-max-steps.yaml \
       --output-dir out/artifacts \
       --no-uart-stdout

GitLab should clear that entrypoint and invoke labwired from its job shell:

image:
  name: ghcr.io/w1ne/labwired:v0.23.0
  entrypoint: [""]
script:
  - labwired test --script examples/ci/dummy-max-steps.yaml --output-dir out/artifacts --no-uart-stdout

Advanced source build

Build from source only when validating an unreleased LabWired commit. It is not the normal CI path:

cargo build --release -p labwired-cli
./target/release/labwired test --script examples/ci/dummy-max-steps.yaml --output-dir out/artifacts --no-uart-stdout