### Configure Embedded Test Suite with Options Source: https://docs.rs/embedded-test/0.6.2/embedded_test/attr This snippet shows a more advanced configuration of the `#[embedded_test::tests]` attribute, allowing customization of `default_timeout`, `executor`, and `setup` functions. It also includes a test with a specific timeout. ```rust #[embedded_test::tests(default_timeout = 10, executor = embassy::executor::Executor::new(), setup = rtt_target::rtt_init_log!())] mod tests { #[init] fn init() { // Initialize the hardware } #[test] fn test() { log::info("Start....") // Test the hardware } #[test] #[timeout(5)] fn test2() { // Test the hardware } } ``` -------------------------------- ### Example embedded-test test module in Rust Source: https://docs.rs/embedded-test/0.6.2/embedded_test/index This Rust code demonstrates how to define a test module for embedded-test. It includes an optional async init function, various types of tests (async, conditional, ignored, failing, panicking, timeout), and shows how to use the state returned by the init function. ```rust #![no_std] #![no_main] #[cfg(test)] #[embedded_test::tests] mod tests { use stm32f7xx_hal::pac::Peripherals; // An optional init function which is called before every test // Asyncness is optional, so is the return value #[init] async fn init() -> Peripherals { Peripherals::take().unwrap() } // Tests can be async (needs feature `embassy`) // Tests can take the state returned by the init function (optional) #[test] async fn takes_state(_state: Peripherals) { assert!(true) } // Tests can be conditionally enabled (with a cfg attribute) #[test] #[cfg(feature = "log")] fn log() { rtt_target::rtt_init_log!(); log::info!("Hello, log!"); assert!(true) } // Tests can be ignored with the #[ignore] attribute #[test] #[ignore] fn it_works_ignored() { assert!(false) } // Tests can fail with a custom error message by returning a Result #[test] fn it_fails_with_err() -> Result<(), &'static str> { Err("It failed because ...") } // Tests can be annotated with #[should_panic] if they are expected to panic #[test] #[should_panic] fn it_passes() { assert!(false) } // Tests can be annotated with #[timeout()] to change the default timeout of 60s #[test] #[timeout(10)] fn it_timeouts() { loop {} // should run into the 10s timeout } } ``` -------------------------------- ### Define Embedded Test Suite using #[tests] Attribute Source: https://docs.rs/embedded-test/0.6.2/embedded_test/attr This snippet demonstrates how to define a test suite module using the `#[embedded_test::tests]` attribute. It includes optional `init` and `test` functions for hardware initialization and testing. ```rust #[embedded_test::tests] mod tests { #[init] fn init() { // Initialize the hardware } #[test] fn test() { // Test the hardware } } ``` -------------------------------- ### Configure probe-rs runner in .cargo/config.toml Source: https://docs.rs/embedded-test/0.6.2/embedded_test/index This snippet demonstrates how to set up probe-rs as the test runner in your .cargo/config.toml file, specifying the target architecture and chip. ```toml [target.thumbv7em-none-eabihf] runner = "probe-rs run --chip STM32F767ZITx" # `probe-rs run` will autodetect whether the elf to flash is a normal firmware or a test binary ``` -------------------------------- ### Linker script argument in build.rs Source: https://docs.rs/embedded-test/0.6.2/embedded_test/index This Rust build script snippet adds a linker argument to specify the embedded-test linker script, which is necessary for the test harness to function correctly. ```rust fn main() { println!("cargo::rustc-link-arg-tests=-Tembedded-test.x"); } ``` -------------------------------- ### Add embedded-test to Cargo.toml Source: https://docs.rs/embedded-test/0.6.2/embedded_test/index This snippet shows how to add the embedded-test crate as a development dependency in your Cargo.toml file and configure it as a test harness. ```toml [dev-dependencies] embedded-test = { version = "0.6.0" } [[test]] name = "example_test" harness = false ``` -------------------------------- ### Rust Implementation: TestOutcome for Result Source: https://docs.rs/embedded-test/0.6.2/embedded_test/trait Implements the TestOutcome trait for the `Result` type. It returns `true` for `Ok` variants and `false` for `Err` variants, indicating test success or failure respectively. ```rust impl TestOutcome for Result { fn is_success(&self) -> bool { // Implementation details... self.is_ok() } } ``` -------------------------------- ### Rust Implementation: TestOutcome for () Source: https://docs.rs/embedded-test/0.6.2/embedded_test/trait Implements the TestOutcome trait for the unit type `()`. This implementation always returns `true`, signifying a successful test. ```rust impl TestOutcome for () { fn is_success(&self) -> bool { // Implementation details... true } } ``` -------------------------------- ### Rust Trait Definition: TestOutcome Source: https://docs.rs/embedded-test/0.6.2/embedded_test/trait Defines the TestOutcome trait, which indicates whether a test succeeded or failed. It requires a single method, `is_success()`, which returns a boolean value. ```rust pub trait TestOutcome: Sealed { // Required method fn is_success(&self) -> bool; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.