Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miri now supports entropy, but is still slow #60018

Merged
merged 2 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/liballoc/tests/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ fn assert_covariance() {
//
// Destructors must be called exactly once per element.
#[test]
#[cfg(not(miri))] // Miri does not support panics nor entropy
#[cfg(not(miri))] // Miri does not support catching panics
fn panic_safe() {
static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0);

Expand Down
21 changes: 15 additions & 6 deletions src/liballoc/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ fn test_reverse() {
}

#[test]
#[cfg(not(miri))] // Miri does not support entropy
#[cfg(not(miri))] // Miri is too slow
fn test_sort() {
let mut rng = thread_rng();

Expand Down Expand Up @@ -466,10 +466,19 @@ fn test_sort() {
}

#[test]
#[cfg(not(miri))] // Miri does not support entropy
fn test_sort_stability() {
for len in (2..25).chain(500..510) {
for _ in 0..10 {
#[cfg(not(miri))] // Miri is too slow
let large_range = 500..510;
#[cfg(not(miri))] // Miri is too slow
let rounds = 10;

#[cfg(miri)]
let large_range = 0..0; // empty range
#[cfg(miri)]
let rounds = 1;

for len in (2..25).chain(large_range) {
for _ in 0..rounds {
let mut counts = [0; 10];

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

#[test]
#[cfg_attr(target_os = "emscripten", ignore)] // no threads
#[cfg(not(miri))] // Miri does not support threads nor entropy
#[cfg(not(miri))] // Miri does not support threads
fn panic_safe() {
let prev = panic::take_hook();
panic::set_hook(Box::new(move |info| {
Expand Down
17 changes: 13 additions & 4 deletions src/libcore/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,22 +1024,31 @@ fn test_rotate_right() {

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

#[cfg(not(miri))] // Miri is too slow
let large_range = 500..510;
#[cfg(not(miri))] // Miri is too slow
let rounds = 100;

#[cfg(miri)]
let large_range = 0..0; // empty range
#[cfg(miri)]
let rounds = 1;

let mut v = [0; 600];
let mut tmp = [0; 600];
let mut rng = SmallRng::from_entropy();

for len in (2..25).chain(500..510) {
for len in (2..25).chain(large_range) {
let v = &mut v[0..len];
let tmp = &mut tmp[0..len];

for &modulus in &[5, 10, 100, 1000] {
for _ in 0..100 {
for _ in 0..rounds {
for i in 0..len {
v[i] = rng.gen::<i32>() % modulus;
}
Expand Down Expand Up @@ -1095,7 +1104,7 @@ fn sort_unstable() {

#[test]
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(miri))] // Miri does not support entropy
#[cfg(not(miri))] // Miri is too slow
fn partition_at_index() {
use core::cmp::Ordering::{Equal, Greater, Less};
use rand::rngs::SmallRng;
Expand Down