Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HIL testing #1297

Merged
merged 45 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
65ef75a
Create the `hil-test` package
jessebraham Dec 14, 2023
ef6cdfb
Add a simple integration test to verify basic GPIO functionality
jessebraham Dec 14, 2023
fc6e84f
WIP
jessebraham Mar 6, 2024
14e87dd
feat: Update with esp-hal unification
SergioGasquez Mar 7, 2024
e8b93aa
build: Update dependencies
SergioGasquez Mar 7, 2024
54cb6db
feat: Add a simple CI workflow test
SergioGasquez Mar 7, 2024
0d07e36
ci: Avoid using a gh-hosted-runner to build
SergioGasquez Mar 8, 2024
e985b44
ci: Remove building bins in gh-hosted-runner
SergioGasquez Mar 8, 2024
d7a62e7
ci: Remove HIL Gpio CI test
SergioGasquez Mar 11, 2024
fbe5fa5
ci: Test all the available tests
SergioGasquez Mar 11, 2024
f880982
test: Add spi_full_duplex test
SergioGasquez Mar 11, 2024
94c16fb
docs: Add documentation
SergioGasquez Mar 11, 2024
5bdbc9f
test: Add uart test
SergioGasquez Mar 11, 2024
94a0f1a
style: Remove unused imports
SergioGasquez Mar 12, 2024
88e7772
docs: Update wiring, document H2 VM
SergioGasquez Mar 12, 2024
8e394b8
ci: Enable H2 tests
SergioGasquez Mar 12, 2024
787f3fc
ci: Add rust-cache action
SergioGasquez Mar 12, 2024
b64f071
docs: Document H2 vm
SergioGasquez Mar 12, 2024
ff3d822
test: Add timeout
SergioGasquez Mar 12, 2024
66f29dd
ci: Enable ESP32-C3 tests
SergioGasquez Mar 13, 2024
e84da21
feat: Add timeouts
SergioGasquez Mar 14, 2024
ee1c7e4
feat: Add aes test
SergioGasquez Mar 14, 2024
ee2e190
ci: Avoid running CI workflow when we change hil-test stuff
SergioGasquez Mar 14, 2024
fd5d142
test: Remove warnings
SergioGasquez Mar 14, 2024
6dbf0b2
feat: Address feedback
SergioGasquez Mar 15, 2024
93447e2
feat: Update features names and spi methods
SergioGasquez Mar 15, 2024
942c166
ci: Remove rust-cache action
SergioGasquez Mar 15, 2024
1bc2a9a
Update HIL to probe-rs#2292 (#1307)
SergioGasquez Mar 18, 2024
9df87f8
ci: Use a matrix
SergioGasquez Mar 18, 2024
6044ae6
ci: Enable ESP32C3
SergioGasquez Mar 18, 2024
a1aa21d
feat: Add a way to cfg away test for unsuported peripherals
SergioGasquez Mar 18, 2024
77affa9
ci: Update trigger conditions
SergioGasquez Mar 19, 2024
72e214a
feat: Update pins to make it work on s3
SergioGasquez Mar 20, 2024
13fd9ea
feat: Changes enabling S3
SergioGasquez Mar 20, 2024
a4202a1
feat: Remove log feature
SergioGasquez Mar 20, 2024
c7c7dea
feat: Adapt for rebase
SergioGasquez Mar 20, 2024
b94099c
feat: Remove env
SergioGasquez Mar 20, 2024
9787fd1
feat: enable S3
SergioGasquez Mar 20, 2024
b736aef
chore: Remove todo
SergioGasquez Mar 20, 2024
17e3ca0
build: Pin dependencies
SergioGasquez Mar 21, 2024
43aeb6f
feat: Add target alias
SergioGasquez Mar 21, 2024
a9b6b8a
docs: Update readme
SergioGasquez Mar 21, 2024
9849317
fix: Fix traits imports after rebase. Use debug
SergioGasquez Mar 21, 2024
1c1d6a3
build: Remove lto
SergioGasquez Mar 21, 2024
6020e8a
feat: Build tests on release mode
SergioGasquez Mar 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ on:
paths-ignore:
- "**/CHANGELOG.md"
- "**/README.md"
- "**/hil-test/**"
push:
branches-ignore:
- "gh-readonly-queue/**"
paths-ignore:
- "**/CHANGELOG.md"
- "**/README.md"
- "**/hil-test/**"
merge_group:
workflow_dispatch:

Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/hil.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: HIL

on:
merge_group:
workflow_dispatch:
inputs:
repository:
description: "Owner and repository to test"
required: true
default: 'esp-rs/esp-hal'
branch:
description: "Branch, tag or SHA to checkout."
required: true
default: "main"

env:
CARGO_TERM_COLOR: always

