ci: enable AddressSanitizer for unit tests

Change-Id: Iffd1f16938c77ccbe03bec776ccee3206b5e68aa
Refs: #2589
diff --git a/.jenkins.d/20-build.sh b/.jenkins.d/20-build.sh
index e3bb195..d96c4bd 100755
--- a/.jenkins.d/20-build.sh
+++ b/.jenkins.d/20-build.sh
@@ -2,6 +2,9 @@
 set -x
 set -e
 
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
+
 # Cleanup
 sudo ./waf -j1 --color=yes distclean
 
@@ -13,5 +16,12 @@
 sudo ./waf -j1 --color=yes distclean
 
 # Configure/build in debug mode with tests
-./waf -j1 --color=yes configure --with-tests --debug
+if [[ "$JOB_NAME" == *"code-coverage" ]]; then
+    COVERAGE="" # TODO add code coverage support
+elif ! has OSX-10.9 $NODE_LABELS && ! has OSX-10.11 $NODE_LABELS; then
+    ASAN="--with-sanitizer=address"
+fi
+./waf -j1 --color=yes configure --debug --with-tests $COVERAGE $ASAN
 ./waf -j1 --color=yes build
+
+# (tests will be run against debug version)
diff --git a/.jenkins.d/30-tests.sh b/.jenkins.d/30-tests.sh
index d045565..19ed25f 100755
--- a/.jenkins.d/30-tests.sh
+++ b/.jenkins.d/30-tests.sh
@@ -2,5 +2,17 @@
 set -x
 set -e
 
-rm -rf $HOME/.ndn
+rm -rf ~/.ndn
+
+ASAN_OPTIONS="color=always"
+ASAN_OPTIONS+=":detect_leaks=false"
+ASAN_OPTIONS+=":detect_stack_use_after_return=true"
+ASAN_OPTIONS+=":check_initialization_order=true"
+ASAN_OPTIONS+=":strict_init_order=true"
+ASAN_OPTIONS+=":detect_invalid_pointer_pairs=1"
+ASAN_OPTIONS+=":detect_container_overflow=false"
+ASAN_OPTIONS+=":strict_string_checks=true"
+ASAN_OPTIONS+=":strip_path_prefix=${PWD}/"
+export ASAN_OPTIONS
+
 ./build/unit-tests -l test_suite