[compiler-rt] r182251 - [lsan] CMakeLists and lit test configs for LSan.
Sergey Matveev
earthdok at google.com
Mon May 20 04:13:34 PDT 2013
Author: smatveev
Date: Mon May 20 06:13:33 2013
New Revision: 182251
URL: http://llvm.org/viewvc/llvm-project?rev=182251&view=rev
Log:
[lsan] CMakeLists and lit test configs for LSan.
Added:
compiler-rt/trunk/lib/lsan/CMakeLists.txt
compiler-rt/trunk/lib/lsan/tests/CMakeLists.txt
compiler-rt/trunk/lib/lsan/tests/lit.cfg
compiler-rt/trunk/lib/lsan/tests/lit.site.cfg.in
Modified:
compiler-rt/trunk/lib/CMakeLists.txt
Modified: compiler-rt/trunk/lib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/CMakeLists.txt?rev=182251&r1=182250&r2=182251&view=diff
==============================================================================
--- compiler-rt/trunk/lib/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/CMakeLists.txt Mon May 20 06:13:33 2013
@@ -16,6 +16,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linu
add_subdirectory(tsan)
add_subdirectory(msan)
add_subdirectory(msandr)
+ add_subdirectory(lsan)
endif()
# The top-level lib directory contains a large amount of C code which provides
Added: compiler-rt/trunk/lib/lsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/CMakeLists.txt?rev=182251&view=auto
==============================================================================
--- compiler-rt/trunk/lib/lsan/CMakeLists.txt (added)
+++ compiler-rt/trunk/lib/lsan/CMakeLists.txt Mon May 20 06:13:33 2013
@@ -0,0 +1,26 @@
+include_directories(..)
+
+set(LSAN_CFLAGS
+ ${SANITIZER_COMMON_CFLAGS})
+
+set(LSAN_SOURCES
+ lsan_interceptors.cc
+ lsan_allocator.cc
+ lsan_thread.cc
+ lsan.cc
+ lsan_common.cc
+ lsan_common_linux.cc)
+
+set(LSAN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+
+set(LSAN_RUNTIME_LIBRARIES)
+set(arch "x86_64")
+add_compiler_rt_static_runtime(clang_rt.lsan-${arch} ${arch}
+ SOURCES ${LSAN_SOURCES}
+ $<TARGET_OBJECTS:RTInterception.${arch}>
+ $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
+ $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
+ CFLAGS ${LSAN_CFLAGS})
+list(APPEND LSAN_RUNTIME_LIBRARIES clang_rt.lsan-${arch})
+
+add_subdirectory(tests)
Added: compiler-rt/trunk/lib/lsan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/tests/CMakeLists.txt?rev=182251&view=auto
==============================================================================
--- compiler-rt/trunk/lib/lsan/tests/CMakeLists.txt (added)
+++ compiler-rt/trunk/lib/lsan/tests/CMakeLists.txt Mon May 20 06:13:33 2013
@@ -0,0 +1,77 @@
+include(CheckCXXCompilerFlag)
+include(CompilerRTCompile)
+include(CompilerRTLink)
+
+include_directories(..)
+include_directories(../..)
+
+set(LSAN_TESTS_SRC
+ lsan_test.cc)
+
+set(LSAN_TESTS_CFLAGS
+ ${LSAN_CFLAGS}
+ ${COMPILER_RT_GTEST_INCLUDE_CFLAGS}
+ -I${COMPILER_RT_SOURCE_DIR}/lib)
+
+add_custom_target(LsanTests)
+set_target_properties(LsanTests PROPERTIES
+ FOLDER "LSan unittests")
+
+set(LSAN_LOADABLE_SRC "lsan_tls_loadable.cc")
+
+# Compile source for the given architecture, using compiler
+# options in ${ARGN}, and add it to the object list.
+macro(lsan_compile obj_list source arch)
+ get_filename_component(basename ${source} NAME)
+ set(output_obj "${basename}.${arch}.o")
+ get_target_flags_for_arch(${arch} TARGET_CFLAGS)
+ clang_compile(${output_obj} ${source}
+ CFLAGS ${ARGN} ${TARGET_CFLAGS}
+ DEPS gtest)
+ list(APPEND ${obj_list} ${output_obj})
+endmacro()
+
+function(add_lsan_test testname arch)
+ set(testname_arch ${testname}-${arch}-Test)
+ get_target_flags_for_arch(${arch} TARGET_LINKFLAGS)
+ add_unittest(LsanTests ${testname_arch} ${ARGN})
+ target_link_libraries(${testname_arch} "clang_rt.lsan-${arch}")
+ set_target_compile_flags(${testname_arch} ${LSAN_TESTS_CFLAGS})
+ set_target_link_flags(${testname_arch} ${TARGET_LINKFLAGS})
+endfunction()
+
+macro(add_lsan_tests_for_arch arch)
+ set(LSAN_TESTS_OBJ)
+ lsan_compile(LSAN_TESTS_OBJ ${LSAN_TESTS_SRC} ${arch} ${LSAN_TESTS_CFLAGS}
+ -I${LSAN_SRC_DIR})
+ add_lsan_test(Lsan ${arch} ${LSAN_TESTS_OBJ})
+ add_library("lsan_tls_loadable-${arch}" SHARED ${LSAN_LOADABLE_SRC})
+ set_property(TARGET "lsan_tls_loadable-${arch}" PROPERTY
+ LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+ add_dependencies(Lsan-${arch}-Test lsan_tls_loadable-${arch})
+endmacro()
+
+# Build tests for 64-bit Linux only.
+if(UNIX AND NOT APPLE AND CAN_TARGET_x86_64)
+ add_lsan_tests_for_arch(x86_64)
+endif()
+
+configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+ ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg)
+
+if(COMPILER_RT_CAN_EXECUTE_TESTS)
+ set(LSAN_TEST_DEPS
+ clang clang-headers
+ ${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()
Added: compiler-rt/trunk/lib/lsan/tests/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/tests/lit.cfg?rev=182251&view=auto
==============================================================================
--- compiler-rt/trunk/lib/lsan/tests/lit.cfg (added)
+++ compiler-rt/trunk/lib/lsan/tests/lit.cfg Mon May 20 06:13:33 2013
@@ -0,0 +1,29 @@
+# -*- 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.
+llvm_src_root = get_required_attr(config, 'llvm_src_root')
+compiler_rt_lit_unit_cfg = os.path.join(llvm_src_root, "projects",
+ "compiler-rt", "lib",
+ "lit.common.unit.cfg")
+lit.load_config(config, compiler_rt_lit_unit_cfg)
+
+# Setup config name.
+config.name = 'LeakSanitizer'
+
+# Setup test source and exec root. For unit tests, we define
+# it as build directory with lsan unit tests.
+llvm_obj_root = get_required_attr(config, "llvm_obj_root")
+config.test_exec_root = os.path.join(llvm_obj_root, "projects",
+ "compiler-rt", "lib",
+ "lsan", "tests")
+config.test_source_root = config.test_exec_root
Added: compiler-rt/trunk/lib/lsan/tests/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/tests/lit.site.cfg.in?rev=182251&view=auto
==============================================================================
--- compiler-rt/trunk/lib/lsan/tests/lit.site.cfg.in (added)
+++ compiler-rt/trunk/lib/lsan/tests/lit.site.cfg.in Mon May 20 06:13:33 2013
@@ -0,0 +1,14 @@
+config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+config.llvm_obj_root = "@LLVM_BINARY_DIR@"
+config.llvm_build_mode = "@LLVM_BUILD_MODE@"
+
+# LLVM tools dir can be passed in lit parameters, so try to
+# apply substitution.
+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, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")
More information about the llvm-commits
mailing list