From 9eeee02fddffb336454a6c08c700bfeb2758756e Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 12 Nov 2020 12:16:27 +0100 Subject: [PATCH] sanitizers: suppress false positive leaks in libtbb --- test/CMakeLists.txt | 1 + test/LeakSanitizer.suppressions | 1 + test/conf.h.in | 1 + test/setup.cpp | 15 +++++++++++++++ 4 files changed, 18 insertions(+) create mode 100644 test/LeakSanitizer.suppressions diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4b108466..e2ecf0a2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,6 +21,7 @@ endif() file(GLOB_RECURSE TESTING_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) set(TESTING_ROOT ${CMAKE_CURRENT_BINARY_DIR}) +set(SOURCES_ROOT ${CMAKE_SOURCE_DIR}) set_source_files_properties(main.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) configure_file(conf.h.in conf.h @ONLY) add_executable(runtests ${TESTING_SRC}) diff --git a/test/LeakSanitizer.suppressions b/test/LeakSanitizer.suppressions new file mode 100644 index 00000000..b5a6615b --- /dev/null +++ b/test/LeakSanitizer.suppressions @@ -0,0 +1 @@ +leak:libtbb.so diff --git a/test/conf.h.in b/test/conf.h.in index 2d2d0360..bb8fa0c5 100644 --- a/test/conf.h.in +++ b/test/conf.h.in @@ -23,5 +23,6 @@ #cmakedefine HAVE_TBB 1 #cmakedefine HAVE_WAITID_NOWAIT 1 +#cmakedefine SOURCES_ROOT "@SOURCES_ROOT@" #cmakedefine TESTING_ROOT "@TESTING_ROOT@" #cmakedefine MEMCACHED_BINARY getenv_else("MEMCACHED_BINARY", "@MEMCACHED_BINARY@") diff --git a/test/setup.cpp b/test/setup.cpp index cfa18e08..22c7c2ad 100644 --- a/test/setup.cpp +++ b/test/setup.cpp @@ -1,4 +1,5 @@ #include "mem_config.h" +#include "test/conf.h" #include "test/lib/env.hpp" #include "test/lib/random.hpp" #include @@ -55,6 +56,9 @@ static inline void setup_signals() { "verify_asan_link_order=1," \ "abort_on_error=0," \ "" +# define LSAN_OPTIONS \ + "suppressions=" SOURCES_ROOT "/test/LeakSanitizer.suppressions," \ + "" static inline void setup_asan(char **argv) { const auto set = getenv("ASAN_OPTIONS"); @@ -64,8 +68,18 @@ static inline void setup_asan(char **argv) { perror("exec()"); } } +static inline void setup_lsan(char **argv) { + const auto set = getenv("LSAN_OPTIONS"); + + if (!set || !*set) { + SET_ENV_EX(lsan, "LSAN_OPTIONS", LSAN_OPTIONS, 0); + execvp(argv[0], argv); + perror("exec()"); + } +} #else # define setup_asan(a) (void) a +# define setup_lsan(a) (void) a #endif #if LIBMEMCACHED_WITH_SASL_SUPPORT @@ -85,6 +99,7 @@ int setup(int &, char ***argv) { setup_signals(); setup_random(); setup_asan(*argv); + setup_lsan(*argv); setup_sasl(); return 0; -- 2.30.2