Skip to content

Commit

Permalink
Remove rtt init features, add new attribute to setup global logger
Browse files Browse the repository at this point in the history
  • Loading branch information
t-moe committed Dec 2, 2024
1 parent 47fa427 commit 919cd26
Show file tree
Hide file tree
Showing 24 changed files with 286 additions and 354 deletions.
3 changes: 3 additions & 0 deletions .idea/embedded-test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/runConfigurations/Run_bin_target_stm32f767.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/runConfigurations/Test_esp32c6_defmt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/runConfigurations/Test_esp32c6_log.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/runConfigurations/Test_stm32f767_defmt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/runConfigurations/Test_stm32f767_log.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- `#[tests(default_timeout = <u32>)]` to configure a suite-wide default timeout.
- `#[tests(setup = <expr>)]` to configure a suite-wide (log) setup function (e.g. `rtt_target::rtt_init_log()`).

## [0.5.0]
### Removed

### Added
- Breaking: Removed Features `init-log` and `init-rtt`.

## [0.5.0]

### Changed

- Breaking: Bump embassy-excecutor to 0.6.1

### Fixed

### Removed

## [0.4.0]

### Added
Expand Down
47 changes: 1 addition & 46 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ categories = ["embedded", "no-std", "development-tools::testing"]

[dependencies]
semihosting = { version = "0.1.7", features = ["args"] }
embedded-test-macros = { version = "0.5.1", path = "./macros" }
embedded-test-macros = { version = "0.6.0", path = "./macros" }
serde = { version = "1.0.193", default-features = false, features = ["derive"] }
serde-json-core = { version = "0.5.1" }
heapless = "0.8.0"

# Optional dependencies
rtt-target = { version = "0.5.0", optional = true }
rtt-log = { version = "0.4.0", optional = true }
defmt = { version = "0.3.8", optional = true }
log = { version = "0.4.20", optional = true }
embassy-executor = { version = "0.6.1", optional = true, default-features = false }
Expand All @@ -35,12 +33,6 @@ defmt = ["dep:defmt"]
# prints testcase exit result to log
log = ["dep:log"]

# calls `rtt_target::rtt_init_print!()` before starting any tests
init-rtt = ["dep:rtt-target"]

# calls `rtt_log::init();` before starting any tests
init-log = ["dep:rtt-log"]

