Skip to content

Commit f412180

Browse files
committed
Run Miri on CI
1 parent dba57a2 commit f412180

File tree

21 files changed

+286
-14
lines changed

21 files changed

+286
-14
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ jobs:
123123
- name: clippy
124124
run: ./ci/clippy.sh
125125

126+
# Run miri.
127+
miri:
128+
name: miri
129+
runs-on: ubuntu-latest
130+
steps:
131+
- uses: actions/checkout@v2
132+
- name: miri
133+
run: ./ci/miri.sh
134+
126135
# Run sanitizers.
127136
san:
128137
name: san
@@ -172,6 +181,7 @@ jobs:
172181
- codegen
173182
- rustfmt
174183
- clippy
184+
- miri
175185
- san
176186
- loom
177187
- docs

ci/miri.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
export RUSTFLAGS="-D warnings"
6+
7+
if [[ "$OSTYPE" != "linux"* ]]; then
8+
exit 0
9+
fi
10+
11+
toolchain=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
12+
rustup set profile minimal
13+
rustup default "$toolchain"
14+
rustup component add miri
15+
16+
# -Zmiri-disable-stacked-borrows is needed for https://github.com/crossbeam-rs/crossbeam/issues/545
17+
# -Zmiri-ignore-leaks is needed for https://github.com/crossbeam-rs/crossbeam/issues/579
18+
export MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-disable-stacked-borrows -Zmiri-ignore-leaks"
19+
cargo miri test --all --exclude benchmarks

crossbeam-channel/tests/after.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Tests for the after channel flavor.
22
3+
#![cfg(not(miri))] // TODO: many assertions failed due to Miri is slow
4+
35
use std::sync::atomic::AtomicUsize;
46
use std::sync::atomic::Ordering;
57
use std::thread;

crossbeam-channel/tests/array.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Tests for the array channel flavor.
22
3+
#![cfg(not(miri))] // TODO: many assertions failed due to Miri is slow
4+
35
use std::any::Any;
46
use std::sync::atomic::AtomicUsize;
57
use std::sync::atomic::Ordering;

crossbeam-channel/tests/golang.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
//! - https://golang.org/LICENSE
1010
//! - https://golang.org/PATENTS
1111
12+
#![cfg(not(miri))] // Miri is too slow
13+
1214
use std::alloc::{GlobalAlloc, Layout, System};
1315
use std::any::Any;
1416
use std::cell::Cell;

crossbeam-channel/tests/iter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fn recv_iter_break() {
5454
.unwrap();
5555
}
5656

