diff options
Diffstat (limited to 'lib/lsan/lit_tests')
-rw-r--r-- | lib/lsan/lit_tests/CMakeLists.txt | 28 | ||||
-rw-r--r-- | lib/lsan/lit_tests/SharedLibs/lit.local.cfg | 4 | ||||
-rw-r--r-- | lib/lsan/lit_tests/Unit/lit.cfg | 26 | ||||
-rw-r--r-- | lib/lsan/lit_tests/Unit/lit.site.cfg.in | 17 | ||||
-rw-r--r-- | lib/lsan/lit_tests/lit.cfg | 50 | ||||
-rw-r--r-- | lib/lsan/lit_tests/lit.site.cfg.in | 20 | ||||
-rw-r--r-- | lib/lsan/lit_tests/use_globals_initialized.cc | 21 |
7 files changed, 166 insertions, 0 deletions
diff --git a/lib/lsan/lit_tests/CMakeLists.txt b/lib/lsan/lit_tests/CMakeLists.txt new file mode 100644 index 000000000000..e1be508202b8 --- /dev/null +++ b/lib/lsan/lit_tests/CMakeLists.txt @@ -0,0 +1,28 @@ +set(LSAN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..) +set(LSAN_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/..) + +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg + ) + +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg + ) + +if(COMPILER_RT_CAN_EXECUTE_TESTS) + set(LSAN_TEST_DEPS + ${SANITIZER_COMMON_LIT_TEST_DEPS} + ${LSAN_RUNTIME_LIBRARIES}) + set(LSAN_TEST_PARAMS + lsan_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg) + if(LLVM_INCLUDE_TESTS) + list(APPEND LSAN_TEST_DEPS LsanTests) + endif() + add_lit_testsuite(check-lsan "Running the LeakSanitizer tests" + ${CMAKE_CURRENT_BINARY_DIR} + PARAMS ${LSAN_TEST_PARAMS} + DEPENDS ${LSAN_TEST_DEPS}) + set_target_properties(check-lsan PROPERTIES FOLDER "LSan tests") +endif() diff --git a/lib/lsan/lit_tests/SharedLibs/lit.local.cfg b/lib/lsan/lit_tests/SharedLibs/lit.local.cfg new file mode 100644 index 000000000000..b3677c17a0f2 --- /dev/null +++ b/lib/lsan/lit_tests/SharedLibs/lit.local.cfg @@ -0,0 +1,4 @@ +# Sources in this directory are compiled as shared libraries and used by +# tests in parent directory. + +config.suffixes = [] diff --git a/lib/lsan/lit_tests/Unit/lit.cfg b/lib/lsan/lit_tests/Unit/lit.cfg new file mode 100644 index 000000000000..bcd1de4477f1 --- /dev/null +++ b/lib/lsan/lit_tests/Unit/lit.cfg @@ -0,0 +1,26 @@ +# -*- Python -*- + +import os + +def get_required_attr(config, attr_name): + attr_value = getattr(config, attr_name, None) + if not attr_value: + lit.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 attributes common for all compiler-rt projects. +compiler_rt_src_root = get_required_attr(config, 'compiler_rt_src_root') +compiler_rt_lit_unit_cfg = os.path.join(compiler_rt_src_root, "lib", + "lit.common.unit.cfg") +lit.load_config(config, compiler_rt_lit_unit_cfg) + +# Setup config name. +config.name = 'LeakSanitizer-Unit' + +# Setup test source and exec root. For unit tests, we define +# it as build directory with LSan unit tests. +lsan_binary_dir = get_required_attr(config, "lsan_binary_dir") +config.test_exec_root = os.path.join(lsan_binary_dir, "tests") +config.test_source_root = config.test_exec_root diff --git a/lib/lsan/lit_tests/Unit/lit.site.cfg.in b/lib/lsan/lit_tests/Unit/lit.site.cfg.in new file mode 100644 index 000000000000..90c88c952156 --- /dev/null +++ b/lib/lsan/lit_tests/Unit/lit.site.cfg.in @@ -0,0 +1,17 @@ +## Autogenerated by LLVM/Clang configuration. +# Do not edit! + +config.target_triple = "@TARGET_TRIPLE@" +config.llvm_src_root = "@LLVM_SOURCE_DIR@" +config.compiler_rt_src_root = "@COMPILER_RT_SOURCE_DIR@" +config.llvm_build_mode = "@LLVM_BUILD_MODE@" +config.lsan_binary_dir = "@LSAN_BINARY_DIR@" + +try: + config.llvm_build_mode = config.llvm_build_mode % lit.params +except KeyError,e: + key, = e.args + lit.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key, key)) + +# Let the main config do the real work. +lit.load_config(config, "@LSAN_SOURCE_DIR@/lit_tests/Unit/lit.cfg") diff --git a/lib/lsan/lit_tests/lit.cfg b/lib/lsan/lit_tests/lit.cfg new file mode 100644 index 000000000000..48e1453334d0 --- /dev/null +++ b/lib/lsan/lit_tests/lit.cfg @@ -0,0 +1,50 @@ +# -*- Python -*- + +import os + +def get_required_attr(config, attr_name): + attr_value = getattr(config, attr_name, None) + if not attr_value: + lit.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 attributes common for all compiler-rt projects. +compiler_rt_src_root = get_required_attr(config, 'compiler_rt_src_root') +compiler_rt_lit_unit_cfg = os.path.join(compiler_rt_src_root, "lib", + "lit.common.unit.cfg") +lit.load_config(config, compiler_rt_lit_unit_cfg) + +# Setup config name. +config.name = 'LeakSanitizer' + +# Setup source root. +config.test_source_root = os.path.dirname(__file__) + +# Setup attributes common for all compiler-rt projects. +compiler_rt_lit_cfg = os.path.join(compiler_rt_src_root, "lib", + "lit.common.cfg") +if (not compiler_rt_lit_cfg) or (not os.path.exists(compiler_rt_lit_cfg)): + lit.fatal("Can't find common compiler-rt lit config at: %r" + % compiler_rt_lit_cfg) +lit.load_config(config, compiler_rt_lit_cfg) + +clang_cxxflags = ("-ccc-cxx " + + "-g " + + "-O0 " + + "-m64 ") + +clang_lsan_cxxflags = clang_cxxflags + "-fsanitize=leak " + +config.substitutions.append( ("%clangxx ", (" " + config.clang + " " + + clang_cxxflags + " ")) ) +config.substitutions.append( ("%clangxx_lsan ", (" " + config.clang + " " + + clang_lsan_cxxflags + " ")) ) + +# Default test suffixes. +config.suffixes = ['.c', '.cc', '.cpp'] + +# 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 diff --git a/lib/lsan/lit_tests/lit.site.cfg.in b/lib/lsan/lit_tests/lit.site.cfg.in new file mode 100644 index 000000000000..3de98a9811f8 --- /dev/null +++ b/lib/lsan/lit_tests/lit.site.cfg.in @@ -0,0 +1,20 @@ +config.host_os = "@HOST_OS@" +config.host_arch = "@HOST_ARCH@" +config.llvm_build_mode = "@LLVM_BUILD_MODE@" +config.llvm_src_root = "@LLVM_SOURCE_DIR@" +config.compiler_rt_src_root = "@COMPILER_RT_SOURCE_DIR@" +config.llvm_obj_root = "@LLVM_BINARY_DIR@" +config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" +config.clang = "@LLVM_BINARY_DIR@/bin/clang" +config.compiler_rt_arch = "@COMPILER_RT_SUPPORTED_ARCH@" + +# LLVM tools dir can be passed in lit parameters, so try to +# apply substitution. +try: + config.llvm_tools_dir = config.llvm_tools_dir % lit.params +except KeyError,e: + key, = e.args + lit.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key, key)) + +# Let the main config do the real work. +lit.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg") diff --git a/lib/lsan/lit_tests/use_globals_initialized.cc b/lib/lsan/lit_tests/use_globals_initialized.cc new file mode 100644 index 000000000000..53c22c8ac057 --- /dev/null +++ b/lib/lsan/lit_tests/use_globals_initialized.cc @@ -0,0 +1,21 @@ +// Test that initialized globals are included in the root set. +// RUN: LSAN_BASE="report_blocks=1:use_stacks=0:use_registers=0" +// RUN: %clangxx_lsan %s -o %t +// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=0" %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: Directly leaked 1337 byte block at [[ADDR]] +// CHECK: SUMMARY: LeakSanitizer: |