Enable capturing asserts inside simulator

When building in simulator mode, mock assert() to call an simulator
function which will enable other code to check if some path failed.

The assert checking interface, was added to boot_go which now
returns the low-level invocation results as well as the number of
asserts triggered.

Some new added tests check for assert() and expect it to happen. To not
abort tests, assert() was changed under sim env to not call c assert()
and instead just do some internal calculation which could be checked
by the simulator after a bootloader run and assert() catching behavior
was made optional (each test choses the behavior it needs).

Signed-off-by: Fabio Utzig <utzig@apache.org>
diff --git a/sim/mcuboot-sys/src/c.rs b/sim/mcuboot-sys/src/c.rs
index 9f364cb..3400bc0 100644
--- a/sim/mcuboot-sys/src/c.rs
+++ b/sim/mcuboot-sys/src/c.rs
@@ -13,11 +13,14 @@
 }
 
 /// Invoke the bootloader on this flash device.
-pub fn boot_go(flash: &mut Flash, areadesc: &AreaDesc, counter: Option<&mut i32>, align: u8) -> i32 {
+pub fn boot_go(flash: &mut Flash, areadesc: &AreaDesc, counter: Option<&mut i32>,
+               align: u8, catch_asserts: bool) -> (i32, u8) {
     let _lock = BOOT_LOCK.lock().unwrap();
 
     unsafe {
         api::set_flash(flash);
+        raw::c_catch_asserts = if catch_asserts { 1 } else { 0 };
+        raw::c_asserts = 0u8;
         raw::sim_flash_align = align;
         raw::flash_counter = match counter {
             None => 0,
@@ -25,11 +28,12 @@
         };
     }
     let result = unsafe { raw::invoke_boot_go(&areadesc.get_c() as *const _) as i32 };
+    let asserts = unsafe { raw::c_asserts };
     unsafe {
         counter.map(|c| *c = raw::flash_counter as i32);
         api::clear_flash();
     };
-    result
+    (result, asserts)
 }
 
 pub fn boot_trailer_sz(align: u8) -> u32 {
@@ -65,6 +69,8 @@
         // for information and tracking.
         pub fn invoke_boot_go(areadesc: *const CAreaDesc) -> libc::c_int;
         pub static mut flash_counter: libc::c_int;
+        pub static mut c_asserts: u8;
+        pub static mut c_catch_asserts: u8;
 
         pub static mut sim_flash_align: u8;
         pub fn boot_slots_trailer_sz(min_write_sz: u8) -> u32;