diff --git a/sim/src/lib.rs b/sim/src/lib.rs index fe2d52e3..d42a7b74 100644 --- a/sim/src/lib.rs +++ b/sim/src/lib.rs @@ -21,6 +21,7 @@ use std::slice; mod caps; mod tlv; +pub mod testlog; use simflash::{Flash, SimFlash}; use mcuboot_sys::{c, AreaDesc, FlashId}; diff --git a/sim/src/testlog.rs b/sim/src/testlog.rs new file mode 100644 index 00000000..c62e0076 --- /dev/null +++ b/sim/src/testlog.rs @@ -0,0 +1,19 @@ +//! Logging support for the test framework. +//! +//! https://stackoverflow.com/questions/30177845/how-to-initialize-the-logger-for-integration-tests +//! +//! The test framework runs the tests, possibly simultaneously, and in various orders. This helper +//! function, which should be called at the beginning of each test, will setup logging for all of +//! the tests. + +use env_logger; +use std::sync::{Once, ONCE_INIT}; + +static INIT: Once = ONCE_INIT; + +/// Setup the logging system. Intended to be called at the beginning of each test. +pub fn setup() { + INIT.call_once(|| { + env_logger::init().unwrap(); + }); +} diff --git a/sim/tests/core.rs b/sim/tests/core.rs index dea9cfed..010f2407 100644 --- a/sim/tests/core.rs +++ b/sim/tests/core.rs @@ -5,9 +5,12 @@ extern crate bootsim; use bootsim::{ALL_DEVICES, RunStatus}; +use bootsim::testlog; #[test] fn core_tests() { + testlog::setup(); + let mut status = RunStatus::new(); for &dev in ALL_DEVICES {