From: Michael Wallner Date: Tue, 15 Sep 2020 12:02:23 +0000 (+0200) Subject: testing: improve sanitizer handling X-Git-Tag: 1.1.0-beta1~236^2~64 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=cbaa9f46519f9b085e28db5f44247d23ca7ec5a4;p=awesomized%2Flibmemcached testing: improve sanitizer handling --- diff --git a/CMake/CheckDebug.cmake b/CMake/CheckDebug.cmake index 2701bdfd..4ab87f25 100644 --- a/CMake/CheckDebug.cmake +++ b/CMake/CheckDebug.cmake @@ -47,8 +47,10 @@ function(check_debug) check_cxx_compiler_flag(-fsanitize=address HAVE_ASAN) cmake_pop_check_state() if(HAVE_ASAN) + add_compile_definitions(HAVE_ASAN) add_compile_options(-fsanitize=address) add_link_options(-lasan) + check_flag(-fsanitize-recover=address IGNORE) endif() endif() @@ -58,8 +60,10 @@ function(check_debug) check_cxx_compiler_flag(-fsanitize=undefined HAVE_UBSAN) cmake_pop_check_state() if(HAVE_UBSAN) + add_compile_definitions(HAVE_UBSAN) add_compile_options(-fsanitize=undefined) add_link_options(-lubsan) + check_flag(-fsanitize-recover=undefined IGNORE) endif() endif() endif() diff --git a/CMake/_Include.cmake b/CMake/_Include.cmake index 97c07831..a6b5463c 100644 --- a/CMake/_Include.cmake +++ b/CMake/_Include.cmake @@ -99,6 +99,7 @@ check_decl(MSG_MORE sys/socket.h) check_decl(MSG_NOSIGNAL sys/socket.h) check_decl(rcvtimeo sys/socket.h) check_decl(sndtimeo sys/socket.h) +check_decl(setenv stdlib.h) check_decl(strerror string.h) check_decl(strerror_r string.h) check_compiles(HAVE_STRERROR_R_CHAR_P "char x, y = *strerror_r(0,&x,1);" string.h) diff --git a/src/libhashkit/jenkins.cc b/src/libhashkit/jenkins.cc index a08287db..9636f3e9 100644 --- a/src/libhashkit/jenkins.cc +++ b/src/libhashkit/jenkins.cc @@ -93,6 +93,9 @@ use a bitmask. For example, if you need only 10 bits, do In which case, the hash table should have hashsize(10) elements. */ +#if HAVE_ASAN +__attribute__((no_sanitize("address"))) +#endif uint32_t hashkit_jenkins(const char *key, size_t length, void *) { uint32_t a,b,c; /* internal state */ diff --git a/src/mem_config.h.in b/src/mem_config.h.in index d2704095..1d1d3d29 100644 --- a/src/mem_config.h.in +++ b/src/mem_config.h.in @@ -33,6 +33,7 @@ #cmakedefine HAVE_POLL_H 1 #cmakedefine HAVE_RCVTIMEO 1 #cmakedefine HAVE_SASL_SASL_H 1 +#cmakedefine HAVE_SETENV 1 #cmakedefine HAVE_SHARED_ENABLED 1 #cmakedefine HAVE_SNDTIMEO 1 #cmakedefine HAVE_STDDEF_H 1 diff --git a/testing/lib/common.hpp b/testing/lib/common.hpp index 17199839..ee177003 100644 --- a/testing/lib/common.hpp +++ b/testing/lib/common.hpp @@ -106,6 +106,7 @@ template class Malloced { T *ptr; public: + explicit Malloced(T *ptr_) : ptr{ptr_} {} @@ -116,4 +117,7 @@ public: auto operator *() { return ptr; } + auto operator ->() { + return ptr; + } }; diff --git a/testing/main.cpp b/testing/main.cpp index 8b945286..b24f727b 100644 --- a/testing/main.cpp +++ b/testing/main.cpp @@ -1,2 +1,15 @@ -#define CATCH_CONFIG_MAIN +#define CATCH_CONFIG_RUNNER #include "lib/catch.hpp" +#include + +int main(int argc, char *argv[]) { +#if HAVE_ASAN +# if HAVE_SETENV + setenv("ASAN_OPTIONS", "halt_on_error=0", 0); +# else + char env[] = "ASAN_OPTIONS=halt_on_error=0"; + putenv(env); +# endif +#endif + return Catch::Session().run(argc, argv); +}