57+
#[cfg_attr(miri, ignore)] // Miri is too slow
5758
#[test]
5859
fn recv_try_iter() {
5960
let (request_s, request_r) = unbounded();

crossbeam-channel/tests/list.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ fn disconnect_wakes_receiver() {
239239

240240
#[test]
241241
fn spsc() {
242+
#[cfg(miri)]
243+
const COUNT: usize = 100;
244+
#[cfg(not(miri))]
242245
const COUNT: usize = 100_000;
243246

244247
let (s, r) = unbounded();
@@ -261,6 +264,9 @@ fn spsc() {
261264

262265
#[test]
263266
fn mpmc() {
267+
#[cfg(miri)]
268+
const COUNT: usize = 100;
269+
#[cfg(not(miri))]
264270
const COUNT: usize = 25_000;
265271
const THREADS: usize = 4;
266272

@@ -295,6 +301,9 @@ fn mpmc() {
295301

296302
#[test]
297303
fn stress_oneshot() {
304+
#[cfg(miri)]
305+
const COUNT: usize = 100;
306+
#[cfg(not(miri))]
298307
const COUNT: usize = 10_000;
299308

300309
for _ in 0..COUNT {
@@ -308,6 +317,7 @@ fn stress_oneshot() {
308317
}
309318
}
310319

320+
#[cfg_attr(miri, ignore)] // Miri is too slow
311321
#[test]
312322
fn stress_iter() {
313323
const COUNT: usize = 100_000;
@@ -371,6 +381,7 @@ fn stress_timeout_two_threads() {
371381
.unwrap();
372382
}
373383

384+
#[cfg_attr(miri, ignore)] // Miri is too slow
374385
#[test]
375386
fn drops() {
376387
static DROPS: AtomicUsize = AtomicUsize::new(0);
@@ -421,6 +432,9 @@ fn drops() {
421432

422433
#[test]
423434
fn linearizable() {
435+
#[cfg(miri)]
436+
const COUNT: usize = 100;
437+
#[cfg(not(miri))]
424438
const COUNT: usize = 25_000;
425439
const THREADS: usize = 4;
426440

@@ -441,6 +455,9 @@ fn linearizable() {
441455

442456
#[test]
443457
fn fairness() {
458+
#[cfg(miri)]
459+
const COUNT: usize = 100;
460+
#[cfg(not(miri))]
444461
const COUNT: usize = 10_000;
445462

446463
let (s1, r1) = unbounded::<()>();
@@ -463,6 +480,9 @@ fn fairness() {
463480

464481
#[test]
465482
fn fairness_duplicates() {
483+
#[cfg(miri)]
484+
const COUNT: usize = 100;
485+
#[cfg(not(miri))]
466486
const COUNT: usize = 10_000;
467487

468488
let (s, r) = unbounded();
@@ -496,6 +516,9 @@ fn recv_in_send() {
496516

497517
#[test]
498518
fn channel_through_channel() {
519+
#[cfg(miri)]
520+
const COUNT: usize = 100;
521+
#[cfg(not(miri))]
499522
const COUNT: usize = 1000;
500523

501524
type T = Box<dyn Any + Send>;

crossbeam-channel/tests/mpsc.rs

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ mod channel_tests {
264264
assert!(tx2.send(1).is_err());
265265
}
266266

267+
#[cfg_attr(miri, ignore)] // Miri is too slow
267268
#[test]
268269
fn port_gone_concurrent() {
269270
let (tx, rx) = channel::<i32>();
@@ -274,6 +275,7 @@ mod channel_tests {
274275
t.join().unwrap();
275276
}
276277

278+
#[cfg_attr(miri, ignore)] // Miri is too slow
277279
#[test]
278280
fn port_gone_concurrent_shared() {
279281
let (tx, rx) = channel::<i32>();
@@ -314,20 +316,28 @@ mod channel_tests {
314316

315317
#[test]
316318
fn stress() {
319+
#[cfg(miri)]
320+
const COUNT: usize = 500;
321+
#[cfg(not(miri))]
322+
const COUNT: usize = 10000;
323+
317324
let (tx, rx) = channel::<i32>();
318325
let t = thread::spawn(move || {
319-
for _ in 0..10000 {
326+
for _ in 0..COUNT {
320327
tx.send(1).unwrap();
321328
}
322329
});
323-
for _ in 0..10000 {
330+
for _ in 0..COUNT {
324331
assert_eq!(rx.recv().unwrap(), 1);
325332
}
326333
t.join().ok().unwrap();
327334
}
328335

329336
#[test]
330337
fn stress_shared() {
338+
#[cfg(miri)]
339+
const AMT: u32 = 500;
340+
#[cfg(not(miri))]
331341
const AMT: u32 = 10000;
332342
const NTHREADS: u32 = 8;
333343
let (tx, rx) = channel::<i32>();
@@ -735,12 +745,17 @@ mod channel_tests {
735745

736746
#[test]
737747
fn recv_a_lot() {
748+
#[cfg(miri)]
749+
const N: usize = 100;
750+
#[cfg(not(miri))]
751+
const N: usize = 10000;
752+
738753
// Regression test that we don't run out of stack in scheduler context
739754
let (tx, rx) = channel();
740-
for _ in 0..10000 {
755+
for _ in 0..N {
741756
tx.send(()).unwrap();
742757
}
743-
for _ in 0..10000 {
758+
for _ in 0..N {
744759
rx.recv().unwrap();
745760
}
746761
}
@@ -841,6 +856,7 @@ mod channel_tests {
841856
t.join().unwrap();
842857
}
843858

859+
#[cfg_attr(miri, ignore)] // Miri is too slow
844860
#[test]
845861
fn test_recv_try_iter() {
846862
let (request_tx, request_rx) = channel();
@@ -955,6 +971,7 @@ mod channel_tests {
955971
}
956972

957973
// Source: https://github.com/rust-lang/rust/blob/master/src/libstd/sync/mpsc/mod.rs
974+
#[cfg(not(miri))] // Miri failed due to https://github.com/rust-lang/miri/issues/1371
958975
mod sync_channel_tests {
959976
use super::*;
960977

@@ -1079,24 +1096,34 @@ mod sync_channel_tests {
10791096

10801097
#[test]
10811098
fn stress() {
1099+
#[cfg(miri)]
1100+
const N: usize = 100;
1101+
#[cfg(not(miri))]
1102+
const N: usize = 10000;
1103+
10821104
let (tx, rx) = sync_channel::<i32>(0);
10831105
let t = thread::spawn(move || {
1084-
for _ in 0..10000 {
1106+
for _ in 0..N {
10851107
tx.send(1).unwrap();
10861108
}
10871109
});
1088-
for _ in 0..10000 {
1110+
for _ in 0..N {
10891111
assert_eq!(rx.recv().unwrap(), 1);
10901112
}
10911113
t.join().unwrap();
10921114
}
10931115

10941116
#[test]
10951117
fn stress_recv_timeout_two_threads() {
1118+
#[cfg(miri)]
1119+
const N: usize = 100;
1120+
#[cfg(not(miri))]
1121+
const N: usize = 10000;
1122+
10961123
let (tx, rx) = sync_channel::<i32>(0);
10971124

10981125
let t = thread::spawn(move || {
1099-
for _ in 0..10000 {
1126+
for _ in 0..N {
11001127
tx.send(1).unwrap();
11011128
}
11021129
});
@@ -1113,7 +1140,7 @@ mod sync_channel_tests {
11131140
}
11141141
}
11151142

1116-
assert_eq!(recv_count, 10000);
1143+
assert_eq!(recv_count, N);
11171144
t.join().unwrap();
11181145
}
11191146

@@ -1449,12 +1476,17 @@ mod sync_channel_tests {
14491476

14501477
#[test]
14511478
fn recv_a_lot() {
1479+
#[cfg(miri)]
1480+
const N: usize = 100;
1481+
#[cfg(not(miri))]
1482+
const N: usize = 10000;
1483+
14521484
// Regression test that we don't run out of stack in scheduler context
1453-
let (tx, rx) = sync_channel(10000);
1454-
for _ in 0..10000 {
1485+
let (tx, rx) = sync_channel(N);
1486+
for _ in 0..N {
14551487
tx.send(()).unwrap();
14561488
}
1457-
for _ in 0..10000 {
1489+
for _ in 0..N {
14581490
rx.recv().unwrap();
14591491
}
14601492
}
@@ -1792,7 +1824,11 @@ mod select_tests {
17921824

17931825
#[test]
17941826
fn stress() {
1827+
#[cfg(miri)]
1828+
const AMT: i32 = 100;
1829+
#[cfg(not(miri))]
17951830
const AMT: i32 = 10000;
1831+
17961832
let (tx1, rx1) = channel::<i32>();
17971833
let (tx2, rx2) = channel::<i32>();
17981834
let (tx3, rx3) = channel::<()>();

crossbeam-channel/tests/ready.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ fn nesting() {
490490

491491
#[test]
492492
fn stress_recv() {
493+
#[cfg(miri)]
494+
const COUNT: usize = 100;
495+
#[cfg(not(miri))]
493496
const COUNT: usize = 10_000;
494497

495498
let (s1, r1) = unbounded();
@@ -527,6 +530,9 @@ fn stress_recv() {
527530

528531
#[test]
529532
fn stress_send() {
533+
#[cfg(miri)]
534+
const COUNT: usize = 100;
535+
#[cfg(not(miri))]
530536
const COUNT: usize = 10_000;
531537

532538
let (s1, r1) = bounded(0);
@@ -561,6 +567,9 @@ fn stress_send() {
561567

562568
#[test]
563569
fn stress_mixed() {
570+
#[cfg(miri)]
571+
const COUNT: usize = 100;
572+
#[cfg(not(miri))]
564573
const COUNT: usize = 10_000;
565574

566575
let (s1, r1) = bounded(0);
@@ -666,6 +675,9 @@ fn send_recv_same_channel() {
666675

667676
#[test]
668677
fn channel_through_channel() {
678+
#[cfg(miri)]
679+
const COUNT: usize = 100;
680+
#[cfg(not(miri))]
669681
const COUNT: usize = 1000;
670682

671683
type T = Box<dyn Any + Send>;
@@ -722,6 +734,9 @@ fn channel_through_channel() {
722734

723735
#[test]
724736
fn fairness1() {
737+
#[cfg(miri)]
738+
const COUNT: usize = 100;
739+
#[cfg(not(miri))]
725740
const COUNT: usize = 10_000;
726741

727742
let (s1, r1) = bounded::<()>(COUNT);
@@ -767,6 +782,9 @@ fn fairness1() {
767782

768783
#[test]
769784
fn fairness2() {
785+
#[cfg(miri)]
786+
const COUNT: usize = 100;
787+
#[cfg(not(miri))]
770788
const COUNT: usize = 100_000;
771789

772790
let (s1, r1) = unbounded::<()>();

0 commit comments

Comments
 (0)