diff --git a/.github/workflows/hil.yml b/.github/workflows/hil.yml index 79bbe6f44..c4665f313 100644 --- a/.github/workflows/hil.yml +++ b/.github/workflows/hil.yml @@ -52,8 +52,7 @@ jobs: components: rust-src - name: Run tests - working-directory: hil-test - run: cargo ${{ matrix.target.soc }} + run: cargo xtask run-tests ${{ matrix.target.soc }} # Test Xtensa targets: # TODO: Add jobs for Xtensa once supported by `probe-rs` diff --git a/hil-test/tests/aes.rs b/hil-test/tests/aes.rs index 8cb6735a6..139772dbb 100644 --- a/hil-test/tests/aes.rs +++ b/hil-test/tests/aes.rs @@ -1,5 +1,7 @@ //! AES Test +//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] @@ -23,30 +25,6 @@ impl Context<'_> { } } -#[cfg(not(any( - feature = "esp32c3", - feature = "esp32c6", - feature = "esp32h2", - feature = "esp32s3" -)))] -mod not_test { - #[esp_hal::entry] - fn main() -> ! { - semihosting::process::exit(0) - } - #[panic_handler] - fn panic(_info: &core::panic::PanicInfo) -> ! { - loop {} - } -} - -#[cfg(test)] -#[cfg(any( - feature = "esp32c3", - feature = "esp32c6", - feature = "esp32h2", - feature = "esp32s3" -))] #[embedded_test::tests] mod tests { use defmt::assert_eq; diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 3e3448ff9..58bb02374 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -296,27 +296,33 @@ pub fn run_example( log::info!(" Features: {}", example.features().join(",")); } - let bin = if example - .example_path() - .strip_prefix(package_path)? - .starts_with("src/bin") - { - format!("--bin={}", example.name()) + let package = example.example_path().strip_prefix(package_path)?; + log::info!("Package: {:?}", package); + let (bin, subcommand) = if package.starts_with("src/bin") { + (format!("--bin={}", example.name()), "run") + } else if package.starts_with("tests") { + (format!("--test={}", example.name()), "test") } else { - format!("--example={}", example.name()) + (format!("--example={}", example.name()), "run") }; let mut features = example.features().to_vec(); features.push(chip.to_string()); let mut builder = CargoArgsBuilder::default() - .subcommand("run") + .subcommand(subcommand) .arg("-Zbuild-std=alloc,core") .arg("--release") .target(target) .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" { + builder = builder.arg("--").arg("--chip").arg(format!("{}", chip)); + } + // If targeting an Xtensa device, we must use the '+esp' toolchain modifier: if target.starts_with("xtensa") { builder = builder.toolchain("esp"); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 7007eb9db..5d5d864a9 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -25,6 +25,8 @@ enum Cli { GenerateEfuseFields(GenerateEfuseFieldsArgs), /// Run the given example for the specified chip. RunExample(RunExampleArgs), + /// Run all applicable tests for a specified chip. + RunTests(RunTestsArgs), } #[derive(Debug, Args)] @@ -100,6 +102,13 @@ struct RunExampleArgs { example: String, } +#[derive(Debug, Args)] +struct RunTestsArgs { + /// Which chip to run the examples for. + #[arg(value_enum)] + chip: Chip, +} + // ---------------------------------------------------------------------------- // Application @@ -118,6 +127,7 @@ fn main() -> Result<()> { Cli::BumpVersion(args) => bump_version(&workspace, args), Cli::GenerateEfuseFields(args) => generate_efuse_src(&workspace, args), Cli::RunExample(args) => run_example(&workspace, args), + Cli::RunTests(args) => run_tests(&workspace, args), } } @@ -293,11 +303,10 @@ fn run_example(workspace: &Path, mut args: RunExampleArgs) -> Result<()> { // Absolute path of the package's root: let package_path = xtask::windows_safe_path(&workspace.join(args.package.to_string())); - // Absolute path to the directory containing the examples: - let example_path = if args.package == Package::Examples { - package_path.join("src").join("bin") - } else { - package_path.join("examples") + let example_path = match args.package { + Package::Examples => package_path.join("src").join("bin"), + Package::HilTest => package_path.join("tests"), + _ => package_path.join("examples"), }; // Determine the appropriate build target for the given package and chip: @@ -325,6 +334,26 @@ fn run_example(workspace: &Path, mut args: RunExampleArgs) -> Result<()> { Ok(()) } +fn run_tests(workspace: &PathBuf, 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 tests = tests.iter() + // Filter down the examples to only those for which the specified chip is supported: + .filter(|example| example.supports_chip(args.chip)); + + for test in tests { + xtask::run_example(&package_path, args.chip, target, &test)?; + } + + Ok(()) +} + // ---------------------------------------------------------------------------- // Helper Functions