sim: Use logging to control output
Use the Rust logging so that normal messaging isn't overwhelmed by
messages printed. The default level is 'error' which will only print
full errors (including the failures at the end).
To run with warnings:
RUST_LOG=warn ./target/release/bootsim ...
This will print warnings, showing the particular failures in mind.
Using 'info' instead of 'warn' will print lots of progress as it runs.
diff --git a/sim/Cargo.lock b/sim/Cargo.lock
index 75ff4ae..9c43c4b 100644
--- a/sim/Cargo.lock
+++ b/sim/Cargo.lock
@@ -3,9 +3,11 @@
version = "0.1.0"
dependencies = [
"docopt 0.6.86 (registry+https://github.com/rust-lang/crates.io-index)",
+ "env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"error-chain 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gcc 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -67,6 +69,15 @@
]
[[package]]
+name = "env_logger"
+version = "0.3.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "error-chain"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -99,6 +110,11 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "log"
+version = "0.3.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "memchr"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -185,11 +201,13 @@
"checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c"
"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850"
"checksum docopt 0.6.86 (registry+https://github.com/rust-lang/crates.io-index)" = "4a7ef30445607f6fc8720f0a0a2c7442284b629cf0d049286860fae23e71c4d9"
+"checksum env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f"
"checksum error-chain 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1cd681735364a04cd5d69f01a4f6768e70473941f8d86d8c224faf6955a75799"
"checksum gcc 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)" = "553f11439bdefe755bf366b264820f1da70f3aaf3924e594b886beb9c831bcf5"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b"
"checksum libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "044d1360593a78f5c8e5e710beccdc24ab71d1f01bc19a29bcacdba22e8475d8"
+"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
"checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f"
diff --git a/sim/Cargo.toml b/sim/Cargo.toml
index 6f685d5..a93f299 100644
--- a/sim/Cargo.toml
+++ b/sim/Cargo.toml
@@ -13,6 +13,8 @@
error-chain = "0.7.1"
docopt = "0.6"
rustc-serialize = "0.3"
+log = "0.3"
+env_logger = "0.3"
[profile.test]
opt-level = 1
diff --git a/sim/csupport/run.c b/sim/csupport/run.c
index 677f40c..e24531f 100644
--- a/sim/csupport/run.c
+++ b/sim/csupport/run.c
@@ -43,7 +43,7 @@
flash_areas = adesc;
if (setjmp(boot_jmpbuf) == 0) {
res = boot_go(&rsp);
- printf("boot_go result: %d (0x%08x)\n", res, rsp.br_image_addr);
+ /* printf("boot_go result: %d (0x%08x)\n", res, rsp.br_image_addr); */
return res;
} else {
return -0x13579;
diff --git a/sim/src/main.rs b/sim/src/main.rs
index 6822605..1f17f17 100644
--- a/sim/src/main.rs
+++ b/sim/src/main.rs
@@ -1,3 +1,5 @@
+#[macro_use] extern crate log;
+extern crate env_logger;
extern crate docopt;
extern crate libc;
extern crate rand;
@@ -65,6 +67,8 @@
}
fn main() {
+ env_logger::init().unwrap();
+
let args: Args = Docopt::new(USAGE)
.and_then(|d| d.decode())
.unwrap_or_else(|e| e.exit());
@@ -117,33 +121,33 @@
mark_upgrade(&mut flash, 0x060000 - trailer_size as usize);
let (fl2, total_count) = try_upgrade(&flash, &areadesc, None);
- println!("First boot, count={}", total_count);
+ info!("First boot, count={}", total_count);
assert!(verify_image(&fl2, 0x020000, &upgrade));
let mut bad = 0;
// Let's try an image halfway through.
for i in 1 .. total_count {
- println!("Try interruption at {}", i);
+ info!("Try interruption at {}", i);
let (fl3, total_count) = try_upgrade(&flash, &areadesc, Some(i));
- println!("Second boot, count={}", total_count);
+ info!("Second boot, count={}", total_count);
if !verify_image(&fl3, 0x020000, &upgrade) {
- println!("FAIL");
+ warn!("FAIL at step {} of {}", i, total_count);
bad += 1;
}
if !verify_image(&fl3, 0x040000, &primary) {
- println!("Slot 1 FAIL");
+ warn!("Slot 1 FAIL at step {} of {}", i, total_count);
bad += 1;
}
}
- println!("{} out of {} failed {:.2}%",
- bad, total_count,
- bad as f32 * 100.0 / total_count as f32);
+ error!("{} out of {} failed {:.2}%",
+ bad, total_count,
+ bad as f32 * 100.0 / total_count as f32);
- println!("Try revert");
+ info!("Try revert");
let fl2 = try_revert(&flash, &areadesc);
assert!(verify_image(&fl2, 0x020000, &primary));
- println!("Try norevert");
+ info!("Try norevert");
let fl2 = try_norevert(&flash, &areadesc);
assert!(verify_image(&fl2, 0x020000, &upgrade));
@@ -276,7 +280,7 @@
if buf != ©[..] {
for i in 0 .. buf.len() {
if buf[i] != copy[i] {
- println!("First failure at {:#x}", offset + i);
+ info!("First failure at {:#x}", offset + i);
break;
}
}