# Enables async test and init functions using embassy-executor.
# Note: You need to enable at least one executor feature on embassy unless you are using the `external-executor` feature
embassy = [
Expand Down
72 changes: 19 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Add the following to your `Cargo.toml`:

```toml
[dev-dependencies]
embedded-test = { version = "0.5.0", features = ["init-log"] }
embedded-test = { version = "0.6.0" }


[[test]]
Expand Down Expand Up @@ -71,13 +71,10 @@ Then you can run your tests with `cargo test --test example_test` or use the but
Having trouble setting up? Checkout out
the [FAQ and common Errors](https://github.com/probe-rs/embedded-test/wiki/FAQ-and-common-Errors) Wiki page.

## Example Test
## Example Test (e.g. `tests/example_test.rs`)

[Example repo](https://github.com/probe-rs/embedded-test-example)
[More Detailed Cargo.toml](https://github.com/probe-rs/embedded-test-example/blob/master/Cargo.toml)
[Async Test Example](https://github.com/probe-rs/embedded-test-example/blob/master/tests/async_test.rs)

Example for `tests/example_test.rs`
Check the [example folder](https://github.com/probe-rs/embedded-test/tree/master/examples)
for a complete example project for stm32/esp32.

```rust
#![no_std]
Expand All @@ -86,66 +83,42 @@ Example for `tests/example_test.rs`
#[cfg(test)]
#[embedded_test::tests]
mod tests {
use esp_hal::{clock::ClockControl, delay::Delay, peripherals::Peripherals, prelude::*};
use stm32f7xx_hal::pac::Peripherals;

// Optional: A init function which is called before every test
// Optional: asyncness
// Optional: Return some state which will be passed to the tests
#[init]
fn init() -> Delay {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::max(system.clock_control).freeze();
let delay = Delay::new(&clocks);

// The init function can return some state, which can be consumed by the testcases
delay
async fn init() -> Peripherals {
Peripherals::take().unwrap()
}

// A test which takes the state returned by the init function (optional)
// Tests can be async (needs feature `embassy`)
// Tests can take the state returned by the init function (optional)
#[test]
fn takes_state(_state: Delay) {
async fn takes_state(_state: Peripherals) {
assert!(true)
}

// Example for a test which is conditionally enabled
// Tests can be conditionally enabled (with a cfg attribute)
#[test]
#[cfg(feature = "log")]
fn log() {
log::info!("Hello, log!"); // Prints via esp-println to rtt
assert!(true)
}

// Another example for a conditionally enabled test
#[test]
#[cfg(feature = "defmt")]
fn defmt() {
use defmt_rtt as _;
defmt::info!("Hello, defmt!"); // Prints via defmt-rtt to rtt
rtt_target::rtt_init_log!();
log::info!("Hello, log!");
assert!(true)
}

// A test which is cfg'ed out
#[test]
#[cfg(abc)]
fn it_works_disabled() {
assert!(false)
}

// Tests can be ignored with the #[ignore] attribute
#[test]
#[ignore]
fn it_works_ignored() {
assert!(false)
}

// A test that fails with a panic
#[test]
fn it_fails1() {
assert!(false)
}

// A test that fails with a returned Err(&str)
// Tests can fail with a custom error message by returning a Result
#[test]
fn it_fails2() -> Result<(), &'static str> {
fn it_fails_with_err() -> Result<(), &'static str> {
Err("It failed because ...")
}

Expand All @@ -156,11 +129,6 @@ mod tests {
assert!(false)
}

// This test should panic, but doesn't => it fails
#[test]
#[should_panic]
fn it_fails3() {}

// Tests can be annotated with #[timeout(<secs>)] to change the default timeout of 60s
#[test]
#[timeout(10)]
Expand All @@ -175,10 +143,8 @@ mod tests {
| Feature | Default? | Description |
|----------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `panic-handler` | Yes | Defines a panic-handler which will invoke `semihosting::process::abort()` on panic |
| `defmt` | No | Prints testcase exit result to defmt. You'll need to setup your defmt `#[global_logger]` yourself. |
| `log` | No | Prints testcase exit result to log. You'll need to setup your logging sink yourself (or combine with the `init-log` feature). |
| `init-rtt` | No | Calls `rtt_target::rtt_init_print!()` before starting any tests |
| `init-log` | No | Calls `rtt_log::init();` before starting any tests. |
| `defmt` | No | Prints testcase exit result to defmt. You'll need to setup your defmt `#[global_logger]` yourself (e.g. `#[embedded_test::tests(setup=rtt_target::rtt_init_defmt!())`) . |
| `log` | No | Prints testcase exit result to log. You'll need to setup your logging sink yourself (e.g. `#[embedded_test::tests(setup=rtt_target::rtt_init_log!())`) |
| `embassy` | No | Enables async test and init functions. Note: You need to enable at least one executor feature on the embassy-executor crate unless you are using the `external-executor` feature. |
| `external-executor` | No | Allows you to bring your own embassy executor which you need to pass to the `#[tests]` macro (e.g. `#[embedded_test::tests(executor = esp_hal::embassy::executor::thread::Executor::new())]`) |
| `xtensa-semihosting` | No | Enables semihosting for xtensa targets. |
Expand Down
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ macro_rules! assert_unique_features {

fn main() -> Result<(), Box<dyn Error>> {
assert_unique_features!("log", "defmt");
assert_unique_features!("init-rtt", "init-log");

let out = &PathBuf::from(env::var("OUT_DIR")?);
let linker_script = fs::read_to_string("embedded-test.x")?;
Expand Down
Loading

0 comments on commit 919cd26

Please sign in to comment.