Commit ca7b5d33 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

sim: Enable logging in simulator test cases

When running simulations as unit tests, use a workaround from
https://stackoverflow.com/questions/30177845/how-to-initialize-the-logger-for-integration-tests
to initialize the logging system.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent dd2b118b
Loading
Loading
Loading
Loading
+1
Changes for sim/src/lib.rs: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ use std::slice;

mod caps;
mod tlv;
pub mod testlog;

use simflash::{Flash, SimFlash};
use mcuboot_sys::{c, AreaDesc, FlashId};
+19
Changes for sim/src/testlog.rs: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
//! 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();
    });
}
+3
Changes for sim/tests/core.rs: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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 {