2012-12-20 21:24:21 +08:00
|
|
|
include(CompilerRTCompile)
|
|
|
|
|
2014-09-11 01:23:58 +08:00
|
|
|
clang_compiler_add_cxx_check()
|
|
|
|
|
2014-12-12 15:08:12 +08:00
|
|
|
# FIXME: use SANITIZER_COMMON_SUPPORTED_ARCH here
|
|
|
|
filter_available_targets(SANITIZER_UNITTEST_SUPPORTED_ARCH x86_64 i386 mips64 mips64el)
|
2015-08-21 01:32:06 +08:00
|
|
|
if(APPLE)
|
|
|
|
darwin_filter_host_archs(SANITIZER_UNITTEST_SUPPORTED_ARCH SANITIZER_COMMON_SUPPORTED_ARCH)
|
|
|
|
endif()
|
2014-12-12 15:08:12 +08:00
|
|
|
|
2012-09-11 18:50:32 +08:00
|
|
|
set(SANITIZER_UNITTESTS
|
|
|
|
sanitizer_allocator_test.cc
|
2013-03-25 16:48:16 +08:00
|
|
|
sanitizer_atomic_test.cc
|
2014-02-12 15:05:24 +08:00
|
|
|
sanitizer_bitvector_test.cc
|
2014-02-12 19:28:09 +08:00
|
|
|
sanitizer_bvgraph_test.cc
|
2012-09-11 18:50:32 +08:00
|
|
|
sanitizer_common_test.cc
|
2014-02-13 15:44:51 +08:00
|
|
|
sanitizer_deadlock_detector_test.cc
|
2012-09-11 18:50:32 +08:00
|
|
|
sanitizer_flags_test.cc
|
2014-01-21 21:01:20 +08:00
|
|
|
sanitizer_format_interceptor_test.cc
|
2013-06-20 17:19:28 +08:00
|
|
|
sanitizer_ioctl_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
|
2013-05-28 20:37:34 +08:00
|
|
|
sanitizer_nolibc_test.cc
|
2013-10-11 22:19:14 +08:00
|
|
|
sanitizer_posix_test.cc
|
2012-11-02 20:36:11 +08:00
|
|
|
sanitizer_printf_test.cc
|
2013-12-25 16:39:38 +08:00
|
|
|
sanitizer_procmaps_test.cc
|
2017-01-20 06:15:54 +08:00
|
|
|
sanitizer_quarantine_test.cc
|
2012-09-11 18:50:32 +08:00
|
|
|
sanitizer_stackdepot_test.cc
|
2014-11-06 06:44:36 +08:00
|
|
|
sanitizer_stacktrace_printer_test.cc
|
2013-02-22 23:10:16 +08:00
|
|
|
sanitizer_stacktrace_test.cc
|
2013-03-15 22:37:21 +08:00
|
|
|
sanitizer_stoptheworld_test.cc
|
2013-06-26 23:37:14 +08:00
|
|
|
sanitizer_suppressions_test.cc
|
2015-03-03 06:15:14 +08:00
|
|
|
sanitizer_symbolizer_test.cc
|
2012-09-11 18:50:32 +08:00
|
|
|
sanitizer_test_main.cc
|
2013-09-16 23:43:23 +08:00
|
|
|
sanitizer_thread_registry_test.cc)
|
2012-09-11 18:50:32 +08:00
|
|
|
|
2013-09-16 23:43:23 +08:00
|
|
|
set(SANITIZER_TEST_HEADERS
|
2014-05-13 16:07:09 +08:00
|
|
|
sanitizer_pthread_wrappers.h
|
2014-05-13 21:25:12 +08:00
|
|
|
sanitizer_test_config.h
|
2013-09-16 23:43:23 +08:00
|
|
|
sanitizer_test_utils.h)
|
2012-12-21 22:04:52 +08:00
|
|
|
foreach(header ${SANITIZER_HEADERS})
|
|
|
|
list(APPEND SANITIZER_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../${header})
|
|
|
|
endforeach()
|
|
|
|
|
2013-03-15 18:39:26 +08:00
|
|
|
set(SANITIZER_TEST_CFLAGS_COMMON
|
2016-01-15 02:18:49 +08:00
|
|
|
${COMPILER_RT_UNITTEST_CFLAGS}
|
2014-03-24 21:29:20 +08:00
|
|
|
${COMPILER_RT_GTEST_CFLAGS}
|
2013-03-15 18:39:26 +08:00
|
|
|
-I${COMPILER_RT_SOURCE_DIR}/include
|
|
|
|
-I${COMPILER_RT_SOURCE_DIR}/lib
|
|
|
|
-I${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common
|
2014-05-28 16:38:13 +08:00
|
|
|
-fno-rtti
|
2014-05-13 21:29:11 +08:00
|
|
|
-O2
|
2014-03-24 17:42:12 +08:00
|
|
|
-Werror=sign-compare
|
|
|
|
-Wno-non-virtual-dtor)
|
2013-03-15 18:39:26 +08:00
|
|
|
|
2015-05-06 00:52:50 +08:00
|
|
|
if(MSVC)
|
|
|
|
# Disable exceptions on Windows until they work reliably.
|
|
|
|
list(APPEND SANITIZER_TEST_CFLAGS_COMMON -fno-exceptions -DGTEST_HAS_SEH=0)
|
|
|
|
endif()
|
|
|
|
|
2014-05-28 16:38:13 +08:00
|
|
|
# -gline-tables-only must be enough for these tests, so use it if possible.
|
|
|
|
if(COMPILER_RT_TEST_COMPILER_ID MATCHES "Clang")
|
2015-05-06 00:52:50 +08:00
|
|
|
list(APPEND SANITIZER_TEST_CFLAGS_COMMON -gline-tables-only)
|
2014-05-28 16:38:13 +08:00
|
|
|
else()
|
2015-05-06 00:52:50 +08:00
|
|
|
list(APPEND SANITIZER_TEST_CFLAGS_COMMON -g)
|
2014-05-28 16:38:13 +08:00
|
|
|
endif()
|
2016-06-30 03:58:02 +08:00
|
|
|
if(MSVC)
|
|
|
|
list(APPEND SANITIZER_TEST_CFLAGS_COMMON -gcodeview)
|
|
|
|
endif()
|
|
|
|
list(APPEND SANITIZER_TEST_LINK_FLAGS_COMMON -g)
|
2014-05-13 21:29:11 +08:00
|
|
|
|
2014-05-19 16:19:38 +08:00
|
|
|
if(NOT MSVC)
|
|
|
|
list(APPEND SANITIZER_TEST_LINK_FLAGS_COMMON --driver-mode=g++)
|
|
|
|
endif()
|
|
|
|
|
2015-06-27 04:39:30 +08:00
|
|
|
if(ANDROID)
|
|
|
|
list(APPEND SANITIZER_TEST_LINK_FLAGS_COMMON -pie)
|
|
|
|
endif()
|
|
|
|
|
2016-10-27 07:23:38 +08:00
|
|
|
if(APPLE)
|
|
|
|
list(APPEND SANITIZER_TEST_CFLAGS_COMMON ${DARWIN_osx_CFLAGS})
|
2017-01-10 12:33:04 +08:00
|
|
|
list(APPEND SANITIZER_TEST_LINK_FLAGS_COMMON ${DARWIN_osx_LINK_FLAGS})
|
2017-01-09 11:51:42 +08:00
|
|
|
|
2017-01-10 12:33:04 +08:00
|
|
|
add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
|
|
|
|
list(APPEND SANITIZER_TEST_LINK_FLAGS_COMMON ${WEAK_SYMBOL_LINK_FLAGS})
|
2016-10-27 07:23:38 +08:00
|
|
|
endif()
|
|
|
|
|
2016-07-08 02:41:08 +08:00
|
|
|
# MSVC linker is allocating 1M for the stack by default, which is not
|
|
|
|
# enough for the unittests. Some unittests require more than 2M.
|
|
|
|
# The default stack size for clang is 8M.
|
|
|
|
if(MSVC)
|
2016-07-13 04:10:28 +08:00
|
|
|
list(APPEND SANITIZER_TEST_LINK_FLAGS_COMMON -Wl,/STACK:0xC00000)
|
2016-07-08 02:41:08 +08:00
|
|
|
endif()
|
|
|
|
|
2014-09-29 21:18:55 +08:00
|
|
|
set(SANITIZER_TEST_LINK_LIBS)
|
2015-07-25 03:00:16 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_LIBLOG log SANITIZER_TEST_LINK_LIBS)
|
2014-09-29 21:18:55 +08:00
|
|
|
# NDK r10 requires -latomic almost always.
|
2014-10-16 06:47:54 +08:00
|
|
|
append_list_if(ANDROID atomic SANITIZER_TEST_LINK_LIBS)
|
2014-09-29 21:18:55 +08:00
|
|
|
|
2014-10-16 06:47:54 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_LIBDL -ldl SANITIZER_TEST_LINK_FLAGS_COMMON)
|
2015-05-30 06:31:28 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_LIBRT -lrt SANITIZER_TEST_LINK_FLAGS_COMMON)
|
2014-10-16 06:47:54 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread SANITIZER_TEST_LINK_FLAGS_COMMON)
|
2014-05-29 19:35:05 +08:00
|
|
|
# x86_64 FreeBSD 9.2 additionally requires libc++ to build the tests. Also,
|
|
|
|
# 'libm' shall be specified explicitly to build i386 tests.
|
2014-04-28 18:33:01 +08:00
|
|
|
if(CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE")
|
2014-05-29 19:35:05 +08:00
|
|
|
list(APPEND SANITIZER_TEST_LINK_FLAGS_COMMON "-lc++ -lm")
|
2014-04-28 18:33:01 +08:00
|
|
|
endif()
|
2013-03-15 18:39:26 +08:00
|
|
|
|
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
|
2016-07-12 05:51:56 +08:00
|
|
|
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
FOLDER "Compiler-RT Runtime tests")
|
2012-12-20 22:38:02 +08:00
|
|
|
endmacro()
|
|
|
|
|
2017-08-16 06:56:10 +08:00
|
|
|
function(get_sanitizer_common_lib_for_arch arch lib)
|
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)
|
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)
|
2016-07-12 05:51:56 +08:00
|
|
|
set_target_properties(SanitizerUnitTests PROPERTIES FOLDER "Compiler-RT Tests")
|
2012-12-20 21:24:21 +08:00
|
|
|
|
|
|
|
# Adds sanitizer tests for architecture.
|
|
|
|
macro(add_sanitizer_tests_for_arch arch)
|
2017-08-16 06:56:10 +08:00
|
|
|
set(extra_flags)
|
2017-05-18 21:19:35 +08:00
|
|
|
if( CMAKE_SIZEOF_VOID_P EQUAL 4 )
|
2017-08-16 06:56:10 +08:00
|
|
|
list(APPEND extra_flags "-D_LARGEFILE_SOURCE")
|
|
|
|
list(APPEND extra_flags "-D_FILE_OFFSET_BITS=64")
|
2017-05-18 21:19:35 +08:00
|
|
|
endif()
|
2017-08-16 06:56:10 +08:00
|
|
|
get_sanitizer_common_lib_for_arch(${arch} SANITIZER_COMMON_LIB)
|
2017-05-18 21:19:35 +08:00
|
|
|
|
2012-12-20 21:24:21 +08:00
|
|
|
set(SANITIZER_TEST_OBJECTS)
|
2017-08-16 06:56:10 +08:00
|
|
|
generate_compiler_rt_tests(SANITIZER_TEST_OBJECTS SanitizerUnitTests
|
|
|
|
"Sanitizer-${arch}-Test" ${arch}
|
|
|
|
RUNTIME "${SANITIZER_COMMON_LIB}"
|
|
|
|
SOURCES ${SANITIZER_UNITTESTS} ${COMPILER_RT_GTEST_SOURCE}
|
|
|
|
COMPILE_DEPS ${SANITIZER_TEST_HEADERS}
|
|
|
|
DEPS gtest
|
|
|
|
CFLAGS ${SANITIZER_TEST_CFLAGS_COMMON} ${extra_flags}
|
|
|
|
LINK_FLAGS ${SANITIZER_TEST_LINK_FLAGS_COMMON} ${extra_flags})
|
2013-05-28 20:37:34 +08:00
|
|
|
|
|
|
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND "${arch}" STREQUAL "x86_64")
|
|
|
|
# Test that the libc-independent part of sanitizer_common is indeed
|
|
|
|
# independent of libc, by linking this binary without libc (here) and
|
|
|
|
# executing it (unit test in sanitizer_nolibc_test.cc).
|
|
|
|
clang_compile(sanitizer_nolibc_test_main.${arch}.o
|
|
|
|
sanitizer_nolibc_test_main.cc
|
|
|
|
CFLAGS ${SANITIZER_TEST_CFLAGS_COMMON} ${TARGET_FLAGS}
|
2014-02-20 20:03:56 +08:00
|
|
|
DEPS ${SANITIZER_TEST_COMPILE_DEPS})
|
2017-08-16 06:56:10 +08:00
|
|
|
add_compiler_rt_test(SanitizerUnitTests "Sanitizer-${arch}-Test-Nolibc" ${arch}
|
2013-05-28 20:37:34 +08:00
|
|
|
OBJECTS sanitizer_nolibc_test_main.${arch}.o
|
|
|
|
-Wl,-whole-archive
|
|
|
|
libRTSanitizerCommon.test.nolibc.${arch}.a
|
|
|
|
-Wl,-no-whole-archive
|
|
|
|
DEPS sanitizer_nolibc_test_main.${arch}.o
|
|
|
|
RTSanitizerCommon.test.nolibc.${arch}
|
|
|
|
LINK_FLAGS -nostdlib ${TARGET_FLAGS})
|
|
|
|
endif()
|
2012-12-20 21:24:21 +08:00
|
|
|
endmacro()
|
|
|
|
|
2014-08-09 08:23:11 +08:00
|
|
|
if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
|
2012-12-27 21:19:23 +08:00
|
|
|
# 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"
|
2015-08-28 06:23:27 +08:00
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.osx>
|
2017-01-12 09:37:35 +08:00
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommonLibc.osx>)
|
2012-12-20 22:38:02 +08:00
|
|
|
else()
|
2013-01-18 20:45:44 +08:00
|
|
|
if(CAN_TARGET_x86_64)
|
2013-05-28 20:37:34 +08:00
|
|
|
add_sanitizer_common_lib("RTSanitizerCommon.test.nolibc.x86_64"
|
2015-07-24 06:05:20 +08:00
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.x86_64>
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommonNoLibc.x86_64>)
|
2012-12-20 22:38:02 +08:00
|
|
|
endif()
|
2014-12-12 15:08:12 +08:00
|
|
|
foreach(arch ${SANITIZER_UNITTEST_SUPPORTED_ARCH})
|
|
|
|
add_sanitizer_common_lib("RTSanitizerCommon.test.${arch}"
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
|
2017-01-12 09:37:35 +08:00
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>)
|
2014-12-12 15:08:12 +08:00
|
|
|
endforeach()
|
2012-12-20 21:24:21 +08:00
|
|
|
endif()
|
2014-12-12 15:08:12 +08:00
|
|
|
foreach(arch ${SANITIZER_UNITTEST_SUPPORTED_ARCH})
|
|
|
|
add_sanitizer_tests_for_arch(${arch})
|
|
|
|
endforeach()
|
2012-12-27 21:19:23 +08:00
|
|
|
endif()
|
2013-01-14 22:08:25 +08:00
|
|
|
|
|
|
|
if(ANDROID)
|
2014-09-29 21:18:55 +08:00
|
|
|
foreach(arch ${SANITIZER_COMMON_SUPPORTED_ARCH})
|
|
|
|
add_executable(SanitizerTest
|
|
|
|
${SANITIZER_UNITTESTS}
|
|
|
|
${COMPILER_RT_GTEST_SOURCE}
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
|
2017-01-12 09:37:35 +08:00
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>)
|
2014-09-29 21:18:55 +08:00
|
|
|
set_target_compile_flags(SanitizerTest
|
|
|
|
${SANITIZER_COMMON_CFLAGS}
|
|
|
|
${SANITIZER_TEST_CFLAGS_COMMON})
|
|
|
|
# Setup correct output directory and link flags.
|
|
|
|
set_target_properties(SanitizerTest PROPERTIES
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
set_target_link_flags(SanitizerTest ${SANITIZER_TEST_LINK_FLAGS_COMMON})
|
|
|
|
target_link_libraries(SanitizerTest ${SANITIZER_TEST_LINK_LIBS})
|
|
|
|
# Add unit test to test suite.
|
|
|
|
add_dependencies(SanitizerUnitTests SanitizerTest)
|
|
|
|
endforeach()
|
2013-01-14 22:08:25 +08:00
|
|
|
endif()
|