Skip to content

Commit 73aaf4a

Browse files
authored
Run sanitizers on CI (#2303)
1 parent 8e9b86e commit 73aaf4a

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,27 @@ jobs:
212212
--workspace --exclude futures-test \
213213
--features unstable --ignore-unknown-features
214214
215+
san:
216+
name: cargo test -Z sanitizer=${{ matrix.sanitizer }}
217+
strategy:
218+
matrix:
219+
sanitizer:
220+
- address
221+
- memory
222+
- thread
223+
runs-on: ubuntu-latest
224+
steps:
225+
- uses: actions/checkout@v2
226+
- name: Install Rust
227+
run: rustup update nightly && rustup default nightly
228+
- run: rustup component add rust-src
229+
- run: cargo -Z build-std test --workspace --all-features --target x86_64-unknown-linux-gnu --lib --tests
230+
env:
231+
# TODO: Once `cfg(sanitize = "..")` is stable, replace
232+
# `cfg(futures_sanitizer)` with `cfg(sanitize = "..")` and remove
233+
# `--cfg futures_sanitizer`.
234+
RUSTFLAGS: -D warnings -Z sanitizer=${{ matrix.sanitizer }} --cfg futures_sanitizer
235+
215236
clippy:
216237
name: cargo clippy
217238
runs-on: ubuntu-latest

‎futures/tests/recurse.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ fn lots() {
55
use std::sync::mpsc;
66
use std::thread;
77

8+
#[cfg(not(futures_sanitizer))]
9+
const N: i32 = 1_000;
10+
#[cfg(futures_sanitizer)] // If N is many, asan reports stack-overflow: https://gist.github.com/taiki-e/099446d21cbec69d4acbacf7a9646136
11+
const N: i32 = 100;
12+
813
fn do_it(input: (i32, i32)) -> BoxFuture<'static, i32> {
914
let (n, x) = input;
1015
if n == 0 {
@@ -16,7 +21,7 @@ fn lots() {
1621

1722
let (tx, rx) = mpsc::channel();
1823
thread::spawn(|| {
19-
block_on(do_it((1_000, 0)).map(move |x| tx.send(x).unwrap()))
24+
block_on(do_it((N, 0)).map(move |x| tx.send(x).unwrap()))
2025
});
21-
assert_eq!(500_500, rx.recv().unwrap());
26+
assert_eq!((0..=N).sum::<i32>(), rx.recv().unwrap());
2227
}

0 commit comments

Comments
 (0)