Commit 5bc62c6b authored by David Brown's avatar David Brown Committed by David Brown
Browse files

sim: Make the test builder optional

Some of the simulated devices aren't large enough to support the 5 slots
needed to test a multi-image configuration.  To allow this to work, make
the return from the `ImagesBuilder` return an option, so that it will be
able to indicate (with `None`) that this configuration isn't possible to
test, and that the test should be skipped.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent 96eb0deb
Loading
Loading
Loading
Loading
+10 −5
Changes for sim/src/image.rs: 10 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -62,7 +62,10 @@ struct ImageData {
}

impl ImagesBuilder {
    pub fn new(device: DeviceName, align: u8, erased_val: u8) -> Self {
    /// Construct a new image builder for the given device.  Returns
    /// Some(builder) if is possible to test this configuration, or None if
    /// not possible (for example, if there aren't enough image slots).
    pub fn new(device: DeviceName, align: u8, erased_val: u8) -> Option<Self> {
        let (flash, areadesc) = Self::make_device(device, align, erased_val);

        let (slot0_base, slot0_len, slot0_dev_id) = areadesc.find(FlashId::Image0);
@@ -87,11 +90,11 @@ impl ImagesBuilder {
            dev_id: slot1_dev_id,
        };

        ImagesBuilder {
        Some(ImagesBuilder {
            flash: flash,
            areadesc: areadesc,
            slots: vec![[slot0, slot1]],
        }
        })
    }

    pub fn each_device<F>(f: F)
@@ -100,8 +103,10 @@ impl ImagesBuilder {
        for &dev in ALL_DEVICES {
            for &align in &[1, 2, 4, 8] {
                for &erased_val in &[0, 0xff] {
                    let run = Self::new(dev, align, erased_val);
                    f(run);
                    match Self::new(dev, align, erased_val) {
                        Some(run) => f(run),
                        None => warn!("Skipping {:?}, insufficient partitions", dev),
                    }
                }
            }
        }
+7 −1
Changes for sim/src/lib.rs: 7 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -161,7 +161,13 @@ impl RunStatus {
    pub fn run_single(&mut self, device: DeviceName, align: u8, erased_val: u8) {
        warn!("Running on device {} with alignment {}", device, align);

        let run = ImagesBuilder::new(device, align, erased_val);
        let run = match ImagesBuilder::new(device, align, erased_val) {
            Some(builder) => builder,
            None => {
                warn!("Skipping device with insuffienct partitions");
                return;
            }
        };

        let mut failed = false;