|
| 1 | +# HIL Bench Controller |
| 2 | + |
| 3 | +Automated Hardware-in-the-Loop (HIL) firmware testing on Raspberry Pi 5 for the Aharoni Lab. |
| 4 | + |
| 5 | +Turns a Raspberry Pi 5 into a self-hosted GitHub Actions runner that can flash MCU firmware, observe serial output, toggle GPIO pins, and report results — enabling automated firmware testing in CI pipelines. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- **Flash firmware** via Atmel-ICE (edbg) or OpenOCD |
| 10 | +- **Serial communication** — listen, send, and pattern-match (`expect`) |
| 11 | +- **GPIO control** — set, get, pulse pins (libgpiod/gpiod, Pi 5 compatible) |
| 12 | +- **Health monitoring** — probe, serial, GPIO, and runner status checks |
| 13 | +- **CI integration** — org-level GitHub Actions runner with example workflows |
| 14 | +- **Idempotent bootstrap** — single script to provision a fresh Pi |
| 15 | + |
| 16 | +## Quick Start |
| 17 | + |
| 18 | +### 1. Bootstrap a Pi |
| 19 | + |
| 20 | +```bash |
| 21 | +git clone https://github.com/Aharoni-Lab/hil-bench-controller.git |
| 22 | +cd hil-bench-controller |
| 23 | +sudo ./bootstrap/bootstrap_pi.sh aharoni-samd51-bench-01 <github-org-token> |
| 24 | +``` |
| 25 | + |
| 26 | +### 2. Edit config |
| 27 | + |
| 28 | +```bash |
| 29 | +sudo vim /etc/hil-bench/config.yaml |
| 30 | +benchctl config validate |
| 31 | +``` |
| 32 | + |
| 33 | +### 3. Flash and test |
| 34 | + |
| 35 | +```bash |
| 36 | +benchctl flash --firmware build/firmware.bin --target samd51 |
| 37 | +benchctl serial expect --target samd51 --pattern "BOOT OK" --timeout 10 |
| 38 | +benchctl gpio get --pin fault --target samd51 |
| 39 | +benchctl health |
| 40 | +``` |
| 41 | + |
| 42 | +## CLI Reference |
| 43 | + |
| 44 | +``` |
| 45 | +benchctl [--config PATH] [--verbose] [--dry-run] |
| 46 | + flash --firmware PATH --target NAME [--verify] [--power-cycle] |
| 47 | + serial listen|send|expect --target NAME [--timeout N] |
| 48 | + gpio set|get|pulse --pin NAME|NUM --value high|low |
| 49 | + health [--json] |
| 50 | + config show|validate|generate |
| 51 | +``` |
| 52 | + |
| 53 | +## CI Integration |
| 54 | + |
| 55 | +Add HIL testing to any firmware repo. See [`examples/firmware-ci.yml`](examples/firmware-ci.yml) for a complete 2-job workflow (build on GitHub → test on bench). |
| 56 | + |
| 57 | +```yaml |
| 58 | +hil-test: |
| 59 | + runs-on: [self-hosted, linux, ARM64, hil, samd51, bench01] |
| 60 | + steps: |
| 61 | + - uses: actions/download-artifact@v4 |
| 62 | + with: { name: firmware } |
| 63 | + - run: benchctl flash --firmware firmware.bin --target samd51 --verify |
| 64 | + - run: benchctl serial expect --target samd51 --pattern "BOOT OK" --timeout 15 |
| 65 | +``` |
| 66 | +
|
| 67 | +## Development |
| 68 | +
|
| 69 | +```bash |
| 70 | +pip install -e ".[dev]" |
| 71 | +ruff check src/ tests/ |
| 72 | +pytest -m "not hardware" |
| 73 | +``` |
| 74 | + |
| 75 | +## Project Structure |
| 76 | + |
| 77 | +``` |
| 78 | +src/hilbench/ Python package |
| 79 | + config.py Pydantic config models + YAML loader |
| 80 | + probe.py edbg/OpenOCD flash abstraction |
| 81 | + serial_io.py pyserial wrapper |
| 82 | + gpio.py gpiod (libgpiod) wrapper |
| 83 | + relay.py Power relay control (stubbed) |
| 84 | + health.py Health check logic |
| 85 | + artifacts.py Firmware artifact resolution |
| 86 | + cli/ Click CLI commands |
| 87 | +bootstrap/ Pi provisioning scripts |
| 88 | +configs/ Config templates |
| 89 | +systemd/ Health check timer |
| 90 | +udev/ Device permission rules |
| 91 | +``` |
| 92 | + |
| 93 | +## License |
| 94 | + |
| 95 | +GPL-3.0-or-later. See [LICENSE](LICENSE). |
0 commit comments