build+ci: enable AddressSanitizer and LeakSanitizer for unit tests

Refs: #2589, #4206

Change-Id: Ie9770134ff87fce438029b97c9ed61dbef3a71a3
diff --git a/.jenkins.d/20-build.sh b/.jenkins.d/20-build.sh
index 464a7ea..6306a52 100755
--- a/.jenkins.d/20-build.sh
+++ b/.jenkins.d/20-build.sh
@@ -6,8 +6,6 @@
 git submodule sync
 git submodule update
 
-COVERAGE=$( python -c "print '--with-coverage' if 'code-coverage' in '$JOB_NAME' else ''" )
-
 # Cleanup
 sudo ./waf -j1 --color=yes distclean
 
@@ -25,13 +23,16 @@
 # Cleanup
 sudo ./waf -j1 --color=yes distclean
 
+if [[ $JOB_NAME == *"code-coverage" ]]; then
+    COVERAGE="--with-coverage"
+elif [[ -n $BUILD_WITH_ASAN || -z $TRAVIS ]]; then
+    ASAN="--with-sanitizer=address"
+fi
+
 # Configure/build in optimized mode with tests
-./waf -j1 --color=yes configure --with-tests $COVERAGE
+./waf -j1 --color=yes configure --with-tests $COVERAGE $ASAN
 ./waf -j1 --color=yes build
 
 # (tests will be run against optimized version)
 
-./waf configure --color=yes --with-tests $COVERAGE
-
-./waf -j1 --color=yes
 sudo ./waf install --color=yes
diff --git a/.jenkins.d/30-tests.sh b/.jenkins.d/30-tests.sh
index 633dfa7..6be5a4a 100755
--- a/.jenkins.d/30-tests.sh
+++ b/.jenkins.d/30-tests.sh
@@ -4,4 +4,14 @@
 
 rm -Rf ~/.ndn
 
+ASAN_OPTIONS="color=always"
+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-nlsr -l test_suite