[Sanitizer] Add new lit testsuite: check-sanitizer that runs unit tests for sanitizer_common runtime (shared between ASan and TSan)

llvm-svn: 163610
This commit is contained in:
Alexey Samsonov 2012-09-11 10:50:32 +00:00
parent 482942ed08
commit 894069796e
5 changed files with 104 additions and 5 deletions

View File

@ -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()

View File

@ -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")

View File

@ -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

View File

@ -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")

View File

@ -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();
}