From 80704f874be72cdb44ec9105e0b32ee365e9361b Mon Sep 17 00:00:00 2001 From: David Brown Date: Thu, 11 Apr 2024 10:42:10 -0600 Subject: [PATCH] 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 --- sim/src/image.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sim/src/image.rs b/sim/src/image.rs index 632dfa568..270ef248a 100644 --- a/sim/src/image.rs +++ b/sim/src/image.rs @@ -689,6 +689,10 @@ impl Images { 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 @@ impl Images { 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] { 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 + } +}