Skip to content

Commit 7492360

Browse files
authored
ci: run unit tests with sanitizers (#1002)
1 parent e7ee5c6 commit 7492360

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

.github/workflows/main.yml

+27-2
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,32 @@ 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+
ASAN_OPTIONS: detect_leaks=1:detect_stack_use_after_return=1
85+
run: |
86+
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
87+
sudo apt-get install -y --no-install-recommends llvm
88+
TARGET="x86_64-unknown-linux-gnu"
89+
SANITIZERS="address thread leak memory"
90+
elif [ "${{ matrix.os }}" = "macos-latest" ]; then
91+
TARGET="aarch64-apple-darwin"
92+
# no memory and leak sanitizer support yet
93+
SANITIZERS="address thread"
94+
# Suppress non-crate leaks on macOS. TODO: Check occasionally if these are still needed.
95+
{
96+
echo "leak:dyld4::RuntimeState"
97+
echo "leak:fetchInitializingClassList"
98+
} > suppressions.txt
99+
export LSAN_OPTIONS="suppressions=$(pwd)/suppressions.txt"
100+
fi
101+
for sanitizer in $SANITIZERS; do
102+
echo "Running tests with $sanitizer sanitizer..."
103+
export RUSTFLAGS="-Z sanitizer=$sanitizer"
104+
export RUSTDOCFLAGS="$RUSTFLAGS"
105+
cargo +nightly test -Z build-std --target "$TARGET"
106+
done
82107
83108
WASM:
84109
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)