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
This commit is contained in:
Dániel Buga 2024-08-19 15:47:22 +02:00 committed by GitHub
parent 6a38053c15
commit ec130877b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 131 additions and 92 deletions

View File

@ -4,6 +4,9 @@ version = "0.0.0"
edition = "2021"
publish = false
[lib]
name = "hil_test"
[[test]]
name = "aes"
harness = false
@ -117,7 +120,6 @@ required-features = ["async", "embassy"]
name = "uart_tx_rx"
harness = false
[[test]]
name = "uart_tx_rx_async"
harness = false
@ -140,7 +142,7 @@ harness = false
cfg-if = "1.0.0"
critical-section = "1.1.2"
defmt = "0.3.8"
defmt-rtt = "0.4.1"
defmt-rtt = { version = "0.4.1", optional = true }
embassy-futures = "0.1.1"
embassy-sync = "0.6.0"
embassy-time = { version = "0.3.1", features = ["generic-queue-64"] }
@ -168,6 +170,8 @@ p256 = { version = "0.13.2", default-features = false, features =
[features]
default = ["async", "embassy"]
defmt = ["dep:defmt-rtt"]
# Device support (required!):
esp32 = [
"embedded-test/xtensa-semihosting",

View File

@ -9,14 +9,13 @@ For assistance with this package please [open an issue] or [start a discussion].
## Quickstart
We use [embedded-test] as our testing framework, which relies on [defmt] internally. This allows us to write unit and integration tests much in the same way you would for a normal Rust project, when the standard library is available, and to execute them using Cargo's built-in test runner.
We use [embedded-test] as our testing framework. This allows us to write unit and integration tests much in the same way you would for a normal Rust project, when the standard library is available, and to execute them using Cargo's built-in test runner.
[embedded-test]: https://github.com/probe-rs/embedded-test
[defmt]: https://github.com/knurling-rs/defmt
### Running Tests Locally
We use [probe-rs] for flashing and running the tests on a target device, however, this **MUST** be installed from the correct revision, and with the correct features enabled:
We use [probe-rs] for flashing and running the tests on a target device, however, this **MUST** be installed from the correct revision:
```text
cargo install probe-rs-tools \
@ -39,6 +38,13 @@ For running a single test on a target, from the `xtask` folder run:
cargo xtask run-tests esp32c6 --test gpio
```
If you want to run a test multiple times:
```shell
# Run GPIO tests for ESP32-C6
cargo xtask run-tests esp32c6 --test gpio --repeat 10
```
Another alternative way of running a single test is, from the `hil-tests` folder:
```shell
# Run GPIO tests for ESP32-C6
@ -138,3 +144,23 @@ sudo reboot
If the test is supported by all the targets, you can omit the header.
6. Write some documentation at the top of the `tests/$PERIPHERAL.rs` file with the pins being used and the required connections, if applicable.
## Logging in tests
The tests can use [defmt] to print logs. To enable log output, add the `defmt` feature to the test
you want to run. Eg:
```rust
//! AES Test
//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: defmt
```
Make sure to remove this addition before you commit any modifications.
> NOTE: log output is disabled by default. Enabling it can introduce some timing issues, which
makes some tests fail randomly. This issue affects all Xtensa devices, as well as ESP32-C2 and
ESP32-C3 currently.
[defmt]: https://github.com/knurling-rs/defmt

24
hil-test/src/lib.rs Normal file
View File

@ -0,0 +1,24 @@
#![no_std]
// By default, we don't want probe-rs to interfere with test timings by halting
// cores and polling RTT. The tests don't produce output most of the time
// anyway. The only cases where output can be interesting are: during
// development, and when a test fails. In these cases, you can enable
// the `defmt` feature to get the output.
#[cfg(not(feature = "defmt"))]
#[defmt::global_logger]
struct Logger;
#[cfg(not(feature = "defmt"))]
unsafe impl defmt::Logger for Logger {
fn acquire() {}
unsafe fn flush() {}
unsafe fn release() {}
unsafe fn write(_bytes: &[u8]) {}
}
#[cfg(feature = "defmt")]
use defmt_rtt as _;
// Make sure esp_backtrace is not removed.
use esp_backtrace as _;

View File

@ -5,12 +5,11 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
aes::{Aes, Mode},
peripherals::Peripherals,
};
use hil_test as _;
struct Context<'a> {
aes: Aes<'a>,

View File

@ -5,8 +5,6 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
aes::{
dma::{CipherMode, WithDmaAes},
@ -17,6 +15,7 @@ use esp_hal::{
dma_buffers,
peripherals::Peripherals,
};
use hil_test as _;
const DMA_BUFFER_SIZE: usize = 16;

View File

@ -5,14 +5,13 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
peripherals::Peripherals,
rtc_cntl::Rtc,
system::SystemControl,
};
use hil_test as _;
struct Context<'a> {
rtc: Rtc<'a>,

View File

@ -7,9 +7,8 @@
use core::ops::Deref;
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::rom::{crc, md5};
use hil_test as _;
#[cfg(test)]
#[embedded_test::tests]

View File

@ -6,10 +6,9 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use embedded_hal::delay::DelayNs;
use esp_backtrace as _;
use esp_hal::{clock::ClockControl, delay::Delay, peripherals::Peripherals, system::SystemControl};
use hil_test as _;
struct Context {
delay: Delay,

View File

@ -5,8 +5,7 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use hil_test as _;
const DATA_SIZE: usize = 1024 * 10;

View File

@ -5,8 +5,6 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
dma::{Dma, DmaError, DmaPriority, Mem2Mem},
@ -16,6 +14,7 @@ use esp_hal::{
peripherals::Peripherals,
system::SystemControl,
};
use hil_test as _;
const DATA_SIZE: usize = 1024 * 10;

View File

@ -13,9 +13,7 @@ use crypto_bigint::{
U192,
U256,
};
use defmt_rtt as _;
use elliptic_curve::sec1::ToEncodedPoint;
use esp_backtrace as _;
#[cfg(feature = "esp32h2")]
use esp_hal::ecc::WorkMode;
use esp_hal::{
@ -25,6 +23,7 @@ use esp_hal::{
Blocking,
};
use hex_literal::hex;
use hil_test as _;
struct TestParams<'a> {
prime_fields: &'a [&'a [u8]],

View File

@ -22,15 +22,12 @@ macro_rules! mk_static {
async fn interrupt_driven_task(signal: &'static Signal<CriticalSectionRawMutex, ()>) {
loop {
signal.wait().await;
defmt::info!("Received");
}
}
#[cfg(test)]
#[embedded_test::tests]
mod test {
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
interrupt::Priority,
@ -38,6 +35,7 @@ mod test {
system::{SoftwareInterrupt, SystemControl},
};
use esp_hal_embassy::InterruptExecutor;
use hil_test as _;
use super::*;
@ -61,6 +59,5 @@ mod test {
spawner.spawn(interrupt_driven_task(signal)).unwrap();
signal.signal(());
defmt::info!("Returned");
}
}

View File

@ -6,9 +6,7 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use embassy_time::{Duration, Ticker, Timer};
use esp_backtrace as _;
use esp_hal::{
clock::{ClockControl, Clocks},
peripherals::Peripherals,
@ -23,6 +21,7 @@ use esp_hal::{
};
#[cfg(not(feature = "esp32"))]
use esp_hal_embassy::InterruptExecutor;
use hil_test as _;
macro_rules! mk_static {
($t:ty,$val:expr) => {{

View File

@ -6,9 +6,8 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{clock::ClockControl, delay::Delay, peripherals::Peripherals, system::SystemControl};
use hil_test as _;
struct Context {
delay: Delay,

View File

@ -12,8 +12,6 @@
use core::cell::RefCell;
use critical_section::Mutex;
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
delay::Delay,
@ -24,6 +22,7 @@ use esp_hal::{
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
InterruptConfigurable,
};
use hil_test as _;
macro_rules! mk_static {
($t:ty,$val:expr) => {{

View File

@ -10,8 +10,6 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
delay::Delay,
@ -24,10 +22,32 @@ use esp_hal::{
prelude::*,
system::SystemControl,
};
use hil_test as _;
// choose values which DON'T restart on every descriptor buffer's start
const ADD: u8 = 5;
const CUT_OFF: u8 = 113;
#[derive(Clone)]
struct SampleSource {
i: u8,
}
impl SampleSource {
// choose values which DON'T restart on every descriptor buffer's start
const ADD: u8 = 5;
const CUT_OFF: u8 = 113;
fn new() -> Self {
Self { i: 0 }
}
}
impl Iterator for SampleSource {
type Item = u8;
fn next(&mut self) -> Option<Self::Item> {
let i = self.i;
self.i = (i + Self::ADD) % Self::CUT_OFF;
Some(i)
}
}
#[cfg(test)]
#[embedded_test::tests]
@ -92,13 +112,9 @@ mod tests {
i2s.rx_conf().modify(|_, w| w.rx_update().set_bit());
}
let mut iteration = 0;
let mut failed = false;
let mut check_i: u8 = 0;
let mut i = 0;
let mut samples = SampleSource::new();
for b in tx_buffer.iter_mut() {
*b = i;
i = (i + ADD) % CUT_OFF;
*b = samples.next().unwrap();
}
let mut rcv = [0u8; 11000];
@ -113,14 +129,16 @@ mod tests {
let mut tx_transfer = i2s_tx.write_dma_circular(&tx_buffer).unwrap();
'outer: loop {
let mut iteration = 0;
let mut sample_idx = 0;
let mut check_samples = SampleSource::new();
loop {
let tx_avail = tx_transfer.available();
// make sure there are more than one descriptor buffers ready to push
if tx_avail > 5000 {
for b in &mut filler[0..tx_avail].iter_mut() {
*b = i;
i = (i + ADD) % CUT_OFF;
*b = samples.next().unwrap();
}
tx_transfer.push(&filler[0..tx_avail]).unwrap();
}
@ -147,11 +165,13 @@ mod tests {
assert!(len > 0);
for &b in &rcv[..len] {
if b != check_i {
failed = true;
break 'outer;
}
check_i = (check_i + ADD) % CUT_OFF;
let expected = check_samples.next().unwrap();
assert_eq!(
b, expected,
"Sample #{} does not match ({} != {})",
sample_idx, b, expected
);
sample_idx += 1;
}
iteration += 1;
@ -167,7 +187,5 @@ mod tests {
break;
}
}
assert!(!failed);
}
}

View File

@ -10,8 +10,6 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
dma::{Dma, DmaChannel0, DmaPriority},
@ -23,6 +21,7 @@ use esp_hal::{
system::SystemControl,
Async,
};
use hil_test as _;
const BUFFER_SIZE: usize = 2000;

View File

@ -10,15 +10,13 @@
use core::{arch::asm, cell::RefCell};
use critical_section::Mutex;
use defmt::info;
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
interrupt::{self, *},
peripherals::{Interrupt, Peripherals},
system::{SoftwareInterrupt, SystemControl},
};
use hil_test as _;
static SWINT0: Mutex<RefCell<Option<SoftwareInterrupt<0>>>> = Mutex::new(RefCell::new(None));
@ -79,7 +77,7 @@ fn interrupt20() {
x = inout(reg) perf_counter,
)
};
info!("Performance counter:{}", perf_counter);
defmt::info!("Performance counter:{}", perf_counter);
// TODO these values should be adjusted to catch smaller regressions
cfg_if::cfg_if! {
if #[cfg(any(feature = "esp32c3", feature = "esp32c2"))] {

View File

@ -5,8 +5,6 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::{ClockControl, Clocks},
dma::{Dma, DmaDescriptor, DmaPriority},
@ -23,6 +21,7 @@ use esp_hal::{
prelude::*,
system::SystemControl,
};
use hil_test as _;
const DATA_SIZE: usize = 1024 * 10;

View File

@ -5,8 +5,6 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::{ClockControl, Clocks},
dma::{Dma, DmaDescriptor, DmaPriority},
@ -23,6 +21,7 @@ use esp_hal::{
prelude::*,
system::SystemControl,
};
use hil_test as _;
const DATA_SIZE: usize = 1024 * 10;

View File

@ -7,9 +7,8 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{delay::Delay, gpio::GpioPin, pcnt::Pcnt};
use hil_test as _;
struct Context<'d> {
pcnt: Pcnt<'d>,

View File

@ -7,8 +7,6 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
gpio::Io,
@ -17,6 +15,7 @@ use esp_hal::{
rmt::{PulseCode, Rmt, RxChannel, RxChannelConfig, TxChannel, TxChannelConfig},
system::SystemControl,
};
use hil_test as _;
#[cfg(test)]
#[embedded_test::tests]

View File

@ -6,8 +6,6 @@
#![no_main]
use crypto_bigint::{Uint, U1024, U512};
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
peripherals::Peripherals,
prelude::*,
@ -20,6 +18,8 @@ use esp_hal::{
},
Blocking,
};
use hil_test as _;
const BIGNUM_1: U512 = Uint::from_be_hex(
"c7f61058f96db3bd87dbab08ab03b4f7f2f864eac249144adea6a65f97803b719d8ca980b7b3c0389c1c7c6\
7dc353c5e0ec11f5fc8ce7f6073796cc8f73fa878",

View File

@ -5,13 +5,12 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
peripherals::Peripherals,
prelude::*,
sha::{Sha, ShaMode},
};
use hil_test as _;
use nb::block;
#[cfg(test)]

View File

@ -13,9 +13,7 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use embedded_hal::spi::SpiBus;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
gpio::Io,
@ -24,6 +22,7 @@ use esp_hal::{
spi::{master::Spi, FullDuplexMode, SpiMode},
system::SystemControl,
};
use hil_test as _;
struct Context {
spi: Spi<'static, esp_hal::peripherals::SPI2, FullDuplexMode>,

View File

@ -21,8 +21,6 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
dma::{Dma, DmaPriority},
@ -36,6 +34,7 @@ use esp_hal::{
},
system::SystemControl,
};
use hil_test as _;
#[cfg(test)]
#[embedded_test::tests]

View File

@ -19,9 +19,7 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use embedded_hal_async::spi::SpiBus;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
dma::{Dma, DmaPriority},
@ -39,6 +37,7 @@ use esp_hal::{
},
system::SystemControl,
};
use hil_test as _;
#[cfg(test)]
#[embedded_test::tests(executor = esp_hal_embassy::Executor::new())]

View File

@ -13,8 +13,7 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use hil_test as _;
#[cfg(test)]
#[embedded_test::tests]

View File

@ -13,8 +13,7 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use hil_test as _;
#[cfg(test)]
#[embedded_test::tests]

View File

@ -11,9 +11,7 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use embedded_hal_02::can::Frame;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
gpio::Io,
@ -23,6 +21,7 @@ use esp_hal::{
twai::{self, filter::SingleStandardFilter, EspTwaiFrame, StandardId, TwaiMode},
Blocking,
};
use hil_test as _;
use nb::block;
struct Context {

View File

@ -11,9 +11,7 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use embedded_hal_02::serial::{Read, Write};
use esp_backtrace as _;
use esp_hal::{
clock::{ClockControl, Clocks},
gpio::Io,
@ -23,6 +21,7 @@ use esp_hal::{
uart::{ClockSource, Uart},
Blocking,
};
use hil_test as _;
use nb::block;
struct Context {

View File

@ -11,8 +11,6 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
gpio::Io,
@ -21,6 +19,7 @@ use esp_hal::{
uart::Uart,
Async,
};
use hil_test as _;
struct Context {
uart: Uart<'static, UART0, Async>,

View File

@ -11,8 +11,6 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
gpio::Io,
@ -22,6 +20,7 @@ use esp_hal::{
uart::{UartRx, UartTx},
Blocking,
};
use hil_test as _;
use nb::block;
struct Context {

View File

@ -11,8 +11,6 @@
#![no_std]
#![no_main]
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
gpio::Io,
@ -21,6 +19,7 @@ use esp_hal::{
uart::{UartRx, UartTx},
Async,
};
use hil_test as _;
struct Context {
tx: UartTx<'static, UART0, Async>,

View File

@ -8,8 +8,6 @@
#[cfg(test)]
#[embedded_test::tests]
mod tests {
use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
peripherals::Peripherals,
@ -17,6 +15,7 @@ mod tests {
timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
usb_serial_jtag::UsbSerialJtag,
};
use hil_test as _;
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
macro_rules! mk_static {