[PATCH] [lsan] CMakeLists and lit test configs for LeakSanitizer.

Sergey Matveev earthdok at google.com
Mon May 20 02:49:10 PDT 2013


    - addressed comments by samsonov

Hi kcc, glider, eugenis, samsonov,

http://llvm-reviews.chandlerc.com/D804

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D804?vs=2004&id=2027#toc

Files:
  lib/CMakeLists.txt
  lib/lsan/CMakeLists.txt
  lib/lsan/tests/CMakeLists.txt
  lib/lsan/tests/lit.cfg
  lib/lsan/tests/lit.site.cfg.in

Index: lib/CMakeLists.txt
===================================================================
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -16,6 +16,7 @@
   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
Index: lib/lsan/CMakeLists.txt
===================================================================
--- /dev/null
+++ lib/lsan/CMakeLists.txt
@@ -0,0 +1,28 @@
+include_directories(..)
+
+set(LSAN_CFLAGS
+  ${SANITIZER_COMMON_CFLAGS}
+  -I${COMPILER_RT_SOURCE_DIR}/lib)
+
+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 ${COMPILER_RT_SOURCE_DIR}/lib/lsan)
+
+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}
+  DEFS ${LSAN_COMMON_DEFINITIONS})
+list(APPEND LSAN_RUNTIME_LIBRARIES clang_rt.lsan-${arch})
+
+add_subdirectory(tests)
Index: lib/lsan/tests/CMakeLists.txt
===================================================================
--- /dev/null
+++ lib/lsan/tests/CMakeLists.txt
@@ -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})
+
+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()
Index: lib/lsan/tests/lit.cfg
===================================================================
--- /dev/null
+++ lib/lsan/tests/lit.cfg
@@ -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
Index: lib/lsan/tests/lit.site.cfg.in
===================================================================
--- /dev/null
+++ lib/lsan/tests/lit.site.cfg.in
@@ -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")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D804.3.patch
Type: text/x-patch
Size: 6029 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130520/70c101bd/attachment.bin>


More information about the llvm-commits mailing list