Skip to content

Commit

Permalink
Test all feature sets (#2901)
Browse files Browse the repository at this point in the history
* Mark interconnect as unstable

* Explicitly set unstable feature in HIL tests

* WIP append feature set name to artifact

* Add name to feature sets, build all combinations

* Fix tests

* Provide a looping executor for stable async tests

* Fix usb serial jtag

* Hide interconnect types
  • Loading branch information
bugadani authored Jan 9, 2025
1 parent 2b80e4d commit 848029b
Show file tree
Hide file tree
Showing 54 changed files with 306 additions and 190 deletions.
18 changes: 1 addition & 17 deletions .github/workflows/hil.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,10 @@ jobs:
- name: Build tests
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
path: /home/runner/work/esp-hal/esp-hal/target/tests/${{ matrix.target.soc }}
if-no-files-found: error
overwrite: true

Expand Down
4 changes: 4 additions & 0 deletions esp-hal/src/gpio/interconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ fn disconnect_peripheral_output_from_pin(pin: &mut AnyPin, signal: gpio::OutputS
/// A configurable input signal between a peripheral and a GPIO pin.
///
/// Multiple input signals can be connected to one pin.
#[instability::unstable]
pub struct InputSignal {
pin: AnyPin,
is_inverted: bool,
Expand Down Expand Up @@ -347,6 +348,7 @@ impl DirectInputSignal {
/// A configurable output signal between a peripheral and a GPIO pin.
///
/// Multiple pins can be connected to one output signal.
#[instability::unstable]
pub struct OutputSignal {
pin: AnyPin,
is_inverted: bool,
Expand Down Expand Up @@ -506,6 +508,7 @@ enum InputConnectionInner {
/// This is mainly intended for internal use, but it can be used to connect
/// peripherals within the MCU without external hardware.
#[derive(Clone)]
#[doc(hidden)] // FIXME: replace with `#[unstable]` when we can mark delegated methods https://github.com/Kobzol/rust-delegate/issues/77
pub struct InputConnection(InputConnectionInner);

impl Peripheral for InputConnection {
Expand Down Expand Up @@ -614,6 +617,7 @@ enum OutputConnectionInner {
///
/// This is mainly intended for internal use, but it can be used to connect
/// peripherals within the MCU without external hardware.
#[doc(hidden)] // FIXME: replace with `#[unstable]` when we can mark delegated methods https://github.com/Kobzol/rust-delegate/issues/77
pub struct OutputConnection(OutputConnectionInner);

impl Sealed for OutputConnection {}
Expand Down
31 changes: 23 additions & 8 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,20 @@ use crate::{
private::{self, Sealed},
};

pub mod interconnect;
mod placeholder;

pub use placeholder::NoPin;

#[cfg(soc_etm)]
crate::unstable_module! {
pub mod interconnect;

#[cfg(soc_etm)]
pub mod etm;
}

#[cfg(lp_io)]
crate::unstable_module! {
#[cfg(lp_io)]
pub mod lp_io;
}

#[cfg(all(rtc_io, not(esp32)))]
crate::unstable_module! {
#[cfg(all(rtc_io, not(esp32)))]
pub mod rtc_io;
}

Expand Down Expand Up @@ -820,6 +817,7 @@ where
///
/// Peripheral signals allow connecting peripherals together without using
/// external hardware.
#[instability::unstable]
pub fn split(self) -> (interconnect::InputSignal, interconnect::OutputSignal) {
(
interconnect::InputSignal::new(self.degrade_pin(private::Internal)),
Expand Down Expand Up @@ -1296,6 +1294,8 @@ impl<'d> Output<'d> {
///
/// Peripheral signals allow connecting peripherals together without using
/// external hardware.
#[inline]
#[instability::unstable]
pub fn split(self) -> (interconnect::InputSignal, interconnect::OutputSignal) {
self.pin.split()
}
Expand All @@ -1305,6 +1305,7 @@ impl<'d> Output<'d> {
///
/// The input signal can be passed to peripherals in place of an input pin.
#[inline]
#[instability::unstable]
pub fn peripheral_input(&self) -> interconnect::InputSignal {
self.pin.peripheral_input()
}
Expand All @@ -1315,6 +1316,7 @@ impl<'d> Output<'d> {
/// The output signal can be passed to peripherals in place of an output
/// pin.
#[inline]
#[instability::unstable]
pub fn into_peripheral_output(self) -> interconnect::OutputSignal {
self.pin.into_peripheral_output()
}
Expand Down Expand Up @@ -1439,6 +1441,7 @@ impl<'d> Input<'d> {
///
/// The input signal can be passed to peripherals in place of an input pin.
#[inline]
#[instability::unstable]
pub fn peripheral_input(&self) -> interconnect::InputSignal {
self.pin.peripheral_input()
}
Expand Down Expand Up @@ -1565,6 +1568,8 @@ impl<'d> Input<'d> {
///
/// Peripheral signals allow connecting peripherals together without using
/// external hardware.
#[inline]
#[instability::unstable]
pub fn split(self) -> (interconnect::InputSignal, interconnect::OutputSignal) {
self.pin.split()
}
Expand All @@ -1575,6 +1580,7 @@ impl<'d> Input<'d> {
/// The output signal can be passed to peripherals in place of an output
/// pin.
#[inline]
#[instability::unstable]
pub fn into_peripheral_output(self) -> interconnect::OutputSignal {
self.pin.into_peripheral_output()
}
Expand Down Expand Up @@ -1654,6 +1660,8 @@ impl<'d> OutputOpenDrain<'d> {
///
/// Peripheral signals allow connecting peripherals together without using
/// external hardware.
#[inline]
#[instability::unstable]
pub fn split(self) -> (interconnect::InputSignal, interconnect::OutputSignal) {
self.pin.split()
}
Expand All @@ -1663,6 +1671,7 @@ impl<'d> OutputOpenDrain<'d> {
///
/// The input signal can be passed to peripherals in place of an input pin.
#[inline]
#[instability::unstable]
pub fn peripheral_input(&self) -> interconnect::InputSignal {
self.pin.peripheral_input()
}
Expand All @@ -1673,6 +1682,7 @@ impl<'d> OutputOpenDrain<'d> {
/// The output signal can be passed to peripherals in place of an output
/// pin.
#[inline]
#[instability::unstable]
pub fn into_peripheral_output(self) -> interconnect::OutputSignal {
self.pin.into_peripheral_output()
}
Expand Down Expand Up @@ -1797,6 +1807,7 @@ impl<'d> Flex<'d> {
///
/// The input signal can be passed to peripherals in place of an input pin.
#[inline]
#[instability::unstable]
pub fn peripheral_input(&self) -> interconnect::InputSignal {
self.pin.degrade_pin(private::Internal).split().0
}
Expand Down Expand Up @@ -1963,6 +1974,8 @@ impl<'d> Flex<'d> {
///
/// Peripheral signals allow connecting peripherals together without using
/// external hardware.
#[inline]
#[instability::unstable]
pub fn split(self) -> (interconnect::InputSignal, interconnect::OutputSignal) {
assert!(self.pin.is_output());
self.pin.degrade_pin(private::Internal).split()
Expand All @@ -1974,6 +1987,7 @@ impl<'d> Flex<'d> {
/// The output signal can be passed to peripherals in place of an output
/// pin.
#[inline]
#[instability::unstable]
pub fn into_peripheral_output(self) -> interconnect::OutputSignal {
self.split().1
}
Expand Down Expand Up @@ -2028,6 +2042,7 @@ pub(crate) mod internal {
/// using external hardware.
#[inline]
#[allow(unused_braces, reason = "False positive")]
#[instability::unstable]
pub fn split(self) -> (interconnect::InputSignal, interconnect::OutputSignal) {
handle_gpio_input!(self, target, { target.split() })
}
Expand Down
12 changes: 7 additions & 5 deletions hil-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ cfg-if = "1.0.0"
critical-section = "1.1.3"
defmt = "0.3.8"
defmt-rtt = { version = "0.4.1", optional = true }
embassy-executor = "0.6.0"
embassy-futures = "0.1.1"
embassy-sync = "0.6.0"
embassy-time = "0.3.2"
Expand All @@ -206,7 +207,7 @@ embedded-hal-async = "1.0.0"
embedded-hal-nb = "1.0.0"
esp-alloc = { path = "../esp-alloc", optional = true }
esp-backtrace = { path = "../esp-backtrace", default-features = false, features = ["exception-handler", "defmt", "semihosting"] }
esp-hal = { path = "../esp-hal", features = ["digest", "unstable"], optional = true }
esp-hal = { path = "../esp-hal", features = ["digest"], optional = true }
esp-hal-embassy = { path = "../esp-hal-embassy", optional = true }
esp-wifi = { path = "../esp-wifi", optional = true, features = ["wifi"] }
portable-atomic = "1.9.0"
Expand All @@ -220,7 +221,7 @@ digest = { version = "0.10.7", default-features = false }
elliptic-curve = { version = "0.13.8", default-features = false, features = ["sec1"] }
embassy-executor = { version = "0.6.0", default-features = false }
# Add the `embedded-test/defmt` feature for more verbose testing
embedded-test = { version = "0.5.0", git = "https://github.com/probe-rs/embedded-test.git", rev = "7109473", default-features = false }
embedded-test = { version = "0.5.0", git = "https://github.com/probe-rs/embedded-test.git", rev = "7109473", default-features = false, features = ["embassy", "external-executor"] }
fugit = "0.3.7"
hex-literal = "0.4.1"
nb = "1.1.0"
Expand All @@ -234,7 +235,8 @@ esp-build = { path = "../esp-build" }
esp-metadata = { path = "../esp-metadata" }

[features]
default = ["embassy"]
default = []
unstable = ["esp-hal/unstable"]

defmt = ["dep:defmt-rtt", "esp-hal/defmt", "embedded-test/defmt"]

Expand Down Expand Up @@ -286,14 +288,14 @@ esp32s3 = [
]
# Async & Embassy:
embassy = [
"embedded-test/embassy",
"embedded-test/external-executor",
"dep:esp-hal-embassy",
]
generic-queue = [
"embassy",
"embassy-time/generic-queue-64"
]
integrated-timers = [
"embassy",
"esp-hal-embassy/integrated-timers",
]
octal-psram = ["esp-hal/octal-psram", "esp-alloc"]
Expand Down
39 changes: 39 additions & 0 deletions hil-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,42 @@ macro_rules! unconnected_pin {
}
}};
}

// A simple looping executor to test async code without esp-hal-embassy (which
// needs `esp-hal/unstable`).
#[cfg(not(feature = "embassy"))]
mod executor {
use core::marker::PhantomData;

use embassy_executor::{raw, Spawner};

#[export_name = "__pender"]
fn __pender(_: *mut ()) {}

pub struct Executor {
inner: raw::Executor,
not_send: PhantomData<*mut ()>,
}

impl Executor {
pub fn new() -> Self {
Self {
inner: raw::Executor::new(core::ptr::null_mut()),
not_send: PhantomData,
}
}

pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! {
init(self.inner.spawner());

loop {
unsafe { self.inner.poll() };
}
}
}
}

#[cfg(feature = "embassy")]
pub use esp_hal_embassy::Executor;
#[cfg(not(feature = "embassy"))]
pub use executor::Executor;
1 change: 1 addition & 0 deletions hil-test/tests/aes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! AES Test
//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: unstable

#![no_std]
#![no_main]
Expand Down
1 change: 1 addition & 0 deletions hil-test/tests/aes_dma.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! AES DMA Test
//% CHIPS: esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: unstable

#![no_std]
#![no_main]
Expand Down
1 change: 1 addition & 0 deletions hil-test/tests/clock_monitor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Clock Monitor Test
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: unstable

#![no_std]
#![no_main]
Expand Down
1 change: 1 addition & 0 deletions hil-test/tests/crc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! CRC and MD5 Tests
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: unstable

#![no_std]
#![no_main]
Expand Down
1 change: 1 addition & 0 deletions hil-test/tests/critical_section.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Ensure invariants of locks are upheld.
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: unstable

// TODO: add multi-core tests

Expand Down
1 change: 1 addition & 0 deletions hil-test/tests/delay.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Delay Test
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: unstable

#![no_std]
#![no_main]
Expand Down
3 changes: 2 additions & 1 deletion hil-test/tests/delay_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! `embedded_hal_async::delay::DelayNs` trait.
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: unstable

#![no_std]
#![no_main]
Expand Down Expand Up @@ -69,7 +70,7 @@ async fn test_async_delay_ms(mut timer: impl DelayNs, duration: u32) {
}

#[cfg(test)]
#[embedded_test::tests(default_timeout = 2, executor = esp_hal_embassy::Executor::new())]
#[embedded_test::tests(default_timeout = 2, executor = hil_test::Executor::new())]
mod tests {
use super::*;

Expand Down
1 change: 1 addition & 0 deletions hil-test/tests/dma_macros.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! DMA macro tests
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: unstable

#![no_std]
#![no_main]
Expand Down
1 change: 1 addition & 0 deletions hil-test/tests/dma_mem2mem.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! DMA Mem2Mem Tests
//% CHIPS: esp32c2 esp32c3 esp32c6 esp32h2 esp32s3
//% FEATURES: unstable

#![no_std]
#![no_main]
Expand Down
1 change: 1 addition & 0 deletions hil-test/tests/ecc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! ECC Test
//% CHIPS: esp32c2 esp32c6 esp32h2
//% FEATURES: unstable

#![no_std]
#![no_main]
Expand Down
Loading

0 comments on commit 848029b

Please sign in to comment.