sim: Allow slow tests to be skipped

The normal simulation test takes several hours to run on most machines. Allow a
few very slow tests to be skipped by setting the environment variable
`MCUBOOT_SKIP_SLOW_TESTS` to some value. For obvious reasons, this shouldn't be
done if these power failure simulation tests are needed.

With this change, on my desktop Linux machine, the test time with the skipping
goes from about 2 hours, to around 5 minutes.

Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/sim/src/image.rs b/sim/src/image.rs
index 632dfa5..270ef24 100644
--- a/sim/src/image.rs
+++ b/sim/src/image.rs
@@ -689,6 +689,10 @@
         let mut fails = 0;
         let total_flash_ops = self.total_count.unwrap();
 
+        if skip_slow_test() {
+            return false;
+        }
+
         // Let's try an image halfway through.
         for i in 1 .. total_flash_ops {
             info!("Try interruption at {}", i);
@@ -775,6 +779,10 @@
 
         let mut fails = 0;
 
+        if skip_slow_test() {
+            return false;
+        }
+
         if self.is_swap_upgrade() {
             for i in 1 .. self.total_count.unwrap() {
                 info!("Try interruption at {}", i);
@@ -2314,3 +2322,14 @@
 fn test_alignments() -> &'static [usize] {
     &[32]
 }
+
+/// For testing, some of the tests are quite slow. This will query for an
+/// environment variable `MCUBOOT_SKIP_SLOW_TESTS`, which can be set to avoid
+/// running these tests.
+fn skip_slow_test() -> bool {
+    if let Ok(_) = std::env::var("MCUBOOT_SKIP_SLOW_TESTS") {
+        true
+    } else {
+        false
+    }
+}