Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Bootloader tests

Bootloader tests run the bootloader emulator, one or more runs per test, and drive it the way the click tests drive firmware: input over the debug link, host messages over the wire port, screenshots hashed against tests/ui_tests/fixtures.json.

Unlike the firmware emulator, a bootloader run is expected to end on its own. A test starts the emulator with explicit startup parameters (a firmware image to preload, a boot command, a record directory), interacts with it, and then reads how the run ended: the process exit code tells the kind of exit, the file trezor.bootargs in the profile directory tells which boot command the bootloader left for the next boot, and the flash file tells whether storage survived. See trezorlib._internal.bootloader_emulator for the wrapper and trezorlib._internal.bootargs for the decoders.

Running

Build a debuglink bootloader emulator with the development keys, then run the suite:

make -C core build_bootloader_emu PYOPT=0 BOOTLOADER_DEVEL=1 TREZOR_MODEL=T3T1
make -C core test_emu_bootloader       # plain
make -C core test_emu_bootloader_ui    # with UI fixtures

The binary is taken from core/build/artifacts/latest/bootloader-emu, or from the path in TREZOR_BOOTLOADER_EMU.

To record fixtures for a model, run with --ui=record:

cd tests
TREZOR_BOOTLOADER_EMU=../core/build/artifacts/T3T1/bootloader-emu pytest bootloader_tests --ui=record

With --ui the screens are recorded from the first frame of every run, so the boot screens are part of the fixtures.

Writing a test

Use the bootloader fixture. bootloader.start(BootloaderStartup(...)) starts a run and returns the emulator; its ctx carries the debug link (debug) and the wire channel (wire). A wire call that needs an on-screen confirmation is made with wire.call_in_background() while the test clicks through the screen. Finish with bootloader.wait_exit() for a run that ends by itself, or bootloader.abort() for a screen that waits for the user to reconnect the device. Both return an ExitRecord with kind, bootargs and storage_erased.

Firmware images come from bootloader_tests/images.py: make_firmware(model, vendor=..., version=...) builds a dev-key signed image with filler code for any model, vendor trust level and version. The emulator never runs firmware, it only verifies it, so that is enough for the install, upgrade and boot flows. The suite therefore needs a bootloader built with the development keys (BOOTLOADER_DEVEL=1).

The bootloader emulator prints its flash layout with -p and takes a boot command from a file with -B; BootArgs.wipe(...), BootArgs.show_rsod(...) and friends build such files.