diff options
author | Andreas Schneider <asn@samba.org> | 2018-09-01 20:46:52 +0200 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2018-10-23 15:38:45 +0200 |
commit | 4adb5cf4748feaf190e1da2444d1ed822314a2f0 (patch) | |
tree | f3c79832f62c0ef4367d64a7890edf89c9898b8f /tests | |
parent | da17de1693abeb5f163ab6b6a85fcfceb1db68ce (diff) | |
download | socket_wrapper-4adb5cf4748feaf190e1da2444d1ed822314a2f0.tar.gz socket_wrapper-4adb5cf4748feaf190e1da2444d1ed822314a2f0.tar.xz socket_wrapper-4adb5cf4748feaf190e1da2444d1ed822314a2f0.zip |
cmake: Support running the tests with AddressSanitizer
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4a89126..464ac9b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -60,6 +60,32 @@ if (HAVE_STRUCT_MSGHDR_MSG_CONTROL) set(SWRAP_TESTS ${SWRAP_TESTS} test_sendmsg_recvmsg_fd) endif (HAVE_STRUCT_MSGHDR_MSG_CONTROL) +if (CMAKE_BUILD_TYPE) + string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) + if (CMAKE_BUILD_TYPE_LOWER STREQUAL "addresssanitizer") + find_library(ASAN_LIBRARY + NAMES asan) + if (NOT ASAN_LIBRARY) + foreach(version RANGE 10 1) + if (NOT ASAN_LIBRARY) + find_library(ASAN_LIBRARY libasan.so.${version}) + endif() + endforeach() + endif() + endif() +endif() + +if (ASAN_LIBRARY) + list(APPEND PRELOAD_LIBRARIES ${ASAN_LIBRARY}) +endif() + +list(APPEND PRELOAD_LIBRARIES ${SOCKET_WRAPPER_LOCATION}) + +string(REPLACE ";" ":" TORTURE_ENVIRONMENT "${PRELOAD_LIBRARIES}") +string(PREPEND TORTURE_ENVIRONMENT "LD_PRELOAD=") + +message(STATUS "TORTURE_ENVIRONMENT=${TORTURE_ENVIRONMENT}") + foreach(_SWRAP_TEST ${SWRAP_TESTS}) add_cmocka_test(${_SWRAP_TEST} ${_SWRAP_TEST}.c ${TORTURE_LIBRARY}) target_compile_options(${_SWRAP_TEST} @@ -78,7 +104,7 @@ foreach(_SWRAP_TEST ${SWRAP_TESTS}) TEST ${_SWRAP_TEST} PROPERTY - ENVIRONMENT LD_PRELOAD=${SOCKET_WRAPPER_LOCATION}) + ENVIRONMENT ${TORTURE_ENVIRONMENT}) endif() endforeach() |