Skip to content

Commit

Permalink
Merge #843
Browse files Browse the repository at this point in the history
843: Fix miri tests r=taiki-e a=alygin

There were several changes in Miri recently, including [breaking ones](rust-lang/miri#2105) and affecting its speed. They caused CI builds failures.

This fix makes the most expensive Miri tests less intensive, so they have decent execution time again.


Co-authored-by: Andrew Lygin <[email protected]>
  • Loading branch information
bors[bot] and alygin authored May 31, 2022
2 parents 78b7ac3 + 48063d3 commit bf17086
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 54 deletions.
2 changes: 1 addition & 1 deletion ci/miri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MIRIFLAGS="-Zmiri-check-number-validity -Zmiri-symbolic-alignment-check -Zmiri-d

# -Zmiri-ignore-leaks is needed for https://github.com/crossbeam-rs/crossbeam/issues/579
# -Zmiri-disable-stacked-borrows is needed for https://github.com/crossbeam-rs/crossbeam/issues/545
MIRIFLAGS="-Zmiri-check-number-validity -Zmiri-symbolic-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-ignore-leaks -Zmiri-compare-exchange-weak-failure-rate=1.0" \
MIRIFLAGS="-Zmiri-check-number-validity -Zmiri-symbolic-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-ignore-leaks -Zmiri-compare-exchange-weak-failure-rate=0.0" \
cargo miri test \
-p crossbeam-deque

Expand Down
10 changes: 5 additions & 5 deletions crossbeam-channel/tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ fn recv_after_disconnect() {
#[test]
fn len() {
#[cfg(miri)]
const COUNT: usize = 250;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 25_000;
#[cfg(miri)]
const CAP: usize = 100;
const CAP: usize = 50;
#[cfg(not(miri))]
const CAP: usize = 1000;

Expand Down Expand Up @@ -500,11 +500,11 @@ fn stress_timeout_two_threads() {
#[test]
fn drops() {
#[cfg(miri)]
const RUNS: usize = 20;
const RUNS: usize = 10;
#[cfg(not(miri))]
const RUNS: usize = 100;
#[cfg(miri)]
const STEPS: usize = 500;
const STEPS: usize = 100;
#[cfg(not(miri))]
const STEPS: usize = 10_000;

Expand Down Expand Up @@ -561,7 +561,7 @@ fn drops() {
#[test]
fn linearizable() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 25_000;
const THREADS: usize = 4;
Expand Down
26 changes: 16 additions & 10 deletions crossbeam-channel/tests/golang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ mod select2 {
use super::*;

#[cfg(miri)]
const N: i32 = 1000;
const N: i32 = 200;
#[cfg(not(miri))]
const N: i32 = 100000;

Expand Down Expand Up @@ -923,6 +923,9 @@ mod sieve1 {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83,
89, 97,
];
#[cfg(miri)]
let a = &a[..10];

for item in a.iter() {
let x = primes.recv().unwrap();
if x != *item {
Expand Down Expand Up @@ -960,6 +963,11 @@ mod chan_test {
#[cfg(not(miri))]
const N: i32 = 200;

#[cfg(miri)]
const MESSAGES_COUNT: i32 = 20;
#[cfg(not(miri))]
const MESSAGES_COUNT: i32 = 100;

for cap in 0..N {
{
// Ensure that receive from empty chan blocks.
Expand Down Expand Up @@ -1066,27 +1074,27 @@ mod chan_test {
}

{
// Send 100 integers,
// Send many integers,
// ensure that we receive them non-corrupted in FIFO order.
let c = make::<i32>(cap as usize);
go!(c, {
for i in 0..100 {
for i in 0..MESSAGES_COUNT {
c.send(i);
}
});
for i in 0..100 {
for i in 0..MESSAGES_COUNT {
if c.recv() != Some(i) {
panic!();
}
}

// Same, but using recv2.
go!(c, {
for i in 0..100 {
for i in 0..MESSAGES_COUNT {
c.send(i);
}
});
for i in 0..100 {
for i in 0..MESSAGES_COUNT {
if c.recv() != Some(i) {
panic!();
}
Expand Down Expand Up @@ -1572,14 +1580,12 @@ mod race_chan_test {
}

// https://github.com/golang/go/blob/master/test/ken/chan.go
#[cfg(not(miri))] // Miri is too slow
mod chan {

use super::*;

#[cfg(not(miri))]
const MESSAGES_PER_CHANEL: u32 = 76;
#[cfg(miri)]
const MESSAGES_PER_CHANEL: u32 = 2; // Miri is too slow on these tests
const MESSAGES_RANGE_LEN: u32 = 100;
const END: i32 = 10000;

Expand Down Expand Up @@ -2080,7 +2086,7 @@ mod chan1 {

// sent messages
#[cfg(miri)]
const N: usize = 100;
const N: usize = 20;
#[cfg(not(miri))]
const N: usize = 1000;
// receiving "goroutines"
Expand Down
25 changes: 20 additions & 5 deletions crossbeam-channel/tests/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ fn recv_timeout() {

#[test]
fn try_send() {
#[cfg(miri)]
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 1000;

let (s, r) = unbounded();
for i in 0..1000 {
for i in 0..COUNT {
assert_eq!(s.try_send(i), Ok(()));
}

Expand All @@ -143,8 +148,13 @@ fn try_send() {

#[test]
fn send() {
#[cfg(miri)]
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 1000;

let (s, r) = unbounded();
for i in 0..1000 {
for i in 0..COUNT {
assert_eq!(s.send(i), Ok(()));
}

Expand All @@ -154,8 +164,13 @@ fn send() {

#[test]
fn send_timeout() {
#[cfg(miri)]
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 1000;

let (s, r) = unbounded();
for i in 0..1000 {
for i in 0..COUNT {
assert_eq!(s.send_timeout(i, ms(i as u64)), Ok(()));
}

Expand Down Expand Up @@ -390,7 +405,7 @@ fn drops() {
#[cfg(not(miri))]
const RUNS: usize = 100;
#[cfg(miri)]
const STEPS: usize = 500;
const STEPS: usize = 100;
#[cfg(not(miri))]
const STEPS: usize = 10_000;

Expand All @@ -409,7 +424,7 @@ fn drops() {

for _ in 0..RUNS {
let steps = rng.gen_range(0..STEPS);
let additional = rng.gen_range(0..1000);
let additional = rng.gen_range(0..STEPS / 10);

DROPS.store(0, Ordering::SeqCst);
let (s, r) = unbounded::<DropCounter>();
Expand Down
6 changes: 3 additions & 3 deletions crossbeam-channel/tests/mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ mod channel_tests {
#[test]
fn stress() {
#[cfg(miri)]
const COUNT: usize = 500;
const COUNT: usize = 100;
#[cfg(not(miri))]
const COUNT: usize = 10000;

Expand All @@ -340,7 +340,7 @@ mod channel_tests {
#[test]
fn stress_shared() {
#[cfg(miri)]
const AMT: u32 = 500;
const AMT: u32 = 100;
#[cfg(not(miri))]
const AMT: u32 = 10000;
const NTHREADS: u32 = 8;
Expand Down Expand Up @@ -747,7 +747,7 @@ mod channel_tests {
#[test]
fn recv_a_lot() {
#[cfg(miri)]
const N: usize = 100;
const N: usize = 50;
#[cfg(not(miri))]
const N: usize = 10000;

Expand Down
16 changes: 8 additions & 8 deletions crossbeam-channel/tests/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ fn nesting() {
#[test]
fn stress_recv() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

Expand Down Expand Up @@ -735,7 +735,7 @@ fn stress_recv() {
#[test]
fn stress_send() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

Expand Down Expand Up @@ -953,7 +953,7 @@ fn matching_with_leftover() {
#[test]
fn channel_through_channel() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 1000;

Expand Down Expand Up @@ -1014,7 +1014,7 @@ fn channel_through_channel() {
#[test]
fn linearizable_try() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 100_000;

Expand Down Expand Up @@ -1069,7 +1069,7 @@ fn linearizable_try() {
#[test]
fn linearizable_timeout() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 100_000;

Expand Down Expand Up @@ -1124,7 +1124,7 @@ fn linearizable_timeout() {
#[test]
fn fairness1() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

Expand Down Expand Up @@ -1173,7 +1173,7 @@ fn fairness1() {
#[test]
fn fairness2() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

Expand Down Expand Up @@ -1292,7 +1292,7 @@ fn send_and_clone() {
#[test]
fn reuse() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

Expand Down
2 changes: 1 addition & 1 deletion crossbeam-channel/tests/select_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ fn panic_receiver() {
#[test]
fn stress_recv() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

Expand Down
14 changes: 7 additions & 7 deletions crossbeam-channel/tests/zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn send_timeout() {
#[test]
fn len() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 25_000;

Expand Down Expand Up @@ -253,7 +253,7 @@ fn disconnect_wakes_receiver() {
#[test]
fn spsc() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 100_000;

Expand All @@ -278,7 +278,7 @@ fn spsc() {
#[test]
fn mpmc() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 25_000;
const THREADS: usize = 4;
Expand Down Expand Up @@ -313,7 +313,7 @@ fn mpmc() {
#[test]
fn stress_oneshot() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

Expand Down Expand Up @@ -451,7 +451,7 @@ fn drops() {
#[test]
fn fairness() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

Expand Down Expand Up @@ -485,7 +485,7 @@ fn fairness() {
#[test]
fn fairness_duplicates() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 10_000;

Expand Down Expand Up @@ -546,7 +546,7 @@ fn recv_in_send() {
#[test]
fn channel_through_channel() {
#[cfg(miri)]
const COUNT: usize = 100;
const COUNT: usize = 50;
#[cfg(not(miri))]
const COUNT: usize = 1000;

Expand Down
Loading

0 comments on commit bf17086

Please sign in to comment.