Skip to content

Commit

Permalink
Run sanitizers on CI (#2303)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jan 1, 2021
1 parent 8e9b86e commit 73aaf4a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -212,6 +212,27 @@ jobs:
--workspace --exclude futures-test \
--features unstable --ignore-unknown-features
san:
name: cargo test -Z sanitizer=${{ matrix.sanitizer }}
strategy:
matrix:
sanitizer:
- address
- memory
- thread
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: rustup component add rust-src
- run: cargo -Z build-std test --workspace --all-features --target x86_64-unknown-linux-gnu --lib --tests
env:
# TODO: Once `cfg(sanitize = "..")` is stable, replace
# `cfg(futures_sanitizer)` with `cfg(sanitize = "..")` and remove
# `--cfg futures_sanitizer`.
RUSTFLAGS: -D warnings -Z sanitizer=${{ matrix.sanitizer }} --cfg futures_sanitizer

clippy:
name: cargo clippy
runs-on: ubuntu-latest
Expand Down
9 changes: 7 additions & 2 deletions futures/tests/recurse.rs
Expand Up @@ -5,6 +5,11 @@ fn lots() {
use std::sync::mpsc;
use std::thread;

#[cfg(not(futures_sanitizer))]
const N: i32 = 1_000;
#[cfg(futures_sanitizer)] // If N is many, asan reports stack-overflow: https://gist.github.com/taiki-e/099446d21cbec69d4acbacf7a9646136
const N: i32 = 100;

fn do_it(input: (i32, i32)) -> BoxFuture<'static, i32> {
let (n, x) = input;
if n == 0 {
Expand All @@ -16,7 +21,7 @@ fn lots() {

let (tx, rx) = mpsc::channel();
thread::spawn(|| {
block_on(do_it((1_000, 0)).map(move |x| tx.send(x).unwrap()))
block_on(do_it((N, 0)).map(move |x| tx.send(x).unwrap()))
});
assert_eq!(500_500, rx.recv().unwrap());
assert_eq!((0..=N).sum::<i32>(), rx.recv().unwrap());
}

0 comments on commit 73aaf4a

Please sign in to comment.