testing: improve sanitizer handling
authorMichael Wallner <mike@php.net>
Tue, 15 Sep 2020 12:02:23 +0000 (14:02 +0200)
committerMichael Wallner <mike@php.net>
Tue, 15 Sep 2020 12:02:23 +0000 (14:02 +0200)
CMake/CheckDebug.cmake
CMake/_Include.cmake
src/libhashkit/jenkins.cc
src/mem_config.h.in
testing/lib/common.hpp
testing/main.cpp

index 2701bdfd0ab3107c5cdf4b11364acb5b4eb93bff..4ab87f259fa37806ec8fa16db97412d348f09e9c 100644 (file)
@@ -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()
index 97c07831c439036beb523d6dc05a48a2be8d5c14..a6b5463c1a1b201be45a823df8a0f5d1884e0cef 100644 (file)
@@ -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)
index a08287dbc2c85fc206586578322acbdad1e776de..9636f3e9084fb5677fe6c390c9a0c523ac47af50 100644 (file)
@@ -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 */
index d27040950b3d658e6ec6c07dfc6d6f578189a944..1d1d3d297d07b7a07c6b9972e9e0a062267369c2 100644 (file)
@@ -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
index 17199839495be35da7fecec89893e65718387215..ee177003bac8fbf3b2a5a0cff0b4be838158fb36 100644 (file)
@@ -106,6 +106,7 @@ template<class T>
 class Malloced {
   T *ptr;
 public:
+  explicit
   Malloced(T *ptr_)
   : ptr{ptr_}
   {}
@@ -116,4 +117,7 @@ public:
   auto operator *() {
     return ptr;
   }
+  auto operator ->() {
+    return ptr;
+  }
 };
index 8b945286fafe5c0e1dd8a22720c17eb86739f8dd..b24f727b7e26a348bf1de944f4c0dcbfec071c44 100644 (file)
@@ -1,2 +1,15 @@
-#define CATCH_CONFIG_MAIN
+#define CATCH_CONFIG_RUNNER
 #include "lib/catch.hpp"
+#include <cstdlib>
+
+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);
+}