esp-hal/hil-test/tests/get_time.rs
Dániel Buga ec130877b7
Disable RTT polling in HIL tests by default (#1960)
* Disable defmt-rtt by default

* Update i2s test based on changes done to async

* fmt

* Update readme

* Update more tests
2024-08-19 13:47:22 +00:00

49 lines
1.0 KiB
Rust

//! current_time Test
// esp32c2 is disabled currently as it fails
//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
#![no_std]
#![no_main]
use esp_hal::{clock::ClockControl, delay::Delay, peripherals::Peripherals, system::SystemControl};
use hil_test as _;
struct Context {
delay: Delay,
}
impl Context {
pub fn init() -> Self {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let delay = Delay::new(&clocks);
Context { delay }
}
}
#[cfg(test)]
#[embedded_test::tests]
mod tests {
use super::*;
#[init]
fn init() -> Context {
Context::init()
}
#[test]
#[timeout(3)]
fn test_current_time(ctx: Context) {
let t1 = esp_hal::time::current_time();
ctx.delay.delay_millis(500);
let t2 = esp_hal::time::current_time();
assert!(t2 > t1);
assert!((t2 - t1).to_millis() >= 500u64);
}
}