Skip to content

Commit 6433a0d

Browse files
committed
Run Miri on CI
1 parent 5406a5e commit 6433a0d

16 files changed

+85
-24
lines changed

.github/workflows/ci.yml

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: CI
22

3+
permissions:
4+
contents: read
5+
36
on:
47
pull_request:
58
push:
@@ -10,8 +13,12 @@ on:
1013
- cron: '0 1 * * *'
1114

1215
env:
13-
RUSTFLAGS: -D warnings
16+
CARGO_INCREMENTAL: 0
17+
CARGO_NET_RETRY: 10
18+
CARGO_TERM_COLOR: always
1419
RUST_BACKTRACE: 1
20+
RUSTFLAGS: -D warnings
21+
RUSTUP_MAX_RETRIES: 10
1522

1623
defaults:
1724
run:
@@ -229,6 +236,16 @@ jobs:
229236
- run: ci/no_atomic_cas.sh
230237
- run: git diff --exit-code
231238

239+
miri:
240+
runs-on: ubuntu-latest
241+
steps:
242+
- uses: actions/checkout@v2
243+
- name: Install Rust
244+
run: rustup toolchain install nightly --component miri && rustup default nightly
245+
- run: cargo miri test --workspace --no-fail-fast
246+
# env:
247+
# MIRIFLAGS: -Zmiri-tag-raw-pointers
248+
232249
san:
233250
name: cargo test -Z sanitizer=${{ matrix.sanitizer }}
234251
strategy:
@@ -261,6 +278,7 @@ jobs:
261278
- run: cargo clippy --workspace --all-features --all-targets
262279

263280
fmt:
281+
name: cargo fmt
264282
runs-on: ubuntu-latest
265283
steps:
266284
- uses: actions/checkout@v2

