Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions hil-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "0.0.0"
edition = "2021"
publish = false

[lib]
name = "hil_test"

[[test]]
name = "aes"
harness = false
Expand Down Expand Up @@ -117,7 +120,6 @@ required-features = ["async", "embassy"]
name = "uart_tx_rx"
harness = false


[[test]]
name = "uart_tx_rx_async"
harness = false
Expand All @@ -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"] }
Expand Down Expand Up @@ -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",
Expand Down
32 changes: 29 additions & 3 deletions hil-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -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 changes: 24 additions & 0 deletions hil-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 _;
3 changes: 1 addition & 2 deletions hil-test/tests/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
3 changes: 1 addition & 2 deletions hil-test/tests/aes_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#![no_std]
#![no_main]

use defmt_rtt as _;
use esp_backtrace as _;
use esp_hal::{
aes::{
dma::{CipherMode, WithDmaAes},
Expand All @@ -17,6 +15,7 @@ use esp_hal::{
dma_buffers,
peripherals::Peripherals,
};
use hil_test as _;

const DMA_BUFFER_SIZE: usize = 16;

Expand Down
3 changes: 1 addition & 2 deletions hil-test/tests/clock_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
3 changes: 1 addition & 2 deletions hil-test/tests/crc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions hil-test/tests/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions hil-test/tests/dma_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions hil-test/tests/dma_mem2mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -16,6 +14,7 @@ use esp_hal::{
peripherals::Peripherals,
system::SystemControl,
};
use hil_test as _;

const DATA_SIZE: usize = 1024 * 10;

Expand Down
3 changes: 1 addition & 2 deletions hil-test/tests/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -25,6 +23,7 @@ use esp_hal::{
Blocking,
};
use hex_literal::hex;
use hil_test as _;

struct TestParams<'a> {
prime_fields: &'a [&'a [u8]],
Expand Down
5 changes: 1 addition & 4 deletions hil-test/tests/embassy_interrupt_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@ 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,
peripherals::Peripherals,
system::{SoftwareInterrupt, SystemControl},
};
use esp_hal_embassy::InterruptExecutor;
use hil_test as _;

use super::*;

Expand All @@ -61,6 +59,5 @@ mod test {
spawner.spawn(interrupt_driven_task(signal)).unwrap();

signal.signal(());
defmt::info!("Returned");
}
}
3 changes: 1 addition & 2 deletions hil-test/tests/embassy_timers_executors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) => {{
Expand Down
3 changes: 1 addition & 2 deletions hil-test/tests/get_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions hil-test/tests/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) => {{
Expand Down
Loading