From 919cd267a692bef3518daa0649ba038de069e6a4 Mon Sep 17 00:00:00 2001 From: Timo Date: Mon, 2 Dec 2024 14:21:10 +0100 Subject: [PATCH] Remove rtt init features, add new attribute to setup global logger --- .idea/embedded-test.iml | 3 + .../Run_bin_target_stm32f767.xml | 19 ++ .../runConfigurations/Test_esp32c6_defmt.xml | 20 ++ .idea/runConfigurations/Test_esp32c6_log.xml | 20 ++ .../Test_stm32f767_defmt.xml | 20 ++ .../runConfigurations/Test_stm32f767_log.xml | 20 ++ CHANGELOG.md | 11 +- Cargo.lock | 47 +--- Cargo.toml | 10 +- README.md | 72 ++---- build.rs | 1 - examples/esp32c6/Cargo.lock | 217 +++++++----------- examples/esp32c6/Cargo.toml | 23 +- examples/esp32c6/src/lib.rs | 2 +- examples/esp32c6/src/main.rs | 6 +- examples/esp32c6/tests/example_test.rs | 26 ++- examples/stm32f767/Cargo.lock | 47 ++-- examples/stm32f767/Cargo.toml | 28 +-- examples/stm32f767/src/lib.rs | 2 +- examples/stm32f767/src/main.rs | 3 - examples/stm32f767/tests/example_test.rs | 25 +- macros/Cargo.toml | 2 +- macros/src/lib.rs | 7 +- src/export.rs | 9 - 24 files changed, 286 insertions(+), 354 deletions(-) create mode 100644 .idea/runConfigurations/Run_bin_target_stm32f767.xml create mode 100644 .idea/runConfigurations/Test_esp32c6_defmt.xml create mode 100644 .idea/runConfigurations/Test_esp32c6_log.xml create mode 100644 .idea/runConfigurations/Test_stm32f767_defmt.xml create mode 100644 .idea/runConfigurations/Test_stm32f767_log.xml diff --git a/.idea/embedded-test.iml b/.idea/embedded-test.iml index 4b65e41..7520542 100644 --- a/.idea/embedded-test.iml +++ b/.idea/embedded-test.iml @@ -8,9 +8,12 @@ + + + diff --git a/.idea/runConfigurations/Run_bin_target_stm32f767.xml b/.idea/runConfigurations/Run_bin_target_stm32f767.xml new file mode 100644 index 0000000..25bd44b --- /dev/null +++ b/.idea/runConfigurations/Run_bin_target_stm32f767.xml @@ -0,0 +1,19 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Test_esp32c6_defmt.xml b/.idea/runConfigurations/Test_esp32c6_defmt.xml new file mode 100644 index 0000000..ed96fcb --- /dev/null +++ b/.idea/runConfigurations/Test_esp32c6_defmt.xml @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Test_esp32c6_log.xml b/.idea/runConfigurations/Test_esp32c6_log.xml new file mode 100644 index 0000000..077d7b5 --- /dev/null +++ b/.idea/runConfigurations/Test_esp32c6_log.xml @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Test_stm32f767_defmt.xml b/.idea/runConfigurations/Test_stm32f767_defmt.xml new file mode 100644 index 0000000..ce1da87 --- /dev/null +++ b/.idea/runConfigurations/Test_stm32f767_defmt.xml @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Test_stm32f767_log.xml b/.idea/runConfigurations/Test_stm32f767_log.xml new file mode 100644 index 0000000..dbe9107 --- /dev/null +++ b/.idea/runConfigurations/Test_stm32f767_log.xml @@ -0,0 +1,20 @@ + + + + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index c583aff..0338e93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,19 +10,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `#[tests(default_timeout = )]` to configure a suite-wide default timeout. +- `#[tests(setup = )]` 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 diff --git a/Cargo.lock b/Cargo.lock index f5847da..8b0575d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -143,8 +143,6 @@ dependencies = [ "embedded-test-macros", "heapless 0.8.0", "log", - "rtt-log", - "rtt-target", "semihosting", "serde", "serde-json-core", @@ -152,7 +150,7 @@ dependencies = [ [[package]] name = "embedded-test-macros" -version = "0.5.1" +version = "0.6.0" dependencies = [ "darling", "proc-macro2", @@ -235,22 +233,6 @@ version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -dependencies = [ - "critical-section", - "portable-atomic", -] - -[[package]] -name = "portable-atomic" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -293,27 +275,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rtt-log" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7ae9de69f95134a36de2a40848955b56dc93ec337d9a08207c55f381c251ecb" -dependencies = [ - "log", - "once_cell", - "rtt-target", -] - -[[package]] -name = "rtt-target" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10b34c9e6832388e45f3c01f1bb60a016384a0a4ad80cdd7d34913bed25037f0" -dependencies = [ - "critical-section", - "ufmt-write", -] - [[package]] name = "rustc_version" version = "0.4.0" @@ -440,12 +401,6 @@ dependencies = [ "syn 2.0.66", ] -[[package]] -name = "ufmt-write" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69" - [[package]] name = "unicode-ident" version = "1.0.12" diff --git a/Cargo.toml b/Cargo.toml index a5012aa..ecd1078 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } @@ -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 = [ diff --git a/README.md b/README.md index 01d10d6..a5b44aa 100644 --- a/README.md +++ b/README.md @@ -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]] @@ -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] @@ -86,50 +83,32 @@ 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] @@ -137,15 +116,9 @@ mod tests { 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 ...") } @@ -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()] to change the default timeout of 60s #[test] #[timeout(10)] @@ -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. | diff --git a/build.rs b/build.rs index f5180c5..ed057ca 100644 --- a/build.rs +++ b/build.rs @@ -21,7 +21,6 @@ macro_rules! assert_unique_features { fn main() -> Result<(), Box> { 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")?; diff --git a/examples/esp32c6/Cargo.lock b/examples/esp32c6/Cargo.lock index 8fbe4fe..89f534a 100644 --- a/examples/esp32c6/Cargo.lock +++ b/examples/esp32c6/Cargo.lock @@ -19,9 +19,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bare-metal" @@ -110,7 +110,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.90", + "syn", ] [[package]] @@ -121,14 +121,14 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.90", + "syn", ] [[package]] name = "defmt" -version = "0.3.8" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a99dd22262668b887121d4672af5a64b238f026099f1a2a1b322066c9ecfe9e0" +checksum = "86f6162c53f659f65d00619fe31f14556a6e9f8752ccc4a41bd177ffcf3d6130" dependencies = [ "bitflags 1.3.2", "defmt-macros", @@ -136,34 +136,24 @@ dependencies = [ [[package]] name = "defmt-macros" -version = "0.3.7" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18bdc7a7b92ac413e19e95240e75d3a73a8d8e78aa24a594c22cbb4d44b4bbda" +checksum = "9d135dd939bad62d7490b0002602d35b358dce5fd9233a709d3c1ef467d4bde6" dependencies = [ "defmt-parser", - "proc-macro-error", + "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] name = "defmt-parser" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4a5fefe330e8d7f31b16a318f9ce81000d8e35e69b93eae154d16d2278f70f" -dependencies = [ - "thiserror", -] - -[[package]] -name = "defmt-rtt" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab697b3dbbc1750b7c8b821aa6f6e7f2480b47a99bc057a2ed7b170ebef0c51" +checksum = "3983b127f13995e68c1e29071e5d115cd96f215ccb5e6812e3728cd6f92653b3" dependencies = [ - "critical-section", - "defmt", + "thiserror", ] [[package]] @@ -174,7 +164,7 @@ checksum = "bc2323e10c92e1cf4d86e11538512e6dc03ceb586842970b6332af3d4046a046" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -223,7 +213,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -357,10 +347,11 @@ dependencies = [ name = "embedded-test" version = "0.5.1" dependencies = [ + "defmt", "embassy-executor", "embedded-test-macros", "heapless 0.8.0", - "rtt-log", + "log", "semihosting", "serde", "serde-json-core", @@ -371,7 +362,6 @@ name = "embedded-test-example-for-esp32c6" version = "0.1.0" dependencies = [ "defmt", - "defmt-rtt", "embassy-executor", "embassy-time", "embedded-test", @@ -380,16 +370,17 @@ dependencies = [ "esp-hal-embassy", "esp-println", "log", + "rtt-target", ] [[package]] name = "embedded-test-macros" -version = "0.5.1" +version = "0.6.0" dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -401,7 +392,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -422,7 +413,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -448,7 +439,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b94a4b8d74e7cc7baabcca5b2277b41877e039ad9cd49959d48ef94dac7eab4b" dependencies = [ "quote", - "syn 2.0.90", + "syn", "termcolor", ] @@ -539,7 +530,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -699,9 +690,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", "hashbrown", @@ -718,9 +709,9 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -734,9 +725,9 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "minijinja" @@ -829,30 +820,6 @@ dependencies = [ "toml_edit", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro-error-attr2" version = "2.0.0" @@ -872,7 +839,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -926,7 +893,7 @@ checksum = "f265be5d634272320a7de94cea15c22a3bfdd4eb42eb43edc528415f066a1f25" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -943,50 +910,42 @@ checksum = "30f19a85fe107b65031e0ba8ec60c34c2494069fe910d6c297f5e7cb5a6f76d0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", -] - -[[package]] -name = "rtt-log" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7ae9de69f95134a36de2a40848955b56dc93ec337d9a08207c55f381c251ecb" -dependencies = [ - "log", - "once_cell", - "rtt-target", + "syn", ] [[package]] name = "rtt-target" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10b34c9e6832388e45f3c01f1bb60a016384a0a4ad80cdd7d34913bed25037f0" +version = "0.6.1" +source = "git+https://github.com/probe-rs/rtt-target?branch=feature/log#2f71e06fb87a90ab18def8b4cd4a5afe3808513b" dependencies = [ "critical-section", + "defmt", + "log", + "once_cell", + "portable-atomic", "ufmt-write", ] [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] [[package]] name = "rustversion" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "scopeguard" @@ -996,15 +955,15 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semihosting" -version = "0.1.7" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d218b01fb5153ebf1129a1a16c184aacdec3ca45cb816ba0782c21a02a20ae8" +checksum = "a5c5996e5d1dec34b0dff3285e27124e70964504e3fd361bce330dc476cebafd" [[package]] name = "semver" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" @@ -1034,7 +993,7 @@ checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -1095,17 +1054,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.90", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "unicode-ident", + "syn", ] [[package]] @@ -1130,22 +1079,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.56" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.56" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] [[package]] @@ -1190,9 +1139,9 @@ checksum = "e87a2ed6b42ec5e28cc3b94c09982969e9227600b2e3dcbc1db927a84c06bd69" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "vcell" @@ -1200,12 +1149,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "void" version = "1.0.2" @@ -1214,27 +1157,27 @@ checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" [[package]] name = "winapi-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ "windows-sys", ] [[package]] name = "windows-sys" -version = "0.52.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -1248,51 +1191,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" @@ -1341,5 +1284,5 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.90", + "syn", ] diff --git a/examples/esp32c6/Cargo.toml b/examples/esp32c6/Cargo.toml index c14a65f..8fbaeed 100644 --- a/examples/esp32c6/Cargo.toml +++ b/examples/esp32c6/Cargo.toml @@ -8,15 +8,10 @@ license = "MIT OR Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -# dependencies when using the log feature +# dependencies when using the log/defmt feature log = { version = "0.4.20", optional = true } - -# dependencies when using the demft feature defmt = { version = "0.3.8", optional = true } -defmt-rtt = { version = "0.4.1", optional = true } - -# dependencies when using the embassy feature -embassy-executor = { default-features = false, version = "0.6.0"} +rtt-target = { git = "https://github.com/probe-rs/rtt-target", branch = "feature/log", optional = true } # Esp32 related dependencies for main.rs. Note: embedded-test comes with its own panic handler and logging sink. esp-backtrace = { version = "0.14.2", features = [ @@ -24,21 +19,21 @@ esp-backtrace = { version = "0.14.2", features = [ "exception-handler", "panic-handler", "println", -]} +] } esp-hal = { version = "0.22.0", features = ["esp32c6"] } esp-println = { version = "0.12.0", features = ["esp32c6", "log"] } -embassy-time = { version = "0.3.1", features = ["generic-queue-8"] } -esp-hal-embassy = { version = "0.5.0", features = ["esp32c6"] } - +embassy-time = { version = "0.3.1", features = ["generic-queue-8"] } +esp-hal-embassy = { version = "0.5.0", features = ["esp32c6"] } +embassy-executor = { default-features = false, version = "0.6.0" } [dev-dependencies] -embedded-test = { version = "0.5.0" , features = ["embassy", "external-executor"], path="../.."} +embedded-test = { version = "0.5.0", features = ["embassy", "external-executor"], path = "../.." } [features] default = ["log"] -log = ["dep:log", "embedded-test/init-log"] -defmt = ["dep:defmt", "dep:defmt-rtt"] +log = ["dep:log", "dep:rtt-target", "rtt-target/log", "embedded-test/log"] +defmt = ["dep:defmt", "dep:rtt-target", "rtt-target/defmt", "embedded-test/defmt"] [[bin]] name = "embedded-test-example-for-esp32c6" diff --git a/examples/esp32c6/src/lib.rs b/examples/esp32c6/src/lib.rs index 2e7f0d4..0c9ac1a 100644 --- a/examples/esp32c6/src/lib.rs +++ b/examples/esp32c6/src/lib.rs @@ -1 +1 @@ -#![no_std] \ No newline at end of file +#![no_std] diff --git a/examples/esp32c6/src/main.rs b/examples/esp32c6/src/main.rs index a5fea2d..30e9cdc 100644 --- a/examples/esp32c6/src/main.rs +++ b/examples/esp32c6/src/main.rs @@ -2,9 +2,9 @@ #![no_main] use embassy_executor::Spawner; -use embassy_time::{Timer, Duration}; +use embassy_time::{Duration, Timer}; use esp_backtrace as _; -use esp_hal::{prelude::*}; +use esp_hal::prelude::*; use log::info; /// ====> Look in the tests directory to see how embedded-test works <==== @@ -31,5 +31,3 @@ async fn main(_spawner: Spawner) -> ! { Timer::after(Duration::from_secs(1)).await; } } - - diff --git a/examples/esp32c6/tests/example_test.rs b/examples/esp32c6/tests/example_test.rs index ef6d030..5bc6233 100644 --- a/examples/esp32c6/tests/example_test.rs +++ b/examples/esp32c6/tests/example_test.rs @@ -3,14 +3,23 @@ struct Context { #[allow(dead_code)] - i2c0: esp_hal::peripherals::I2C0 + i2c0: esp_hal::peripherals::I2C0, +} + +/// Sets up the logging before entering the test-body, so that embedded-test internal logs (e.g. Running Test <...>) can also be printed. +/// Note: you can also inline this method in the attribute. e.g. `#[embedded_test::tests(setup=rtt_target::rtt_init_log!())]` +fn setup_log() { + #[cfg(feature = "log")] + rtt_target::rtt_init_log!(); + #[cfg(feature = "defmt")] + rtt_target::rtt_init_defmt!(); } #[cfg(test)] -#[embedded_test::tests(executor=esp_hal_embassy::Executor::new())] +#[embedded_test::tests(executor=esp_hal_embassy::Executor::new(), setup=crate::setup_log())] mod tests { - use esp_hal::{prelude::*}; use super::*; + use esp_hal::prelude::*; // Optional: A init function which is called before every test // asyncness of init fn is optional @@ -27,7 +36,9 @@ mod tests { esp_hal_embassy::init(timer0.alarm0); // The init function can return some state, which can be consumed by the testcases - Context { i2c0: peripherals.I2C0} + Context { + i2c0: peripherals.I2C0, + } } // A test which takes the state returned by the init function (optional) @@ -41,7 +52,7 @@ mod tests { #[test] #[cfg(feature = "log")] fn log() { - log::info!("Hello, log!"); // Prints via esp-println to rtt + log::info!("Hello, log!"); assert!(true) } @@ -49,8 +60,7 @@ mod tests { #[test] #[cfg(feature = "defmt")] fn defmt() { - use defmt_rtt as _; - defmt::info!("Hello, defmt!"); // Prints via defmt-rtt to rtt + defmt::info!("Hello, defmt!"); assert!(true) } @@ -98,4 +108,4 @@ mod tests { fn it_timeouts() { loop {} // should run into the 10s timeout } -} \ No newline at end of file +} diff --git a/examples/stm32f767/Cargo.lock b/examples/stm32f767/Cargo.lock index 2b97013..ab7e1b0 100644 --- a/examples/stm32f767/Cargo.lock +++ b/examples/stm32f767/Cargo.lock @@ -118,9 +118,9 @@ dependencies = [ [[package]] name = "critical-section" -version = "1.1.2" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" [[package]] name = "darling" @@ -189,16 +189,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "defmt-rtt" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab697b3dbbc1750b7c8b821aa6f6e7f2480b47a99bc057a2ed7b170ebef0c51" -dependencies = [ - "critical-section", - "defmt", -] - [[package]] name = "deranged" version = "0.3.11" @@ -260,7 +250,6 @@ dependencies = [ "embedded-test-macros", "heapless 0.8.0", "log", - "rtt-log", "semihosting", "serde", "serde-json-core", @@ -273,16 +262,16 @@ dependencies = [ "cortex-m", "cortex-m-rt", "defmt", - "defmt-rtt", "embassy-executor", "embedded-test", "log", + "rtt-target", "stm32f7xx-hal", ] [[package]] name = "embedded-test-macros" -version = "0.5.1" +version = "0.6.0" dependencies = [ "darling", "proc-macro2", @@ -386,9 +375,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "micromath" @@ -419,9 +408,9 @@ checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" dependencies = [ "critical-section", "portable-atomic", @@ -485,24 +474,16 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -[[package]] -name = "rtt-log" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7ae9de69f95134a36de2a40848955b56dc93ec337d9a08207c55f381c251ecb" -dependencies = [ - "log", - "once_cell", - "rtt-target", -] - [[package]] name = "rtt-target" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10b34c9e6832388e45f3c01f1bb60a016384a0a4ad80cdd7d34913bed25037f0" +version = "0.6.1" +source = "git+https://github.com/probe-rs/rtt-target?branch=feature/log#2f71e06fb87a90ab18def8b4cd4a5afe3808513b" dependencies = [ "critical-section", + "defmt", + "log", + "once_cell", + "portable-atomic", "ufmt-write", ] diff --git a/examples/stm32f767/Cargo.toml b/examples/stm32f767/Cargo.toml index 1cdc1f7..9451c02 100644 --- a/examples/stm32f767/Cargo.toml +++ b/examples/stm32f767/Cargo.toml @@ -8,31 +8,25 @@ license = "MIT OR Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cortex-m = { version = "0.7" , features = ["critical-section-single-core"]} +cortex-m = { version = "0.7", features = ["critical-section-single-core"] } cortex-m-rt = "0.7" -stm32f7xx-hal = { version = "0.8" , features = ["stm32f767"]} # replace the model of your microcontroller here - -embassy-executor = { default-features = false, version="0.6.0", features = ["executor-thread", "arch-cortex-m"] } -# Note: You need to enable at least one executor feature on embassy 0.5.x - -# dependencies when using the log feature -log = { version = "0.4.20", optional = true} - -# dependencies when using the demft feature -defmt = { version = "0.3.5", optional = true } -defmt-rtt = { version = "0.4.0", optional = true } +stm32f7xx-hal = { version = "0.8", features = ["stm32f767"] } # replace the model of your microcontroller here +embassy-executor = { default-features = false, version = "0.6.0", features = ["executor-thread", "arch-cortex-m"] } +# Note: You need to enable at least one executor feature on embassy 0.6.x +# dependencies when using the log/defmt feature +log = { version = "0.4.20", optional = true } +defmt = { version = "0.3.8", optional = true } +rtt-target = { git = "https://github.com/probe-rs/rtt-target", branch = "feature/log", optional = true } [dev-dependencies] -embedded-test = {version="0.5.0", features = ["embassy"], path= "../.."} - +embedded-test = { version = "0.5.0", features = ["embassy"], path = "../.." } [features] default = ["log"] -log = ["dep:log", "embedded-test/log", "embedded-test/init-log"] -defmt = ["dep:defmt-rtt", "dep:defmt", "embedded-test/defmt"] -# Note: You must adapt .cargo/config when disabling the defmt feature +log = ["dep:log", "dep:rtt-target", "rtt-target/log", "embedded-test/log"] +defmt = ["dep:defmt", "dep:rtt-target", "rtt-target/defmt", "embedded-test/defmt"] [[bin]] name = "embedded-test-example-for-stm32f767" diff --git a/examples/stm32f767/src/lib.rs b/examples/stm32f767/src/lib.rs index 2e7f0d4..0c9ac1a 100644 --- a/examples/stm32f767/src/lib.rs +++ b/examples/stm32f767/src/lib.rs @@ -1 +1 @@ -#![no_std] \ No newline at end of file +#![no_std] diff --git a/examples/stm32f767/src/main.rs b/examples/stm32f767/src/main.rs index 58de150..bebdbca 100644 --- a/examples/stm32f767/src/main.rs +++ b/examples/stm32f767/src/main.rs @@ -3,7 +3,6 @@ /// ====> Look in the tests directory to see how embedded-test works <==== /// This file here is just a simple blinky example, as found in the examples of the stm32f7xx-hal crate. - use core::panic::PanicInfo; use stm32f7xx_hal::gpio::GpioExt; use stm32f7xx_hal::pac; @@ -42,5 +41,3 @@ fn main() -> ! { fn panic(_panic: &PanicInfo<'_>) -> ! { loop {} } - - diff --git a/examples/stm32f767/tests/example_test.rs b/examples/stm32f767/tests/example_test.rs index f20a2db..219c13c 100644 --- a/examples/stm32f767/tests/example_test.rs +++ b/examples/stm32f767/tests/example_test.rs @@ -1,19 +1,25 @@ #![no_std] #![no_main] +/// Sets up the logging before entering the test-body, so that embedded-test internal logs (e.g. Running Test <...>) can also be printed. +/// Note: you can also inline this method in the attribute. e.g. `#[embedded_test::tests(setup=rtt_target::rtt_init_log!())]` +fn setup_log() { + #[cfg(feature = "log")] + rtt_target::rtt_init_log!(); + #[cfg(feature = "defmt")] + rtt_target::rtt_init_defmt!(); +} + #[cfg(test)] -#[embedded_test::tests] +#[embedded_test::tests(setup=crate::setup_log())] mod unit_tests { - - // import hal which provides exception handler - use stm32f7xx_hal::{pac::Peripherals}; + use stm32f7xx_hal::pac::Peripherals; // Optional: A init function which is called before every test - // asyncness is optional and needs feature embassy + // async + return value are optional #[init] async fn init() -> Peripherals { - let p = Peripherals::take().unwrap(); - p + Peripherals::take().unwrap() } // A test which takes the state returned by the init function (optional) @@ -27,7 +33,7 @@ mod unit_tests { #[test] #[cfg(feature = "log")] fn log() { - log::info!("Hello, log!"); // Prints via esp-println to rtt + log::info!("Hello, log!"); assert!(true) } @@ -35,8 +41,7 @@ mod unit_tests { #[test] #[cfg(feature = "defmt")] fn defmt() { - use defmt_rtt as _; - defmt::info!("Hello, defmt!"); // Prints via defmt-rtt to rtt + defmt::info!("Hello, defmt!"); assert!(true) } diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 04ad4b8..50e535b 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "embedded-test-macros" description = "proc-macros for the embedded-test crate" -version = "0.5.1" +version = "0.6.0" edition = "2021" repository = "https://github.com/probe-rs/embedded-test" license = "MIT OR Apache-2.0" diff --git a/macros/src/lib.rs b/macros/src/lib.rs index b403520..2e3219c 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -62,6 +62,7 @@ fn tests_impl(args: TokenStream, input: TokenStream) -> parse::Result, default_timeout: Option, + setup: Option, } let attr_args = match NestedMeta::parse_meta_list(args.into()) { @@ -411,6 +412,7 @@ fn tests_impl(args: TokenStream, input: TokenStream) -> parse::Result parse::Result ! { - #krate::export::init_logging(); + { + #setup + } + const TEST_COUNT : usize = #test_count; const TEST_NAMES_STRLEN : usize = #test_names_strlen; let mut test_funcs: #krate::export::Vec<#krate::export::Test, TEST_COUNT> = #krate::export::Vec::new(); diff --git a/src/export.rs b/src/export.rs index 61974c8..2463acd 100644 --- a/src/export.rs +++ b/src/export.rs @@ -116,12 +116,3 @@ pub fn check_outcome(outcome: T) -> ! { semihosting::process::abort(); } } - -pub fn init_logging() { - #[cfg(feature = "init-rtt")] - rtt_target::rtt_init_print!(); - #[cfg(feature = "init-log")] - rtt_log::init(); - - // Unfortunately we can't do the same with defmt_rtt as this needs to be registered as `#[defmt::global_logger]` in the toplevel crate -}