Skip to content

HIL testing framework for hardware wallet verification #3

@Amperstrand

Description

@Amperstrand

Goal

A hardware-in-the-loop (HIL) testing framework that runs the full integration test suite (3 basic + 3 seedkeeper + 13 RPC = 19 tests) against real hardware via serial communication.

How It Works

  1. HIL firmware (make hil) — builds with HIL_ENABLED = True, which starts a UART command listener on the ST-Link debug port (9600 baud)
  2. HIL controller (test/hil/controller.py) — connects to debug UART and USB VCP, automates the GUI flow (PIN entry, secret selection, popup dismissal)
  3. HIL test runner (test/hil/run_integration.py) — loads test modules, auto-starts Bitcoin Core, runs all 19 tests

HIL Commands (via debug UART)

Command Response Purpose
TEST_WIPE OK:WIPED Wipe wallet storage + hard reset
TEST_KEYSTORE OK:KEYSTORE:SeedKeeper or OK:KEYSTORE:Internal Detect active keystore
TEST_SECRETS OK:SECRETS:id:label,... List BIP39 secrets on card
TEST_FINGERPRINT OK:FINGERPRINT:hex Get current fingerprint
TEST_MNEMONIC OK:MNEMONIC:words Get loaded mnemonic (debug only)
TEST_STATUS OK:STATUS:... Get device status
TEST_SCREEN OK:SCREEN:ClassName:... Get current GUI screen
TEST_UI:value OK:UI Send GUI input
TEST_RESET (resets device) Hard reset

Test Results

19/19 pass (~332 seconds) on STM32F469 Discovery board with SeedKeeper card:

  • 3 basic tests: fingerprint, xpub, sign_psbt
  • 3 seedkeeper tests: fingerprint format, xpub, read-only error
  • 13 RPC tests: legacy, legacy_sh, miniscript, no_derivation, sh_wpkh, sh_wsh, sighashes, sighashes_legacy, strange_derivation, weird_wsh, with_private, wpkh, wsh

New Files

File Purpose
src/hil.py HIL command handler (UART listener, commands)
manifests/disco-hil.py HIL firmware build manifest
test/hil/controller.py Hardware controller (serial, popup drain, keystore loading)
test/hil/run_integration.py HIL test runner
test/integration/tests/test_seedkeeper.py SeedKeeper-specific HIL tests
test/integration/util/bitcoin_core.py BitcoinCoreManager (auto-start bitcoind)

Modified Files

File Change
src/platform.py hil_test_mode flag
src/specter.py HIL listener, heartbeat disable, USB auto-enable
src/hosts/usb.py HIL auto-enable USB
src/main.py dupterm guard, network = "regtest" override
src/gui/tcp_gui.py TEST_STATUS/TEST_SCREEN/TEST_RESET for simulator
Makefile hil and hil-test targets
test/integration/util/controller.py SIGSEGV detection

Known Limitations

Upstream Target

Depends on SeedKeeper PR (#2). PR to cryptoadvance/specter-diy. Does NOT touch any submodule.

Metadata

Metadata

Assignees

No one assigned

    Labels

    hilHardware-in-the-loop testingupstream-prCandidate for upstream PR

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions