//! This example shows how a embedded program can be written that is testable on the host with //! libtest. //! //! The tests can be run with: //! ```bash //! cargo test --example=test-on-host --target=x86_64-unknown-linux-gnu //! ``` #![cfg_attr(not(test), no_main)] #![no_std] #[cfg(not(test))] extern crate panic_halt; use hal::{pac, prelude::*, rcc::Config}; #[cfg_attr(not(test), cortex_m_rt::entry)] // this is the entrypoint unless testing fn main() -> ! { let dp = pac::Peripherals::take().unwrap(); let cp = cortex_m::Peripherals::take().unwrap(); // Configure the clock. let mut rcc = dp.RCC.freeze(Config::hsi16()); // Acquire the GPIOA peripheral. This also enables the clock for GPIOA in // the RCC register. let gpioa = dp.GPIOA.split(&mut rcc); // Configure PA5 as output. let mut led = gpioa.pa5.into_push_pull_output(); // Get the delay provider. let mut delay = cp.SYST.delay(rcc.clocks); loop { led.set_high().unwrap(); delay.delay_ms(500_u16); let important_number = some_function(19); delay.delay_ms(important_number as u16); led.set_low().unwrap(); delay.delay_ms(500_u16); } } fn some_function(num: i32) -> i32 { num * 2 } #[cfg(test)] mod tests { use crate::some_function; #[test] fn test_it_works() { assert_eq!(some_function(9), 18) } }