diff --git a/hil-test/.cargo/config.toml b/hil-test/.cargo/config.toml index e26588c0f40..b4e91a4d0dd 100644 --- a/hil-test/.cargo/config.toml +++ b/hil-test/.cargo/config.toml @@ -1,18 +1,22 @@ [env] -DEFMT_LOG="debug" +DEFMT_LOG="info" +RUST_LOG = "warn" [target.'cfg(target_arch = "riscv32")'] -runner = "probe-rs test --" +runner = "probe-rs run" rustflags = [ "-C", "link-arg=-Tlinkall.x", - "-C", "link-arg=-Tdefmt.x", + "-C", "link-arg=-Tembedded-test.x", + "-C", "link-arg=-Tdefmt.x", # Comment this line when using log feature ] [target.'cfg(target_arch = "xtensa")'] # TODO: Xtensa not yet fully supported by `probe-rs` -runner = "probe-rs test --" +runner = "probe-rs run" rustflags = [ "-C", "link-arg=-nostartfiles", "-C", "link-arg=-Wl,-Tlinkall.x", "-C", "link-arg=-Tdefmt.x", + "-C", "link-arg=-Tembedded-test.x", + ] diff --git a/hil-test/Cargo.toml b/hil-test/Cargo.toml index 9bd3dc0f099..82760b94007 100644 --- a/hil-test/Cargo.toml +++ b/hil-test/Cargo.toml @@ -4,10 +4,6 @@ version = "0.0.0" edition = "2021" publish = false -[lib] -harness = false -test = false - [[test]] name = "aes" harness = false @@ -24,23 +20,22 @@ harness = false name = "uart" harness = false - [dependencies] -defmt = "0.3.5" -defmt-rtt = "0.4.0" -embedded-test = "0.3.0" -panic-probe = "0.3.1" -semihosting = "0.1.6" - -# HAL package: -esp-hal = { path = "../esp-hal", features = ["defmt", "eh1"], optional = true } - -# Traits: +defmt = { version = "0.3.5", optional = true } +defmt-rtt = { version = "0.4.0", optional = true } +log = { version = "0.4.20", optional = true } +esp-hal = { path = "../esp-hal", features = ["eh1"], optional = true } embedded-hal = { version = "0.2.7", features = ["unproven"] } embedded-hal-async = { version = "1.0.0", optional = true } embedded-hal-1 = { version = "1.0.0", package = "embedded-hal" } +embassy-executor = { default-features = false, version = "0.5.0", features = ["executor-thread", "arch-riscv32"], optional = true } + +[dev-dependencies] +embedded-test = {git = "https://github.com/probe-rs/embedded-test/", branch = "next"} [features] +default = ["defmt"] +# Device support (required!): esp32 = ["esp-hal/esp32"] esp32c2 = ["esp-hal/esp32c2"] esp32c3 = ["esp-hal/esp32c3"] @@ -48,18 +43,21 @@ esp32c6 = ["esp-hal/esp32c6"] esp32h2 = ["esp-hal/esp32h2"] esp32s2 = ["esp-hal/esp32s2"] esp32s3 = ["esp-hal/esp32s3"] - # Async & Embassy: async = ["dep:embedded-hal-async", "esp-hal?/async"] - -embassy = ["esp-hal?/embassy"] - +embassy = ["esp-hal?/embassy", "embedded-test/embassy", "dep:embassy-executor"] embassy-executor-interrupt = ["esp-hal?/embassy-executor-interrupt"] embassy-executor-thread = ["esp-hal?/embassy-executor-thread"] - embassy-time-systick-16mhz = ["esp-hal?/embassy-time-systick-16mhz"] embassy-time-systick-80mhz = ["esp-hal?/embassy-time-systick-80mhz"] embassy-time-timg0 = ["esp-hal?/embassy-time-timg0"] +# Loggging: +# Adding log feature of embedded test to defmt or log makes the testing more verbose +# log = ["dep:log", "embedded-test/log", "embedded-test/init-log"] +# defmt = ["dep:defmt", "dep:defmt-rtt", "embedded-test/defmt"] +log = ["dep:log", "embedded-test/init-log", "esp-hal?/log"] +# Using defmt crate requires editting `.cargo/config.toml`rustflags. +defmt = ["dep:defmt", "dep:defmt-rtt", "esp-hal?/defmt"] # cargo build/run [profile.dev] @@ -98,9 +96,3 @@ incremental = false lto = 'fat' opt-level = 3 # <- overflow-checks = false # <- - -# TODO: remove when able -[patch.crates-io] -# FIXME: defmt patch can be removed since embedded-test already takes care of that? -defmt = { git = "https://github.com/t-moe/defmt", branch = "features/defmt_test_riscv" } -panic-probe = { git = "https://github.com/t-moe/defmt", branch = "features/defmt_test_riscv" } diff --git a/hil-test/README.md b/hil-test/README.md index 059e74d2cfc..830bf65f9d7 100644 --- a/hil-test/README.md +++ b/hil-test/README.md @@ -59,6 +59,23 @@ The `hil.yml` workflow will build the test suite for all our available targets a Currently, here are the Virtual Machines set up for HIL testing: - ESP32-C3: - Has an `ESP32-C3-DevKit-RUST-1` connected via USB-JTAG-SERIAL. + - Pins 2 and 4 are connected for `spi_full_duplex` and `uart` tests. + - VM has the following setup: + ``` + # Install Rust: + $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain stable -y --profile minimal + # Source the current shell: + $ source "$HOME/.cargo/env" + # Install dependencies + $ sudo apt install -y pkg-config libudev-dev + # Install probe-rs + $ cargo install probe-rs --git=https://github.com/probe-rs/probe-rs --branch=feature/testing-rebased --features=cli --bin=probe-rs --locked --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 + $ sudo usermod -a -G plugdev $USER + # Reboot the VM + ``` - ESP32-C6: - Has an `ESP32-C6-DevKitC-1 V1.2` connected via USB-JTAG-SERIAL. - Pins 2 and 4 are connected for `spi_full_duplex` and `uart` tests. @@ -71,7 +88,7 @@ Currently, here are the Virtual Machines set up for HIL testing: # Install dependencies $ sudo apt install -y pkg-config libudev-dev # Install probe-rs - $ cargo install probe-rs --git=https://github.com/SergioGasquez/probe-rs --branch=feature/testing --features=cli --bin=probe-rs --locked --force + $ cargo install probe-rs --git=https://github.com/probe-rs/probe-rs --branch=feature/testing-rebased --features=cli --bin=probe-rs --locked --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 @@ -90,7 +107,7 @@ Currently, here are the Virtual Machines set up for HIL testing: # Install dependencies $ sudo apt install -y pkg-config libudev-dev # Install probe-rs - $ cargo install probe-rs --git=https://github.com/SergioGasquez/probe-rs --branch=feature/testing --features=cli --bin=probe-rs --locked --force + $ cargo install probe-rs --git=https://github.com/probe-rs/probe-rs --branch=feature/testing-rebased --features=cli --bin=probe-rs --locked --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 diff --git a/hil-test/src/lib.rs b/hil-test/src/lib.rs deleted file mode 100644 index 387b9783564..00000000000 --- a/hil-test/src/lib.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![no_std] - -use defmt_rtt as _; -use panic_probe as _; - -pub use esp_hal; diff --git a/hil-test/tests/aes.rs b/hil-test/tests/aes.rs index ab840f846d3..4aecf5e1601 100644 --- a/hil-test/tests/aes.rs +++ b/hil-test/tests/aes.rs @@ -3,7 +3,9 @@ #![no_std] #![no_main] -use hil_test::esp_hal::{ +#[cfg(feature = "defmt")] +use defmt_rtt as _; +use esp_hal::{ aes::{Aes, Mode}, peripherals::Peripherals, }; @@ -21,8 +23,10 @@ impl Context<'_> { } } +#[cfg(test)] #[embedded_test::tests] mod tests { + #[cfg(feature = "defmt")] use defmt::assert_eq; use super::*; diff --git a/hil-test/tests/gpio.rs b/hil-test/tests/gpio.rs index e4a6665fe21..18ecdf6fad7 100644 --- a/hil-test/tests/gpio.rs +++ b/hil-test/tests/gpio.rs @@ -7,8 +7,10 @@ #![no_std] #![no_main] +#[cfg(feature = "defmt")] +use defmt_rtt as _; use embedded_hal_1::digital::{InputPin as _, OutputPin as _, StatefulOutputPin as _}; -use hil_test::esp_hal::{ +use esp_hal::{ gpio::{GpioPin, Input, Output, PullDown, PushPull, IO}, peripherals::Peripherals, }; @@ -30,9 +32,11 @@ impl Context { } } +#[cfg(test)] #[embedded_test::tests] mod tests { - use defmt::{assert_eq, unwrap}; + #[cfg(feature = "defmt")] + use defmt::assert_eq; use super::*; @@ -53,18 +57,18 @@ mod tests { // `StatefulOutputPin`: assert_eq!(ctx.io1.is_set_low(), Ok(true)); assert_eq!(ctx.io1.is_set_high(), Ok(false)); - unwrap!(ctx.io1.set_high()); + assert!(ctx.io1.set_high().is_ok()); assert_eq!(ctx.io1.is_set_low(), Ok(false)); assert_eq!(ctx.io1.is_set_high(), Ok(true)); // `ToggleableOutputPin`: - unwrap!(ctx.io1.toggle()); + assert!(ctx.io1.toggle().is_ok()); assert_eq!(ctx.io1.is_set_low(), Ok(true)); assert_eq!(ctx.io1.is_set_high(), Ok(false)); - unwrap!(ctx.io1.toggle()); + assert!(ctx.io1.toggle().is_ok()); assert_eq!(ctx.io1.is_set_low(), Ok(false)); assert_eq!(ctx.io1.is_set_high(), Ok(true)); // Leave in initial state for next test - unwrap!(ctx.io1.toggle()); + assert!(ctx.io1.toggle().is_ok()); } } diff --git a/hil-test/tests/spi_full_duplex.rs b/hil-test/tests/spi_full_duplex.rs index f936f43a943..88a56bf52e4 100644 --- a/hil-test/tests/spi_full_duplex.rs +++ b/hil-test/tests/spi_full_duplex.rs @@ -11,7 +11,9 @@ #![no_std] #![no_main] -use hil_test::esp_hal::{ +#[cfg(feature = "defmt")] +use defmt_rtt as _; +use esp_hal::{ clock::ClockControl, gpio::IO, peripherals::Peripherals, @@ -46,8 +48,10 @@ impl Context { } } +#[cfg(test)] #[embedded_test::tests] mod tests { + #[cfg(feature = "defmt")] use defmt::assert_eq; use super::*; diff --git a/hil-test/tests/uart.rs b/hil-test/tests/uart.rs index c350416ab8d..9c7a419ce54 100644 --- a/hil-test/tests/uart.rs +++ b/hil-test/tests/uart.rs @@ -9,7 +9,9 @@ #![no_std] #![no_main] -use hil_test::esp_hal::{ +#[cfg(feature = "defmt")] +use defmt_rtt as _; +use esp_hal::{ clock::ClockControl, peripherals::{Peripherals, UART0}, prelude::*, @@ -48,8 +50,10 @@ impl Context { } } +#[cfg(test)] #[embedded_test::tests] mod tests { + #[cfg(feature = "defmt")] use defmt::assert_eq; use super::*;