diff options
Diffstat (limited to 'compiler-rt/lib/lsan/lit_tests')
39 files changed, 0 insertions, 1126 deletions
diff --git a/compiler-rt/lib/lsan/lit_tests/AsanConfig/lit.cfg b/compiler-rt/lib/lsan/lit_tests/AsanConfig/lit.cfg deleted file mode 100644 index edb5adfd3b6..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/AsanConfig/lit.cfg +++ /dev/null @@ -1,34 +0,0 @@ -# -*- Python -*- - -import os - -def get_required_attr(config, attr_name): - attr_value = getattr(config, attr_name, None) - if not attr_value: - lit_config.fatal( - "No attribute %r in test configuration! You may need to run " - "tests from your build directory or add this attribute " - "to lit.site.cfg " % attr_name) - return attr_value - -lsan_lit_src_root = get_required_attr(config, "lsan_lit_src_root") -lsan_lit_cfg = os.path.join(lsan_lit_src_root, "lit.common.cfg") -if not os.path.exists(lsan_lit_cfg): - lit_config.fatal("Can't find common LSan lit config at: %r" % lsan_lit_cfg) -lit_config.load_config(config, lsan_lit_cfg) - -config.available_features.add('asan') - -config.name = 'LeakSanitizer-AddressSanitizer' - -clang_lsan_cxxflags = config.clang_cxxflags + " -fsanitize=address " - -config.substitutions.append( ("%clangxx_lsan ", (" " + config.clang + " " + - clang_lsan_cxxflags + " ")) ) - -clang_lsan_cflags = config.clang_cflags + " -fsanitize=address " - -config.substitutions.append( ("%clang_lsan ", (" " + config.clang + " " + - clang_lsan_cflags + " ")) ) - -config.environment['ASAN_OPTIONS'] = 'detect_leaks=1' diff --git a/compiler-rt/lib/lsan/lit_tests/AsanConfig/lit.site.cfg.in b/compiler-rt/lib/lsan/lit_tests/AsanConfig/lit.site.cfg.in deleted file mode 100644 index 95f006954e5..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/AsanConfig/lit.site.cfg.in +++ /dev/null @@ -1,8 +0,0 @@ -# Load common config for all compiler-rt lit tests. -lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") - -# Tool-specific config options. -config.lsan_lit_src_root = "@LSAN_LIT_SOURCE_DIR@" - -# Load tool-specific config that would do the real work. -lit_config.load_config(config, "@LSAN_LIT_SOURCE_DIR@/AsanConfig/lit.cfg") diff --git a/compiler-rt/lib/lsan/lit_tests/CMakeLists.txt b/compiler-rt/lib/lsan/lit_tests/CMakeLists.txt deleted file mode 100644 index 9b26357fb2b..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -set(LSAN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..) -set(LSAN_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/..) - -set(LSAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) - -configure_lit_site_cfg( - ${CMAKE_CURRENT_SOURCE_DIR}/LsanConfig/lit.site.cfg.in - ${CMAKE_CURRENT_BINARY_DIR}/LsanConfig/lit.site.cfg - ) - -configure_lit_site_cfg( - ${CMAKE_CURRENT_SOURCE_DIR}/AsanConfig/lit.site.cfg.in - ${CMAKE_CURRENT_BINARY_DIR}/AsanConfig/lit.site.cfg - ) - -if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT APPLE AND NOT ANDROID) - set(LSAN_TEST_DEPS - ${SANITIZER_COMMON_LIT_TEST_DEPS} - ${LSAN_RUNTIME_LIBRARIES}) - foreach(arch ${LSAN_SUPPORTED_ARCH}) - list(APPEND LSAN_TEST_DEPS clang_rt.asan-${arch}) - endforeach() - add_lit_testsuite(check-lsan "Running the LeakSanitizer tests" - ${CMAKE_CURRENT_BINARY_DIR}/LsanConfig - ${CMAKE_CURRENT_BINARY_DIR}/AsanConfig - DEPENDS ${LSAN_TEST_DEPS}) - set_target_properties(check-lsan PROPERTIES FOLDER "LSan tests") -endif() diff --git a/compiler-rt/lib/lsan/lit_tests/LsanConfig/lit.cfg b/compiler-rt/lib/lsan/lit_tests/LsanConfig/lit.cfg deleted file mode 100644 index 84faf9167a7..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/LsanConfig/lit.cfg +++ /dev/null @@ -1,30 +0,0 @@ -# -*- Python -*- - -import os - -def get_required_attr(config, attr_name): - attr_value = getattr(config, attr_name, None) - if not attr_value: - lit_config.fatal( - "No attribute %r in test configuration! You may need to run " - "tests from your build directory or add this attribute " - "to lit.site.cfg " % attr_name) - return attr_value - -lsan_lit_src_root = get_required_attr(config, "lsan_lit_src_root") -lsan_lit_cfg = os.path.join(lsan_lit_src_root, "lit.common.cfg") -if not os.path.exists(lsan_lit_cfg): - lit_config.fatal("Can't find common LSan lit config at: %r" % lsan_lit_cfg) -lit_config.load_config(config, lsan_lit_cfg) - -config.name = 'LeakSanitizer-Standalone' - -clang_lsan_cxxflags = config.clang_cxxflags + " -fsanitize=leak " - -config.substitutions.append( ("%clangxx_lsan ", (" " + config.clang + " " + - clang_lsan_cxxflags + " ")) ) - -clang_lsan_cflags = config.clang_cflags + " -fsanitize=leak " - -config.substitutions.append( ("%clang_lsan ", (" " + config.clang + " " + - clang_lsan_cflags + " ")) ) diff --git a/compiler-rt/lib/lsan/lit_tests/LsanConfig/lit.site.cfg.in b/compiler-rt/lib/lsan/lit_tests/LsanConfig/lit.site.cfg.in deleted file mode 100644 index 8e9076e9405..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/LsanConfig/lit.site.cfg.in +++ /dev/null @@ -1,8 +0,0 @@ -# Load common config for all compiler-rt lit tests. -lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") - -# Tool-specific config options. -config.lsan_lit_src_root = "@LSAN_LIT_SOURCE_DIR@" - -# Load tool-specific config that would do the real work. -lit_config.load_config(config, "@LSAN_LIT_SOURCE_DIR@/LsanConfig/lit.cfg") diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/cleanup_in_tsd_destructor.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/cleanup_in_tsd_destructor.cc deleted file mode 100644 index 1cae226d4ec..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/cleanup_in_tsd_destructor.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Regression test for thread lifetime tracking. Thread data should be -// considered live during the thread's termination, at least until the -// user-installed TSD destructors have finished running (since they may contain -// additional cleanup tasks). LSan doesn't actually meet that goal 100%, but it -// makes its best effort. -// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:use_tls=1 %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:use_tls=0 not %t 2>&1 | FileCheck %s - -#include <assert.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> - -#include "sanitizer/lsan_interface.h" - -pthread_key_t key; -__thread void *p; - -void key_destructor(void *arg) { - // Generally this may happen on a different thread. - __lsan_do_leak_check(); -} - -void *thread_func(void *arg) { - p = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", p); - int res = pthread_setspecific(key, (void*)1); - assert(res == 0); - return 0; -} - -int main() { - int res = pthread_key_create(&key, &key_destructor); - assert(res == 0); - pthread_t thread_id; - res = pthread_create(&thread_id, 0, thread_func, 0); - assert(res == 0); - res = pthread_join(thread_id, 0); - assert(res == 0); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: [[ADDR]] (1337 bytes) diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/disabler.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/disabler.cc deleted file mode 100644 index db0cd8fabe4..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/disabler.cc +++ /dev/null @@ -1,23 +0,0 @@ -// Test for ScopedDisabler. -// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE not %t 2>&1 | FileCheck %s - -#include <stdio.h> -#include <stdlib.h> - -#include "sanitizer/lsan_interface.h" - -int main() { - void **p; - { - __lsan::ScopedDisabler d; - p = new void *; - } - *reinterpret_cast<void **>(p) = malloc(666); - void *q = malloc(1337); - // Break optimization. - fprintf(stderr, "Test alloc: %p.\n", q); - return 0; -} -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s) diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/disabler_in_tsd_destructor.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/disabler_in_tsd_destructor.cc deleted file mode 100644 index 94e4fc390b3..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/disabler_in_tsd_destructor.cc +++ /dev/null @@ -1,38 +0,0 @@ -// 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: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE %t - -#include <assert.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> - -#include "sanitizer/lsan_interface.h" - -pthread_key_t key; - -void key_destructor(void *arg) { - __lsan::ScopedDisabler d; - void *p = malloc(1337); - // Break optimization. - fprintf(stderr, "Test alloc: %p.\n", p); - pthread_setspecific(key, 0); -} - -void *thread_func(void *arg) { - int res = pthread_setspecific(key, (void*)1); - assert(res == 0); - return 0; -} - -int main() { - int res = pthread_key_create(&key, &key_destructor); - assert(res == 0); - pthread_t thread_id; - res = pthread_create(&thread_id, 0, thread_func, 0); - assert(res == 0); - res = pthread_join(thread_id, 0); - assert(res == 0); - return 0; -} diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/do_leak_check_override.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/do_leak_check_override.cc deleted file mode 100644 index be0ed0a6d48..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/do_leak_check_override.cc +++ /dev/null @@ -1,36 +0,0 @@ -// Test for __lsan_do_leak_check(). We test it by making the leak check run -// before global destructors, which also tests compatibility with HeapChecker's -// "normal" mode (LSan runs in "strict" mode by default). -// RUN: LSAN_BASE="use_stacks=0:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE not %t 2>&1 | FileCheck --check-prefix=CHECK-strict %s -// RUN: LSAN_OPTIONS=$LSAN_BASE not %t foo 2>&1 | FileCheck --check-prefix=CHECK-normal %s - -#include <stdio.h> -#include <stdlib.h> -#include <sanitizer/lsan_interface.h> - -struct LeakyGlobal { - LeakyGlobal() { - p = malloc(1337); - } - ~LeakyGlobal() { - p = 0; - } - void *p; -}; - -LeakyGlobal leaky_global; - -int main(int argc, char *argv[]) { - // Register leak check to run before global destructors. - if (argc > 1) - atexit(&__lsan_do_leak_check); - void *p = malloc(666); - printf("Test alloc: %p\n", p); - printf("Test alloc in leaky global: %p\n", leaky_global.p); - return 0; -} - -// CHECK-strict: SUMMARY: {{(Leak|Address)}}Sanitizer: 2003 byte(s) leaked in 2 allocation(s) -// CHECK-normal: SUMMARY: {{(Leak|Address)}}Sanitizer: 666 byte(s) leaked in 1 allocation(s) diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/fork.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/fork.cc deleted file mode 100644 index 69258d9a0c7..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/fork.cc +++ /dev/null @@ -1,24 +0,0 @@ -// Test that thread local data is handled correctly after forking without exec(). -// RUN: %clangxx_lsan %s -o %t -// RUN: %t 2>&1 - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <sys/wait.h> -#include <unistd.h> - -__thread void *thread_local_var; - -int main() { - int status = 0; - thread_local_var = malloc(1337); - pid_t pid = fork(); - assert(pid >= 0); - if (pid > 0) { - waitpid(pid, &status, 0); - assert(WIFEXITED(status)); - return WEXITSTATUS(status); - } - return 0; -} diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/fork_threaded.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/fork_threaded.cc deleted file mode 100644 index 24a586109e2..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/fork_threaded.cc +++ /dev/null @@ -1,43 +0,0 @@ -// Test that thread local data is handled correctly after forking without -// exec(). In this test leak checking is initiated from a non-main thread. -// RUN: %clangxx_lsan %s -o %t -// RUN: %t 2>&1 - -#include <assert.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> -#include <sys/wait.h> -#include <unistd.h> - -__thread void *thread_local_var; - -void *exit_thread_func(void *arg) { - exit(0); -} - -void ExitFromThread() { - pthread_t tid; - int res; - res = pthread_create(&tid, 0, exit_thread_func, 0); - assert(res == 0); - pthread_join(tid, 0); -} - -int main() { - int status = 0; - thread_local_var = malloc(1337); - pid_t pid = fork(); - assert(pid >= 0); - if (pid > 0) { - waitpid(pid, &status, 0); - assert(WIFEXITED(status)); - return WEXITSTATUS(status); - } else { - // Spawn a thread and call exit() from there, to check that we track main - // thread's pid correctly even if leak checking is initiated from another - // thread. - ExitFromThread(); - } - return 0; -} diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/high_allocator_contention.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/high_allocator_contention.cc deleted file mode 100644 index 1cecb2a550a..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/high_allocator_contention.cc +++ /dev/null @@ -1,48 +0,0 @@ -// A benchmark that executes malloc/free pairs in parallel. -// Usage: ./a.out number_of_threads total_number_of_allocations -// RUN: %clangxx_lsan %s -o %t -// RUN: %t 5 1000000 2>&1 -#include <assert.h> -#include <pthread.h> -#include <stdlib.h> -#include <stdio.h> - -int num_threads; -int total_num_alloc; -const int kMaxNumThreads = 5000; -pthread_t tid[kMaxNumThreads]; - -pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -bool go = false; - -void *thread_fun(void *arg) { - pthread_mutex_lock(&mutex); - while (!go) pthread_cond_wait(&cond, &mutex); - pthread_mutex_unlock(&mutex); - for (int i = 0; i < total_num_alloc / num_threads; i++) { - void *p = malloc(10); - __asm__ __volatile__("" : : "r"(p) : "memory"); - free((void *)p); - } - return 0; -} - -int main(int argc, char** argv) { - assert(argc == 3); - num_threads = atoi(argv[1]); - assert(num_threads > 0); - assert(num_threads <= kMaxNumThreads); - total_num_alloc = atoi(argv[2]); - assert(total_num_alloc > 0); - printf("%d threads, %d allocations in each\n", num_threads, - total_num_alloc / num_threads); - for (int i = 0; i < num_threads; i++) - pthread_create(&tid[i], 0, thread_fun, 0); - pthread_mutex_lock(&mutex); - go = true; - pthread_cond_broadcast(&cond); - pthread_mutex_unlock(&mutex); - for (int i = 0; i < num_threads; i++) pthread_join(tid[i], 0); - return 0; -} diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/ignore_object.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/ignore_object.cc deleted file mode 100644 index 4cf303b0054..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/ignore_object.cc +++ /dev/null @@ -1,24 +0,0 @@ -// Test for __lsan_ignore_object(). -// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=0:verbosity=2" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE ASAN_OPTIONS=$ASAN_OPTIONS:"verbosity=2" not %t 2>&1 | FileCheck %s - -#include <stdio.h> -#include <stdlib.h> - -#include "sanitizer/lsan_interface.h" - -int main() { - // Explicitly ignored object. - void **p = new void *; - // Transitively ignored object. - *p = malloc(666); - // Non-ignored object. - volatile void *q = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", p); - __lsan_ignore_object(p); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: ignoring heap object at [[ADDR]] -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s) diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/ignore_object_errors.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/ignore_object_errors.cc deleted file mode 100644 index c49d2c7eada..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/ignore_object_errors.cc +++ /dev/null @@ -1,22 +0,0 @@ -// Test for incorrect use of __lsan_ignore_object(). -// RUN: LSAN_BASE="verbosity=2" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE ASAN_OPTIONS=$ASAN_OPTIONS:verbosity=2 %t 2>&1 | FileCheck %s - -#include <stdio.h> -#include <stdlib.h> - -#include "sanitizer/lsan_interface.h" - -int main() { - void *p = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", p); - __lsan_ignore_object(p); - __lsan_ignore_object(p); - free(p); - __lsan_ignore_object(p); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: heap object at [[ADDR]] is already being ignored -// CHECK: no heap object found at [[ADDR]] diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/large_allocation_leak.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/large_allocation_leak.cc deleted file mode 100644 index 38219341d89..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/large_allocation_leak.cc +++ /dev/null @@ -1,18 +0,0 @@ -// Test that LargeMmapAllocator's chunks aren't reachable via some internal data structure. -// RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE not %t 2>&1 | FileCheck %s - -#include <stdio.h> -#include <stdlib.h> - -int main() { - // maxsize in primary allocator is always less than this (1 << 25). - void *large_alloc = malloc(33554432); - fprintf(stderr, "Test alloc: %p.\n", large_alloc); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (33554432 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/leak_check_at_exit.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/leak_check_at_exit.cc deleted file mode 100644 index d921afc8462..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/leak_check_at_exit.cc +++ /dev/null @@ -1,21 +0,0 @@ -// Test for the leak_check_at_exit flag. -// RUN: LSAN_BASE="use_stacks=0:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE not %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-do -// RUN: LSAN_OPTIONS=$LSAN_BASE not %t 2>&1 | FileCheck %s --check-prefix=CHECK-do -// RUN: LSAN_OPTIONS=$LSAN_BASE:"leak_check_at_exit=0" ASAN_OPTIONS="$ASAN_OPTIONS:leak_check_at_exit=0" not %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-do -// RUN: LSAN_OPTIONS=%LSAN_BASE:"leak_check_at_exit=0" ASAN_OPTIONS="$ASAN_OPTIONS:leak_check_at_exit=0" %t 2>&1 | FileCheck %s --check-prefix=CHECK-dont - -#include <stdio.h> -#include <stdlib.h> -#include <sanitizer/lsan_interface.h> - -int main(int argc, char *argv[]) { - fprintf(stderr, "Test alloc: %p.\n", malloc(1337)); - if (argc > 1) - __lsan_do_leak_check(); - return 0; -} - -// CHECK-do: SUMMARY: {{(Leak|Address)}}Sanitizer: -// CHECK-dont-NOT: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/link_turned_off.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/link_turned_off.cc deleted file mode 100644 index 93628a1d15e..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/link_turned_off.cc +++ /dev/null @@ -1,24 +0,0 @@ -// Test for disabling LSan at link-time. -// RUN: LSAN_BASE="use_stacks=0:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE %t -// RUN: LSAN_OPTIONS=$LSAN_BASE not %t foo 2>&1 | FileCheck %s - -#include <sanitizer/lsan_interface.h> - -int argc_copy; - -extern "C" { -int __lsan_is_turned_off() { - return (argc_copy == 1); -} -} - -int main(int argc, char *argv[]) { - volatile int *x = new int; - *x = 42; - argc_copy = argc; - return 0; -} - -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 4 byte(s) leaked in 1 allocation(s) diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/new_array_with_dtor_0.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/new_array_with_dtor_0.cc deleted file mode 100644 index 3784d81a53c..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/new_array_with_dtor_0.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Regression test: -// https://code.google.com/p/address-sanitizer/issues/detail?id=257 -// RUN: %clangxx_lsan %s -o %t && %t 2>&1 | FileCheck %s - -#include <stdio.h> - -struct T { - ~T() { printf("~T\n"); } -}; - -T *t; - -int main(int argc, char **argv) { - t = new T[argc - 1]; - printf("OK\n"); -} - -// CHECK: OK - diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/pointer_to_self.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/pointer_to_self.cc deleted file mode 100644 index c638c2b7eb8..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/pointer_to_self.cc +++ /dev/null @@ -1,18 +0,0 @@ -// Regression test: pointers to self should not confuse LSan into thinking the -// object is indirectly leaked. Only external pointers count. -// RUN: LSAN_BASE="report_objects=1:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %t 2>&1 | FileCheck %s - -#include <stdio.h> -#include <stdlib.h> - -int main() { - void *p = malloc(1337); - *reinterpret_cast<void **>(p) = p; - fprintf(stderr, "Test alloc: %p.\n", p); -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/print_suppressions.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/print_suppressions.cc deleted file mode 100644 index 97e67a01631..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/print_suppressions.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Print matched suppressions only if print_suppressions=1 AND at least one is -// matched. Default is print_suppressions=true. -// RUN: LSAN_BASE="use_registers=0:use_stacks=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:print_suppressions=0 %t 2>&1 | FileCheck %s --check-prefix=CHECK-dont-print -// RUN: LSAN_OPTIONS=$LSAN_BASE %t 2>&1 | FileCheck %s --check-prefix=CHECK-dont-print -// RUN: LSAN_OPTIONS=$LSAN_BASE:print_suppressions=0 %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-dont-print -// RUN: LSAN_OPTIONS=$LSAN_BASE %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-print - -#include <stdio.h> -#include <stdlib.h> - -#include "sanitizer/lsan_interface.h" - -extern "C" -const char *__lsan_default_suppressions() { - return "leak:*LSanTestLeakingFunc*"; -} - -void LSanTestLeakingFunc() { - void *p = malloc(666); - fprintf(stderr, "Test alloc: %p.\n", p); -} - -int main(int argc, char **argv) { - printf("print for nonempty output\n"); - if (argc > 1) - LSanTestLeakingFunc(); - return 0; -} -// CHECK-print: Suppressions used: -// CHECK-print: 1 666 *LSanTestLeakingFunc* -// CHECK-dont-print-NOT: Suppressions used: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/register_root_region.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/register_root_region.cc deleted file mode 100644 index 27349aaef4b..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/register_root_region.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Test for __lsan_(un)register_root_region(). -// RUN: LSAN_BASE="use_stacks=0:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE %t -// RUN: LSAN_OPTIONS=$LSAN_BASE not %t foo 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE:use_root_regions=0 not %t 2>&1 | FileCheck %s - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <sys/mman.h> -#include <unistd.h> - -#include <sanitizer/lsan_interface.h> - -int main(int argc, char *argv[]) { - size_t size = getpagesize() * 2; - void *p = - mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - assert(p); - // Make half of the memory inaccessible. LSan must not crash trying to read it. - assert(0 == mprotect((char *)p + size / 2, size / 2, PROT_NONE)); - - __lsan_register_root_region(p, size); - *((void **)p) = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", p); - if (argc > 1) - __lsan_unregister_root_region(p, size); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s) diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/sanity_check_pure_c.c b/compiler-rt/lib/lsan/lit_tests/TestCases/sanity_check_pure_c.c deleted file mode 100644 index 085412b47d5..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/sanity_check_pure_c.c +++ /dev/null @@ -1,10 +0,0 @@ -// Check that we can build C code. -// RUN: %clang_lsan %s -o %t -#ifdef __cplusplus -#error "This test must be built in C mode" -#endif - -int main() { - // FIXME: ideally this should somehow check that we don't have libstdc++ - return 0; -} diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/stale_stack_leak.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/stale_stack_leak.cc deleted file mode 100644 index 4a53910abd7..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/stale_stack_leak.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Test that out-of-scope local variables are ignored by LSan. -// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=1" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE not %t 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE":exitcode=0" %t 2>&1 | FileCheck --check-prefix=CHECK-sanity %s - -#include <stdio.h> -#include <stdlib.h> - -void **pp; - -// Put pointer far enough on the stack that LSan has space to run in without -// overwriting it. -// Hopefully the argument p will be passed on a register, saving us from false -// negatives. -__attribute__((noinline)) -void *PutPointerOnStaleStack(void *p) { - void *locals[2048]; - locals[0] = p; - pp = &locals[0]; - fprintf(stderr, "Test alloc: %p.\n", locals[0]); - return 0; -} - -int main() { - PutPointerOnStaleStack(malloc(1337)); - return 0; -} - -// This must run after LSan, to ensure LSan didn't overwrite the pointer before -// it had a chance to see it. If LSan is invoked with atexit(), this works. -// Otherwise, we need a different method. -__attribute__((destructor)) -void ConfirmPointerHasSurvived() { - fprintf(stderr, "Value after LSan: %p.\n", *pp); -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK-sanity: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: -// CHECK-sanity: Value after LSan: [[ADDR]]. diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/suppressions_default.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/suppressions_default.cc deleted file mode 100644 index 96807466226..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/suppressions_default.cc +++ /dev/null @@ -1,28 +0,0 @@ -// RUN: LSAN_BASE="use_registers=0:use_stacks=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE not %t 2>&1 | FileCheck %s - -#include <stdio.h> -#include <stdlib.h> - -#include "sanitizer/lsan_interface.h" - -extern "C" -const char *__lsan_default_suppressions() { - return "leak:*LSanTestLeakingFunc*"; -} - -void LSanTestLeakingFunc() { - void *p = malloc(666); - fprintf(stderr, "Test alloc: %p.\n", p); -} - -int main() { - LSanTestLeakingFunc(); - void *q = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", q); - return 0; -} -// CHECK: Suppressions used: -// CHECK: 1 666 *LSanTestLeakingFunc* -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s) diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/suppressions_file.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/suppressions_file.cc deleted file mode 100644 index bc8913a6c37..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/suppressions_file.cc +++ /dev/null @@ -1,26 +0,0 @@ -// RUN: LSAN_BASE="use_registers=0:use_stacks=0" -// RUN: %clangxx_lsan %s -o %t - -// RUN: echo "leak:*LSanTestLeakingFunc*" > %t.supp1 -// RUN: LSAN_OPTIONS=$LSAN_BASE:suppressions=%t.supp1 not %t 2>&1 | FileCheck %s - -// RUN: echo "leak:%t" > %t.supp2 -// RUN: LSAN_OPTIONS=$LSAN_BASE:suppressions="%t.supp2":symbolize=false %t - -#include <stdio.h> -#include <stdlib.h> - -void LSanTestLeakingFunc() { - void *p = malloc(666); - fprintf(stderr, "Test alloc: %p.\n", p); -} - -int main() { - LSanTestLeakingFunc(); - void *q = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", q); - return 0; -} -// CHECK: Suppressions used: -// CHECK: 1 666 *LSanTestLeakingFunc* -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s) diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/swapcontext.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/swapcontext.cc deleted file mode 100644 index a06685ca2f0..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/swapcontext.cc +++ /dev/null @@ -1,42 +0,0 @@ -// We can't unwind stack if we're running coroutines on heap-allocated -// memory. Make sure we don't report these leaks. - -// RUN: %clangxx_lsan %s -o %t -// RUN: %t 2>&1 -// RUN: not %t foo 2>&1 | FileCheck %s - -#include <stdio.h> -#include <ucontext.h> -#include <unistd.h> - -const int kStackSize = 1 << 20; - -void Child() { - int child_stack; - printf("Child: %p\n", &child_stack); - int *leaked = new int[666]; -} - -int main(int argc, char *argv[]) { - char stack_memory[kStackSize + 1]; - char *heap_memory = new char[kStackSize + 1]; - char *child_stack = (argc > 1) ? stack_memory : heap_memory; - - printf("Child stack: %p\n", child_stack); - ucontext_t orig_context; - ucontext_t child_context; - getcontext(&child_context); - child_context.uc_stack.ss_sp = child_stack; - child_context.uc_stack.ss_size = kStackSize / 2; - child_context.uc_link = &orig_context; - makecontext(&child_context, Child, 0); - if (swapcontext(&orig_context, &child_context) < 0) { - perror("swapcontext"); - return 1; - } - - delete[] heap_memory; - return 0; -} - -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 2664 byte(s) leaked in 1 allocation(s) diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_after_return.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_after_return.cc deleted file mode 100644 index ffa20f39952..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/use_after_return.cc +++ /dev/null @@ -1,23 +0,0 @@ -// Test that fake stack (introduced by ASan's use-after-return mode) is included -// in the root set. -// RUN: LSAN_BASE="report_objects=1:use_registers=0" -// RUN: %clangxx_lsan %s -O2 -o %t -// RUN: ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1 LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %t 2>&1 | FileCheck %s -// RUN: ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1 LSAN_OPTIONS=$LSAN_BASE:"use_stacks=1" %t 2>&1 -// RUN: ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1 LSAN_OPTIONS="" %t 2>&1 - -#include <stdio.h> -#include <stdlib.h> - -int main() { - void *stack_var = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", stack_var); - // Take pointer to variable, to ensure it's not optimized into a register. - fprintf(stderr, "Stack var at: %p.\n", &stack_var); - // Do not return from main to prevent the pointer from going out of scope. - exit(0); -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_globals_initialized.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_globals_initialized.cc deleted file mode 100644 index 2a5331cfda7..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/use_globals_initialized.cc +++ /dev/null @@ -1,21 +0,0 @@ -// Test that initialized globals are included in the root set. -// RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=0" not %t 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=1" %t 2>&1 -// RUN: LSAN_OPTIONS="" %t 2>&1 - -#include <stdio.h> -#include <stdlib.h> - -void *data_var = (void *)1; - -int main() { - data_var = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", data_var); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_globals_uninitialized.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_globals_uninitialized.cc deleted file mode 100644 index 9fdb1fdd507..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/use_globals_uninitialized.cc +++ /dev/null @@ -1,21 +0,0 @@ -// Test that uninitialized globals are included in the root set. -// RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=0" not %t 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=1" %t 2>&1 -// RUN: LSAN_OPTIONS="" %t 2>&1 - -#include <stdio.h> -#include <stdlib.h> - -void *bss_var; - -int main() { - bss_var = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", bss_var); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_poisoned_asan.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_poisoned_asan.cc deleted file mode 100644 index 1a72ac22363..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/use_poisoned_asan.cc +++ /dev/null @@ -1,25 +0,0 @@ -// ASan-poisoned memory should be ignored if use_poisoned is false. -// REQUIRES: asan -// RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_poisoned=0" not %t 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_poisoned=1" %t 2>&1 - -#include <stdio.h> -#include <stdlib.h> -#include <sanitizer/asan_interface.h> -#include <assert.h> - -void **p; - -int main() { - p = new void *; - *p = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", *p); - __asan_poison_memory_region(p, sizeof(*p)); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: AddressSanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_registers.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_registers.cc deleted file mode 100644 index 1a90994e373..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/use_registers.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Test that registers of running threads are included in the root set. -// RUN: LSAN_BASE="report_objects=1:use_stacks=0" -// RUN: %clangxx_lsan -pthread %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_registers=0" not %t 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_registers=1" %t 2>&1 -// RUN: LSAN_OPTIONS="" %t 2>&1 - -#include <assert.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> - -extern "C" -void *registers_thread_func(void *arg) { - int *sync = reinterpret_cast<int *>(arg); - void *p = malloc(1337); - // To store the pointer, choose a register which is unlikely to be reused by - // a function call. -#if defined(__i386__) - asm ( "mov %0, %%esi" - : - : "r" (p) - ); -#elif defined(__x86_64__) - asm ( "mov %0, %%r15" - : - : "r" (p) - ); -#else -#error "Test is not supported on this architecture." -#endif - fprintf(stderr, "Test alloc: %p.\n", p); - fflush(stderr); - __sync_fetch_and_xor(sync, 1); - while (true) - pthread_yield(); -} - -int main() { - int sync = 0; - pthread_t thread_id; - int res = pthread_create(&thread_id, 0, registers_thread_func, &sync); - assert(res == 0); - while (!__sync_fetch_and_xor(&sync, 0)) - pthread_yield(); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_stacks.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_stacks.cc deleted file mode 100644 index aea90bba1a8..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/use_stacks.cc +++ /dev/null @@ -1,20 +0,0 @@ -// Test that stack of main thread is included in the root set. -// RUN: LSAN_BASE="report_objects=1:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %t 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=1" %t 2>&1 -// RUN: LSAN_OPTIONS="" %t 2>&1 - -#include <stdio.h> -#include <stdlib.h> - -int main() { - void *stack_var = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", stack_var); - // Do not return from main to prevent the pointer from going out of scope. - exit(0); -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_stacks_threaded.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_stacks_threaded.cc deleted file mode 100644 index bcb4b1e2d71..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/use_stacks_threaded.cc +++ /dev/null @@ -1,36 +0,0 @@ -// Test that stacks of non-main threads are included in the root set. -// RUN: LSAN_BASE="report_objects=1:use_registers=0" -// RUN: %clangxx_lsan -pthread %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %t 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=1" %t 2>&1 -// RUN: LSAN_OPTIONS="" %t 2>&1 - -#include <assert.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> - -extern "C" -void *stacks_thread_func(void *arg) { - int *sync = reinterpret_cast<int *>(arg); - void *p = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", p); - fflush(stderr); - __sync_fetch_and_xor(sync, 1); - while (true) - pthread_yield(); -} - -int main() { - int sync = 0; - pthread_t thread_id; - int res = pthread_create(&thread_id, 0, stacks_thread_func, &sync); - assert(res == 0); - while (!__sync_fetch_and_xor(&sync, 0)) - pthread_yield(); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_tls_dynamic.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_tls_dynamic.cc deleted file mode 100644 index 552206a1477..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/use_tls_dynamic.cc +++ /dev/null @@ -1,50 +0,0 @@ -// 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: %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 %t 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=1" %t 2>&1 -// RUN: LSAN_OPTIONS="" %t 2>&1 - -#ifndef BUILD_DSO -#include <assert.h> -#include <dlfcn.h> -#include <stdio.h> -#include <stdlib.h> -#include <string> - -int main(int argc, char *argv[]) { - std::string path = std::string(argv[0]) + "-so.so"; - - void *handle = dlopen(path.c_str(), RTLD_LAZY); - assert(handle != 0); - typedef void **(* store_t)(void *p); - store_t StoreToTLS = (store_t)dlsym(handle, "StoreToTLS"); - assert(dlerror() == 0); - - void *p = malloc(1337); - // If we don't know about dynamic TLS, we will return a false leak above. - void **p_in_tls = StoreToTLS(p); - assert(*p_in_tls == p); - fprintf(stderr, "Test alloc: %p.\n", p); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: - -#else // BUILD_DSO -// A loadable module with a large thread local section, which would require -// allocation of a new TLS storage chunk when loaded with dlopen(). We use it -// to test the reachability of such chunks in LSan tests. - -// This must be large enough that it doesn't fit into preallocated static TLS -// space (see STATIC_TLS_SURPLUS in glibc). -__thread void *huge_thread_local_array[(1 << 20) / sizeof(void *)]; // NOLINT - -extern "C" void **StoreToTLS(void *p) { - huge_thread_local_array[0] = p; - return &huge_thread_local_array[0]; -} -#endif // BUILD_DSO diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_dynamic.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_dynamic.cc deleted file mode 100644 index cfb6b2dd985..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_dynamic.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Test that dynamically allocated thread-specific storage is included in the root set. -// RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=0" not %t 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=1" %t 2>&1 -// RUN: LSAN_OPTIONS="" %t 2>&1 - -#include <assert.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> - -// From glibc: this many keys are stored in the thread descriptor directly. -const unsigned PTHREAD_KEY_2NDLEVEL_SIZE = 32; - -int main() { - static const unsigned kDummyKeysCount = PTHREAD_KEY_2NDLEVEL_SIZE; - int res; - pthread_key_t dummy_keys[kDummyKeysCount]; - for (unsigned i = 0; i < kDummyKeysCount; i++) { - res = pthread_key_create(&dummy_keys[i], NULL); - assert(res == 0); - } - pthread_key_t key; - res = pthread_key_create(&key, NULL); - assert(key >= PTHREAD_KEY_2NDLEVEL_SIZE); - assert(res == 0); - void *p = malloc(1337); - res = pthread_setspecific(key, p); - assert(res == 0); - fprintf(stderr, "Test alloc: %p.\n", p); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_static.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_static.cc deleted file mode 100644 index 4def4c021bf..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/use_tls_pthread_specific_static.cc +++ /dev/null @@ -1,31 +0,0 @@ -// Test that statically allocated thread-specific storage is included in the root set. -// RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=0" not %t 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=1" %t 2>&1 -// RUN: LSAN_OPTIONS="" %t 2>&1 - -#include <assert.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> - -// From glibc: this many keys are stored in the thread descriptor directly. -const unsigned PTHREAD_KEY_2NDLEVEL_SIZE = 32; - -int main() { - pthread_key_t key; - int res; - res = pthread_key_create(&key, NULL); - assert(res == 0); - assert(key < PTHREAD_KEY_2NDLEVEL_SIZE); - void *p = malloc(1337); - res = pthread_setspecific(key, p); - assert(res == 0); - fprintf(stderr, "Test alloc: %p.\n", p); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_tls_static.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_tls_static.cc deleted file mode 100644 index 1c5512568fb..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/use_tls_static.cc +++ /dev/null @@ -1,21 +0,0 @@ -// Test that statically allocated TLS space is included in the root set. -// RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=0" not %t 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_tls=1" %t 2>&1 -// RUN: LSAN_OPTIONS="" %t 2>&1 - -#include <stdio.h> -#include <stdlib.h> - -__thread void *tls_var; - -int main() { - tls_var = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", tls_var); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_unaligned.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_unaligned.cc deleted file mode 100644 index 50eb749527c..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/TestCases/use_unaligned.cc +++ /dev/null @@ -1,23 +0,0 @@ -// Test that unaligned pointers are detected correctly. -// RUN: LSAN_BASE="report_objects=1:use_stacks=0:use_registers=0" -// RUN: %clangxx_lsan %s -o %t -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_unaligned=0" not %t 2>&1 | FileCheck %s -// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_unaligned=1" %t 2>&1 - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -void *arr[2]; - -int main() { - void *p = malloc(1337); - fprintf(stderr, "Test alloc: %p.\n", p); - char *char_arr = (char *)arr; - memcpy(char_arr + 1, &p, sizeof(p)); - return 0; -} -// CHECK: Test alloc: [[ADDR:.*]]. -// CHECK: LeakSanitizer: detected memory leaks -// CHECK: [[ADDR]] (1337 bytes) -// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: diff --git a/compiler-rt/lib/lsan/lit_tests/lit.common.cfg b/compiler-rt/lib/lsan/lit_tests/lit.common.cfg deleted file mode 100644 index 96dc1b1f55f..00000000000 --- a/compiler-rt/lib/lsan/lit_tests/lit.common.cfg +++ /dev/null @@ -1,43 +0,0 @@ -# -*- Python -*- - -# Common configuration for running leak detection tests under LSan/ASan. - -import os - -def get_required_attr(config, attr_name): - attr_value = getattr(config, attr_name, None) - if not attr_value: - lit_config.fatal( - "No attribute %r in test configuration! You may need to run " - "tests from your build directory or add this attribute " - "to lit.site.cfg " % attr_name) - return attr_value - -# Setup source root. -lsan_lit_src_root = get_required_attr(config, 'lsan_lit_src_root') -config.test_source_root = os.path.join(lsan_lit_src_root, 'TestCases') - -clang_cxxflags = ("--driver-mode=g++ " - + "-g " - + "-O0 " - + "-m64 ") - -clang_cflags = ("-g " - + "-O0 " - + "-m64 ") - -config.clang_cxxflags = clang_cxxflags - -config.substitutions.append( ("%clangxx ", (" " + config.clang + " " + - clang_cxxflags + " ")) ) - -config.clang_cflags = clang_cflags - -config.substitutions.append( ("%clang ", (" " + config.clang + " " + - clang_cflags + " ")) ) - -# LeakSanitizer tests are currently supported on x86-64 Linux only. -if config.host_os not in ['Linux'] or config.host_arch not in ['x86_64']: - config.unsupported = True - -config.suffixes = ['.c', '.cc', '.cpp'] |