jobs:
# Test RISC-V targets:
riscv-hil:
name: HIL Test | ${{ matrix.target.soc }}
runs-on:
labels: [self-hosted, "${{ matrix.target.runner }}"]
strategy:
fail-fast: false
matrix:
target:
- soc: esp32c3
runner: rustboard
rust-target: riscv32imc-unknown-none-elf
- soc: esp32c6
runner: esp32c6-usb
rust-target: riscv32imac-unknown-none-elf
- soc: esp32h2
runner: esp32h2-usb
rust-target: riscv32imac-unknown-none-elf
steps:
- uses: actions/checkout@v4
if: github.event_name != 'workflow_dispatch'

- uses: actions/checkout@v4
if: github.event_name == 'workflow_dispatch'
with:
repository: ${{ github.event.inputs.repository }}
ref: ${{ github.event.inputs.branch }}

- uses: dtolnay/rust-toolchain@v1
with:
target: ${{ matrix.target.rust-target }}
toolchain: nightly
components: rust-src

- name: Run tests
working-directory: hil-test
run: cargo ${{ matrix.target.soc }}

# Test Xtensa targets:
# TODO: Add jobs for Xtensa once supported by `probe-rs`
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ exclude = [
"esp-metadata",
"esp-riscv-rt",
"examples",
"hil-test",
]
29 changes: 29 additions & 0 deletions hil-test/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[alias]
# esp32 = "test --release --features=esp32 --target=xtensa-esp32-none-elf -- --chip esp32-3.3v"
# esp32c2 = "test --release --features=esp32c2 --target=riscv32imc-unknown-none-elf -- --chip esp32c2"
esp32c3 = "test --release --features=esp32c3 --target=riscv32imc-unknown-none-elf -- --chip esp32c3"
esp32c6 = "test --release --features=esp32c6 --target=riscv32imac-unknown-none-elf -- --chip esp32c6"
esp32h2 = "test --release --features=esp32h2 --target=riscv32imac-unknown-none-elf -- --chip esp32h2"
# esp32p4 = "test --release --features=esp32p4 --target=riscv32imafc-unknown-none-elf -- --chip esp32p4"
# esp32s2 = "test --release --features=esp32s2 --target=xtensa-esp32s2-none-elf -- --chip esp32s2"
esp32s3 = "test --release --features=esp32s3 --target=xtensa-esp32s3-none-elf -- --chip esp32s3"

[target.'cfg(target_arch = "riscv32")']
runner = "probe-rs run"
rustflags = [
"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-Tembedded-test.x",
"-C", "link-arg=-Tdefmt.x",
]

[target.'cfg(target_arch = "xtensa")']
runner = "probe-rs run"
rustflags = [
"-C", "link-arg=-nostartfiles",
"-C", "link-arg=-Wl,-Tlinkall.x",
"-C", "link-arg=-Tdefmt.x",
"-C", "link-arg=-Tembedded-test.x",
]

[unstable]
build-std = ["core"]
93 changes: 93 additions & 0 deletions hil-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[package]
name = "hil-test"
version = "0.0.0"
edition = "2021"
publish = false

[[test]]
name = "aes"
harness = false

[[test]]
name = "gpio"
harness = false

[[test]]
name = "spi_full_duplex"
harness = false

[[test]]
name = "uart"
harness = false

[dependencies]
defmt = { version = "0.3.5" }
defmt-rtt = { version = "0.4.0" }
esp-hal = { path = "../esp-hal", features = ["embedded-hal", "embedded-hal-02", "defmt"], optional = true }
embedded-hal-02 = { version = "0.2.7", package = "embedded-hal", features = ["unproven"] }
embedded-hal-async = { version = "1.0.0", optional = true }
embedded-hal = { version = "1.0.0" }
embedded-hal-nb = { version = "1.0.0", optional = true }
embassy-executor = { default-features = false, version = "0.5.0", features = ["executor-thread", "arch-riscv32"], optional = true }
semihosting = "0.1.6"

[dev-dependencies]
# Add the `embedded-test/defmt` feature for more verbose testing
embedded-test = {git = "https://github.com/probe-rs/embedded-test", rev = "8e3f925"}

[features]
# Device support (required!):
esp32 = ["esp-hal/esp32"]
esp32c2 = ["esp-hal/esp32c2"]
esp32c3 = ["esp-hal/esp32c3"]
esp32c6 = ["esp-hal/esp32c6"]
esp32h2 = ["esp-hal/esp32h2"]
esp32s2 = ["esp-hal/esp32s2"]
esp32s3 = ["esp-hal/esp32s3"]
# Async & Embassy:
async = ["dep:embedded-hal-async", "esp-hal?/async"]
embassy = ["esp-hal?/embassy", "embedded-test/embassy", "dep:embassy-executor"]
embassy-executor-interrupt = ["esp-hal?/embassy-executor-interrupt"]
embassy-executor-thread = ["esp-hal?/embassy-executor-thread"]
embassy-time-systick-16mhz = ["esp-hal?/embassy-time-systick-16mhz"]
embassy-time-systick-80mhz = ["esp-hal?/embassy-time-systick-80mhz"]
embassy-time-timg0 = ["esp-hal?/embassy-time-timg0"]

