Skip to content

Commit

Permalink
Auto merge of rust-lang#3379 - RalfJung:time-with-isolation, r=saethlin
Browse files Browse the repository at this point in the history
explain time-with-isolation test better

Fixes rust-lang/miri#3377

`@saethlin` do you think this is better?
  • Loading branch information
bors committed Mar 14, 2024
2 parents ee2bd39 + 1bc4d62 commit 76d364b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
13 changes: 12 additions & 1 deletion src/tools/miri/tests/pass/shims/time-with-isolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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();
}
2 changes: 2 additions & 0 deletions src/tools/miri/tests/pass/shims/time-with-isolation.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The loop took around 7s
(It's fine for this number to change when you `--bless` this test.)
8 changes: 0 additions & 8 deletions src/tools/miri/tests/pass/shims/time-with-isolation2.rs

This file was deleted.

This file was deleted.

0 comments on commit 76d364b

Please sign in to comment.