SDK docs menu

Getting started

Quickstart

This test runs against hardlabs/demo-board, which every account has. It's an STM32F405 with an MCP9808 temperature sensor, an OLED, three LEDs and a button. Its firmware prints the temperature, raises an alarm above 60 °C and takes the button press as an acknowledgement. You need the SDK installed and signed in (see Installation).

Write a test

test_demo.py
def test_overheat_raises_the_alarm(hardlabs_board):
    board = hardlabs_board
    board.wait_for("temp")                                  # the first reading
    board.do("temperature-sensor-mcp9808.overheat-75-c")    # set the sensor to 75 °C
    board.wait_for("ALARM", within=5)
    assert board.read("alert-pin")

    board.do("button.sw1")
    board.wait_for("alarm acknowledged", within=5)

Run it

pytest test_demo.py --hardlabs-sim hardlabs/demo-board

What happens:

  • The hardlabs_board fixture boots the board once for the test session and stops it at the end.
  • Board.wait_for waits for a console line. within=5 means five seconds of simulated time, however long that takes in real time.
  • Board.do and Board.read take the names the board's panels use. Board.controls lists them.
  • If the test fails, pytest's report includes the console's last lines.

Use your own board

Pass your board's name and the firmware you build:

pytest tests/ --hardlabs-sim company_name/board_name --hardlabs-firmware build/app.elf

Next: Loading firmware for bootloaders and raw images, or Using your own test framework if your tests already talk to the device over a serial port.