From 1bc4d62f81e0b665b00e4f8ff16f24eab8ee02bd Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 14 Mar 2024 07:51:47 +0100 Subject: [PATCH] explain time-with-isolation test better --- .../miri/tests/pass/shims/time-with-isolation.rs | 13 ++++++++++++- .../tests/pass/shims/time-with-isolation.stdout | 2 ++ .../miri/tests/pass/shims/time-with-isolation2.rs | 8 -------- .../tests/pass/shims/time-with-isolation2.stdout | 1 - 4 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 src/tools/miri/tests/pass/shims/time-with-isolation.stdout delete mode 100644 src/tools/miri/tests/pass/shims/time-with-isolation2.rs delete mode 100644 src/tools/miri/tests/pass/shims/time-with-isolation2.stdout diff --git a/src/tools/miri/tests/pass/shims/time-with-isolation.rs b/src/tools/miri/tests/pass/shims/time-with-isolation.rs index a0c3c6bbaa9..645d42ad975 100644 --- a/src/tools/miri/tests/pass/shims/time-with-isolation.rs +++ b/src/tools/miri/tests/pass/shims/time-with-isolation.rs @@ -24,7 +24,8 @@ fn test_time_passes() { assert_eq!(now2 - diff, now1); // The virtual clock is deterministic and I got 15ms on a 64-bit Linux machine. However, this // changes according to the platform so we use an interval to be safe. This should be updated - // if `NANOSECONDS_PER_BASIC_BLOCK` changes. + // if `NANOSECONDS_PER_BASIC_BLOCK` changes. It may also need updating if the standard library + // code that runs in the loop above changes. assert!(diff.as_millis() > 5); assert!(diff.as_millis() < 20); } @@ -37,8 +38,18 @@ fn test_block_for_one_second() { while Instant::now() < end {} } +/// Ensures that we get the same behavior across all targets. +fn test_deterministic() { + let begin = Instant::now(); + for _ in 0..100_000 {} + let time = begin.elapsed(); + println!("The loop took around {}s", time.as_secs()); + println!("(It's fine for this number to change when you `--bless` this test.)") +} + fn main() { test_time_passes(); test_block_for_one_second(); test_sleep(); + test_deterministic(); } diff --git a/src/tools/miri/tests/pass/shims/time-with-isolation.stdout b/src/tools/miri/tests/pass/shims/time-with-isolation.stdout new file mode 100644 index 00000000000..f3d071e001e --- /dev/null +++ b/src/tools/miri/tests/pass/shims/time-with-isolation.stdout @@ -0,0 +1,2 @@ +The loop took around 7s +(It's fine for this number to change when you `--bless` this test.) diff --git a/src/tools/miri/tests/pass/shims/time-with-isolation2.rs b/src/tools/miri/tests/pass/shims/time-with-isolation2.rs deleted file mode 100644 index 24e72e22fd8..00000000000 --- a/src/tools/miri/tests/pass/shims/time-with-isolation2.rs +++ /dev/null @@ -1,8 +0,0 @@ -use std::time::Instant; - -fn main() { - let begin = Instant::now(); - for _ in 0..100_000 {} - let time = begin.elapsed(); - println!("The loop took around {}s", time.as_secs()); -} diff --git a/src/tools/miri/tests/pass/shims/time-with-isolation2.stdout b/src/tools/miri/tests/pass/shims/time-with-isolation2.stdout deleted file mode 100644 index c68b40b744b..00000000000 --- a/src/tools/miri/tests/pass/shims/time-with-isolation2.stdout +++ /dev/null @@ -1 +0,0 @@ -The loop took around 7s