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

Make tests faster in Miri #74974

Merged
merged 4 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
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
2 changes: 1 addition & 1 deletion library/alloc/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ 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) };
let lens = if cfg!(miri) { (1..10).chain(0..0) } else { (1..20).chain(70..MAX_LEN) };
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the "20" case without measuring, which clearly was a mistake. So let's remove it again.

(We have to chain to make this type-check.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(We have to chain to make this type-check.)

Perhaps this rationale is best left in a comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done.

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
4 changes: 2 additions & 2 deletions library/core/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,14 +1268,14 @@ fn sort_unstable() {
use rand::{rngs::StdRng, seq::SliceRandom, Rng, SeedableRng};

// Miri is too slow
let large_range = if cfg!(miri) { 0..0 } else { 500..510 };
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