Skip to content

Commit

Permalink
Update probe-rs, prebuild xtask for HIL tests (#1939)
Browse files Browse the repository at this point in the history
* Update probe-rs

* Differentiate jobs

* Explicitly print that probe-rs's execution failed

* Do not capture stdin/stderr

* Pre-build xtask binary

* Use current_directory

* Print more info when a file can't be read

* Do not erase flash after a failure

* get_time: fail faster

* Make xtask runnable
  • Loading branch information
bugadani authored Aug 14, 2024
1 parent 460eaa2 commit 9e87792
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 47 deletions.
76 changes: 56 additions & 20 deletions .github/workflows/hil.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,48 @@ env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build-xtasks:
name: Build xtasks | ${{ matrix.host.arch }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
host:
- arch: armv7
rust-target: armv7-unknown-linux-gnueabihf
- arch: aarch64
rust-target: aarch64-unknown-linux-gnu

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 }}

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
components: rust-src

- name: Install cross
run: cargo install cross

- name: Build xtasks
run: cross build --release --target ${{ matrix.host.rust-target }}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: xtask-${{ matrix.host.arch }}
path: target/${{ matrix.host.rust-target }}/release/xtask

build-tests:
name: HIL Test | ${{ matrix.target.soc }}
name: Build HIL Tests | ${{ matrix.target.soc }}
runs-on: ubuntu-latest

strategy:
Expand Down Expand Up @@ -92,8 +132,8 @@ jobs:
overwrite: true

hil:
name: HIL Test | ${{ matrix.target.soc }}
needs: build-tests
name: Run HIL Tests | ${{ matrix.target.soc }}
needs: [build-tests, build-xtasks]
runs-on:
labels: [self-hosted, "${{ matrix.target.runner }}"]
strategy:
Expand All @@ -104,45 +144,41 @@ jobs:
- soc: esp32c2
runner: esp32c2-jtag
usb: USB2
host: aarch64
- soc: esp32c3
runner: esp32c3-usb
usb: ACM0
host: armv7
- soc: esp32c6
runner: esp32c6-usb
usb: ACM0
host: armv7
- soc: esp32h2
runner: esp32h2-usb
usb: USB0
host: armv7
# Xtensa devices:
- soc: esp32s2
runner: esp32s2-jtag
usb: USB1
host: armv7
- soc: esp32s3
runner: esp32s3-usb
usb: USB0
host: armv7
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: actions/download-artifact@v4
with:
name: tests-${{ matrix.target.soc }}
path: tests-${{ matrix.target.soc }}

- uses: actions/download-artifact@v4
with:
name: xtask-${{ matrix.target.host }}

- name: Run Tests
id: run-tests
run: |
export PATH=$PATH:/home/espressif/.cargo/bin
cargo xtask run-elfs ${{ matrix.target.soc }} tests-${{ matrix.target.soc }}
- name: Erase Flash on Failure
if: ${{ failure() && steps.run-tests.conclusion == 'failure' }}
env:
ESPFLASH_PORT: /dev/tty${{ matrix.target.usb }}
run: |
export PATH=$PATH:/home/espressif/.cargo/bin
espflash erase-flash
chmod +x xtask
./xtask run-elfs ${{ matrix.target.soc }} tests-${{ matrix.target.soc }}
4 changes: 2 additions & 2 deletions hil-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ We use [probe-rs] for flashing and running the tests on a target device, however
```text
cargo install probe-rs-tools \
--git https://github.com/probe-rs/probe-rs \
--rev bba1bb5 --force --locked
--rev 9bde591 --force --locked
```

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].
Expand Down Expand Up @@ -108,7 +108,7 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-t
# Install dependencies
sudo apt install -y pkg-config libudev-dev
# Install probe-rs
cargo install probe-rs-tools --git https://github.com/probe-rs/probe-rs --rev bba1bb5 --force
cargo install probe-rs-tools --git https://github.com/probe-rs/probe-rs --rev 9bde591 --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
Expand Down
1 change: 1 addition & 0 deletions hil-test/tests/get_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mod tests {
}

#[test]
#[timeout(3)]
fn test_current_time(ctx: Context) {
let t1 = esp_hal::time::current_time();
ctx.delay.delay_millis(500);
Expand Down
17 changes: 10 additions & 7 deletions xtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
process::Command,
};

