Skip to content

Commit 6c08b99

Browse files
committed
ci: run unit tests with sanitizers
1 parent e7ee5c6 commit 6c08b99

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

.github/workflows/main.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ jobs:
2525
rust: beta
2626
- os: windows-latest
2727
rust: beta
28-
- os: macos-latest
29-
rust: nightly
3028

3129
runs-on: ${{ matrix.os }}
3230

@@ -35,6 +33,7 @@ jobs:
3533
- uses: dtolnay/rust-toolchain@master
3634
with:
3735
toolchain: ${{ matrix.rust }}
36+
components: ${{ matrix.rust == 'nightly' && 'rust-src' || '' }}
3837
# Add toolchain for no_std tests
3938
- run: rustup toolchain install nightly
4039
- name: Downgrade deps on Rust 1.63.0
@@ -79,6 +78,35 @@ jobs:
7978
run: >
8079
cd url
8180
&& cargo check --target aarch64-unknown-none -v --no-default-features
81+
- name: Run tests with sanitizers
82+
if: (matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest') && matrix.rust == 'nightly'
83+
env:
84+
RUST_LOG: trace
85+
ASAN_OPTIONS: detect_leaks=1:detect_stack_use_after_return=1
86+
run: |
87+
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
88+
sudo apt-get install -y --no-install-recommends llvm
89+
TARGET="x86_64-unknown-linux-gnu"
90+
SANITIZERS="address thread leak memory"
91+
elif [ "${{ matrix.os }}" = "macos-latest" ]; then
92+
# llvm-symbolizer (as part of llvm) is installed by default on macOS runners
93+
TARGET="aarch64-apple-darwin"
94+
# no memory and leak sanitizer support yet
95+
SANITIZERS="address thread"
96+
# Suppress non-crate leaks on macOS. TODO: Check occasionally if these are still needed.
97+
{
98+
echo "leak:dyld4::RuntimeState"
99+
echo "leak:fetchInitializingClassList"
100+
} > suppressions.txt
101+
# shellcheck disable=SC2155
102+
export LSAN_OPTIONS="suppressions=$(pwd)/suppressions.txt"
103+
fi
104+
for sanitizer in $SANITIZERS; do
105+
echo "Running tests with $sanitizer sanitizer..."
106+
export RUSTFLAGS="-Z sanitizer=$sanitizer"
107+
export RUSTDOCFLAGS="$RUSTFLAGS"
108+
cargo +nightly test -Z build-std --target "$TARGET"
109+
done
82110
83111
WASM:
84112
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)