Run tests under AddressSanitizer

Change-Id: If13535670c53e02c1b3aec84d437b2853eef4040
diff --git a/test.sh b/test.sh
index 1fa772e..826a1e4 100755
--- a/test.sh
+++ b/test.sh
@@ -15,13 +15,22 @@
 rsa-test-generate-large-keys
 experimental-sha512-ec"
 
+# If --target is not explicitly passed to cargo, it will apply RUSTFLAGS to proc
+# macros, which cannot be sanitized.
+TARGET=$(rustc -Vv |grep host |cut -d ' ' -f 2)
+export RUSTFLAGS="-Z sanitizer=address"
+
 # Test with each feature individually
-for features in $FEATURES run-symbol-conflict-test; do
-    cargo test --features "$features"
+for features in $FEATURES; do
+    cargo test --features "$features" --target "$TARGET"
 done
 
+# The symbol conflict test doesn't pass --target to cargo, so sanitizing it
+# doesn't work and would in any case be redundant.
+RUSTFLAGS="" cargo test --features run-symbol-conflict-test --test integration_tests -- test_symbol_conflict
+
 # Test with all features together to make sure they work
 # correctly together. Don't both with run-symbol-conflict-test
 # since a) it takes a long time and, b) it isn't affected by
 # other features.
-cargo test --features "$FEATURES"
+cargo test --features "$FEATURES" --target "$TARGET"