Commit 85904a80 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

sim: Remove more cfg around validate-slot-0

Turn some more conditional compilation into runtime decisions based on
how the code being tested is compiled.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent 8d0afa73
Loading
Loading
Loading
Loading
+1
Changes for sim/src/caps.rs: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ pub enum Caps {
    OverwriteUpgrade = (1 << 4),
    EncRsa           = (1 << 5),
    EncKw            = (1 << 6),
    ValidateSlot0    = (1 << 7),
}

impl Caps {
+34 −32
Changes for sim/src/image.rs: 34 added lines, 32 removed lines.
Original line number Diff line number Diff line
@@ -338,11 +338,11 @@ impl Images {
    /// This test runs a simple upgrade with no fails in the images, but
    /// allowing for fails in the status area. This should run to the end
    /// and warn that write fails were detected...
    #[cfg(not(feature = "validate-slot0"))]
    pub fn run_with_status_fails_complete(&self) -> bool { false }

    #[cfg(feature = "validate-slot0")]
    pub fn run_with_status_fails_complete(&self) -> bool {
        if !Caps::ValidateSlot0.present() {
            return false;
        }

        let mut flashmap = self.flashmap.clone();
        let mut fails = 0;

@@ -392,8 +392,11 @@ impl Images {
    /// This test runs a simple upgrade with no fails in the images, but
    /// allowing for fails in the status area. This should run to the end
    /// and warn that write fails were detected...
    #[cfg(feature = "validate-slot0")]
    pub fn run_with_status_fails_with_reset(&self) -> bool {
        if Caps::OverwriteUpgrade.present() {
            false
        } else if Caps::ValidateSlot0.present() {

            let mut flashmap = self.flashmap.clone();
            let mut fails = 0;
            let mut count = self.total_count.unwrap() / 2;
@@ -431,12 +434,33 @@ impl Images {
            }

            fails > 0
        } else {
            let mut flashmap = self.flashmap.clone();
            let mut fails = 0;

            info!("Try interrupted swap with status fails");

            mark_permanent_upgrade(&mut flashmap, &self.slots[1]);
            self.mark_bad_status_with_rate(&mut flashmap, 0, 1.0);

            // This is expected to fail while writing to bad regions...
            let (_, asserts) = c::boot_go(&mut flashmap, &self.areadesc, None, true);
            if asserts == 0 {
                warn!("No assert() detected");
                fails += 1;
            }

            fails > 0
        }
    }

    /// Adds a new flash area that fails statistically
    #[cfg(not(feature = "overwrite-only"))]
    fn mark_bad_status_with_rate(&self, flashmap: &mut SimFlashMap, slot: usize,
                                 rate: f32) {
        if Caps::OverwriteUpgrade.present() {
            return;
        }

        let dev_id = &self.slots[slot].dev_id;
        let flash = flashmap.get_mut(&dev_id).unwrap();
        let align = flash.align();
@@ -448,8 +472,11 @@ impl Images {
        let _ = flash.add_bad_region(status_off, self.status_sz(align), rate);
    }

    #[cfg(feature = "validate-slot0")]
    fn reset_bad_status(&self, flashmap: &mut SimFlashMap, slot: usize) {
        if !Caps::ValidateSlot0.present() {
            return;
        }

        let dev_id = &self.slots[slot].dev_id;
        let flash = flashmap.get_mut(&dev_id).unwrap();
        flash.reset_bad_regions();
@@ -459,31 +486,6 @@ impl Images {
        flash.set_verify_writes(false);
    }

    #[cfg(not(feature = "validate-slot0"))]
    #[cfg(not(feature = "overwrite-only"))]
    pub fn run_with_status_fails_with_reset(&self) -> bool {
        let mut flashmap = self.flashmap.clone();
        let mut fails = 0;

        info!("Try interrupted swap with status fails");

        mark_permanent_upgrade(&mut flashmap, &self.slots[1]);
        self.mark_bad_status_with_rate(&mut flashmap, 0, 1.0);

        // This is expected to fail while writing to bad regions...
        let (_, asserts) = c::boot_go(&mut flashmap, &self.areadesc, None, true);
        if asserts == 0 {
            warn!("No assert() detected");
            fails += 1;
        }

        fails > 0
    }

    #[cfg(feature = "overwrite-only")]
    pub fn run_with_status_fails_with_reset(&self) -> bool {
        false
    }
}

/// Test a boot, optionally stopping after 'n' flash options.  Returns a count