mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-03 07:05:19 +00:00
HIL xtask support (#1404)
* allow running tests via xtask * Add run-tests xtask subcommand * Use xtask in HIL ci
This commit is contained in:
parent
fd9f7895f6
commit
315b8cc0ff
3
.github/workflows/hil.yml
vendored
3
.github/workflows/hil.yml
vendored
@ -52,8 +52,7 @@ jobs:
|
|||||||
components: rust-src
|
components: rust-src
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
working-directory: hil-test
|
run: cargo xtask run-tests ${{ matrix.target.soc }}
|
||||||
run: cargo ${{ matrix.target.soc }}
|
|
||||||
|
|
||||||
# Test Xtensa targets:
|
# Test Xtensa targets:
|
||||||
# TODO: Add jobs for Xtensa once supported by `probe-rs`
|
# TODO: Add jobs for Xtensa once supported by `probe-rs`
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
//! AES Test
|
//! AES Test
|
||||||
|
|
||||||
|
//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
|
||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![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]
|
#[embedded_test::tests]
|
||||||
mod tests {
|
mod tests {
|
||||||
use defmt::assert_eq;
|
use defmt::assert_eq;
|
||||||
|
@ -296,27 +296,33 @@ pub fn run_example(
|
|||||||
log::info!(" Features: {}", example.features().join(","));
|
log::info!(" Features: {}", example.features().join(","));
|
||||||
}
|
}
|
||||||
|
|
||||||
let bin = if example
|
let package = example.example_path().strip_prefix(package_path)?;
|
||||||
.example_path()
|
log::info!("Package: {:?}", package);
|
||||||
.strip_prefix(package_path)?
|
let (bin, subcommand) = if package.starts_with("src/bin") {
|
||||||
.starts_with("src/bin")
|
(format!("--bin={}", example.name()), "run")
|
||||||
{
|
} else if package.starts_with("tests") {
|
||||||
format!("--bin={}", example.name())
|
(format!("--test={}", example.name()), "test")
|
||||||
} else {
|
} else {
|
||||||
format!("--example={}", example.name())
|
(format!("--example={}", example.name()), "run")
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut features = example.features().to_vec();
|
let mut features = example.features().to_vec();
|
||||||
features.push(chip.to_string());
|
features.push(chip.to_string());
|
||||||
|
|
||||||
let mut builder = CargoArgsBuilder::default()
|
let mut builder = CargoArgsBuilder::default()
|
||||||
.subcommand("run")
|
.subcommand(subcommand)
|
||||||
.arg("-Zbuild-std=alloc,core")
|
.arg("-Zbuild-std=alloc,core")
|
||||||
.arg("--release")
|
.arg("--release")
|
||||||
.target(target)
|
.target(target)
|
||||||
.features(&features)
|
.features(&features)
|
||||||
.arg(bin);
|
.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 targeting an Xtensa device, we must use the '+esp' toolchain modifier:
|
||||||
if target.starts_with("xtensa") {
|
if target.starts_with("xtensa") {
|
||||||
builder = builder.toolchain("esp");
|
builder = builder.toolchain("esp");
|
||||||
|
@ -25,6 +25,8 @@ enum Cli {
|
|||||||
GenerateEfuseFields(GenerateEfuseFieldsArgs),
|
GenerateEfuseFields(GenerateEfuseFieldsArgs),
|
||||||
/// Run the given example for the specified chip.
|
/// Run the given example for the specified chip.
|
||||||
RunExample(RunExampleArgs),
|
RunExample(RunExampleArgs),
|
||||||
|
/// Run all applicable tests for a specified chip.
|
||||||
|
RunTests(RunTestsArgs),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Args)]
|
#[derive(Debug, Args)]
|
||||||
@ -100,6 +102,13 @@ struct RunExampleArgs {
|
|||||||
example: String,
|
example: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Args)]
|
||||||
|
struct RunTestsArgs {
|
||||||
|
/// Which chip to run the examples for.
|
||||||
|
#[arg(value_enum)]
|
||||||
|
chip: Chip,
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Application
|
// Application
|
||||||
|
|
||||||
@ -118,6 +127,7 @@ fn main() -> Result<()> {
|
|||||||
Cli::BumpVersion(args) => bump_version(&workspace, args),
|
Cli::BumpVersion(args) => bump_version(&workspace, args),
|
||||||
Cli::GenerateEfuseFields(args) => generate_efuse_src(&workspace, args),
|
Cli::GenerateEfuseFields(args) => generate_efuse_src(&workspace, args),
|
||||||
Cli::RunExample(args) => run_example(&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:
|
// Absolute path of the package's root:
|
||||||
let package_path = xtask::windows_safe_path(&workspace.join(args.package.to_string()));
|
let package_path = xtask::windows_safe_path(&workspace.join(args.package.to_string()));
|
||||||
|
|
||||||
// Absolute path to the directory containing the examples:
|
let example_path = match args.package {
|
||||||
let example_path = if args.package == Package::Examples {
|
Package::Examples => package_path.join("src").join("bin"),
|
||||||
package_path.join("src").join("bin")
|
Package::HilTest => package_path.join("tests"),
|
||||||
} else {
|
_ => package_path.join("examples"),
|
||||||
package_path.join("examples")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Determine the appropriate build target for the given package and chip:
|
// 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(())
|
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
|
// Helper Functions
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user