futures-channel/tests/mpsc.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ fn tx_close_gets_none() {
200200

201201
#[test]
202202
fn stress_shared_unbounded() {
203+
#[cfg(miri)]
204+
const AMT: u32 = 100;
205+
#[cfg(not(miri))]
203206
const AMT: u32 = 10000;
204207
const NTHREADS: u32 = 8;
205208
let (tx, rx) = mpsc::unbounded::<i32>();
@@ -229,6 +232,9 @@ fn stress_shared_unbounded() {
229232

230233
#[test]
231234
fn stress_shared_bounded_hard() {
235+
#[cfg(miri)]
236+
const AMT: u32 = 100;
237+
#[cfg(not(miri))]
232238
const AMT: u32 = 10000;
233239
const NTHREADS: u32 = 8;
234240
let (tx, rx) = mpsc::channel::<i32>(0);
@@ -259,6 +265,9 @@ fn stress_shared_bounded_hard() {
259265
#[allow(clippy::same_item_push)]
260266
#[test]
261267
fn stress_receiver_multi_task_bounded_hard() {
268+
#[cfg(miri)]
269+
const AMT: usize = 100;
270+
#[cfg(not(miri))]
262271
const AMT: usize = 10_000;
263272
const NTHREADS: u32 = 2;
264273

@@ -327,6 +336,11 @@ fn stress_receiver_multi_task_bounded_hard() {
327336
/// after sender dropped.
328337
#[test]
329338
fn stress_drop_sender() {
339+
#[cfg(miri)]
340+
const ITER: usize = 100;
341+
#[cfg(not(miri))]
342+
const ITER: usize = 10000;
343+
330344
fn list() -> impl Stream<Item = i32> {
331345
let (tx, rx) = mpsc::channel(1);
332346
thread::spawn(move || {
@@ -335,7 +349,7 @@ fn stress_drop_sender() {
335349
rx
336350
}
337351

338-
for _ in 0..10000 {
352+
for _ in 0..ITER {
339353
let v: Vec<_> = block_on(list().collect());
340354
assert_eq!(v, vec![1, 2, 3]);
341355
}
@@ -380,9 +394,12 @@ fn stress_close_receiver_iter() {
380394
}
381395
}
382396

397+
#[cfg_attr(miri, ignore)] // Miri is too slow
383398
#[test]
384399
fn stress_close_receiver() {
385-
for _ in 0..10000 {
400+
const ITER: usize = 10000;
401+
402+
for _ in 0..ITER {
386403
stress_close_receiver_iter();
387404
}
388405
}
@@ -397,6 +414,9 @@ async fn stress_poll_ready_sender(mut sender: mpsc::Sender<u32>, count: u32) {
397414
#[allow(clippy::same_item_push)]
398415
#[test]
399416
fn stress_poll_ready() {
417+
#[cfg(miri)]
418+
const AMT: u32 = 100;
419+
#[cfg(not(miri))]
400420
const AMT: u32 = 1000;
401421
const NTHREADS: u32 = 8;
402422

@@ -424,6 +444,7 @@ fn stress_poll_ready() {
424444
stress(16);
425445
}
426446

447+
#[cfg_attr(miri, ignore)] // Miri is too slow
427448
#[test]
428449
fn try_send_1() {
429450
const N: usize = 3000;

futures/tests/compat.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![cfg(feature = "compat")]
2+
#![cfg(not(miri))] // unsupported operation: can't call foreign function: kqueue
23

34
use futures::compat::Future01CompatExt;
45
use futures::prelude::*;

futures/tests/eventual.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(not(miri))] // https://github.com/rust-lang/miri/issues/1038
2+
13
use futures::channel::oneshot;
24
use futures::executor::ThreadPool;
35
use futures::future::{self, ok, Future, FutureExt, TryFutureExt};

futures/tests/future_join_all.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1+
use futures::pin_mut;
12
use futures::executor::block_on;
23
use futures::future::{join_all, ready, Future, JoinAll};
34
use std::fmt::Debug;
45

5-
fn assert_done<T, F>(actual_fut: F, expected: T)
6+
#[track_caller]
7+
fn assert_done<T>(actual_fut: impl Future<Output = T>, expected: T)
68
where
79
T: PartialEq + Debug,
8-
F: FnOnce() -> Box<dyn Future<Output = T> + Unpin>,
910
{
10-
let output = block_on(actual_fut());
11+
pin_mut!(actual_fut);
12+
let output = block_on(actual_fut);
1113
assert_eq!(output, expected);
1214
}
1315

1416
#[test]
1517
fn collect_collects() {
16-
assert_done(|| Box::new(join_all(vec![ready(1), ready(2)])), vec![1, 2]);
17-
assert_done(|| Box::new(join_all(vec![ready(1)])), vec![1]);
18+
assert_done(join_all(vec![ready(1), ready(2)]), vec![1, 2]);
19+
assert_done(join_all(vec![ready(1)]), vec![1]);
1820
// REVIEW: should this be implemented?
19-
// assert_done(|| Box::new(join_all(Vec::<i32>::new())), vec![]);
21+
// assert_done(join_all(Vec::<i32>::new()), vec![]);
2022

2123
// TODO: needs more tests
2224
}
@@ -25,18 +27,18 @@ fn collect_collects() {
2527
fn join_all_iter_lifetime() {
2628
// In futures-rs version 0.1, this function would fail to typecheck due to an overly
2729
// conservative type parameterization of `JoinAll`.
28-
fn sizes(bufs: Vec<&[u8]>) -> Box<dyn Future<Output = Vec<usize>> + Unpin> {
30+
fn sizes(bufs: Vec<&[u8]>) -> impl Future<Output = Vec<usize>> {
2931
let iter = bufs.into_iter().map(|b| ready::<usize>(b.len()));
30-
Box::new(join_all(iter))
32+
join_all(iter)
3133
}
3234

33-
assert_done(|| sizes(vec![&[1, 2, 3], &[], &[0]]), vec![3_usize, 0, 1]);
35+
assert_done(sizes(vec![&[1, 2, 3], &[], &[0]]), vec![3_usize, 0, 1]);
3436
}
3537

3638
#[test]
3739
fn join_all_from_iter() {
3840
assert_done(
39-
|| Box::new(vec![ready(1), ready(2)].into_iter().collect::<JoinAll<_>>()),
41+
vec![ready(1), ready(2)].into_iter().collect::<JoinAll<_>>(),
4042
vec![1, 2],
4143
)
4244
}

futures/tests/future_shared.rs

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fn drop_in_poll() {
9696
assert_eq!(block_on(future1), 1);
9797
}
9898

99+
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
99100
#[test]
100101
fn peek() {
101102
let mut local_pool = LocalPool::new();

futures/tests/future_try_join_all.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
use futures::executor::block_on;
2+
use futures::pin_mut;
23
use futures_util::future::{err, ok, try_join_all, TryJoinAll};
34
use std::fmt::Debug;
45
use std::future::Future;
56

6-
fn assert_done<T, F>(actual_fut: F, expected: T)
7+
#[track_caller]
8+
fn assert_done<T>(actual_fut: impl Future<Output = T>, expected: T)
79
where
810
T: PartialEq + Debug,
9-
F: FnOnce() -> Box<dyn Future<Output = T> + Unpin>,
1011
{
11-
let output = block_on(actual_fut());
12+
pin_mut!(actual_fut);
13+
let output = block_on(actual_fut);
1214
assert_eq!(output, expected);
1315
}
1416

1517
#[test]
1618
fn collect_collects() {
17-
assert_done(|| Box::new(try_join_all(vec![ok(1), ok(2)])), Ok::<_, usize>(vec![1, 2]));
18-
assert_done(|| Box::new(try_join_all(vec![ok(1), err(2)])), Err(2));
19-
assert_done(|| Box::new(try_join_all(vec![ok(1)])), Ok::<_, usize>(vec![1]));
19+
assert_done(try_join_all(vec![ok(1), ok(2)]), Ok::<_, usize>(vec![1, 2]));
20+
assert_done(try_join_all(vec![ok(1), err(2)]), Err(2));
21+
assert_done(try_join_all(vec![ok(1)]), Ok::<_, usize>(vec![1]));
2022
// REVIEW: should this be implemented?
21-
// assert_done(|| Box::new(try_join_all(Vec::<i32>::new())), Ok(vec![]));
23+
// assert_done(try_join_all(Vec::<i32>::new()), Ok(vec![]));
2224

2325
// TODO: needs more tests
2426
}
@@ -27,18 +29,18 @@ fn collect_collects() {
2729
fn try_join_all_iter_lifetime() {
2830
// In futures-rs version 0.1, this function would fail to typecheck due to an overly
2931
// conservative type parameterization of `TryJoinAll`.
30-
fn sizes(bufs: Vec<&[u8]>) -> Box<dyn Future<Output = Result<Vec<usize>, ()>> + Unpin> {
32+
fn sizes(bufs: Vec<&[u8]>) -> impl Future<Output = Result<Vec<usize>, ()>> {
3133
let iter = bufs.into_iter().map(|b| ok::<usize, ()>(b.len()));
32-
Box::new(try_join_all(iter))
34+
try_join_all(iter)
3335
}
3436

35-
assert_done(|| sizes(vec![&[1, 2, 3], &[], &[0]]), Ok(vec![3_usize, 0, 1]));
37+
assert_done(sizes(vec![&[1, 2, 3], &[], &[0]]), Ok(vec![3_usize, 0, 1]));
3638
}
3739

3840
#[test]
3941
fn try_join_all_from_iter() {
4042
assert_done(
41-
|| Box::new(vec![ok(1), ok(2)].into_iter().collect::<TryJoinAll<_>>()),
43+
vec![ok(1), ok(2)].into_iter().collect::<TryJoinAll<_>>(),
4244
Ok::<_, usize>(vec![1, 2]),
4345
)
4446
}

futures/tests/lock_mutex.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fn mutex_wakes_waiters() {
3434
assert!(waiter.poll_unpin(&mut panic_context()).is_ready());
3535
}
3636

37+
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
3738
#[test]
3839
fn mutex_contested() {
3940
let (tx, mut rx) = mpsc::unbounded();

futures/tests/macro_comma_support.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fn ready() {
1414
}))
1515
}
1616

17+
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
1718
#[test]
1819
fn poll() {
1920
use futures::poll;

futures/tests/ready_queue.rs

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ fn dropping_ready_queue() {
9393

9494
#[test]
9595
fn stress() {
96+
#[cfg(miri)]
97+
const ITER: usize = 30;
98+
#[cfg(not(miri))]
9699
const ITER: usize = 300;
97100

98101
for i in 0..ITER {

futures/tests/recurse.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use futures::future::{self, BoxFuture, FutureExt};
33
use std::sync::mpsc;
44
use std::thread;
55

6+
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
67
#[test]
78
fn lots() {
89
#[cfg(not(futures_sanitizer))]

futures/tests/sink.rs

+1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ fn mpsc_blocking_start_send() {
288288

289289
// test `flush` by using `with` to make the first insertion into a sink block
290290
// until a oneshot is completed
291+
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
291292
#[test]
292293
fn with_flush() {
293294
let (tx, rx) = oneshot::channel();

futures/tests/stream_futures_ordered.rs

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fn works_1() {
2626
assert_eq!(None, iter.next());
2727
}
2828

29+
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
2930
#[test]
3031
fn works_2() {
3132
let (a_tx, a_rx) = oneshot::channel::<i32>();
@@ -54,6 +55,7 @@ fn from_iterator() {
5455
assert_eq!(block_on(stream.collect::<Vec<_>>()), vec![1, 2, 3]);
5556
}
5657

58+
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
5759
#[test]
5860
fn queue_never_unblocked() {
5961
let (_a_tx, a_rx) = oneshot::channel::<Box<dyn Any + Send>>();

futures/tests/stream_futures_unordered.rs

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ fn works_1() {
5656
assert_eq!(None, iter.next());
5757
}
5858

59+
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
5960
#[test]
6061
fn works_2() {
6162
let (a_tx, a_rx) = oneshot::channel::<i32>();
@@ -85,6 +86,7 @@ fn from_iterator() {
8586
assert_eq!(block_on(stream.collect::<Vec<_>>()), vec![1, 2, 3]);
8687
}
8788

89+
#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038
8890
#[test]
8991
fn finished_future() {
9092
let (_a_tx, a_rx) = oneshot::channel::<i32>();

futures/tests/stream_try_stream.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(not(miri))] // https://github.com/rust-lang/miri/issues/1038
2+
13
use futures::{
24
stream::{self, StreamExt, TryStreamExt},
35
task::Poll,

futures/tests/task_atomic_waker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::sync::atomic::Ordering;
66
use std::sync::Arc;
77
use std::thread;
88

9+
#[cfg_attr(miri, ignore)] // Miri is too slow
910
#[test]
1011
fn basic() {
1112
let atomic_waker = Arc::new(AtomicWaker::new());

0 commit comments

Comments
 (0)