diff --git a/.github/workflows/hil.yml b/.github/workflows/hil.yml index 01e7ab8ca..ae3f858ef 100644 --- a/.github/workflows/hil.yml +++ b/.github/workflows/hil.yml @@ -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' @@ -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 + diff --git a/hil-test/README.md b/hil-test/README.md index 994c04308..38dadd265 100644 --- a/hil-test/README.md +++ b/hil-test/README.md @@ -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. diff --git a/xtask/src/main.rs b/xtask/src/main.rs index d9413149b..f97bc9cd6 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -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. @@ -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), @@ -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 = 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"));