[llvm-commits] [compiler-rt] r163610 - in /compiler-rt/trunk/lib/sanitizer_common: CMakeLists.txt tests/CMakeLists.txt tests/lit.cfg tests/lit.site.cfg.in tests/sanitizer_test_main.cc

Alexey Samsonov samsonov at google.com
Tue Sep 11 03:50:33 PDT 2012


Author: samsonov
Date: Tue Sep 11 05:50:32 2012
New Revision: 163610

URL: http://llvm.org/viewvc/llvm-project?rev=163610&view=rev
Log:
[Sanitizer] Add new lit testsuite: check-sanitizer that runs unit tests for sanitizer_common runtime (shared between ASan and TSan)

Added:
    compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/tests/lit.cfg
    compiler-rt/trunk/lib/sanitizer_common/tests/lit.site.cfg.in
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt

Modified: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=163610&r1=163609&r2=163610&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Tue Sep 11 05:50:32 2012
@@ -10,6 +10,7 @@
   sanitizer_mac.cc
   sanitizer_posix.cc
   sanitizer_printf.cc
+  sanitizer_stackdepot.cc
   sanitizer_stacktrace.cc
   sanitizer_symbolizer.cc
   sanitizer_symbolizer_linux.cc
@@ -20,8 +21,6 @@
 
 set(SANITIZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
 
-set(SANITIZER_COMMON_DEFINITIONS)
-
 set(SANITIZER_RUNTIME_LIBRARIES)
 if(APPLE)
   # Build universal binary on APPLE.
@@ -53,7 +52,15 @@
   endif()
 endif()
 
-set_property(TARGET ${SANITIZER_RUNTIME_LIBRARIES} APPEND PROPERTY
-  COMPILE_DEFINITIONS ${SANITIZER_COMMON_DEFINITIONS})
+# Unit tests for common sanitizer runtime.
+if(LLVM_INCLUDE_TESTS)
+  # Build stand-alone static sanitizer runtime for use in unit tests.
+  add_library(RTSanitizerCommon.test STATIC ${SANITIZER_SOURCES})
+  # Build test library with debug info.
+  set_target_compile_flags(RTSanitizerCommon.test
+    ${SANITIZER_CFLAGS} -g -Werror)
+  set_target_properties(RTSanitizerCommon.test PROPERTIES
+    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
 
-# FIXME: Add support for running sanitizer_common unit tests.
+  add_subdirectory(tests)
+endif()

Added: compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt?rev=163610&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt (added)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt Tue Sep 11 05:50:32 2012
@@ -0,0 +1,35 @@
+set(SANITIZER_UNITTESTS
+  sanitizer_allocator64_test.cc
+  sanitizer_allocator_test.cc
+  sanitizer_common_test.cc
+  sanitizer_flags_test.cc
+  sanitizer_list_test.cc
+  sanitizer_stackdepot_test.cc
+  sanitizer_test_main.cc
+  )
+
+include_directories(..)
+include_directories(../..)
+
+# Unittest target.
+add_custom_target(SanitizerUnitTests)
+set_target_properties(SanitizerUnitTests PROPERTIES
+  FOLDER "Sanitizer unittests")
+add_unittest(SanitizerUnitTests SanitizerUnitTest ${SANITIZER_UNITTESTS})
+# Link with sanitizer runtime.
+target_link_libraries(SanitizerUnitTest RTSanitizerCommon.test)
+# Build unit tests with debug info.
+set_property(TARGET SanitizerUnitTest APPEND_STRING
+  PROPERTY COMPILE_FLAGS " -g -Werror")
+
+# Run unittests as a part of lit testsuite.
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  )
+
+add_lit_testsuite(check-sanitizer "Running sanitizer library unittests"
+  ${CMAKE_CURRENT_BINARY_DIR}
+  DEPENDS SanitizerUnitTests
+  )
+set_target_properties(check-sanitizer PROPERTIES FOLDER "Sanitizer unittests")

Added: compiler-rt/trunk/lib/sanitizer_common/tests/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/lit.cfg?rev=163610&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/lit.cfg (added)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/lit.cfg Tue Sep 11 05:50:32 2012
@@ -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 = 'SanitizerCommon-Unit'
+
+# Setup test source and exec root. For unit tests, we define
+# it as build directory with sanitizer_common 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",
+                                     "sanitizer_common", "tests")
+config.test_source_root = config.test_exec_root

Added: compiler-rt/trunk/lib/sanitizer_common/tests/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/lit.site.cfg.in?rev=163610&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/lit.site.cfg.in (added)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/lit.site.cfg.in Tue Sep 11 05:50:32 2012
@@ -0,0 +1,9 @@
+## Autogenerated by LLVM/Clang configuration.
+# Do not edit!
+
+config.build_type = "@CMAKE_BUILD_TYPE@"
+config.llvm_obj_root = "@LLVM_BINARY_DIR@"
+config.llvm_src_root = "@LLVM_SOURCE_DIR@"
+
+# Let the main config do the real work.
+lit.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")

Added: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc?rev=163610&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_main.cc Tue Sep 11 05:50:32 2012
@@ -0,0 +1,19 @@
+//===-- sanitizer_test_main.cc --------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of ThreadSanitizer/AddressSanitizer runtime.
+//
+//===----------------------------------------------------------------------===//
+#include "gtest/gtest.h"
+
+int main(int argc, char **argv) {
+  testing::GTEST_FLAG(death_test_style) = "threadsafe";
+  testing::InitGoogleTest(&argc, argv);
+  return RUN_ALL_TESTS();
+}





More information about the llvm-commits mailing list