# cargo build/run
[profile.dev]
codegen-units = 1
debug = 2
debug-assertions = true # <-
incremental = false
opt-level = 'z' # <-
overflow-checks = true # <-

# cargo test
[profile.test]
codegen-units = 1
debug = 2
debug-assertions = true # <-
incremental = false
opt-level = 3 # <-
overflow-checks = true # <-

# cargo build/run --release
[profile.release]
codegen-units = 1
debug = 2
debug-assertions = false # <-
incremental = false
opt-level = 3 # <-
overflow-checks = false # <-

# cargo test --release
[profile.bench]
codegen-units = 1
debug = 2
debug-assertions = false # <-
incremental = false
opt-level = 3 # <-
overflow-checks = false # <-

[patch.crates-io]
semihosting = { git = "https://github.com/taiki-e/semihosting", rev = "c829c19" }
95 changes: 95 additions & 0 deletions hil-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# hil-test

Hardware-in-loop testing for `esp-hal`.

For assistance with this package please [open an issue] or [start a discussion].

[open an issue]: https://github.com/esp-rs/esp-hal/issues/new
[start a discussion]: https://github.com/esp-rs/esp-hal/discussions/new/choose

## Quickstart

We use [embedded-test] as our testing framework, which relies on [defmt] internally. This allows us to write unit and integration tests much in the same way you would for a normal Rust project, when the standard library is available, and to execute them using Cargo's built-in test runner.

[embedded-test]: https://github.com/probe-rs/embedded-test
[defmt]: https://github.com/knurling-rs/defmt

### Running Tests Locally

We use [probe-rs] for flashing and running the tests on a target device, however, this **MUST** be installed from the correct revision, and with the correct features enabled:

```text
cargo install probe-rs \
--git=https://github.com/probe-rs/probe-rs \
--rev=b431b24 \
--features=cli \
--bin=probe-rs
```

Target device **MUST** connected via its USB-Serial-JTAG port, or if unavailable (eg. ESP32, ESP32-C2, ESP32-S2) then you must connect a compatible debug probe such as an [ESP-Prog].

You can run all test for a given device using:

```shell
cargo +nightly esp32c6
# or
cargo +esp esp32s3
```

For running a single test on a target:

```shell
# Run GPIO tests for ESP32-C6
CARGO_BUILD_TARGET=riscv32imac-unknown-none-elf \
PROBE_RS_CHIP=esp32c6 \
cargo +nightly test --features=esp32c6 --test=gpio
```
- If the `--test` argument is omitted, then all tests will be run.
- The build target **MUST** be specified via the `CARGO_BUILD_TARGET` environment variable or as an argument (`--target`).
- The chip **MUST** be specified via the `PROBE_RS_CHIP` environment variable or as an argument of `probe-rs` (`--chip`).

Some tests will require physical connections, please see the current [configuration in our runners](#running-tests-remotes-ie-on-self-hosted-runners).

### Running Tests Remotes (ie. On Self-Hosted Runners)
The [`hil.yml`] workflow builds the test suite for all our available targets and executes them.

Our Virtual Machines have the following setup:
- ESP32-C3 (`rustboard`):
- Devkit: `ESP32-C3-DevKit-RUST-1` connected via USB-Serial-JTAG.
- `GPIO2` and `GPIO4` are connected.
- VM: Configured with the following [setup](#vm-setup)
- ESP32-C6 (`esp32c6-usb`):
- Devkit: `ESP32-C6-DevKitC-1 V1.2` connected via USB-Serial-JTAG (`USB` port).
- `GPIO2` and `GPIO4` are connected.
- VM: Configured with the following [setup](#vm-setup)
- ESP32-H2 (`esp32h2-usb`):
- Devkit: `ESP32-H2-DevKitM-1` connected via USB-Serial-JTAG (`USB` port).
- `GPIO2` and `GPIO4` are connected.
- VM: Configured with the following [setup](#vm-setup)

[`hil.yml`]: https://github.com/esp-rs/esp-hal/blob/main/.github/workflows/hil.yml

#### VM Setup
```bash
# Install Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain stable -y --profile minimal
# Source the current shell:
source "$HOME/.cargo/env"
# Install dependencies
sudo apt install -y pkg-config libudev-dev
# Install probe-rs
cargo install probe-rs --git=https://github.com/probe-rs/probe-rs --rev=b431b24 --features=cli --bin=probe-rs --locked --force
# Add the udev rules
wget -O - https://probe.rs/files/69-probe-rs.rules | sudo tee /etc/udev/rules.d/69-probe-rs.rules > /dev/null
# Add the user to plugdev group
sudo usermod -a -G plugdev $USER
# Reboot the VM
```

## Adding New Tests

1. Create a new integration test file (`tests/$PERIPHERAL.rs`)
2. Add a corresponding `[[test]]` entry to `Cargol.toml` (**MUST** set `harness = false`)
3. Write the tests
4. Document any necessary physical connections on boards connected to self-hosted runners
5. Write some documentation at the top of the `tests/$PERIPHERAL.rs` file with the pins being used and the required connections, if applicable.
Loading
Loading