Skip to content

Commit

Permalink
Run sanitizers on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Dec 9, 2020
1 parent 47110fd commit 1ca2c56
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 9 deletions.
9 changes: 8 additions & 1 deletion ci/crossbeam-channel.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash

cd "$(dirname "$0")"/../crossbeam-channel
set -ex

script_dir="$(cd "$(dirname "$0")" && pwd)"
cd "$script_dir"/../crossbeam-channel

export RUSTFLAGS="-D warnings"

cargo check --bins --examples --tests
Expand All @@ -11,6 +13,11 @@ cargo test -- --test-threads=1
if [[ "$RUST_VERSION" == "nightly"* ]]; then
cd benchmarks
cargo check --bins
cd ..

RUSTDOCFLAGS=-Dwarnings cargo doc --no-deps --all-features

# Run sanitizers
export TSAN_OPTIONS="suppressions=$script_dir/tsan"
"$script_dir"/san.sh --features sanitize
fi
8 changes: 7 additions & 1 deletion ci/crossbeam-deque.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#!/bin/bash

cd "$(dirname "$0")"/../crossbeam-deque
set -ex

script_dir="$(cd "$(dirname "$0")" && pwd)"
cd "$script_dir"/../crossbeam-deque

export RUSTFLAGS="-D warnings"

cargo check --bins --examples --tests
cargo test

if [[ "$RUST_VERSION" == "nightly"* ]]; then
RUSTDOCFLAGS=-Dwarnings cargo doc --no-deps --all-features

# Run sanitizers
export TSAN_OPTIONS="suppressions=$script_dir/tsan"
"$script_dir"/san.sh
fi
9 changes: 7 additions & 2 deletions ci/crossbeam-epoch.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash

cd "$(dirname "$0")"/../crossbeam-epoch
set -ex

script_dir="$(cd "$(dirname "$0")" && pwd)"
cd "$script_dir"/../crossbeam-epoch

export RUSTFLAGS="-D warnings"

cargo check --bins --examples --tests
Expand All @@ -14,7 +16,10 @@ if [[ "$RUST_VERSION" == "nightly"* ]]; then
RUSTDOCFLAGS=-Dwarnings cargo doc --no-deps --all-features

if [[ "$OSTYPE" == "linux"* ]]; then
ASAN_OPTIONS="detect_odr_violation=0 detect_leaks=0" \
# Run sanitizers
export TSAN_OPTIONS="suppressions=$script_dir/tsan"
"$script_dir"/san.sh --features sanitize,nightly

RUSTFLAGS="-Z sanitizer=address" \
cargo run \
--release \
Expand Down
7 changes: 6 additions & 1 deletion ci/crossbeam-queue.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#!/bin/bash

cd "$(dirname "$0")"/../crossbeam-queue
set -ex

script_dir="$(cd "$(dirname "$0")" && pwd)"
cd "$script_dir"/../crossbeam-queue

export RUSTFLAGS="-D warnings"

cargo check --bins --examples --tests
cargo test

if [[ "$RUST_VERSION" == "nightly"* ]]; then
RUSTDOCFLAGS=-Dwarnings cargo doc --no-deps --all-features

# Run sanitizers
"$script_dir"/san.sh --features nightly
fi
9 changes: 8 additions & 1 deletion ci/crossbeam-skiplist.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash

cd "$(dirname "$0")"/../crossbeam-skiplist
set -ex

script_dir="$(cd "$(dirname "$0")" && pwd)"
cd "$script_dir"/../crossbeam-skiplist

export RUSTFLAGS="-D warnings"

cargo check --bins --examples --tests
Expand All @@ -12,4 +14,9 @@ if [[ "$RUST_VERSION" == "nightly"* ]]; then
cargo test --features nightly

RUSTDOCFLAGS=-Dwarnings cargo doc --no-deps --all-features

# Run sanitizers
# https://github.com/crossbeam-rs/crossbeam/issues/614
export ASAN_OPTIONS="detect_leaks=0"
"$script_dir"/san.sh --features nightly
fi
7 changes: 6 additions & 1 deletion ci/crossbeam-utils.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash

cd "$(dirname "$0")"/../crossbeam-utils
set -ex

script_dir="$(cd "$(dirname "$0")" && pwd)"
cd "$script_dir"/../crossbeam-utils

export RUSTFLAGS="-D warnings"

cargo check --bins --examples --tests
Expand All @@ -12,4 +14,7 @@ if [[ "$RUST_VERSION" == "nightly"* ]]; then
cargo test --features nightly

RUSTDOCFLAGS=-Dwarnings cargo doc --no-deps --all-features

