Skip to content

Commit eb958e1

Browse files
authored
Rollup merge of #60018 - RalfJung:miri-test-libstd, r=oli-obk
Miri now supports entropy, but is still slow Adjust the `cfg` and their comments in the test suites accordingly.
2 parents 23e8aaf + d55e4b7 commit eb958e1

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

src/liballoc/tests/binary_heap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ fn assert_covariance() {
282282
//
283283
// Destructors must be called exactly once per element.
284284
#[test]
285-
#[cfg(not(miri))] // Miri does not support panics nor entropy
285+
#[cfg(not(miri))] // Miri does not support catching panics
286286
fn panic_safe() {
287287
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);
288288

src/liballoc/tests/slice.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ fn test_reverse() {
389389
}
390390

391391
#[test]
392-
#[cfg(not(miri))] // Miri does not support entropy
392+
#[cfg(not(miri))] // Miri is too slow
393393
fn test_sort() {
394394
let mut rng = thread_rng();
395395

@@ -466,10 +466,19 @@ fn test_sort() {
466466
}
467467

468468
#[test]
469-
#[cfg(not(miri))] // Miri does not support entropy
470469
fn test_sort_stability() {
471-
for len in (2..25).chain(500..510) {
472-
for _ in 0..10 {
470+
#[cfg(not(miri))] // Miri is too slow
471+
let large_range = 500..510;
472+
#[cfg(not(miri))] // Miri is too slow
473+
let rounds = 10;
474+
475+
#[cfg(miri)]
476+
let large_range = 0..0; // empty range
477+
#[cfg(miri)]
478+
let rounds = 1;
479+
480+
for len in (2..25).chain(large_range) {
481+
for _ in 0..rounds {
473482
let mut counts = [0; 10];
474483

475484
// create a vector like [(6, 1), (5, 1), (6, 2), ...],
@@ -1397,7 +1406,7 @@ fn test_box_slice_clone() {
13971406
#[test]
13981407
#[allow(unused_must_use)] // here, we care about the side effects of `.clone()`
13991408
#[cfg_attr(target_os = "emscripten", ignore)]
1400-
#[cfg(not(miri))] // Miri does not support threads nor entropy
1409+
#[cfg(not(miri))] // Miri does not support threads
14011410
fn test_box_slice_clone_panics() {
14021411
use std::sync::Arc;
14031412
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -1589,7 +1598,7 @@ thread_local!(static SILENCE_PANIC: Cell<bool> = Cell::new(false));
15891598

15901599
#[test]
15911600
#[cfg_attr(target_os = "emscripten", ignore)] // no threads
1592-
#[cfg(not(miri))] // Miri does not support threads nor entropy
1601+
#[cfg(not(miri))] // Miri does not support threads
15931602
fn panic_safe() {
15941603
let prev = panic::take_hook();
15951604
panic::set_hook(Box::new(move |info| {

src/libcore/tests/slice.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1024,22 +1024,31 @@ fn test_rotate_right() {
10241024

10251025
#[test]
10261026
#[cfg(not(target_arch = "wasm32"))]
1027-
#[cfg(not(miri))] // Miri does not support entropy
10281027
fn sort_unstable() {
10291028
use core::cmp::Ordering::{Equal, Greater, Less};
10301029
use core::slice::heapsort;
10311030
use rand::{FromEntropy, Rng, rngs::SmallRng, seq::SliceRandom};
10321031

1032+
#[cfg(not(miri))] // Miri is too slow
1033+
let large_range = 500..510;
1034+
#[cfg(not(miri))] // Miri is too slow
1035+
let rounds = 100;
1036+
1037+
#[cfg(miri)]
1038+
let large_range = 0..0; // empty range
1039+
#[cfg(miri)]
1040+
let rounds = 1;
1041+
10331042
let mut v = [0; 600];
10341043
let mut tmp = [0; 600];
10351044
let mut rng = SmallRng::from_entropy();
10361045

1037-
for len in (2..25).chain(500..510) {
1046+
for len in (2..25).chain(large_range) {
10381047
let v = &mut v[0..len];
10391048
let tmp = &mut tmp[0..len];
10401049

10411050
for &modulus in &[5, 10, 100, 1000] {
1042-
for _ in 0..100 {
1051+
for _ in 0..rounds {
10431052
for i in 0..len {
10441053
v[i] = rng.gen::<i32>() % modulus;
10451054
}
@@ -1095,7 +1104,7 @@ fn sort_unstable() {
10951104

10961105
#[test]
10971106
#[cfg(not(target_arch = "wasm32"))]
1098-
#[cfg(not(miri))] // Miri does not support entropy
1107+
#[cfg(not(miri))] // Miri is too slow
10991108
fn partition_at_index() {
11001109
use core::cmp::Ordering::{Equal, Greater, Less};
11011110
use rand::rngs::SmallRng;

0 commit comments

Comments
 (0)