PROTON-2134 Enable asan in Travis CI with proton-python binding

The lsan suppressions for python binary is needed due to warnings like

    27: Direct leak of 4832 byte(s) in 137 object(s) allocated from:
    27:     #0 0x7f53059be961 in realloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98961)
    27:     #1 0x49522b  (/usr/bin/python2.7+0x49522b)
diff --git a/.travis.yml b/.travis.yml
index b6c5466..b4d741b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -28,6 +28,14 @@
 matrix:
   include:
   - os: linux
+    compiler: gcc
+    env:
+    - QPID_PROTON_CMAKE_ARGS='-DRUNTIME_CHECK=asan'
+  - os: linux
+    compiler: clang
+    env:
+    - QPID_PROTON_CMAKE_ARGS='-DRUNTIME_CHECK=asan '
+  - os: linux
     env:
     - QPID_PROTON_CMAKE_ARGS='-DRUNTIME_CHECK=tsan'
   - os: linux
diff --git a/tests/RuntimeCheck.cmake b/tests/RuntimeCheck.cmake
index b2f9233..c8c9077 100644
--- a/tests/RuntimeCheck.cmake
+++ b/tests/RuntimeCheck.cmake
@@ -96,8 +96,15 @@
 elseif(RUNTIME_CHECK STREQUAL "asan")
   assert_has_sanitizers()
   message(STATUS "Runtime memory checker: gcc/clang memory sanitizers")
-  set(SANITIZE_FLAGS "-g -fno-omit-frame-pointer -fsanitize=address,undefined")
+  # clang defaults to static sanitizer libs (which is preferred), but then we cannot LD_PRELOAD
+  if (CMAKE_C_COMPILER_ID MATCHES "Clang")
+      set(CLANG_ASAN_FLAG "-shared-libasan")
+  endif()
+
+  set(SANITIZE_FLAGS "-g -fno-omit-frame-pointer ${CLANG_ASAN_FLAG} -fsanitize=address,undefined -fsanitize-recover=vptr")
   set(TEST_WRAP_PREFIX "${CMAKE_SOURCE_DIR}/tests/preload_asan.sh $<TARGET_FILE:qpid-proton-core>")
+  list(APPEND TEST_ENV "UBSAN_OPTIONS=suppressions=${CMAKE_SOURCE_DIR}/tests/ubsan.supp")
+  list(APPEND TEST_ENV "LSAN_OPTIONS=suppressions=${CMAKE_SOURCE_DIR}/tests/lsan.supp")
 
 elseif(RUNTIME_CHECK STREQUAL "tsan")
   assert_has_sanitizers()
diff --git a/tests/lsan.supp b/tests/lsan.supp
new file mode 100644
index 0000000..06ff33d
--- /dev/null
+++ b/tests/lsan.supp
@@ -0,0 +1,112 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# c/src/core/codec.c
+leak:^pn_data$
+leak:^pni_data_grow$
+
+# c/src/core/buffer.c
+leak:^pn_buffer$
+leak:^pn_buffer_ensure$
+
+# c/src/core/error.c
+leak:^pn_error$
+
+# c/src/core/object/list.c
+leak:^pn_list$
+
+# c/src/core/object/map.c
+leak:^pni_map_allocate$
+
+# c/src/core/object/object.c
+leak:^pn_object_new$
+
+# c/src/core/object/record.c
+leak:^pni_record_create$
+
+# c/src/core/object/string.c
+leak:^pn_stringn$
+leak:^pn_string_grow$
+
+# c/src/core/transport.c
+leak:^pn_transport$
+
+# c/src/ssl/openssl.c
+leak:^pn_ssl_domain$
+
+# SWIG
+leak:^SWIG_Python_addvarlink$
+
+leak:bin/swig3
+
+# OpenSSL
+leak:^c2i_ASN1_BIT_STRING$
+leak:^CRYPTO_zalloc$
+leak:^CRYPTO_malloc$
+leak:^CRYPTO_realloc$
+leak:^BUF_MEM_grow$
+leak:^ASN1_STRING_set$
+leak:^x509_name_canon.part.0$
+leak:^OPENSSL_sk_insert$
+leak:^asn1_primitive_new$
+leak:^BN_MONT_CTX_new$
+leak:^EC_GROUP_copy$
+leak:^c2i_ASN1_OBJECT$
+leak:^CRYPTO_strndup$
+leak:^OPENSSL_sk_dup$
+leak:^new_dir$
+leak:^add_cert_dir.isra.0.part.1$
+leak:libcrypto.so
+
+# Python
+leak:^PyList_Append$
+leak:^listappend$
+leak:^PyThread_allocate_lock$
+leak:^PyList_New$
+leak:^list_resize$
+leak:^s_init$
+leak:^PyType_GenericAlloc$
+leak:^PyString_FromStringAndSize$
+leak:^_PyObject_GC_Malloc$
+leak:^_PyObject_GC_Resize$
+leak:^PyString_FromString$
+leak:^PyString_Concat$
+leak:^_PyString_Resize$
+leak:^_ctypes_alloc_format_string$
+leak:^PyCStructUnionType_update_stgdict$
+
+leak:bin/python2
+leak:bin/python3
+leak:bin/python
+leak:_ctypes
+leak:libpython
+
+# Sasl 2 library
+leak:^_plug_strdup$
+
+# /usr/sbin/saslpasswd2 binary
+leak:saslpasswd2
+
+leak:libdigestmd5.so
+
+# bash in python-test
+leak:bash
+
+# ruby in ruby-example-test
+leak:libruby.so
\ No newline at end of file
diff --git a/tests/preload_asan.sh b/tests/preload_asan.sh
index 7f713a1..73171c2 100755
--- a/tests/preload_asan.sh
+++ b/tests/preload_asan.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
 #
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
@@ -29,11 +29,8 @@
 EXE=$2
 
 case $EXE in
-    *ruby*|*.rb|*python*|*.py)
+    *ruby*|*.rb)
         # ruby has spurious leaks and causes asan errors.
-        #
-        # python tests have many leaks that may be real, but need to be
-        # analysed & fixed or suppressed before turning this on
 
         # Disable link order check to run with limited sanitizing
         # Still seeing problems.
@@ -44,7 +41,10 @@
         # Preload the asan library linked to LIB. Note we need to
         # check the actual linkage, there may be multiple asan lib
         # versions installed and we must use the same one.
-        libasan=$(ldd $LIB | awk "/(libasan\\.so[.0-9]*)/ { print \$1 }")
+
+        # ldd prints something like this (proton compiled with clang)
+        #  libclang_rt.asan-x86_64.so => /lib64/.../libclang_rt.asan-x86_64.so (0x00007f3d7fdad000)
+        libasan=$(ldd "$LIB" | awk "/(asan.*\\.so[.0-9]*)/ { print \$3 }")
         LD_PRELOAD="$libasan:$LD_PRELOAD"
         export LD_PRELOAD
         ;;
diff --git a/tests/ubsan.supp b/tests/ubsan.supp
new file mode 100644
index 0000000..c484f9d
--- /dev/null
+++ b/tests/ubsan.supp
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# cpp/include/proton/scalar_base.hpp
+# gcc on travis does not accept vptr:, it needs vptr_check:
+vptr_check:conversion_error