From 2c06d27275a137b9193dab7b5179c58579edc285 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 27 Nov 2024 09:55:50 +0100 Subject: [PATCH] ci: run unit tests with sanitizers --- .github/workflows/main.yml | 25 +++++++++++++++++++++++-- url_debug_tests/Cargo.toml | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f78d4f94d..7364706e6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,8 +25,6 @@ jobs: rust: beta - os: windows-latest rust: beta - - os: macos-latest - rust: nightly runs-on: ${{ matrix.os }} @@ -35,6 +33,7 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.rust }} + components: ${{ matrix.rust == 'nightly' && 'rust-src' || '' }} # Add toolchain for no_std tests - run: rustup toolchain install nightly - name: Downgrade deps on Rust 1.63.0 @@ -79,6 +78,28 @@ jobs: run: > cd url && cargo check --target aarch64-unknown-none -v --no-default-features + - name: Run tests with sanitizers + if: (matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest') && matrix.rust == 'nightly' + env: + RUST_LOG: trace + ASAN_OPTIONS: detect_leaks=1:detect_stack_use_after_return=1 + run: | + if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then + sudo apt-get install -y --no-install-recommends llvm + TARGET="x86_64-unknown-linux-gnu" + SANITIZERS="address thread leak memory" + elif [ "${{ matrix.os }}" = "macos-latest" ]; then + # llvm-symbolizer (as part of llvm) is installed by default on macOS runners + TARGET="aarch64-apple-darwin" + # no memory and leak sanitizer support yet + SANITIZERS="address thread" + fi + for sanitizer in $SANITIZERS; do + echo "Running tests with $sanitizer sanitizer..." + export RUSTFLAGS="-Z sanitizer=$sanitizer" + export RUSTDOCFLAGS="$RUSTFLAGS" + cargo +nightly test -Z build-std --target "$TARGET" + done WASM: runs-on: ubuntu-latest diff --git a/url_debug_tests/Cargo.toml b/url_debug_tests/Cargo.toml index ca9b16b81..d54f3dc72 100644 --- a/url_debug_tests/Cargo.toml +++ b/url_debug_tests/Cargo.toml @@ -4,6 +4,7 @@ name = "url_debug_tests" version = "0.0.0" description = "Tests for debugger visualizers defined for the url crate such as url.natvis" publish = false +edition = "2018" rust-version = "1.60" [dev-dependencies]