Provide a looping executor for stable async tests
This commit is contained in:
parent
674e5799f6
commit
5173e14ff2
@ -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"
|
||||
@ -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"
|
||||
@ -234,7 +235,7 @@ 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"]
|
||||
@ -287,8 +288,6 @@ esp32s3 = [
|
||||
]
|
||||
# Async & Embassy:
|
||||
embassy = [
|
||||
"embedded-test/embassy",
|
||||
"embedded-test/external-executor",
|
||||
"dep:esp-hal-embassy",
|
||||
]
|
||||
generic-queue = [
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -70,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::*;
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ struct Context {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = hil_test::Executor::new())]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ async fn interrupt_driven_task(mut i2s_tx: esp_hal::i2s::master::I2sTx<'static,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = hil_test::Executor::new())]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
|
||||
@ -122,7 +122,7 @@ fn set_up_embassy_with_systimer(peripherals: Peripherals) {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = hil_test::Executor::new())]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::test_cases::*;
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
//! GPIO Test
|
||||
|
||||
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
|
||||
//% FEATURES: unstable generic-queue
|
||||
//% FEATURES: unstable embassy generic-queue
|
||||
//% FEATURES(stable):
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
@ -9,14 +10,22 @@
|
||||
use core::cell::RefCell;
|
||||
|
||||
use critical_section::Mutex;
|
||||
#[cfg(feature = "unstable")]
|
||||
use embassy_time::{Duration, Timer};
|
||||
use esp_hal::{
|
||||
delay::Delay,
|
||||
gpio::{AnyPin, Input, Io, Level, Output, Pin, Pull},
|
||||
interrupt::InterruptConfigurable,
|
||||
gpio::{AnyPin, Input, Level, Output, OutputOpenDrain, Pin, Pull},
|
||||
macros::handler,
|
||||
};
|
||||
#[cfg(feature = "unstable")]
|
||||
use esp_hal::{
|
||||
gpio::{Event, Flex, Io},
|
||||
interrupt::InterruptConfigurable,
|
||||
timer::timg::TimerGroup,
|
||||
};
|
||||
use hil_test as _;
|
||||
#[cfg(feature = "unstable")]
|
||||
use portable_atomic::{AtomicUsize, Ordering};
|
||||
|
||||
static COUNTER: Mutex<RefCell<u32>> = Mutex::new(RefCell::new(0));
|
||||
static INPUT_PIN: Mutex<RefCell<Option<Input>>> = Mutex::new(RefCell::new(None));
|
||||
@ -39,27 +48,25 @@ pub fn interrupt_handler() {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = hil_test::Executor::new())]
|
||||
mod tests {
|
||||
use embassy_time::{Duration, Timer};
|
||||
use esp_hal::gpio::{Event, Flex, OutputOpenDrain};
|
||||
use portable_atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[init]
|
||||
fn init() -> Context {
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let mut io = Io::new(peripherals.IO_MUX);
|
||||
io.set_interrupt_handler(interrupt_handler);
|
||||
|
||||
let delay = Delay::new();
|
||||
|
||||
let (gpio1, gpio2) = hil_test::common_test_pins!(peripherals);
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
{
|
||||
// Interrupts are unstable
|
||||
let mut io = Io::new(peripherals.IO_MUX);
|
||||
io.set_interrupt_handler(interrupt_handler);
|
||||
|
||||
// Timers are unstable
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
}
|
||||
@ -72,6 +79,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable")] // Timers are unstable
|
||||
async fn async_edge(ctx: Context) {
|
||||
let counter = AtomicUsize::new(0);
|
||||
let Context {
|
||||
@ -198,7 +206,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "unstable")]
|
||||
#[cfg(feature = "unstable")] // Interrupts are unstable
|
||||
fn gpio_interrupt(ctx: Context) {
|
||||
let mut test_gpio1 = Input::new(ctx.test_gpio1, Pull::Down);
|
||||
let mut test_gpio2 = Output::new(ctx.test_gpio2, Level::Low);
|
||||
|
||||
@ -66,7 +66,7 @@ async fn drive_pins(gpio1: impl Into<AnyPin>, gpio2: impl Into<AnyPin>) -> usize
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(executor = hil_test::Executor::new())]
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -97,7 +97,7 @@ fn enable_loopback() {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = hil_test::Executor::new())]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ struct Context<'d> {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = hil_test::Executor::new())]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ struct Context {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = hil_test::Executor::new())]
|
||||
mod tests {
|
||||
use defmt::info;
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ const fn compute_mprime(modulus: &U512) -> u32 {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(default_timeout = 5, executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(default_timeout = 5, executor = hil_test::Executor::new())]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ struct Context {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = hil_test::Executor::new())]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@ -95,7 +95,7 @@ impl BitbangSpi {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(default_timeout = 10, executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(default_timeout = 10, executor = hil_test::Executor::new())]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ struct Context {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = hil_test::Executor::new())]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ struct Context {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = esp_hal_embassy::Executor::new())]
|
||||
#[embedded_test::tests(default_timeout = 3, executor = hil_test::Executor::new())]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user