summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-09-11 10:50:32 +0000
committerAlexey Samsonov <samsonov@google.com>2012-09-11 10:50:32 +0000
commit3f3ca96358ed02ef13c5cfd5d6bc4d33dd861c2a (patch)
tree18e338fc48e814c5d4ca0f3c25091027ac32f83f /lib
parentd7ed1f09f316628b2d981a1d8c2cf0f5af30e90e (diff)
[Sanitizer] Add new lit testsuite: check-sanitizer that runs unit tests for sanitizer_common runtime (shared between ASan and TSan)
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@163610 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/sanitizer_common/CMakeLists.txt17
-rw-r--r--lib/sanitizer_common/tests/CMakeLists.txt35
-rw-r--r--lib/sanitizer_common/tests/lit.cfg29
-rw-r--r--lib/sanitizer_common/tests/lit.site.cfg.in9
-rw-r--r--lib/sanitizer_common/tests/sanitizer_test_main.cc19
5 files changed, 104 insertions, 5 deletions
diff --git a/lib/sanitizer_common/CMakeLists.txt b/lib/sanitizer_common/CMakeLists.txt
index 9d798821f..c43e747fc 100644
--- a/lib/sanitizer_common/CMakeLists.txt
+++ b/lib/sanitizer_common/CMakeLists.txt
@@ -10,6 +10,7 @@ set(SANITIZER_SOURCES
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_SOURCES
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 @@ else()
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()
diff --git a/lib/sanitizer_common/tests/CMakeLists.txt b/lib/sanitizer_common/tests/CMakeLists.txt
new file mode 100644
index 000000000..83837014d
--- /dev/null
+++ b/lib/sanitizer_common/tests/CMakeLists.txt
@@ -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")
diff --git a/lib/sanitizer_common/tests/lit.cfg b/lib/sanitizer_common/tests/lit.cfg
new file mode 100644
index 000000000..d77475398
--- /dev/null
+++ b/lib/sanitizer_common/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 = '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
diff --git a/lib/sanitizer_common/tests/lit.site.cfg.in b/lib/sanitizer_common/tests/lit.site.cfg.in
new file mode 100644
index 000000000..bb9a28d6a
--- /dev/null
+++ b/lib/sanitizer_common/tests/lit.site.cfg.in
@@ -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")
diff --git a/lib/sanitizer_common/tests/sanitizer_test_main.cc b/lib/sanitizer_common/tests/sanitizer_test_main.cc
new file mode 100644
index 000000000..12d1d15af
--- /dev/null
+++ b/lib/sanitizer_common/tests/sanitizer_test_main.cc
@@ -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();
+}