Skip to content

Commit

Permalink
Rollup merge of #74974 - RalfJung:miri-tests, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Make tests faster in Miri

Reduce some test iteration counts in Miri.
  • Loading branch information
JohnTitor authored Aug 2, 2020
2 parents 1033c74 + ff0c3a9 commit 7d18040
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
17 changes: 11 additions & 6 deletions library/alloc/src/collections/vec_deque/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ fn test_insert() {
let cap = tester.capacity();

// len is the length *after* insertion
for len in 1..cap {
let minlen = if cfg!(miri) { cap - 1 } else { 1 }; // Miri is too slow
for len in minlen..cap {
// 0, 1, 2, .., len - 1
let expected = (0..).take(len).collect::<VecDeque<_>>();
for tail_pos in 0..cap {
Expand Down Expand Up @@ -221,7 +222,8 @@ fn test_remove() {
let cap = tester.capacity();

// len is the length *after* removal
for len in 0..cap - 1 {
let minlen = if cfg!(miri) { cap - 2 } else { 0 }; // Miri is too slow
for len in minlen..cap - 1 {
// 0, 1, 2, .., len - 1
let expected = (0..).take(len).collect::<VecDeque<_>>();
for tail_pos in 0..cap {
Expand Down Expand Up @@ -251,7 +253,8 @@ fn test_range() {
let mut tester: VecDeque<usize> = VecDeque::with_capacity(7);

let cap = tester.capacity();
for len in 0..=cap {
let minlen = if cfg!(miri) { cap - 1 } else { 0 }; // Miri is too slow
for len in minlen..=cap {
for tail in 0..=cap {
for start in 0..=len {
for end in start..=len {
Expand Down Expand Up @@ -384,7 +387,8 @@ fn test_split_off() {
let cap = tester.capacity();

// len is the length *before* splitting
for len in 0..cap {
let minlen = if cfg!(miri) { cap - 1 } else { 0 }; // Miri is too slow
for len in minlen..cap {
// index to split at
for at in 0..=len {
// 0, 1, 2, .., at - 1 (may be empty)
Expand Down Expand Up @@ -495,8 +499,9 @@ fn test_vec_from_vecdeque() {
fn test_clone_from() {
let m = vec![1; 8];
let n = vec![2; 12];
for pfv in 0..8 {
for pfu in 0..8 {
let limit = if cfg!(miri) { 4 } else { 8 }; // Miri is too slow
for pfv in 0..limit {
for pfu in 0..limit {
for longer in 0..2 {
let (vr, ur) = if longer == 0 { (&m, &n) } else { (&n, &m) };
let mut v = VecDeque::from(vr.clone());
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1721,8 +1721,8 @@ fn panic_safe() {

let mut rng = thread_rng();

// Miri is too slow
let lens = if cfg!(miri) { (1..10).chain(20..21) } else { (1..20).chain(70..MAX_LEN) };
// Miri is too slow (but still need to `chain` to make the types match)
let lens = if cfg!(miri) { (1..10).chain(0..0) } else { (1..20).chain(70..MAX_LEN) };
let moduli: &[u32] = if cfg!(miri) { &[5] } else { &[5, 20, 50] };

for len in lens {
Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/num/flt2dec/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn exact_f32_random_equivalence_test() {
fn exact_f64_random_equivalence_test() {
use core::num::flt2dec::strategy::dragon::format_exact as fallback;
// Miri is too slow
let n = if cfg!(miri) { 3 } else { 1_000 };
let n = if cfg!(miri) { 2 } else { 1_000 };

for k in 1..21 {
f64_random_equivalence_test(
Expand Down
1 change: 1 addition & 0 deletions library/core/tests/num/flt2dec/strategy/grisu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::super::*;
use core::num::flt2dec::strategy::grisu::*;

#[test]
#[cfg_attr(miri, ignore)] // Miri is too slow
fn test_cached_power() {
assert_eq!(CACHED_POW10.first().unwrap().1, CACHED_POW10_FIRST_E);
assert_eq!(CACHED_POW10.last().unwrap().1, CACHED_POW10_LAST_E);
Expand Down
6 changes: 3 additions & 3 deletions library/core/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,15 +1358,15 @@ fn sort_unstable() {
use core::slice::heapsort;
use rand::{rngs::StdRng, seq::SliceRandom, Rng, SeedableRng};

// Miri is too slow
let large_range = if cfg!(miri) { 0..0 } else { 500..510 };
// Miri is too slow (but still need to `chain` to make the types match)
let lens = if cfg!(miri) { (2..20).chain(0..0) } else { (2..25).chain(500..510) };
let rounds = if cfg!(miri) { 1 } else { 100 };

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

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

Expand Down

0 comments on commit 7d18040

Please sign in to comment.