use anyhow::{bail, Result};
use anyhow::{bail, Context, Result};
use cargo::CargoAction;
use clap::ValueEnum;
use esp_metadata::Chip;
Expand Down Expand Up @@ -151,7 +151,8 @@ pub fn load_examples(path: &Path) -> Result<Vec<Metadata>> {

for entry in fs::read_dir(path)? {
let path = windows_safe_path(&entry?.path());
let text = fs::read_to_string(&path)?;
let text = fs::read_to_string(&path)
.with_context(|| format!("Could not read {}", path.display()))?;

let mut chips = Vec::new();
let mut features = Vec::new();
Expand Down Expand Up @@ -184,7 +185,7 @@ pub fn load_examples(path: &Path) -> Result<Vec<Metadata>> {
} else if key == "FEATURES" {
features = split.into();
} else {
log::warn!("Unregognized metadata key '{key}', ignoring");
log::warn!("Unrecognized metadata key '{key}', ignoring");
}
}

Expand Down Expand Up @@ -240,8 +241,6 @@ pub fn execute_app(
.features(&features)
.arg(bin);

// probe-rs cannot currently do auto detection, so we need to tell probe-rs run
// which chip we are testing
if subcommand == "test" && chip == Chip::Esp32c2 {
builder = builder.arg("--").arg("--speed").arg("15000");
}
Expand Down Expand Up @@ -311,7 +310,8 @@ pub fn build_package(
/// Bump the version of the specified package by the specified amount.
pub fn bump_version(workspace: &Path, package: Package, amount: Version) -> Result<()> {
let manifest_path = workspace.join(package.to_string()).join("Cargo.toml");
let manifest = fs::read_to_string(&manifest_path)?;
let manifest = fs::read_to_string(&manifest_path)
.with_context(|| format!("Could not read {}", manifest_path.display()))?;

let mut manifest = manifest.parse::<toml_edit::DocumentMut>()?;

Expand Down Expand Up @@ -530,7 +530,10 @@ pub fn package_version(workspace: &Path, package: Package) -> Result<semver::Ver
version: semver::Version,
}

let manifest = fs::read_to_string(workspace.join(package.to_string()).join("Cargo.toml"))?;
let path = workspace.join(package.to_string()).join("Cargo.toml");
let path = windows_safe_path(&path);
let manifest =
fs::read_to_string(&path).with_context(|| format!("Could not read {}", path.display()))?;
let manifest: Manifest = basic_toml::from_str(&manifest)?;

Ok(manifest.package.version)
Expand Down
32 changes: 14 additions & 18 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
process::Command,
};

use anyhow::{bail, Result};
use anyhow::{bail, Context as _, Result};
use clap::{Args, Parser};
use esp_metadata::{Arch, Chip, Config};
use minijinja::Value;
Expand Down Expand Up @@ -153,8 +153,7 @@ fn main() -> Result<()> {
.filter_module("xtask", log::LevelFilter::Info)
.init();

let workspace = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let workspace = workspace.parent().unwrap().canonicalize()?;
let workspace = std::env::current_dir()?;

match Cli::parse() {
Cli::BuildDocumentation(args) => build_documentation(&workspace, args),
Expand Down Expand Up @@ -676,24 +675,21 @@ fn run_elfs(args: RunElfArgs) -> Result<()> {

log::info!("Running test '{}' for '{}'", elf_name, args.chip);

let command = if args.chip == Chip::Esp32c2 {
Command::new("probe-rs")
.arg("run")
.arg("--speed")
.arg("15000")
.arg(elf_path)
.output()?
} else {
Command::new("probe-rs").arg("run").arg(elf_path).output()?
let mut command = Command::new("probe-rs");
command.arg("run").arg(elf_path);

if args.chip == Chip::Esp32c2 {
command.arg("--speed").arg("15000");
};

println!(
"{}\n{}",
String::from_utf8_lossy(&command.stderr),
String::from_utf8_lossy(&command.stdout)
);
let mut command = command.spawn().context("Failed to execute probe-rs")?;
let status = command
.wait()
.context("Error while waiting for probe-rs to exit")?;

log::info!("'{elf_name}' done");

if !command.status.success() {
if !status.success() {
failed.push(elf_name);
}
}
Expand Down

0 comments on commit 9e87792

Please sign in to comment.