Skip to content

Hardware-in-the-loop testing in GitLab CI

Two ways to put real hardware in a GitLab pipeline: the ready-made CI template (CLI-based, zero setup) or the Python SDK for full pytest suites. Both flash your binary to a physical board and fail the pipeline when the hardware run fails.

Template source on GitHub

Option 1: the CI template

Include the template and extend it:

yaml
include:
  - remote: 'https://raw.githubusercontent.com/siliconrig/srig-integrations/main/templates/gitlab-ci.yml'

hil-test:
  extends: .siliconrig-hil
  stage: test
  variables:
    SRIG_BOARD: stm32-h753
    SRIG_FIRMWARE: build/firmware.bin
    SRIG_SERIAL_TIMEOUT: "30s"
  timeout: 10m

.siliconrig-hil installs the CLI, creates a session, flashes SRIG_FIRMWARE, captures serial output to serial-output.txt (kept as a job artifact, also on failure), and ends the session in after_script so a failing test never leaves a session running.

Override script: to assert on the output:

yaml
hil-test:
  extends: .siliconrig-hil
  variables:
    SRIG_BOARD: rp2350
    SRIG_FIRMWARE: build/app.uf2
  script:
    - srig serial --timeout 30s --log serial-output.txt
    - grep "BENCH_DONE" serial-output.txt

There is also .siliconrig-flash for flash-only jobs (e.g. deploying a golden image) without serial capture.

Option 2: the Python SDK

For richer assertions, drive the board from pytest:

yaml
hardware-test:
  image: python:3.12
  stage: test
  variables:
    SRIG_API_KEY: $SRIG_API_KEY
  script:
    - pip install siliconrig pytest
    - pytest tests/hil/ -v
  timeout: 10m

See the Python SDK guide for the board fixture pattern (session per test, flash once, interact over serial).

Setup

  1. Create an API key in the dashboard, named after the project (e.g. GitLab CI - my-firmware).
  2. Add it as a masked CI/CD variable SRIG_API_KEY (Settings → CI/CD → Variables).
  3. Pick a board type and point SRIG_FIRMWARE at your build output.

Tips

  • Always set timeout: on the job. A board that never prints the expected line should fail fast, not eat your pipeline minutes.
  • Keep serial logs as artifacts (the template already does) so a red pipeline shows you what the board actually said.
  • Firmware uploads are limited to 16 MB.