2012-12-20 21:24:21 +08:00
|
|
|
include(CompilerRTCompile)
|
|
|
|
|
2012-09-11 18:50:32 +08:00
|
|
|
set(SANITIZER_UNITTESTS
|
|
|
|
sanitizer_allocator_test.cc
|
|
|
|
sanitizer_common_test.cc
|
|
|
|
sanitizer_flags_test.cc
|
2012-10-26 21:24:20 +08:00
|
|
|
sanitizer_libc_test.cc
|
2013-02-27 19:22:40 +08:00
|
|
|
sanitizer_linux_test.cc
|
2012-09-11 18:50:32 +08:00
|
|
|
sanitizer_list_test.cc
|
2013-01-14 15:51:39 +08:00
|
|
|
sanitizer_mutex_test.cc
|
2012-11-02 20:36:11 +08:00
|
|
|
sanitizer_printf_test.cc
|
2013-01-18 19:17:23 +08:00
|
|
|
sanitizer_scanf_interceptor_test.cc
|
2012-09-11 18:50:32 +08:00
|
|
|
sanitizer_stackdepot_test.cc
|
2013-02-22 23:10:16 +08:00
|
|
|
sanitizer_stacktrace_test.cc
|
2012-09-11 18:50:32 +08:00
|
|
|
sanitizer_test_main.cc
|
2013-03-14 21:54:30 +08:00
|
|
|
sanitizer_thread_registry_test.cc
|
2012-09-11 18:50:32 +08:00
|
|
|
)
|
|
|
|
|
2012-12-21 22:04:52 +08:00
|
|
|
set(SANITIZER_TEST_HEADERS)
|
|
|
|
foreach(header ${SANITIZER_HEADERS})
|
|
|
|
list(APPEND SANITIZER_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../${header})
|
|
|
|
endforeach()
|
|
|
|
|
2012-09-11 18:50:32 +08:00
|
|
|
include_directories(..)
|
|
|
|
include_directories(../..)
|
|
|
|
|
2012-12-20 22:38:02 +08:00
|
|
|
# Adds static library which contains sanitizer_common object file
|
|
|
|
# (universal binary on Mac and arch-specific object files on Linux).
|
|
|
|
macro(add_sanitizer_common_lib library)
|
|
|
|
add_library(${library} STATIC ${ARGN})
|
|
|
|
set_target_properties(${library} PROPERTIES
|
|
|
|
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
endmacro()
|
|
|
|
|
2012-12-21 16:56:14 +08:00
|
|
|
function(get_sanitizer_common_lib_for_arch arch lib lib_name)
|
2012-12-20 22:38:02 +08:00
|
|
|
if(APPLE)
|
2012-12-21 16:56:14 +08:00
|
|
|
set(tgt_name "RTSanitizerCommon.test.osx")
|
2012-12-20 22:38:02 +08:00
|
|
|
else()
|
2012-12-21 16:56:14 +08:00
|
|
|
set(tgt_name "RTSanitizerCommon.test.${arch}")
|
2012-12-20 22:38:02 +08:00
|
|
|
endif()
|
2012-12-21 16:56:14 +08:00
|
|
|
set(${lib} "${tgt_name}" PARENT_SCOPE)
|
|
|
|
set(${lib_name} "lib${tgt_name}.a" PARENT_SCOPE)
|
2012-12-20 22:38:02 +08:00
|
|
|
endfunction()
|
|
|
|
|
2012-12-20 21:24:21 +08:00
|
|
|
# Sanitizer_common unit tests testsuite.
|
2012-09-11 18:50:32 +08:00
|
|
|
add_custom_target(SanitizerUnitTests)
|
|
|
|
set_target_properties(SanitizerUnitTests PROPERTIES
|
|
|
|
FOLDER "Sanitizer unittests")
|
2012-12-20 21:24:21 +08:00
|
|
|
|
|
|
|
# Adds sanitizer tests for architecture.
|
|
|
|
macro(add_sanitizer_tests_for_arch arch)
|
|
|
|
get_target_flags_for_arch(${arch} TARGET_FLAGS)
|
|
|
|
set(SANITIZER_TEST_SOURCES ${SANITIZER_UNITTESTS}
|
|
|
|
${COMPILER_RT_GTEST_SOURCE})
|
|
|
|
set(SANITIZER_TEST_CFLAGS ${COMPILER_RT_GTEST_INCLUDE_CFLAGS}
|
|
|
|
-I${COMPILER_RT_SOURCE_DIR}/include
|
|
|
|
-I${COMPILER_RT_SOURCE_DIR}/lib
|
|
|
|
-I${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common
|
2013-03-15 15:08:52 +08:00
|
|
|
-DGTEST_HAS_RTTI=0
|
|
|
|
-O2 -g -fno-rtti
|
|
|
|
-Wall -Werror -Werror=sign-compare ${TARGET_FLAGS})
|
2013-03-13 16:19:53 +08:00
|
|
|
set(SANITIZER_TEST_LINK_FLAGS -lstdc++ -lpthread -ldl ${TARGET_FLAGS})
|
2012-12-20 21:24:21 +08:00
|
|
|
set(SANITIZER_TEST_OBJECTS)
|
|
|
|
foreach(source ${SANITIZER_TEST_SOURCES})
|
|
|
|
get_filename_component(basename ${source} NAME)
|
|
|
|
set(output_obj "${basename}.${arch}.o")
|
|
|
|
clang_compile(${output_obj} ${source}
|
|
|
|
CFLAGS ${SANITIZER_TEST_CFLAGS}
|
2012-12-21 22:04:52 +08:00
|
|
|
DEPS gtest ${SANITIZER_RUNTIME_LIBRARIES}
|
|
|
|
${SANITIZER_TEST_HEADERS})
|
2012-12-20 21:24:21 +08:00
|
|
|
list(APPEND SANITIZER_TEST_OBJECTS ${output_obj})
|
|
|
|
endforeach()
|
2012-12-21 16:56:14 +08:00
|
|
|
get_sanitizer_common_lib_for_arch(${arch} SANITIZER_COMMON_LIB
|
|
|
|
SANITIZER_COMMON_LIB_NAME)
|
2012-12-20 21:24:21 +08:00
|
|
|
# Add unittest target.
|
|
|
|
set(SANITIZER_TEST_NAME "Sanitizer-${arch}-Test")
|
|
|
|
add_compiler_rt_test(SanitizerUnitTests ${SANITIZER_TEST_NAME}
|
|
|
|
OBJECTS ${SANITIZER_TEST_OBJECTS}
|
|
|
|
${SANITIZER_COMMON_LIB_NAME}
|
2012-12-21 16:56:14 +08:00
|
|
|
DEPS ${SANITIZER_TEST_OBJECTS} ${SANITIZER_COMMON_LIB}
|
2012-12-20 21:24:21 +08:00
|
|
|
LINK_FLAGS ${SANITIZER_TEST_LINK_FLAGS})
|
|
|
|
endmacro()
|
|
|
|
|
2012-12-27 21:19:23 +08:00
|
|
|
if(COMPILER_RT_CAN_EXECUTE_TESTS)
|
|
|
|
# We use just-built clang to build sanitizer_common unittests, so we must
|
|
|
|
# be sure that produced binaries would work.
|
2012-12-20 22:38:02 +08:00
|
|
|
if(APPLE)
|
|
|
|
add_sanitizer_common_lib("RTSanitizerCommon.test.osx"
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.osx>)
|
|
|
|
else()
|
2013-01-18 20:45:44 +08:00
|
|
|
if(CAN_TARGET_x86_64)
|
2012-12-20 22:38:02 +08:00
|
|
|
add_sanitizer_common_lib("RTSanitizerCommon.test.x86_64"
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.x86_64>)
|
|
|
|
endif()
|
2013-01-18 20:45:44 +08:00
|
|
|
if(CAN_TARGET_i386)
|
2012-12-20 22:38:02 +08:00
|
|
|
add_sanitizer_common_lib("RTSanitizerCommon.test.i386"
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.i386>)
|
|
|
|
endif()
|
|
|
|
endif()
|
2013-01-18 20:45:44 +08:00
|
|
|
if(CAN_TARGET_x86_64)
|
2012-12-20 21:24:21 +08:00
|
|
|
add_sanitizer_tests_for_arch(x86_64)
|
|
|
|
endif()
|
2013-01-18 20:45:44 +08:00
|
|
|
if(CAN_TARGET_i386)
|
2012-12-20 21:24:21 +08:00
|
|
|
add_sanitizer_tests_for_arch(i386)
|
|
|
|
endif()
|
2012-09-11 18:50:32 +08:00
|
|
|
|
2012-12-27 21:19:23 +08:00
|
|
|
# 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
|
|
|
|
)
|
2012-09-11 18:50:32 +08:00
|
|
|
|
2012-12-27 21:19:23 +08:00
|
|
|
add_lit_testsuite(check-sanitizer "Running sanitizer library unittests"
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
DEPENDS SanitizerUnitTests
|
|
|
|
)
|
|
|
|
set_target_properties(check-sanitizer PROPERTIES FOLDER "Sanitizer unittests")
|
|
|
|
endif()
|
2013-01-14 22:08:25 +08:00
|
|
|
|
|
|
|
if(ANDROID)
|
|
|
|
# We assume that unit tests on Android are built in a build
|
|
|
|
# tree with fresh Clang as a host compiler.
|
|
|
|
add_executable(SanitizerTest
|
|
|
|
${SANITIZER_UNITTESTS}
|
|
|
|
${COMPILER_RT_GTEST_SOURCE}
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.arm.android>
|
|
|
|
)
|
|
|
|
set_target_compile_flags(SanitizerTest
|
|
|
|
${SANITIZER_COMMON_CFLAGS}
|
|
|
|
${COMPILER_RT_GTEST_INCLUDE_CFLAGS}
|
|
|
|
-I${COMPILER_RT_SOURCE_DIR}/include
|
|
|
|
-I${COMPILER_RT_SOURCE_DIR}/lib
|
|
|
|
-I${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common
|
|
|
|
-O2 -g
|
|
|
|
)
|
|
|
|
# Setup correct output directory and link flags.
|
2013-01-14 22:52:35 +08:00
|
|
|
set_target_properties(SanitizerTest PROPERTIES
|
2013-01-28 15:16:22 +08:00
|
|
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
2013-01-14 22:08:25 +08:00
|
|
|
set_target_link_flags(SanitizerTest ${SANITIZER_TEST_LINK_FLAGS})
|
|
|
|
# Add unit test to test suite.
|
|
|
|
add_dependencies(SanitizerUnitTests SanitizerTest)
|
|
|
|
endif()
|