Skip to content

Commit

Permalink
ci: Adapt HIL tests to use RPi (#1493)
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez authored Apr 22, 2024
1 parent 3dfea21 commit 20c7789
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 16 deletions.
81 changes: 66 additions & 15 deletions .github/workflows/hil.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,23 @@ env:
CARGO_TERM_COLOR: always

jobs:
hil:
name: HIL Test | ${{ matrix.target.soc }}
runs-on:
labels: [self-hosted, "${{ matrix.target.runner }}"]
build-tests:
name: Build Tests | ${{ matrix.target.soc }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
target:
# RISC-V devices:
- soc: esp32c3
runner: rustboard
rust-target: riscv32imc-unknown-none-elf
# - soc: esp32c3
# 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
# Xtensa devices:
- soc: esp32s3
runner: esp32s3-usb
# - soc: esp32h2
# rust-target: riscv32imac-unknown-none-elf
# # Xtensa devices:
# - soc: esp32s3
steps:
- uses: actions/checkout@v4
if: github.event_name != 'workflow_dispatch'
Expand All @@ -64,4 +60,59 @@ jobs:
ldproxy: false

- name: Run tests
run: cargo xtask run-tests ${{ matrix.target.soc }}
run: cargo xtask build-tests ${{ matrix.target.soc }}

- name: Prepare artifact
run: |
# Create the 'tests' directory if it doesn't exist
mkdir -p tests
# Find ELF files in the specified path and move them to 'tests'
find "hil-test/target/${{ matrix.target.rust-target }}/release/deps/" -type f -exec file {} + | \
grep ELF | \
awk -F: '{print $1}' | \
xargs -I {} mv {} tests
# Rename files in 'tests' by removing everything after the first dash
for file in tests/*-*; do
base_name="$(basename "$file" | cut -d'-' -f1)"
mv "$file" "tests/$base_name"
done
- uses: actions/upload-artifact@v4
with:
name: tests-${{ matrix.target.soc }}
path: /home/runner/work/esp-hal/esp-hal/tests
if-no-files-found: error

hil:
name: HIL Test | ${{ matrix.target.soc }}
needs: build-tests
runs-on:
labels: [self-hosted, "${{ matrix.target.runner }}"]
strategy:
fail-fast: false
matrix:
target:
# RISC-V devices:
# - soc: esp32c3
# runner: rustboard
- soc: esp32c6
runner: esp32c6-usb
# - soc: esp32h2
# runner: esp32h2-usb
# # Xtensa devices:
# - soc: esp32s3
# runner: esp32s3-usb
steps:
- uses: actions/download-artifact@v4
with:
name: tests-${{ matrix.target.soc }}
path: tests
- name: Run tests
run: |
export PATH=$PATH:/home/espressif/.cargo/bin
for file in "tests"/*; do
probe-rs run --chip ${{ matrix.target.soc }} "$file"
done
2 changes: 1 addition & 1 deletion hil-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Our Virtual Machines have the following 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: Ubuntu 20.04.5 configured with the following [setup](#vm-setup)
- RPi: Raspbian 12 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.
Expand Down
44 changes: 44 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ enum Cli {
BuildExamples(BuildExamplesArgs),
/// Build the specified package with the given options.
BuildPackage(BuildPackageArgs),
/// Build all applicable tests or the specified test for a specified chip.
BuildTests(RunTestsArgs),
/// Bump the version of the specified package(s).
BumpVersion(BumpVersionArgs),
/// Generate the eFuse fields source file from a CSV.
Expand Down Expand Up @@ -127,6 +129,7 @@ fn main() -> Result<()> {
Cli::BuildDocumentation(args) => build_documentation(&workspace, args),
Cli::BuildExamples(args) => build_examples(&workspace, args),
Cli::BuildPackage(args) => build_package(&workspace, args),
Cli::BuildTests(args) => build_tests(&workspace, args),
Cli::BumpVersion(args) => bump_version(&workspace, args),
Cli::GenerateEfuseFields(args) => generate_efuse_src(&workspace, args),
Cli::RunExample(args) => run_example(&workspace, args),
Expand Down Expand Up @@ -334,6 +337,47 @@ fn run_example(workspace: &Path, mut args: RunExampleArgs) -> Result<()> {
Ok(())
}

fn build_tests(workspace: &Path, args: RunTestsArgs) -> Result<(), anyhow::Error> {
// Absolute path of the package's root:
let package_path = xtask::windows_safe_path(&workspace.join("hil-test"));

// Determine the appropriate build target for the given package and chip:
let target = target_triple(&Package::HilTest, &args.chip)?;

// Load all examples and parse their metadata:
let tests = xtask::load_examples(&package_path.join("tests"))?;
let mut supported_tests = tests
.iter()
// Filter down the examples to only those for which the specified chip is supported:
.filter(|example| example.supports_chip(args.chip));
if let Some(test_name) = &args.test {
let test = supported_tests.find_map(|example| {
if &example.name() == test_name {
Some(example.clone())
} else {
None
}
});
if let Some(test) = test {
xtask::build_example(&package_path, args.chip, target, &test)?;
} else {
log::error!("Test not found or unsupported for the given chip");
}
} else {
let mut failed_tests: Vec<String> = Vec::new();
for test in supported_tests {
if xtask::build_example(&package_path, args.chip, target, test).is_err() {
failed_tests.push(test.name());
}
}
if !failed_tests.is_empty() {
bail!("Failed tests: {:?}", failed_tests);
}
}

Ok(())
}

fn run_tests(workspace: &Path, args: RunTestsArgs) -> Result<(), anyhow::Error> {
// Absolute path of the package's root:
let package_path = xtask::windows_safe_path(&workspace.join("hil-test"));
Expand Down

0 comments on commit 20c7789

Please sign in to comment.