From 4d78dc35da3f0d2e87d78144d2f3b7140fb62601 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 4 Feb 2023 15:57:58 +0100 Subject: [PATCH] Add test_sanitizer Makefile target Runs the tests with a sanitizer enabled. --- Makefile | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Makefile b/Makefile index 514798c9..e5316cb5 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,9 @@ # Targets available via Rustup that are supported. TARGETS ?= aarch64-apple-ios aarch64-linux-android arm-linux-androideabi i686-unknown-linux-gnu x86_64-apple-darwin x86_64-apple-ios x86_64-pc-windows-msvc x86_64-unknown-freebsd x86_64-unknown-illumos x86_64-unknown-linux-gnu x86_64-unknown-netbsd x86_64-unknown-redox +# Example value: `nightly-x86_64-apple-darwin`. +RUSTUP_TOOLCHAIN ?= $(shell rustup show active-toolchain | cut -d' ' -f1) +# Architecture target. Example value: `x86_64-apple-darwin`. +RUSTUP_TARGET ?= $(shell echo $(RUSTUP_TOOLCHAIN) | cut -d'-' -f2,3,4,5) test: cargo test --all-features @@ -10,6 +14,15 @@ test_all: check_all_targets cargo hack test --feature-powerset cargo hack test --feature-powerset --release +# NOTE: Requires a nightly compiler. +# NOTE: Keep `RUSTFLAGS` and `RUSTDOCFLAGS` in sync to ensure the doc tests +# compile correctly. +test_sanitizer: + @if [ -z $${SAN+x} ]; then echo "Required '\$$SAN' variable is not set" 1>&2; exit 1; fi + RUSTFLAGS="-Z sanitizer=$$SAN -Z sanitizer-memory-track-origins" \ + RUSTDOCFLAGS="-Z sanitizer=$$SAN -Z sanitizer-memory-track-origins" \ + cargo test -Z build-std --all-features --target $(RUSTUP_TARGET) + # Check all targets using all features. check_all_targets: $(TARGETS) $(TARGETS):