Skip to content

Commit 76d364b

Browse files
committed
Auto merge of rust-lang#3379 - RalfJung:time-with-isolation, r=saethlin
explain time-with-isolation test better Fixes rust-lang/miri#3377 `@saethlin` do you think this is better?
2 parents ee2bd39 + 1bc4d62 commit 76d364b

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/tools/miri/tests/pass/shims/time-with-isolation.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ fn test_time_passes() {
2424
assert_eq!(now2 - diff, now1);
2525
// The virtual clock is deterministic and I got 15ms on a 64-bit Linux machine. However, this
2626
// changes according to the platform so we use an interval to be safe. This should be updated
27-
// if `NANOSECONDS_PER_BASIC_BLOCK` changes.
27+
// if `NANOSECONDS_PER_BASIC_BLOCK` changes. It may also need updating if the standard library
28+
// code that runs in the loop above changes.
2829
assert!(diff.as_millis() > 5);
2930
assert!(diff.as_millis() < 20);
3031
}
@@ -37,8 +38,18 @@ fn test_block_for_one_second() {
3738
while Instant::now() < end {}
3839
}
3940

41+
/// Ensures that we get the same behavior across all targets.
42+
fn test_deterministic() {
43+
let begin = Instant::now();
44+
for _ in 0..100_000 {}
45+
let time = begin.elapsed();
46+
println!("The loop took around {}s", time.as_secs());
47+
println!("(It's fine for this number to change when you `--bless` this test.)")
48+
}
49+
4050
fn main() {
4151
test_time_passes();
4252
test_block_for_one_second();
4353
test_sleep();
54+
test_deterministic();
4455
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The loop took around 7s
2+
(It's fine for this number to change when you `--bless` this test.)

src/tools/miri/tests/pass/shims/time-with-isolation2.rs

-8
This file was deleted.

src/tools/miri/tests/pass/shims/time-with-isolation2.stdout

-1
This file was deleted.

0 commit comments

Comments
 (0)