Skip to content

Commit

Permalink
HIL(QOL): Use global timeout instead of timeout macros (#2489)
Browse files Browse the repository at this point in the history
* HIL(QOL): Add missing timeouts to various tests

* Increase timeouts for ECC

* Use global timeout in hil tests

* sha: increase test_digest_of_size_1_to_200 timeout from 10 to 15 seconds
  • Loading branch information
JurajSadel authored Dec 4, 2024
1 parent 91d7f23 commit d54f844
Show file tree
Hide file tree
Showing 44 changed files with 46 additions and 144 deletions.
2 changes: 1 addition & 1 deletion hil-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,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", default-features = false }
embedded-test = { version = "0.5.0", git = "https://github.com/probe-rs/embedded-test.git", rev = "7109473", default-features = false }
fugit = "0.3.7"
hex-literal = "0.4.1"
nb = "1.1.0"
Expand Down
2 changes: 1 addition & 1 deletion hil-test/tests/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct Context<'a> {
}

#[cfg(test)]
#[embedded_test::tests]
#[embedded_test::tests(default_timeout = 3)]
mod tests {
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion hil-test/tests/aes_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use hil_test as _;
const DMA_BUFFER_SIZE: usize = 16;

#[cfg(test)]
#[embedded_test::tests]
#[embedded_test::tests(default_timeout = 3)]
mod tests {
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion hil-test/tests/clock_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Context<'a> {
}

#[cfg(test)]
#[embedded_test::tests]
#[embedded_test::tests(default_timeout = 3)]
mod tests {
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion hil-test/tests/crc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use esp_hal::rom::{crc, md5};
use hil_test as _;

#[cfg(test)]
#[embedded_test::tests]
#[embedded_test::tests(default_timeout = 3)]
mod tests {
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion hil-test/tests/critical_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use hil_test as _;

#[cfg(test)]
#[embedded_test::tests]
#[embedded_test::tests(default_timeout = 3)]
mod tests {
use esp_hal::sync::Locked;

Expand Down
5 changes: 1 addition & 4 deletions hil-test/tests/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Context {
}

#[cfg(test)]
#[embedded_test::tests]
#[embedded_test::tests(default_timeout = 2)]
mod tests {
use super::*;

Expand All @@ -27,7 +27,6 @@ mod tests {
}

#[test]
#[timeout(2)]
fn delay_ns(mut ctx: Context) {
let t1 = esp_hal::time::now();
ctx.delay.delay_ns(600_000_000);
Expand All @@ -42,7 +41,6 @@ mod tests {
}

#[test]
#[timeout(2)]
fn delay_700millis(ctx: Context) {
let t1 = esp_hal::time::now();
ctx.delay.delay_millis(700);
Expand All @@ -57,7 +55,6 @@ mod tests {
}

#[test]
#[timeout(2)]
fn delay_1_500_000us(mut ctx: Context) {
let t1 = esp_hal::time::now();
ctx.delay.delay_us(1_500_000);
Expand Down
11 changes: 1 addition & 10 deletions hil-test/tests/delay_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async fn test_async_delay_ms(mut timer: impl DelayNs, duration: u32) {
}

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

Expand All @@ -82,15 +82,13 @@ mod tests {

#[cfg(systimer)]
#[test]
#[timeout(2)]
async fn test_systimer_async_delay_ns(ctx: Context) {
let alarms = SystemTimer::new(ctx.peripherals.SYSTIMER);

test_async_delay_ns(OneShotTimer::new(alarms.alarm0).into_async(), 10_000_000).await;
}

#[test]
#[timeout(2)]
async fn test_timg0_async_delay_ns(ctx: Context) {
let timg0 = TimerGroup::new(ctx.peripherals.TIMG0);

Expand All @@ -101,7 +99,6 @@ mod tests {

#[cfg(timg1)]
#[test]
#[timeout(2)]
async fn test_timg1_async_delay_ns(ctx: Context) {
let timg1 = TimerGroup::new(ctx.peripherals.TIMG1);

Expand All @@ -112,15 +109,13 @@ mod tests {

#[cfg(systimer)]
#[test]
#[timeout(2)]
async fn test_systimer_async_delay_us(ctx: Context) {
let alarms = SystemTimer::new(ctx.peripherals.SYSTIMER);

test_async_delay_us(OneShotTimer::new(alarms.alarm0).into_async(), 10_000).await;
}

#[test]
#[timeout(2)]
async fn test_timg0_async_delay_us(ctx: Context) {
let timg0 = TimerGroup::new(ctx.peripherals.TIMG0);

Expand All @@ -131,7 +126,6 @@ mod tests {

#[cfg(timg1)]
#[test]
#[timeout(2)]
async fn test_timg1_async_delay_us(ctx: Context) {
let timg1 = TimerGroup::new(ctx.peripherals.TIMG1);

Expand All @@ -142,15 +136,13 @@ mod tests {

#[cfg(systimer)]
#[test]
#[timeout(2)]
async fn test_systimer_async_delay_ms(ctx: Context) {
let alarms = SystemTimer::new(ctx.peripherals.SYSTIMER);

test_async_delay_ms(OneShotTimer::new(alarms.alarm0).into_async(), 10).await;
}

#[test]
#[timeout(2)]
async fn test_timg0_async_delay_ms(ctx: Context) {
let timg0 = TimerGroup::new(ctx.peripherals.TIMG0);

Expand All @@ -161,7 +153,6 @@ mod tests {

#[cfg(timg1)]
#[test]
#[timeout(2)]
async fn test_timg1_async_delay_ms(ctx: Context) {
let timg1 = TimerGroup::new(ctx.peripherals.TIMG1);

Expand Down
2 changes: 1 addition & 1 deletion hil-test/tests/dma_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) const fn compute_circular_size(size: usize, chunk_size: usize) -> usi
}

#[cfg(test)]
#[embedded_test::tests]
#[embedded_test::tests(default_timeout = 3)]
mod tests {
// defmt::* is load-bearing, it ensures that the assert in dma_buffers! is not
// using defmt's non-const assert. Doing so would result in a compile error.
Expand Down
2 changes: 1 addition & 1 deletion hil-test/tests/dma_mem2mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct Context {
}

#[cfg(test)]
#[embedded_test::tests]
#[embedded_test::tests(default_timeout = 3)]
mod tests {
use super::*;

Expand Down
3 changes: 2 additions & 1 deletion hil-test/tests/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Context<'a> {
}

#[cfg(test)]
#[embedded_test::tests]
#[embedded_test::tests(default_timeout = 10)]
mod tests {
use super::*;

Expand All @@ -64,6 +64,7 @@ mod tests {
}

#[test]
#[timeout(5)]
fn test_ecc_affine_point_multiplication(mut ctx: Context<'static>) {
for &prime_field in TEST_PARAMS_VECTOR.prime_fields {
match prime_field.len() {
Expand Down
4 changes: 1 addition & 3 deletions hil-test/tests/embassy_interrupt_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Context {
}

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

Expand Down Expand Up @@ -91,7 +91,6 @@ mod test {
}

#[test]
#[timeout(3)]
async fn run_interrupt_executor_test(ctx: Context) {
let interrupt_executor =
mk_static!(InterruptExecutor<1>, InterruptExecutor::new(ctx.interrupt));
Expand All @@ -112,7 +111,6 @@ mod test {

#[test]
#[cfg(multi_core)]
#[timeout(3)]
async fn run_interrupt_executor_test_on_core_1(mut ctx: Context) {
let app_core_stack = mk_static!(Stack<8192>, Stack::new());
let response = &*mk_static!(Signal<CriticalSectionRawMutex, ()>, Signal::new());
Expand Down
4 changes: 1 addition & 3 deletions hil-test/tests/embassy_interrupt_spi_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ async fn interrupt_driven_task(mut i2s_tx: esp_hal::i2s::master::I2sTx<'static,
}

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

#[test]
#[timeout(3)]
async fn dma_does_not_lock_up_when_used_in_different_executors() {
let peripherals = esp_hal::init(esp_hal::Config::default());

Expand Down Expand Up @@ -199,7 +198,6 @@ mod test {
// Reproducer of https://github.com/esp-rs/esp-hal/issues/2369
#[cfg(multi_core)]
#[test]
#[timeout(3)]
async fn dma_does_not_lock_up_on_core_1() {
use embassy_time::Timer;
use esp_hal::peripherals::SPI2;
Expand Down
12 changes: 1 addition & 11 deletions hil-test/tests/embassy_timers_executors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn set_up_embassy_with_systimer(peripherals: Peripherals) {
}

#[cfg(test)]
#[embedded_test::tests(executor = esp_hal_embassy::Executor::new())]
#[embedded_test::tests(default_timeout = 3, executor = esp_hal_embassy::Executor::new())]
mod test {
use super::*;
use crate::test_cases::*;
Expand All @@ -135,15 +135,13 @@ mod test {
}

#[test]
#[timeout(3)]
async fn test_one_shot_timg(peripherals: Peripherals) {
set_up_embassy_with_timg0(peripherals);

run_test_one_shot_async().await;
}

#[test]
#[timeout(3)]
#[cfg(not(feature = "esp32"))]
async fn test_one_shot_systimer(peripherals: Peripherals) {
set_up_embassy_with_systimer(peripherals);
Expand All @@ -152,15 +150,13 @@ mod test {
}

#[test]
#[timeout(3)]
fn test_periodic_timg(peripherals: Peripherals) {
let timg0 = TimerGroup::new(peripherals.TIMG0);

run_test_periodic_timer(timg0.timer0);
}

#[test]
#[timeout(3)]
#[cfg(not(feature = "esp32"))]
fn test_periodic_systimer(peripherals: Peripherals) {
let systimer = SystemTimer::new(peripherals.SYSTIMER);
Expand All @@ -169,15 +165,13 @@ mod test {
}

#[test]
#[timeout(3)]
fn test_periodic_oneshot_timg(peripherals: Peripherals) {
let mut timg0 = TimerGroup::new(peripherals.TIMG0);
run_test_periodic_timer(&mut timg0.timer0);
run_test_oneshot_timer(&mut timg0.timer0);
}

#[test]
#[timeout(3)]
#[cfg(not(feature = "esp32"))]
fn test_periodic_oneshot_systimer(peripherals: Peripherals) {
let mut systimer = SystemTimer::new(peripherals.SYSTIMER);
Expand All @@ -186,15 +180,13 @@ mod test {
}

#[test]
#[timeout(3)]
async fn test_join_timg(peripherals: Peripherals) {
set_up_embassy_with_timg0(peripherals);

run_join_test().await;
}

#[test]
#[timeout(3)]
#[cfg(not(feature = "esp32"))]
async fn test_join_systimer(peripherals: Peripherals) {
set_up_embassy_with_systimer(peripherals);
Expand All @@ -204,7 +196,6 @@ mod test {

/// Test that the ticker works in tasks ran by the interrupt executors.
#[test]
#[timeout(3)]
#[cfg(not(feature = "esp32"))]
async fn test_interrupt_executor(peripherals: Peripherals) {
let timg0 = TimerGroup::new(peripherals.TIMG0);
Expand Down Expand Up @@ -257,7 +248,6 @@ mod test {

/// Test that timg0 and systimer don't have vastly different tick rates.
#[test]
#[timeout(3)]
async fn tick_test_timer_tick_rates(peripherals: Peripherals) {
set_up_embassy_with_timg0(peripherals);

Expand Down
5 changes: 1 addition & 4 deletions hil-test/tests/esp_wifi_floats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ cfg_if::cfg_if! {
}

#[cfg(test)]
#[embedded_test::tests]
#[embedded_test::tests(default_timeout = 3)]
mod tests {
use super::*;

Expand All @@ -70,7 +70,6 @@ mod tests {

#[cfg(multi_core)]
#[test]
#[timeout(3)]
fn fpu_is_enabled_on_core1(peripherals: Peripherals) {
let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL);

Expand All @@ -94,7 +93,6 @@ mod tests {
}

#[test]
#[timeout(3)]
fn fpu_stays_enabled_with_wifi(peripherals: Peripherals) {
let timg0 = TimerGroup::new(peripherals.TIMG0);
let _init = esp_wifi::init(
Expand Down Expand Up @@ -124,7 +122,6 @@ mod tests {

#[cfg(multi_core)]
#[test]
#[timeout(3)]
fn fpu_stays_enabled_with_wifi_on_core1(peripherals: Peripherals) {
let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL);

Expand Down
Loading

0 comments on commit d54f844

Please sign in to comment.