From 7fcfcf201d8d388ea0a52929fc171d7b1990d905 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 1 Jun 2020 20:07:27 +0300 Subject: [PATCH] Fix unit tests under MSan --- base/common/phdr_cache.cpp | 16 +--------------- src/Common/tests/gtest_rw_lock.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/base/common/phdr_cache.cpp b/base/common/phdr_cache.cpp index a5cb466f425..f362fb64285 100644 --- a/base/common/phdr_cache.cpp +++ b/base/common/phdr_cache.cpp @@ -1,20 +1,6 @@ /// This code was based on the code by Fedor Korotkiy (prime@yandex-team.ru) for YT product in Yandex. -#if defined(__has_feature) - #if __has_feature(address_sanitizer) - #define ADDRESS_SANITIZER 1 - #endif - #if __has_feature(thread_sanitizer) - #define THREAD_SANITIZER 1 - #endif -#else - #if defined(__SANITIZE_ADDRESS__) - #define ADDRESS_SANITIZER 1 - #endif - #if defined(__SANITIZE_THREAD__) - #define THREAD_SANITIZER 1 - #endif -#endif +#include #if defined(__linux__) && !defined(THREAD_SANITIZER) #define USE_PHDR_CACHE 1 diff --git a/src/Common/tests/gtest_rw_lock.cpp b/src/Common/tests/gtest_rw_lock.cpp index 73987a25508..5f40a6b57d3 100644 --- a/src/Common/tests/gtest_rw_lock.cpp +++ b/src/Common/tests/gtest_rw_lock.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,13 @@ namespace DB TEST(Common, RWLock1) { + /// Tests with threads require this, because otherwise + /// when tested under Memory Sanitizer, + /// it tries to obtain stack trace on 'free' invocation at thread exit, + /// but cannot do that due to infinite recursion. + /// Alternative solution: disable PHDR Cache under memory sanitizer. + updatePHDRCache(); + constexpr int cycles = 1000; const std::vector pool_sizes{1, 2, 4, 8}; @@ -92,6 +100,8 @@ TEST(Common, RWLock1) TEST(Common, RWLockRecursive) { + updatePHDRCache(); + constexpr auto cycles = 10000; static auto fifo_lock = RWLockImpl::create(); @@ -134,6 +144,8 @@ TEST(Common, RWLockRecursive) TEST(Common, RWLockDeadlock) { + updatePHDRCache(); + static auto lock1 = RWLockImpl::create(); static auto lock2 = RWLockImpl::create(); @@ -216,6 +228,8 @@ TEST(Common, RWLockDeadlock) TEST(Common, RWLockPerfTestReaders) { + updatePHDRCache(); + constexpr int cycles = 100000; // 100k const std::vector pool_sizes{1, 2, 4, 8};