Guides
Testing with pytest
Installing hardlabs-sdk registers a pytest plugin. It signs in and boots the board only when a test asks for it, so the rest of your suite runs as before.
Choose the board and firmware
pytest --hardlabs-sim company_name/board_name --hardlabs-firmware build/app.elfRepeat --hardlabs-firmware for each image. In CI, set HARDLABS_SIM and HARDLABS_FIRMWARE instead (images separated by spaces).
Drive the board
hardlabs_board is a Board, booted once for the session:
def test_reports_safe_mode(hardlabs_board):
hardlabs_board.send("status")
hardlabs_board.wait_for("mode: SAFE")Start a test from a fresh boot
Tests share one session, so state carries over. Mark a test to boot the board afresh before it runs, with its memory chips back to the images you gave them:
import pytest
@pytest.mark.hardlabs_fresh
def test_first_boot_banner(hardlabs_board):
hardlabs_board.wait_for("bootloader v", within=2)Memory chips
--hardlabs-firmware config.bin@U7 gives a memory chip an image. --hardlabs-save-memory nvm/ saves every chip when the run ends, and --hardlabs-memory nvm/ starts them from a saved run. See Memory chips.
Open serial ports
hardlabs_serial opens a port for the session and returns the same SerialBridge every time you ask for that port. See Swap a bench rig for the simulation.
Failure reports
When a test fails, the report adds two sections: the console's last 40 lines, and Board.problems, which lists the firmware's crashes, failed asserts and restarts, and behaviour the simulation may not cover.
Parallel runs
One account has one session per board. Don't split a board's tests across pytest-xdist workers: a second worker restarts the board under the first. See Continuous integration.
Every fixture, option and environment variable is in the pytest plugin reference.