# Run sanitizers
"$script_dir"/san.sh --features nightly
fi
7 changes: 6 additions & 1 deletion ci/crossbeam.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash

cd "$(dirname "$0")"/..
set -ex

script_dir="$(cd "$(dirname "$0")" && pwd)"
cd "$script_dir"/..

export RUSTFLAGS="-D warnings"

cargo check --bins --examples --tests
Expand All @@ -12,4 +14,7 @@ if [[ "$RUST_VERSION" == "nightly"* ]]; then
cargo test --features nightly

RUSTDOCFLAGS=-Dwarnings cargo doc --no-deps --all-features

# Run sanitizers
"$script_dir"/san.sh --features nightly
fi
31 changes: 31 additions & 0 deletions ci/san.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -ex

if [[ "$OSTYPE" != "linux"* ]]; then
exit 0
fi

rustup component add rust-src

# Run address sanitizer
cargo clean
RUSTFLAGS="-Z sanitizer=address" \
cargo test --release --target x86_64-unknown-linux-gnu --tests "$@"

# Run leak sanitizer (when memory leak detection is enabled)
if [[ "$ASAN_OPTIONS" != *"detect_leaks=0"* ]]; then
cargo clean
RUSTFLAGS="-Z sanitizer=leak" \
cargo test --release --target x86_64-unknown-linux-gnu --tests "$@"
fi

# Run memory sanitizer
cargo clean
RUSTFLAGS="-Z sanitizer=memory" \
cargo test -Zbuild-std --release --target x86_64-unknown-linux-gnu --tests "$@"

# Run thread sanitizer
cargo clean
RUSTFLAGS="-Z sanitizer=thread" \
cargo test -Zbuild-std --release --target x86_64-unknown-linux-gnu --tests "$@"
13 changes: 13 additions & 0 deletions ci/tsan
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# TSAN suppressions file for crossbeam

# The epoch-based GC uses fences.
race:crossbeam_epoch

# Push and steal operations in crossbeam-deque may cause data races, but such
# data races are safe. If a data race happens, the value read by `steal` is
# forgotten and the steal operation is then retried.
race:crossbeam_deque*push
race:crossbeam_deque*steal

# AtomicCell::compare_exchange uses fences if it is not lock-free.
race:crossbeam_utils::atomic::atomic_cell::AtomicCell<T>::compare_exchange
6 changes: 6 additions & 0 deletions crossbeam-channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ default = ["std"]
# This is enabled by default.
std = ["crossbeam-utils/std"]

# TODO: Once `cfg(sanitize = "..")` is stable, replace this.
# An internal feature used when running sanitizers.
# This is not part of the public API and crossbeam may make breaking changes
# to them at any time.
sanitize = []

[dependencies]
cfg-if = "1"

Expand Down
2 changes: 2 additions & 0 deletions crossbeam-channel/tests/tick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ fn recv() {
assert_eq!(r.try_recv(), Err(TryRecvError::Empty));
}

#[cfg(not(feature = "sanitize"))] // TODO: assertions failed due to tsan is slow
#[test]
fn recv_timeout() {
let start = Instant::now();
Expand Down Expand Up @@ -251,6 +252,7 @@ fn select() {
assert_eq!(hits.load(Ordering::SeqCst), 8);
}

#[cfg(not(feature = "sanitize"))] // TODO: assertions failed due to tsan is slow
#[test]
fn ready() {
const THREADS: usize = 4;
Expand Down
5 changes: 4 additions & 1 deletion crossbeam-epoch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ alloc = []
# of crossbeam may make breaking changes to them at any time.
nightly = ["crossbeam-utils/nightly"]

# TODO: docs
# TODO: Once `cfg(sanitize = "..")` is stable, replace this.
# An internal feature used when running sanitizers.
# This is not part of the public API and crossbeam may make breaking changes
# to them at any time.
sanitize = [] # Makes it more likely to trigger any potential data races.

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions crossbeam-epoch/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ mod tests {
.unwrap();
}

#[cfg(not(feature = "sanitize"))] // TODO: assertions failed due to tsan is slow
#[test]
fn incremental() {
const COUNT: usize = 100_000;
Expand Down
1 change: 1 addition & 0 deletions crossbeam-epoch/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ pub struct Local {

// Make sure `Local` is less than or equal to 2048 bytes.
// https://github.com/crossbeam-rs/crossbeam/issues/551
#[cfg(not(feature = "sanitize"))] // `feature = "sanitize"` reduces the size of `Local`
#[test]
fn local_size() {
assert!(core::mem::size_of::<Local>() <= 2048, "An allocation of `Local` should be <= 2048 bytes.");
Expand Down

0 comments on commit 1ca2c56

Please sign in to comment.