Loading sim/src/main.rs +73 −3 Changes for sim/src/main.rs: 73 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -150,7 +150,7 @@ fn main() { error!("{} Tests ran with {} failures", status.failures + status.passes, status.failures); process::exit(1); } else { warn!("{} Tests ran successfully", status.passes); error!("{} Tests ran successfully", status.passes); process::exit(0); } } Loading Loading @@ -257,6 +257,8 @@ impl RunStatus { // Set an alignment, and position the magic value. c::set_sim_flash_align(align); failed |= run_norevert_newimage(&flash, &areadesc, &images); mark_upgrade(&mut flash, &images.slot1); // upgrades without fails, counts number of flash operations Loading Loading @@ -305,12 +307,13 @@ fn run_basic_upgrade(flash: &SimFlash, areadesc: &AreaDesc, images: &Images) fn run_basic_revert(flash: &SimFlash, areadesc: &AreaDesc, images: &Images) -> bool { let mut fails = 0; // FIXME: this test would also pass if no swap is ever performed??? if Caps::SwapUpgrade.present() { for count in 2 .. 5 { info!("Try revert: {}", count); let fl = try_revert(&flash, &areadesc, count); if !verify_image(&fl, images.slot0.base_off, &images.primary) { warn!("Revert failure on count {}", count); error!("Revert failure on count {}", count); fails += 1; } } Loading Loading @@ -353,8 +356,10 @@ fn run_perm_with_fails(flash: &SimFlash, areadesc: &AreaDesc, images: &Images, } } info!("{} out of {} failed {:.2}%", fails, total_flash_ops, if fails > 0 { error!("{} out of {} failed {:.2}%", fails, total_flash_ops, fails as f32 * 100.0 / total_flash_ops as f32); } fails > 0 } Loading Loading @@ -390,6 +395,10 @@ fn run_perm_with_random_fails(flash: &SimFlash, areadesc: &AreaDesc, fails += 1; } if fails > 0 { error!("Error testing perm upgrade with {} fails", total_fails); } fails > 0 } Loading @@ -401,6 +410,7 @@ fn run_revert_with_fails(flash: &SimFlash, areadesc: &AreaDesc, images: &Images, for i in 1 .. (total_count - 1) { info!("Try interruption at {}", i); if try_revert_with_fail_at(&flash, &areadesc, &images, i) { error!("Revert failed at interruption {}", i); fails += 1; } } Loading @@ -422,6 +432,9 @@ fn run_norevert(flash: &SimFlash, areadesc: &AreaDesc, images: &Images) -> bool fails += 1; } //FIXME: copy_done is written by boot_go, is it ok if no copy // was ever done? if !verify_image(&fl, images.slot0.base_off, &images.upgrade) { warn!("Slot 0 image verification FAIL"); fails += 1; Loading @@ -440,6 +453,12 @@ fn run_norevert(flash: &SimFlash, areadesc: &AreaDesc, images: &Images) -> bool // Marks image in slot0 as permanent, no revert should happen... mark_permanent_upgrade(&mut fl, &images.slot0); if !verify_trailer(&fl, images.slot0.trailer_off, MAGIC_VALID, IMAGE_OK, COPY_DONE) { warn!("Mismatched trailer for Slot 0"); fails += 1; } if c::boot_go(&mut fl, &areadesc) != 0 { warn!("Failed second boot"); fails += 1; Loading @@ -455,6 +474,57 @@ fn run_norevert(flash: &SimFlash, areadesc: &AreaDesc, images: &Images) -> bool fails += 1; } if fails > 0 { error!("Error running upgrade without revert"); } fails > 0 } // Tests a new image written to slot0 that already has magic and image_ok set // while there is no image on slot1, so no revert should ever happen... fn run_norevert_newimage(flash: &SimFlash, areadesc: &AreaDesc, images: &Images) -> bool { let mut fl = flash.clone(); let mut fails = 0; info!("Try non-revert on imgtool generated image"); c::set_flash_counter(0); mark_upgrade(&mut fl, &images.slot0); // This simulates writing an image created by imgtool to Slot 0 if !verify_trailer(&fl, images.slot0.trailer_off, MAGIC_VALID, UNSET, UNSET) { warn!("Mismatched trailer for Slot 0"); fails += 1; } // Run the bootloader... if c::boot_go(&mut fl, &areadesc) != 0 { warn!("Failed first boot"); fails += 1; } // State should not have changed if !verify_image(&fl, images.slot0.base_off, &images.primary) { warn!("Failed image verification"); fails += 1; } if !verify_trailer(&fl, images.slot0.trailer_off, MAGIC_VALID, UNSET, UNSET) { warn!("Mismatched trailer for Slot 0"); fails += 1; } if !verify_trailer(&fl, images.slot1.trailer_off, MAGIC_UNSET, UNSET, UNSET) { warn!("Mismatched trailer for Slot 1"); fails += 1; } if fails > 0 { error!("Expected a non revert with new image"); } fails > 0 } Loading Loading
sim/src/main.rs +73 −3 Changes for sim/src/main.rs: 73 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -150,7 +150,7 @@ fn main() { error!("{} Tests ran with {} failures", status.failures + status.passes, status.failures); process::exit(1); } else { warn!("{} Tests ran successfully", status.passes); error!("{} Tests ran successfully", status.passes); process::exit(0); } } Loading Loading @@ -257,6 +257,8 @@ impl RunStatus { // Set an alignment, and position the magic value. c::set_sim_flash_align(align); failed |= run_norevert_newimage(&flash, &areadesc, &images); mark_upgrade(&mut flash, &images.slot1); // upgrades without fails, counts number of flash operations Loading Loading @@ -305,12 +307,13 @@ fn run_basic_upgrade(flash: &SimFlash, areadesc: &AreaDesc, images: &Images) fn run_basic_revert(flash: &SimFlash, areadesc: &AreaDesc, images: &Images) -> bool { let mut fails = 0; // FIXME: this test would also pass if no swap is ever performed??? if Caps::SwapUpgrade.present() { for count in 2 .. 5 { info!("Try revert: {}", count); let fl = try_revert(&flash, &areadesc, count); if !verify_image(&fl, images.slot0.base_off, &images.primary) { warn!("Revert failure on count {}", count); error!("Revert failure on count {}", count); fails += 1; } } Loading Loading @@ -353,8 +356,10 @@ fn run_perm_with_fails(flash: &SimFlash, areadesc: &AreaDesc, images: &Images, } } info!("{} out of {} failed {:.2}%", fails, total_flash_ops, if fails > 0 { error!("{} out of {} failed {:.2}%", fails, total_flash_ops, fails as f32 * 100.0 / total_flash_ops as f32); } fails > 0 } Loading Loading @@ -390,6 +395,10 @@ fn run_perm_with_random_fails(flash: &SimFlash, areadesc: &AreaDesc, fails += 1; } if fails > 0 { error!("Error testing perm upgrade with {} fails", total_fails); } fails > 0 } Loading @@ -401,6 +410,7 @@ fn run_revert_with_fails(flash: &SimFlash, areadesc: &AreaDesc, images: &Images, for i in 1 .. (total_count - 1) { info!("Try interruption at {}", i); if try_revert_with_fail_at(&flash, &areadesc, &images, i) { error!("Revert failed at interruption {}", i); fails += 1; } } Loading @@ -422,6 +432,9 @@ fn run_norevert(flash: &SimFlash, areadesc: &AreaDesc, images: &Images) -> bool fails += 1; } //FIXME: copy_done is written by boot_go, is it ok if no copy // was ever done? if !verify_image(&fl, images.slot0.base_off, &images.upgrade) { warn!("Slot 0 image verification FAIL"); fails += 1; Loading @@ -440,6 +453,12 @@ fn run_norevert(flash: &SimFlash, areadesc: &AreaDesc, images: &Images) -> bool // Marks image in slot0 as permanent, no revert should happen... mark_permanent_upgrade(&mut fl, &images.slot0); if !verify_trailer(&fl, images.slot0.trailer_off, MAGIC_VALID, IMAGE_OK, COPY_DONE) { warn!("Mismatched trailer for Slot 0"); fails += 1; } if c::boot_go(&mut fl, &areadesc) != 0 { warn!("Failed second boot"); fails += 1; Loading @@ -455,6 +474,57 @@ fn run_norevert(flash: &SimFlash, areadesc: &AreaDesc, images: &Images) -> bool fails += 1; } if fails > 0 { error!("Error running upgrade without revert"); } fails > 0 } // Tests a new image written to slot0 that already has magic and image_ok set // while there is no image on slot1, so no revert should ever happen... fn run_norevert_newimage(flash: &SimFlash, areadesc: &AreaDesc, images: &Images) -> bool { let mut fl = flash.clone(); let mut fails = 0; info!("Try non-revert on imgtool generated image"); c::set_flash_counter(0); mark_upgrade(&mut fl, &images.slot0); // This simulates writing an image created by imgtool to Slot 0 if !verify_trailer(&fl, images.slot0.trailer_off, MAGIC_VALID, UNSET, UNSET) { warn!("Mismatched trailer for Slot 0"); fails += 1; } // Run the bootloader... if c::boot_go(&mut fl, &areadesc) != 0 { warn!("Failed first boot"); fails += 1; } // State should not have changed if !verify_image(&fl, images.slot0.base_off, &images.primary) { warn!("Failed image verification"); fails += 1; } if !verify_trailer(&fl, images.slot0.trailer_off, MAGIC_VALID, UNSET, UNSET) { warn!("Mismatched trailer for Slot 0"); fails += 1; } if !verify_trailer(&fl, images.slot1.trailer_off, MAGIC_UNSET, UNSET, UNSET) { warn!("Mismatched trailer for Slot 1"); fails += 1; } if fails > 0 { error!("Expected a non revert with new image"); } fails > 0 } Loading