Commit ed4a5363 authored by Fabio Utzig's avatar Fabio Utzig Committed by David Brown
Browse files

Fix test/revert upgrade flash count

When doing a test with fails, the total number of flash accesses is
first calculated doing an upgrade without fails, which is then used to
fail/resume at all test points. The count was always considering the
setting of a permanent upgrade, which added 1 to the total count in a
non-permanent upgrade. This amount was being discounted when running
the test/revert with fails, although the discount was only ok for single
images. This adds a new image constructor that does not run a permanent
upgrade and thus gets the correct number of flash accesses for a
test/revert no matter how many images are being tested.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent 8af7f793
Loading
Loading
Loading
Loading
+19 −8
Changes for sim/src/image.rs: 19 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -155,15 +155,14 @@ impl ImagesBuilder {
        }
    }

    /// Construct an `Images` for normal testing.
    pub fn make_image(self) -> Images {
    fn make_image_with_permanent(self, permanent: bool) -> Images {
        let mut images = self.make_no_upgrade_image();
        for image in &images.images {
            mark_upgrade(&mut images.flash, &image.slots[1]);
        }

        // upgrades without fails, counts number of flash operations
        let total_count = match images.run_basic_upgrade() {
        let total_count = match images.run_basic_upgrade(permanent) {
            Ok(v)  => v,
            Err(_) => {
                panic!("Unable to perform basic upgrade");
@@ -174,6 +173,16 @@ impl ImagesBuilder {
        images
    }

    /// Construct an `Images` for normal testing with perm upgrade.
    pub fn make_image(self) -> Images {
        self.make_image_with_permanent(true)
    }

    /// Construct an `Images` for normal testing with test upgrade.
    pub fn make_non_permanent_image(self) -> Images {
        self.make_image_with_permanent(false)
    }

    pub fn make_bad_secondary_slot_image(self) -> Images {
        let mut bad_flash = self.flash;
        let images = self.slots.into_iter().map(|slots| {
@@ -304,8 +313,8 @@ impl Images {
    ///
    /// Returns the number of flash operations which can later be used to
    /// inject failures at chosen steps.
    pub fn run_basic_upgrade(&self) -> Result<i32, ()> {
        let (flash, total_count) = self.try_upgrade(None);
    pub fn run_basic_upgrade(&self, permanent: bool) -> Result<i32, ()> {
        let (flash, total_count) = self.try_upgrade(None, permanent);
        info!("Total flash operation count={}", total_count);

        if !self.verify_images(&flash, 0, 1) {
@@ -345,7 +354,7 @@ impl Images {
        // Let's try an image halfway through.
        for i in 1 .. total_flash_ops {
            info!("Try interruption at {}", i);
            let (flash, count) = self.try_upgrade(Some(i));
            let (flash, count) = self.try_upgrade(Some(i), true);
            info!("Second boot, count={}", count);
            if !self.verify_images(&flash, 0, 1) {
                warn!("FAIL at step {} of {}", i, total_flash_ops);
@@ -431,7 +440,7 @@ impl Images {
        let mut fails = 0;

        if Caps::SwapUpgrade.present() {
            for i in 1 .. (self.total_count.unwrap() - 1) {
            for i in 1 .. self.total_count.unwrap() {
                info!("Try interruption at {}", i);
                if self.try_revert_with_fail_at(i) {
                    error!("Revert failed at interruption {}", i);
@@ -779,11 +788,13 @@ impl Images {

    /// Test a boot, optionally stopping after 'n' flash options.  Returns a count
    /// of the number of flash operations done total.
    fn try_upgrade(&self, stop: Option<i32>) -> (SimMultiFlash, i32) {
    fn try_upgrade(&self, stop: Option<i32>, permanent: bool) -> (SimMultiFlash, i32) {
        // Clone the flash to have a new copy.
        let mut flash = self.flash.clone();

        if permanent {
            self.mark_permanent_upgrades(&mut flash, 1);
        }

        let mut counter = stop.unwrap_or(0);

+1 −1
Changes for sim/tests/core.rs: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ macro_rules! sim_test {
sim_test!(bad_secondary_slot, make_bad_secondary_slot_image, run_signfail_upgrade);
sim_test!(norevert_newimage, make_no_upgrade_image, run_norevert_newimage);
sim_test!(basic_revert, make_image, run_basic_revert);
sim_test!(revert_with_fails, make_image, run_revert_with_fails);
sim_test!(revert_with_fails, make_non_permanent_image, run_revert_with_fails);
sim_test!(perm_with_fails, make_image, run_perm_with_fails);
sim_test!(perm_with_random_fails, make_image, run_perm_with_random_fails_5);
sim_test!(norevert, make_image, run_norevert);