diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2016-07-23 20:45:36 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2016-07-23 20:45:36 +0000 |
commit | 6f08730ec5f639f05f2f15354171e4a3c9af9dc1 (patch) | |
tree | 7374e9d4448083010ada98d17976199c7e945d47 /test/lsan | |
parent | c003a57e2e4a1ad9be0338806bc1038b6987155f (diff) | |
download | src-6f08730ec5f639f05f2f15354171e4a3c9af9dc1.tar.gz src-6f08730ec5f639f05f2f15354171e4a3c9af9dc1.zip |
Vendor import of compiler-rt release_39 branch r276489:vendor/compiler-rt/compiler-rt-release_39-r276489
Notes
Notes:
svn path=/vendor/compiler-rt/dist/; revision=303235
svn path=/vendor/compiler-rt/compiler-rt-release_39-r276489/; revision=303236; tag=vendor/compiler-rt/compiler-rt-release_39-r276489
Diffstat (limited to 'test/lsan')
-rw-r--r-- | test/lsan/CMakeLists.txt | 49 | ||||
-rw-r--r-- | test/lsan/TestCases/disabler_in_tsd_destructor.c | 2 | ||||
-rw-r--r-- | test/lsan/TestCases/guard-page.c | 60 | ||||
-rw-r--r-- | test/lsan/TestCases/high_allocator_contention.cc | 3 | ||||
-rw-r--r-- | test/lsan/TestCases/leak_check_before_thread_started.cc | 13 | ||||
-rw-r--r-- | test/lsan/TestCases/use_registers.cc | 5 | ||||
-rw-r--r-- | test/lsan/TestCases/use_tls_dynamic.cc | 2 | ||||
-rw-r--r-- | test/lsan/lit.common.cfg | 3 | ||||
-rw-r--r-- | test/lsan/lit.site.cfg.in | 9 |
9 files changed, 127 insertions, 19 deletions
diff --git a/test/lsan/CMakeLists.txt b/test/lsan/CMakeLists.txt index 6cca00a90b6b..e3d363a1f275 100644 --- a/test/lsan/CMakeLists.txt +++ b/test/lsan/CMakeLists.txt @@ -1,21 +1,48 @@ set(LSAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(LSAN_LIT_TEST_MODE "Standalone") -configure_lit_site_cfg( - ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in - ${CMAKE_CURRENT_BINARY_DIR}/LsanConfig/lit.site.cfg) +set(LSAN_TESTSUITES) + +set(LSAN_TEST_ARCH ${LSAN_SUPPORTED_ARCH}) +if(APPLE) + darwin_filter_host_archs(LSAN_SUPPORTED_ARCH LSAN_TEST_ARCH) +endif() + +foreach(arch ${LSAN_TEST_ARCH}) + set(LSAN_TEST_TARGET_ARCH ${arch}) + string(TOLOWER "-${arch}" LSAN_TEST_CONFIG_SUFFIX) + if(ANDROID OR ${arch} MATCHES "arm|aarch64") + # This is only true if we are cross-compiling. + # Build all tests with host compiler and use host tools. + set(LSAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER}) + set(LSAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS}) + else() + get_target_flags_for_arch(${arch} LSAN_TEST_TARGET_CFLAGS) + string(REPLACE ";" " " LSAN_TEST_TARGET_CFLAGS "${LSAN_TEST_TARGET_CFLAGS}") + endif() + + string(TOUPPER ${arch} ARCH_UPPER_CASE) + set(LSAN_LIT_TEST_MODE "Standalone") + set(CONFIG_NAME ${ARCH_UPPER_CASE}LsanConfig) + + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg) + list(APPEND LSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) + + set(CONFIG_NAME ${ARCH_UPPER_CASE}AsanConfig) + set(LSAN_LIT_TEST_MODE "AddressSanitizer") -set(LSAN_LIT_TEST_MODE "AddressSanitizer") -configure_lit_site_cfg( - ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in - ${CMAKE_CURRENT_BINARY_DIR}/AsanConfig/lit.site.cfg) + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg) + list(APPEND LSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) +endforeach() set(LSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS}) if(NOT COMPILER_RT_STANDALONE_BUILD) list(APPEND LSAN_TEST_DEPS lsan asan) endif() add_lit_testsuite(check-lsan "Running the LeakSanitizer tests" - ${CMAKE_CURRENT_BINARY_DIR}/LsanConfig - ${CMAKE_CURRENT_BINARY_DIR}/AsanConfig + ${LSAN_TESTSUITES} DEPENDS ${LSAN_TEST_DEPS}) -set_target_properties(check-lsan PROPERTIES FOLDER "LSan tests") +set_target_properties(check-lsan PROPERTIES FOLDER "Compiler-RT Misc") diff --git a/test/lsan/TestCases/disabler_in_tsd_destructor.c b/test/lsan/TestCases/disabler_in_tsd_destructor.c index 982fb899ec5b..4a3a7ac14c3b 100644 --- a/test/lsan/TestCases/disabler_in_tsd_destructor.c +++ b/test/lsan/TestCases/disabler_in_tsd_destructor.c @@ -1,5 +1,5 @@ // Regression test. Disabler should not depend on TSD validity. -// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=1" +// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=1:use_ld_allocations=0" // RUN: %clang_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE %run %t diff --git a/test/lsan/TestCases/guard-page.c b/test/lsan/TestCases/guard-page.c new file mode 100644 index 000000000000..5c70a9f08aca --- /dev/null +++ b/test/lsan/TestCases/guard-page.c @@ -0,0 +1,60 @@ +// Check that if LSan finds that SP doesn't point into thread stack (e.g. +// if swapcontext is used), LSan will not hit the guard page. +// RUN: %clang_lsan %s -o %t && %run %t +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <pthread.h> +#include <ucontext.h> + +pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +int ctxfunc_started = 0; + +static void die(const char* msg, int err) { + if (err == 0) + err = errno; + fprintf(stderr, "%s: %s\n", msg, strerror(err)); + exit(EXIT_FAILURE); +} + +static void ctxfunc() { + pthread_mutex_lock(&mutex); + ctxfunc_started = 1; + pthread_cond_signal(&cond); + pthread_mutex_unlock(&mutex); + // Leave this context alive when the program exits. + for (;;); +} + +static void* thread(void* arg) { + (void)arg; + ucontext_t ctx; + void* stack; + + if (getcontext(&ctx) < 0) + die("getcontext", 0); + stack = malloc(1 << 10); + if (stack == NULL) + die("malloc", 0); + ctx.uc_stack.ss_sp = stack; + ctx.uc_stack.ss_size = 1 << 10; + makecontext(&ctx, ctxfunc, 0); + setcontext(&ctx); + die("setcontext", 0); + return NULL; +} + +int main() { + pthread_t tid; + int i; + + pthread_mutex_lock(&mutex); + i = pthread_create(&tid, NULL, thread, NULL); + if (i != 0) + die("pthread_create", i); + while (!ctxfunc_started) pthread_cond_wait(&cond, &mutex); + pthread_mutex_unlock(&mutex); + return 0; +} diff --git a/test/lsan/TestCases/high_allocator_contention.cc b/test/lsan/TestCases/high_allocator_contention.cc index 2543897bcbb4..f423fd48c79c 100644 --- a/test/lsan/TestCases/high_allocator_contention.cc +++ b/test/lsan/TestCases/high_allocator_contention.cc @@ -1,7 +1,8 @@ // A benchmark that executes malloc/free pairs in parallel. // Usage: ./a.out number_of_threads total_number_of_allocations +// RUN: LSAN_BASE="use_ld_allocations=0" // RUN: %clangxx_lsan %s -o %t -// RUN: %run %t 5 1000000 2>&1 +// RUN: LSAN_OPTIONS=$LSAN_BASE %run %t 5 1000000 2>&1 #include <assert.h> #include <pthread.h> #include <stdlib.h> diff --git a/test/lsan/TestCases/leak_check_before_thread_started.cc b/test/lsan/TestCases/leak_check_before_thread_started.cc index 0bd4837f14c0..ca818e1e269c 100644 --- a/test/lsan/TestCases/leak_check_before_thread_started.cc +++ b/test/lsan/TestCases/leak_check_before_thread_started.cc @@ -4,12 +4,19 @@ // RUN: LSAN_OPTIONS="log_pointers=1:log_threads=1" %run %t #include <assert.h> #include <pthread.h> +#include <stdio.h> #include <stdlib.h> -#include <unistd.h> + +pthread_cond_t cond = PTHREAD_COND_INITIALIZER; +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +bool flag = false; void *func(void *arg) { - sleep(1); + // This mutex will never be grabbed. + fprintf(stderr, "entered func()\n"); + pthread_mutex_lock(&mutex); free(arg); + pthread_mutex_unlock(&mutex); return 0; } @@ -22,6 +29,8 @@ void create_detached_thread() { void *arg = malloc(1337); assert(arg); + // This mutex is never unlocked by the main thread. + pthread_mutex_lock(&mutex); int res = pthread_create(&thread_id, &attr, func, arg); assert(res == 0); } diff --git a/test/lsan/TestCases/use_registers.cc b/test/lsan/TestCases/use_registers.cc index ce11c3f77bcb..74301a26c32c 100644 --- a/test/lsan/TestCases/use_registers.cc +++ b/test/lsan/TestCases/use_registers.cc @@ -27,6 +27,11 @@ void *registers_thread_func(void *arg) { : : "r" (p) ); +#elif defined(__mips__) + asm ( "move $16, %0" + : + : "r" (p) + ); #else #error "Test is not supported on this architecture." #endif diff --git a/test/lsan/TestCases/use_tls_dynamic.cc b/test/lsan/TestCases/use_tls_dynamic.cc index 860db041ae40..207894b0fffd 100644 --- a/test/lsan/TestCases/use_tls_dynamic.cc +++ b/test/lsan/TestCases/use_tls_dynamic.cc @@ -1,5 +1,5 @@ // Test that dynamically allocated TLS space is included in the root set. -// RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" +// RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0:use_ld_allocations=0" // RUN: %clangxx %s -DBUILD_DSO -fPIC -shared -o %t-so.so // RUN: %clangxx_lsan %s -o %t // RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=0" not %run %t 2>&1 | FileCheck %s diff --git a/test/lsan/lit.common.cfg b/test/lsan/lit.common.cfg index ba9c283ca84a..a04c113269f2 100644 --- a/test/lsan/lit.common.cfg +++ b/test/lsan/lit.common.cfg @@ -27,8 +27,9 @@ elif lsan_lit_test_mode == "AddressSanitizer": config.available_features.add('asan') else: lit_config.fatal("Unknown LSan test mode: %r" % lsan_lit_test_mode) +config.name += config.name_suffix -clang_cflags = ["-O0", "-m64"] + config.debug_info_flags +clang_cflags = ["-O0", config.target_cflags] + config.debug_info_flags clang_cxxflags = config.cxx_mode_flags + clang_cflags clang_lsan_cflags = clang_cflags + lsan_cflags clang_lsan_cxxflags = clang_cxxflags + lsan_cflags diff --git a/test/lsan/lit.site.cfg.in b/test/lsan/lit.site.cfg.in index 7d2877bdc528..de893474d280 100644 --- a/test/lsan/lit.site.cfg.in +++ b/test/lsan/lit.site.cfg.in @@ -1,8 +1,13 @@ -# Load common config for all compiler-rt lit tests. -lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") +@LIT_SITE_CFG_IN_HEADER@ # Tool-specific config options. +config.name_suffix = "@LSAN_TEST_CONFIG_SUFFIX@" +config.target_cflags = "@LSAN_TEST_TARGET_CFLAGS@" config.lsan_lit_test_mode = "@LSAN_LIT_TEST_MODE@" +config.target_arch = "@LSAN_TEST_TARGET_ARCH@" + +# Load common config for all compiler-rt lit tests. +lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") # Load tool-specific config that would do the real work. lit_config.load_config(config, "@LSAN_LIT_SOURCE_DIR@/lit.common.cfg") |