sim: Skip (most) tests when flash is not modified
Some configurations of MCUboot do not modify the flash, but instead
MCUboot operates in a mode where it detects the best image to run.
Detect this, and skip what is currently a majority of the tests that
expect the upgrade to be moving data around in flash.
Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/sim/src/image.rs b/sim/src/image.rs
index 5898560..d5355eb 100644
--- a/sim/src/image.rs
+++ b/sim/src/image.rs
@@ -207,6 +207,11 @@
mark_upgrade(&mut images.flash, &image.slots[1]);
}
+ // The count is meaningless if no flash operations are performed.
+ if !Caps::modifies_flash() {
+ return images;
+ }
+
// upgrades without fails, counts number of flash operations
let total_count = match images.run_basic_upgrade(permanent) {
Some(v) => v,
@@ -456,6 +461,10 @@
/// Test a simple upgrade, with dependencies given, and verify that the
/// image does as is described in the test.
pub fn run_check_deps(&self, deps: &DepTest) -> bool {
+ if !Caps::modifies_flash() {
+ return false;
+ }
+
let (flash, _) = self.try_upgrade(None, true);
self.verify_dep_images(&flash, deps)
@@ -466,7 +475,7 @@
}
pub fn run_basic_revert(&self) -> bool {
- if Caps::OverwriteUpgrade.present() {
+ if Caps::OverwriteUpgrade.present() || !Caps::modifies_flash() {
return false;
}
@@ -488,6 +497,10 @@
}
pub fn run_perm_with_fails(&self) -> bool {
+ if !Caps::modifies_flash() {
+ return false;
+ }
+
let mut fails = 0;
let total_flash_ops = self.total_count.unwrap();
@@ -529,6 +542,10 @@
}
pub fn run_perm_with_random_fails(&self, total_fails: usize) -> bool {
+ if !Caps::modifies_flash() {
+ return false;
+ }
+
let mut fails = 0;
let total_flash_ops = self.total_count.unwrap();
let (flash, total_counts) = self.try_random_fails(total_flash_ops, total_fails);
@@ -567,7 +584,7 @@
}
pub fn run_revert_with_fails(&self) -> bool {
- if Caps::OverwriteUpgrade.present() {
+ if Caps::OverwriteUpgrade.present() || !Caps::modifies_flash() {
return false;
}
@@ -587,7 +604,7 @@
}
pub fn run_norevert(&self) -> bool {
- if Caps::OverwriteUpgrade.present() {
+ if Caps::OverwriteUpgrade.present() || !Caps::modifies_flash() {
return false;
}
@@ -686,6 +703,11 @@
// image_ok set while there is no image on the secondary slot, so no revert
// should ever happen...
pub fn run_norevert_newimage(&self) -> bool {
+ if !Caps::modifies_flash() {
+ info!("Skipping run_norevert_newimage, as configuration doesn't modify flash");
+ return false;
+ }
+
let mut flash = self.flash.clone();
let mut fails = 0;
@@ -739,6 +761,12 @@
info!("Try upgrade image with bad signature");
+ // Only perform this test if an upgrade is expected to happen.
+ if !Caps::modifies_flash() {
+ info!("Skipping upgrade image with bad signature");
+ return false;
+ }
+
self.mark_upgrades(&mut flash, 0);
self.mark_permanent_upgrades(&mut flash, 0);
self.mark_upgrades(&mut flash, 1);
@@ -776,6 +804,10 @@
// Should detect there is a leftover trailer in an otherwise erased
// secondary slot and erase its trailer.
pub fn run_secondary_leftover_trailer(&self) -> bool {
+ if !Caps::modifies_flash() {
+ return false;
+ }
+
let mut flash = self.flash.clone();
let mut fails = 0;
@@ -821,7 +853,7 @@
/// allowing for fails in the status area. This should run to the end
/// and warn that write fails were detected...
pub fn run_with_status_fails_complete(&self) -> bool {
- if !Caps::ValidatePrimarySlot.present() {
+ if !Caps::ValidatePrimarySlot.present() || !Caps::modifies_flash() {
return false;
}
@@ -875,7 +907,7 @@
/// allowing for fails in the status area. This should run to the end
/// and warn that write fails were detected...
pub fn run_with_status_fails_with_reset(&self) -> bool {
- if Caps::OverwriteUpgrade.present() {
+ if Caps::OverwriteUpgrade.present() || !Caps::modifies_flash() {
false
} else if Caps::ValidatePrimarySlot.present() {