forked from esp-rs/esp-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Cover all aes modes (esp-rs#1423)
- Loading branch information
1 parent
5d61074
commit 3068d25
Showing
4 changed files
with
138 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//! Clock Monitor Test | ||
|
||
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
use defmt_rtt as _; | ||
use esp_backtrace as _; | ||
use esp_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, rtc_cntl::Rtc}; | ||
|
||
struct Context<'a> { | ||
rtc: Rtc<'a>, | ||
} | ||
|
||
impl Context<'_> { | ||
pub fn init() -> Self { | ||
let peripherals = Peripherals::take(); | ||
let system = peripherals.SYSTEM.split(); | ||
ClockControl::boot_defaults(system.clock_control).freeze(); | ||
|
||
let rtc = Rtc::new(peripherals.LPWR, None); | ||
|
||
Context { rtc } | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
#[embedded_test::tests] | ||
mod tests { | ||
use super::*; | ||
|
||
#[init] | ||
fn init() -> Context<'static> { | ||
Context::init() | ||
} | ||
|
||
#[test] | ||
fn test_estimated_clock(mut ctx: Context<'static>) { | ||
// We call the function twice since sometimes the first call gives a | ||
// wrong result | ||
ctx.rtc.estimate_xtal_frequency(); | ||
let estimated_xtal_freq = ctx.rtc.estimate_xtal_frequency(); | ||
|
||
#[cfg(feature = "esp32c2")] // 26 MHz | ||
assert!(estimated_xtal_freq > 22 && estimated_xtal_freq < 30); | ||
#[cfg(feature = "esp32h2")] // 32 MHz | ||
assert!(estimated_xtal_freq > 26 && estimated_xtal_freq < 36); | ||
#[cfg(not(any(feature = "esp32h2", feature = "esp32c2")))] // 40 MHz | ||
assert!(estimated_xtal_freq > 34 && estimated_xtal_freq < 44); | ||
} | ||
} |