forked from OSchip/llvm-project
[sanitizers CMake] NFC Refactor the logic for compiling and generating tests
into a function. Most CMake configuration under compiler-rt/lib/*/tests have almost-the-same-but-not-quite functions of the form add_X_[unit]tests for compiling and running the tests. Much of the logic is duplicated with minor variations across different sub-folders. This can harm productivity for multiple reasons: For newcomers, resulting CMake files are very large, hard to understand, and hide the intention of the code. Changes for enabling certain architectures end up being unnecessarily large, as they get duplicated across multiple folders. Adding new sub-projects requires more effort than it should, as a developer has to again copy-n-paste the configuration, and it's not even clear from which sub-project it should be copy-n-pasted. With this change the logic of compile-and-generate-a-set-of-tests is extracted into a function, which hopefully makes writing and reading CMake much easier. Differential Revision: https://reviews.llvm.org/D36116 llvm-svn: 310971
This commit is contained in:
parent
0a1a276d91
commit
769124dc5e
|
@ -287,15 +287,57 @@ if(MSVC)
|
|||
list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations)
|
||||
endif()
|
||||
|
||||
# Compile and register compiler-rt tests.
|
||||
# generate_compiler_rt_tests(<output object files> <test_suite> <test_name>
|
||||
# <test architecture>
|
||||
# KIND <custom prefix>
|
||||
# SUBDIR <subdirectory for testing binary>
|
||||
# SOURCES <sources to compile>
|
||||
# RUNTIME <tests runtime to link in>
|
||||
# CFLAGS <compile-time flags>
|
||||
# COMPILE_DEPS <compile-time dependencies>
|
||||
# DEPS <dependencies>
|
||||
# LINK_FLAGS <flags to use during linking>
|
||||
# )
|
||||
function(generate_compiler_rt_tests test_objects test_suite testname arch)
|
||||
cmake_parse_arguments(TEST "" "KIND;RUNTIME;SUBDIR"
|
||||
"SOURCES;COMPILE_DEPS;DEPS;CFLAGS;LINK_FLAGS" ${ARGN})
|
||||
|
||||
foreach(source ${TEST_SOURCES})
|
||||
sanitizer_test_compile(
|
||||
"${test_objects}" "${source}" "${arch}"
|
||||
KIND ${TEST_KIND}
|
||||
COMPILE_DEPS ${TEST_COMPILE_DEPS}
|
||||
DEPS ${TEST_DEPS}
|
||||
CFLAGS ${TEST_CFLAGS}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
set(TEST_DEPS ${${test_objects}})
|
||||
|
||||
if(NOT "${TEST_RUNTIME}" STREQUAL "")
|
||||
list(APPEND TEST_DEPS ${TEST_RUNTIME})
|
||||
list(APPEND "${test_objects}" $<TARGET_FILE:${TEST_RUNTIME}>)
|
||||
endif()
|
||||
|
||||
add_compiler_rt_test(${test_suite} "${testname}" "${arch}"
|
||||
SUBDIR ${TEST_SUBDIR}
|
||||
OBJECTS ${${test_objects}}
|
||||
DEPS ${TEST_DEPS}
|
||||
LINK_FLAGS ${TARGET_LINK_FLAGS}
|
||||
)
|
||||
set("${test_objects}" "${${test_objects}}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Link objects into a single executable with COMPILER_RT_TEST_COMPILER,
|
||||
# using specified link flags. Make executable a part of provided
|
||||
# test_suite.
|
||||
# add_compiler_rt_test(<test_suite> <test_name>
|
||||
# add_compiler_rt_test(<test_suite> <test_name> <arch>
|
||||
# SUBDIR <subdirectory for binary>
|
||||
# OBJECTS <object files>
|
||||
# DEPS <deps (e.g. runtime libs)>
|
||||
# LINK_FLAGS <link flags>)
|
||||
function(add_compiler_rt_test test_suite test_name)
|
||||
function(add_compiler_rt_test test_suite test_name arch)
|
||||
cmake_parse_arguments(TEST "" "SUBDIR" "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
|
||||
set(output_dir ${CMAKE_CURRENT_BINARY_DIR})
|
||||
if(TEST_SUBDIR)
|
||||
|
@ -312,6 +354,10 @@ function(add_compiler_rt_test test_suite test_name)
|
|||
if(NOT COMPILER_RT_STANDALONE_BUILD)
|
||||
list(APPEND TEST_DEPS clang)
|
||||
endif()
|
||||
|
||||
get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
|
||||
list(APPEND TEST_LINK_FLAGS ${TARGET_LINK_FLAGS})
|
||||
|
||||
# If we're not on MSVC, include the linker flags from CMAKE but override them
|
||||
# with the provided link flags. This ensures that flags which are required to
|
||||
# link programs at all are included, but the changes needed for the test
|
||||
|
|
|
@ -125,37 +125,6 @@ append_list_if(COMPILER_RT_HAS_LIBLOG log ASAN_UNITTEST_NOINST_LIBS)
|
|||
# NDK r10 requires -latomic almost always.
|
||||
append_list_if(ANDROID atomic ASAN_UNITTEST_NOINST_LIBS)
|
||||
|
||||
macro(asan_compile obj_list source arch kind)
|
||||
cmake_parse_arguments(ASAN_TEST "" "" "CFLAGS" ${ARGN})
|
||||
sanitizer_test_compile(${obj_list} ${source} ${arch}
|
||||
KIND ${kind}
|
||||
COMPILE_DEPS ${ASAN_UNITTEST_HEADERS} ${ASAN_BLACKLIST_FILE}
|
||||
DEPS gtest asan
|
||||
CFLAGS ${ASAN_TEST_CFLAGS}
|
||||
)
|
||||
endmacro()
|
||||
|
||||
# Link ASan unit test for a given architecture from a set
|
||||
# of objects in with given linker flags.
|
||||
macro(add_asan_test test_suite test_name arch kind)
|
||||
cmake_parse_arguments(TEST "WITH_TEST_RUNTIME" "" "OBJECTS;LINK_FLAGS;SUBDIR" ${ARGN})
|
||||
get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
|
||||
set(TEST_DEPS ${TEST_OBJECTS})
|
||||
if(NOT COMPILER_RT_STANDALONE_BUILD)
|
||||
list(APPEND TEST_DEPS asan)
|
||||
endif()
|
||||
if(TEST_WITH_TEST_RUNTIME)
|
||||
list(APPEND TEST_DEPS ${ASAN_TEST_RUNTIME})
|
||||
list(APPEND TEST_OBJECTS $<TARGET_FILE:${ASAN_TEST_RUNTIME}>)
|
||||
endif()
|
||||
add_compiler_rt_test(${test_suite} ${test_name}
|
||||
SUBDIR ${TEST_SUBDIR}
|
||||
OBJECTS ${TEST_OBJECTS}
|
||||
DEPS ${TEST_DEPS}
|
||||
LINK_FLAGS ${TEST_LINK_FLAGS}
|
||||
${TARGET_LINK_FLAGS})
|
||||
endmacro()
|
||||
|
||||
# Main AddressSanitizer unit tests.
|
||||
add_custom_target(AsanUnitTests)
|
||||
set_target_properties(AsanUnitTests PROPERTIES FOLDER "Compiler-RT Tests")
|
||||
|
@ -193,102 +162,111 @@ set(ASAN_BENCHMARKS_SOURCES
|
|||
${COMPILER_RT_GTEST_SOURCE}
|
||||
asan_benchmarks_test.cc)
|
||||
|
||||
# Adds ASan unit tests and benchmarks for architecture.
|
||||
macro(add_asan_tests_for_arch_and_kind arch kind cflags)
|
||||
# Instrumented tests.
|
||||
function(add_asan_tests arch test_runtime)
|
||||
cmake_parse_arguments(TEST "" "KIND" "CFLAGS" ${ARGN})
|
||||
|
||||
# Closure to keep the values.
|
||||
function(generate_asan_tests test_objects test_suite testname)
|
||||
generate_compiler_rt_tests(${test_objects} ${test_suite} ${testname} ${arch}
|
||||
COMPILE_DEPS ${ASAN_UNITTEST_HEADERS} ${ASAN_BLACKLIST_FILE}
|
||||
DEPS gtest asan
|
||||
KIND ${TEST_KIND}
|
||||
${ARGN}
|
||||
)
|
||||
set("${test_objects}" "${${test_objects}}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
set(ASAN_INST_TEST_OBJECTS)
|
||||
foreach(src ${ASAN_INST_TEST_SOURCES})
|
||||
asan_compile(ASAN_INST_TEST_OBJECTS ${src} ${arch} ${kind}
|
||||
CFLAGS ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} ${cflags})
|
||||
endforeach()
|
||||
generate_asan_tests(ASAN_INST_TEST_OBJECTS AsanUnitTests
|
||||
"Asan-${arch}${TEST_KIND}-Test"
|
||||
SUBDIR "default"
|
||||
LINK_FLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINK_FLAGS}
|
||||
SOURCES ${ASAN_INST_TEST_SOURCES}
|
||||
CFLAGS ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} ${TEST_CFLAGS})
|
||||
|
||||
if (MSVC)
|
||||
# With the MSVC CRT, the choice between static and dynamic CRT is made at
|
||||
# compile time with a macro. Simulate the effect of passing /MD to clang-cl.
|
||||
set(ASAN_INST_DYNAMIC_TEST_OBJECTS)
|
||||
foreach(src ${ASAN_INST_TEST_SOURCES})
|
||||
asan_compile(ASAN_INST_DYNAMIC_TEST_OBJECTS ${src} ${arch} ${kind}
|
||||
CFLAGS ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} -D_MT -D_DLL ${cflags})
|
||||
endforeach()
|
||||
# Clang links the static CRT by default. Override that to use the dynamic
|
||||
# CRT.
|
||||
set(ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINK_FLAGS
|
||||
${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINK_FLAGS}
|
||||
-Wl,-nodefaultlib:libcmt,-defaultlib:msvcrt,-defaultlib:oldnames)
|
||||
else()
|
||||
set(ASAN_INST_DYNAMIC_TEST_OBJECTS ${ASAN_INST_TEST_OBJECTS})
|
||||
endif()
|
||||
|
||||
add_asan_test(AsanUnitTests "Asan-${arch}${kind}-Test"
|
||||
${arch} ${kind} SUBDIR "default"
|
||||
OBJECTS ${ASAN_INST_TEST_OBJECTS}
|
||||
LINK_FLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINK_FLAGS})
|
||||
if(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME)
|
||||
set(dynamic_test_name "Asan-${arch}${TEST_KIND}-Dynamic-Test")
|
||||
if(MSVC)
|
||||
|
||||
add_asan_test(AsanDynamicUnitTests "Asan-${arch}${kind}-Dynamic-Test"
|
||||
${arch} ${kind} SUBDIR "dynamic"
|
||||
OBJECTS ${ASAN_INST_DYNAMIC_TEST_OBJECTS}
|
||||
LINK_FLAGS ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINK_FLAGS})
|
||||
# With the MSVC CRT, the choice between static and dynamic CRT is made at
|
||||
# compile time with a macro. Simulate the effect of passing /MD to clang-cl.
|
||||
set(ASAN_DYNAMIC_TEST_OBJECTS)
|
||||
generate_asan_tests(ASAN_DYNAMIC_TEST_OBJECTS
|
||||
AsanDynamicUnitTests "${dynamic_test_name}"
|
||||
SUBDIR "dynamic"
|
||||
CFLAGS ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} -D_MT -D_DLL
|
||||
SOURCES ${ASAN_INST_TEST_SOURCES}
|
||||
LINK_FLAGS ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINK_FLAGS}
|
||||
-Wl,-nodefaultlib:libcmt,-defaultlib:msvcrt,-defaultlib:oldnames
|
||||
)
|
||||
else()
|
||||
|
||||
# Otherwise, reuse ASAN_INST_TEST_OBJECTS.
|
||||
add_compiler_rt_test(AsanDynamicUnitTests "${dynamic_test_name}" "${arch}"
|
||||
SUBDIR "dynamic"
|
||||
OBJECTS ${ASAN_INST_TEST_OBJECTS}
|
||||
DEPS gtest asan ${ASAN_INST_TEST_OBJECTS}
|
||||
LINK_FLAGS ${ASAN_DYNAMIC_UNITTEST_INSTRUMENTED_LINK_FLAGS}
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Add static ASan runtime that will be linked with uninstrumented tests.
|
||||
set(ASAN_TEST_RUNTIME RTAsanTest.${arch}${kind})
|
||||
if(APPLE)
|
||||
set(ASAN_TEST_RUNTIME_OBJECTS
|
||||
$<TARGET_OBJECTS:RTAsan_dynamic.osx>
|
||||
$<TARGET_OBJECTS:RTInterception.osx>
|
||||
$<TARGET_OBJECTS:RTSanitizerCommon.osx>
|
||||
$<TARGET_OBJECTS:RTSanitizerCommonLibc.osx>
|
||||
$<TARGET_OBJECTS:RTLSanCommon.osx>
|
||||
$<TARGET_OBJECTS:RTUbsan.osx>)
|
||||
else()
|
||||
set(ASAN_TEST_RUNTIME_OBJECTS
|
||||
$<TARGET_OBJECTS:RTAsan.${arch}>
|
||||
$<TARGET_OBJECTS:RTAsan_cxx.${arch}>
|
||||
$<TARGET_OBJECTS:RTInterception.${arch}>
|
||||
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
|
||||
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
|
||||
$<TARGET_OBJECTS:RTLSanCommon.${arch}>
|
||||
$<TARGET_OBJECTS:RTUbsan.${arch}>
|
||||
$<TARGET_OBJECTS:RTUbsan_cxx.${arch}>)
|
||||
endif()
|
||||
add_library(${ASAN_TEST_RUNTIME} STATIC ${ASAN_TEST_RUNTIME_OBJECTS})
|
||||
set_target_properties(${ASAN_TEST_RUNTIME} PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
FOLDER "Compiler-RT Runtime tests")
|
||||
# Uninstrumented tests.
|
||||
set(ASAN_NOINST_TEST_OBJECTS)
|
||||
foreach(src ${ASAN_NOINST_TEST_SOURCES})
|
||||
asan_compile(ASAN_NOINST_TEST_OBJECTS ${src} ${arch} ${kind}
|
||||
CFLAGS ${ASAN_UNITTEST_COMMON_CFLAGS} ${cflags})
|
||||
endforeach()
|
||||
add_asan_test(AsanUnitTests "Asan-${arch}${kind}-Noinst-Test"
|
||||
${arch} ${kind} SUBDIR "default"
|
||||
OBJECTS ${ASAN_NOINST_TEST_OBJECTS}
|
||||
LINK_FLAGS ${ASAN_UNITTEST_NOINST_LINK_FLAGS}
|
||||
WITH_TEST_RUNTIME)
|
||||
generate_asan_tests(ASAN_NOINST_TEST_OBJECTS
|
||||
AsanUnitTests "Asan-${arch}${TEST_KIND}-Noinst-Test"
|
||||
SUBDIR "default"
|
||||
CFLAGS ${ASAN_UNITTEST_COMMON_CFLAGS}
|
||||
LINK_FLAGS ${ASAN_UNITTEST_NOINST_LINK_FLAGS}
|
||||
SOURCES ${ASAN_NOINST_TEST_SOURCES}
|
||||
RUNTIME ${test_runtime})
|
||||
|
||||
# Benchmarks.
|
||||
set(ASAN_BENCHMARKS_OBJECTS)
|
||||
foreach(src ${ASAN_BENCHMARKS_SOURCES})
|
||||
asan_compile(ASAN_BENCHMARKS_OBJECTS ${src} ${arch} ${kind}
|
||||
CFLAGS ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS} ${cflags})
|
||||
endforeach()
|
||||
add_asan_test(AsanBenchmarks "Asan-${arch}${kind}-Benchmark"
|
||||
${arch} ${kind} SUBDIR "default"
|
||||
OBJECTS ${ASAN_BENCHMARKS_OBJECTS}
|
||||
LINK_FLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINK_FLAGS})
|
||||
endmacro()
|
||||
set(ASAN_BENCHMARK_OBJECTS)
|
||||
generate_asan_tests(ASAN_BENCHMARK_OBJECTS
|
||||
AsanBenchmarks "Asan-${arch}${TEST_KIND}-Benchmark"
|
||||
SUBDIR "default"
|
||||
CFLAGS ${ASAN_UNITTEST_INSTRUMENTED_CFLAGS}
|
||||
SOURCES ${ASAN_BENCHMARKS_SOURCES}
|
||||
LINK_FLAGS ${ASAN_UNITTEST_INSTRUMENTED_LINK_FLAGS})
|
||||
endfunction()
|
||||
|
||||
if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
|
||||
set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
|
||||
if(APPLE)
|
||||
darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
|
||||
endif()
|
||||
|
||||
foreach(arch ${ASAN_TEST_ARCH})
|
||||
add_asan_tests_for_arch_and_kind(${arch} "-inline" "")
|
||||
add_asan_tests_for_arch_and_kind(${arch} "-with-calls"
|
||||
"-mllvm;-asan-instrumentation-with-call-threshold=0")
|
||||
|
||||
# Add static ASan runtime that will be linked with uninstrumented tests.
|
||||
set(ASAN_TEST_RUNTIME RTAsanTest.${arch})
|
||||
if(APPLE)
|
||||
set(ASAN_TEST_RUNTIME_OBJECTS
|
||||
$<TARGET_OBJECTS:RTAsan_dynamic.osx>
|
||||
$<TARGET_OBJECTS:RTInterception.osx>
|
||||
$<TARGET_OBJECTS:RTSanitizerCommon.osx>
|
||||
$<TARGET_OBJECTS:RTSanitizerCommonLibc.osx>
|
||||
$<TARGET_OBJECTS:RTLSanCommon.osx>
|
||||
$<TARGET_OBJECTS:RTUbsan.osx>)
|
||||
else()
|
||||
set(ASAN_TEST_RUNTIME_OBJECTS
|
||||
$<TARGET_OBJECTS:RTAsan.${arch}>
|
||||
$<TARGET_OBJECTS:RTAsan_cxx.${arch}>
|
||||
$<TARGET_OBJECTS:RTInterception.${arch}>
|
||||
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
|
||||
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
|
||||
$<TARGET_OBJECTS:RTLSanCommon.${arch}>
|
||||
$<TARGET_OBJECTS:RTUbsan.${arch}>
|
||||
$<TARGET_OBJECTS:RTUbsan_cxx.${arch}>)
|
||||
endif()
|
||||
add_library(${ASAN_TEST_RUNTIME} STATIC ${ASAN_TEST_RUNTIME_OBJECTS})
|
||||
set_target_properties(${ASAN_TEST_RUNTIME} PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
FOLDER "Compiler-RT Runtime tests")
|
||||
|
||||
add_asan_tests(${arch} ${ASAN_TEST_RUNTIME} KIND "-inline")
|
||||
add_asan_tests(${arch} ${ASAN_TEST_RUNTIME} KIND "-with-calls"
|
||||
CFLAGS -mllvm -asan-instrumentation-with-call-threshold=0)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
|
|
|
@ -67,14 +67,13 @@ macro(add_interceptor_lib library)
|
|||
FOLDER "Compiler-RT Runtime tests")
|
||||
endmacro()
|
||||
|
||||
function(get_interception_lib_for_arch arch lib lib_name)
|
||||
function(get_interception_lib_for_arch arch lib)
|
||||
if(APPLE)
|
||||
set(tgt_name "RTInterception.test.osx")
|
||||
else()
|
||||
set(tgt_name "RTInterception.test.${arch}")
|
||||
endif()
|
||||
set(${lib} "${tgt_name}" PARENT_SCOPE)
|
||||
set(${lib_name} $<TARGET_FILE:${tgt_name}> PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Interception unit tests testsuite.
|
||||
|
@ -84,32 +83,16 @@ set_target_properties(InterceptionUnitTests PROPERTIES
|
|||
|
||||
# Adds interception tests for architecture.
|
||||
macro(add_interception_tests_for_arch arch)
|
||||
get_target_flags_for_arch(${arch} TARGET_FLAGS)
|
||||
set(INTERCEPTION_TEST_SOURCES ${INTERCEPTION_UNITTESTS}
|
||||
${COMPILER_RT_GTEST_SOURCE})
|
||||
set(INTERCEPTION_TEST_COMPILE_DEPS ${INTERCEPTION_TEST_HEADERS})
|
||||
if(NOT COMPILER_RT_STANDALONE_BUILD)
|
||||
list(APPEND INTERCEPTION_TEST_COMPILE_DEPS gtest)
|
||||
endif()
|
||||
set(INTERCEPTION_TEST_OBJECTS)
|
||||
foreach(source ${INTERCEPTION_TEST_SOURCES})
|
||||
get_filename_component(basename ${source} NAME)
|
||||
set(output_obj "${CMAKE_CFG_RESOLVED_INTDIR}${basename}.${arch}.o")
|
||||
clang_compile(${output_obj} ${source}
|
||||
CFLAGS ${INTERCEPTION_TEST_CFLAGS_COMMON} ${TARGET_FLAGS}
|
||||
DEPS ${INTERCEPTION_TEST_COMPILE_DEPS})
|
||||
list(APPEND INTERCEPTION_TEST_OBJECTS ${output_obj})
|
||||
endforeach()
|
||||
get_interception_lib_for_arch(${arch} INTERCEPTION_COMMON_LIB
|
||||
INTERCEPTION_COMMON_LIB_NAME)
|
||||
# Add unittest target.
|
||||
set(INTERCEPTION_TEST_NAME "Interception-${arch}-Test")
|
||||
add_compiler_rt_test(InterceptionUnitTests ${INTERCEPTION_TEST_NAME}
|
||||
OBJECTS ${INTERCEPTION_TEST_OBJECTS}
|
||||
${INTERCEPTION_COMMON_LIB_NAME}
|
||||
DEPS ${INTERCEPTION_TEST_OBJECTS} ${INTERCEPTION_COMMON_LIB}
|
||||
LINK_FLAGS ${INTERCEPTION_TEST_LINK_FLAGS_COMMON}
|
||||
${TARGET_FLAGS})
|
||||
get_interception_lib_for_arch(${arch} INTERCEPTION_COMMON_LIB)
|
||||
generate_compiler_rt_tests(INTERCEPTION_TEST_OBJECTS
|
||||
InterceptionUnitTests "Interception-${arch}-Test" ${arch}
|
||||
RUNTIME ${INTERCEPTION_COMMON_LIB}
|
||||
SOURCES ${INTERCEPTION_UNITTESTS} ${COMPILER_RT_GTEST_SOURCE}
|
||||
COMPILE_DEPS gtest ${INTERCEPTION_TEST_HEADERS}
|
||||
DEPS gtest
|
||||
CFLAGS ${INTERCEPTION_TEST_CFLAGS_COMMON}
|
||||
LINK_FLAGS ${INTERCEPTION_TEST_LINK_FLAGS_COMMON})
|
||||
endmacro()
|
||||
|
||||
if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID AND NOT APPLE)
|
||||
|
|
|
@ -120,14 +120,13 @@ macro(add_sanitizer_common_lib library)
|
|||
FOLDER "Compiler-RT Runtime tests")
|
||||
endmacro()
|
||||
|
||||
function(get_sanitizer_common_lib_for_arch arch lib lib_name)
|
||||
function(get_sanitizer_common_lib_for_arch arch lib)
|
||||
if(APPLE)
|
||||
set(tgt_name "RTSanitizerCommon.test.osx")
|
||||
else()
|
||||
set(tgt_name "RTSanitizerCommon.test.${arch}")
|
||||
endif()
|
||||
set(${lib} "${tgt_name}" PARENT_SCOPE)
|
||||
set(${lib_name} $<TARGET_FILE:${tgt_name}> PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Sanitizer_common unit tests testsuite.
|
||||
|
@ -136,41 +135,22 @@ set_target_properties(SanitizerUnitTests PROPERTIES FOLDER "Compiler-RT Tests")
|
|||
|
||||
# Adds sanitizer tests for architecture.
|
||||
macro(add_sanitizer_tests_for_arch arch)
|
||||
get_target_flags_for_arch(${arch} TARGET_FLAGS)
|
||||
|
||||
# If the sanitizer library was built with _FILE_OFFSET_BITS=64 we need
|
||||
# to ensure that the library and tests agree on the layout of certain
|
||||
# structures such as 'struct stat'.
|
||||
set(extra_flags)
|
||||
if( CMAKE_SIZEOF_VOID_P EQUAL 4 )
|
||||
list(APPEND TARGET_FLAGS "-D_LARGEFILE_SOURCE")
|
||||
list(APPEND TARGET_FLAGS "-D_FILE_OFFSET_BITS=64")
|
||||
list(APPEND extra_flags "-D_LARGEFILE_SOURCE")
|
||||
list(APPEND extra_flags "-D_FILE_OFFSET_BITS=64")
|
||||
endif()
|
||||
get_sanitizer_common_lib_for_arch(${arch} SANITIZER_COMMON_LIB)
|
||||
|
||||
set(SANITIZER_TEST_SOURCES ${SANITIZER_UNITTESTS}
|
||||
${COMPILER_RT_GTEST_SOURCE})
|
||||
set(SANITIZER_TEST_COMPILE_DEPS ${SANITIZER_TEST_HEADERS})
|
||||
if(NOT COMPILER_RT_STANDALONE_BUILD)
|
||||
list(APPEND SANITIZER_TEST_COMPILE_DEPS gtest)
|
||||
endif()
|
||||
set(SANITIZER_TEST_OBJECTS)
|
||||
foreach(source ${SANITIZER_TEST_SOURCES})
|
||||
get_filename_component(basename ${source} NAME)
|
||||
set(output_obj "${CMAKE_CFG_RESOLVED_INTDIR}${basename}.${arch}.o")
|
||||
clang_compile(${output_obj} ${source}
|
||||
CFLAGS ${SANITIZER_TEST_CFLAGS_COMMON} ${TARGET_FLAGS}
|
||||
DEPS ${SANITIZER_TEST_COMPILE_DEPS})
|
||||
list(APPEND SANITIZER_TEST_OBJECTS ${output_obj})
|
||||
endforeach()
|
||||
get_sanitizer_common_lib_for_arch(${arch} SANITIZER_COMMON_LIB
|
||||
SANITIZER_COMMON_LIB_NAME)
|
||||
# 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}
|
||||
DEPS ${SANITIZER_TEST_OBJECTS} ${SANITIZER_COMMON_LIB}
|
||||
LINK_FLAGS ${SANITIZER_TEST_LINK_FLAGS_COMMON}
|
||||
${TARGET_FLAGS})
|
||||
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})
|
||||
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND "${arch}" STREQUAL "x86_64")
|
||||
# Test that the libc-independent part of sanitizer_common is indeed
|
||||
|
@ -180,7 +160,7 @@ macro(add_sanitizer_tests_for_arch arch)
|
|||
sanitizer_nolibc_test_main.cc
|
||||
CFLAGS ${SANITIZER_TEST_CFLAGS_COMMON} ${TARGET_FLAGS}
|
||||
DEPS ${SANITIZER_TEST_COMPILE_DEPS})
|
||||
add_compiler_rt_test(SanitizerUnitTests "Sanitizer-${arch}-Test-Nolibc"
|
||||
add_compiler_rt_test(SanitizerUnitTests "Sanitizer-${arch}-Test-Nolibc" ${arch}
|
||||
OBJECTS sanitizer_nolibc_test_main.${arch}.o
|
||||
-Wl,-whole-archive
|
||||
libRTSanitizerCommon.test.nolibc.${arch}.a
|
||||
|
|
|
@ -15,8 +15,6 @@ set(TSAN_UNITTEST_CFLAGS
|
|||
|
||||
set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH})
|
||||
if(APPLE)
|
||||
darwin_filter_host_archs(TSAN_SUPPORTED_ARCH TSAN_TEST_ARCH)
|
||||
list(APPEND TSAN_UNITTEST_CFLAGS ${DARWIN_osx_CFLAGS})
|
||||
|
||||
# Create a static library for test dependencies.
|
||||
set(TSAN_TEST_RUNTIME_OBJECTS
|
||||
|
@ -29,6 +27,15 @@ if(APPLE)
|
|||
add_library(${TSAN_TEST_RUNTIME} STATIC ${TSAN_TEST_RUNTIME_OBJECTS})
|
||||
set_target_properties(${TSAN_TEST_RUNTIME} PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
darwin_filter_host_archs(TSAN_SUPPORTED_ARCH TSAN_TEST_ARCH)
|
||||
list(APPEND TSAN_UNITTEST_CFLAGS ${DARWIN_osx_CFLAGS})
|
||||
|
||||
set(LINK_FLAGS "-lc++")
|
||||
add_weak_symbols("ubsan" LINK_FLAGS)
|
||||
add_weak_symbols("sanitizer_common" LINK_FLAGS)
|
||||
else()
|
||||
set(LINK_FLAGS "-fsanitize=thread;-lstdc++;-lm")
|
||||
endif()
|
||||
|
||||
set(TSAN_RTL_HEADERS)
|
||||
|
@ -42,44 +49,14 @@ endforeach()
|
|||
macro(add_tsan_unittest testname)
|
||||
cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN})
|
||||
if(UNIX)
|
||||
foreach(arch ${TSAN_TEST_ARCH})
|
||||
set(TEST_OBJECTS)
|
||||
foreach(SOURCE ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE})
|
||||
sanitizer_test_compile(
|
||||
TEST_OBJECTS ${SOURCE} ${arch}
|
||||
COMPILE_DEPS ${TSAN_RTL_HEADERS} ${TEST_HEADERS}
|
||||
DEPS gtest tsan
|
||||
CFLAGS ${TSAN_UNITTEST_CFLAGS}
|
||||
)
|
||||
endforeach()
|
||||
get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
|
||||
set(TEST_DEPS ${TEST_OBJECTS})
|
||||
if(NOT APPLE)
|
||||
# FIXME: Looks like we should link TSan with just-built runtime,
|
||||
# and not rely on -fsanitize=thread, as these tests are essentially
|
||||
# unit tests.
|
||||
add_compiler_rt_test(TsanUnitTests ${testname}
|
||||
OBJECTS ${TEST_OBJECTS}
|
||||
DEPS ${TEST_DEPS}
|
||||
LINK_FLAGS ${TARGET_LINK_FLAGS}
|
||||
-fsanitize=thread
|
||||
-lstdc++ -lm)
|
||||
else()
|
||||
list(APPEND TEST_OBJECTS $<TARGET_FILE:${TSAN_TEST_RUNTIME}>)
|
||||
list(APPEND TEST_DEPS ${TSAN_TEST_RUNTIME})
|
||||
|
||||
add_weak_symbols("ubsan" WEAK_SYMBOL_LINK_FLAGS)
|
||||
add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
|
||||
|
||||
# Intentionally do *not* link with `-fsanitize=thread`. We already link
|
||||
# against a static version of the runtime, and we don't want the dynamic
|
||||
# one.
|
||||
add_compiler_rt_test(TsanUnitTests "${testname}-${arch}-Test"
|
||||
OBJECTS ${TEST_OBJECTS}
|
||||
DEPS ${TEST_DEPS}
|
||||
LINK_FLAGS ${TARGET_LINK_FLAGS} ${DARWIN_osx_LINK_FLAGS}
|
||||
${WEAK_SYMBOL_LINK_FLAGS} -lc++)
|
||||
endif()
|
||||
foreach(arch ${ASAN_TEST_ARCH})
|
||||
generate_compiler_rt_tests(TsanUnitTests ${testname} ${arch}
|
||||
SOURCES ${TEST_SOURCES}
|
||||
RUNTIME ${TSAN_TEST_RUNTIME}
|
||||
COMPILE_DEPS ${TEST_HEADERS} ${TSAN_RTL_HEADERS}
|
||||
DEPS gtest tsan
|
||||
CFLAGS ${TSAN_UNITTEST_CFLAGS}
|
||||
LINK_FLAGS ${LINK_FLAGS})
|
||||
endforeach()
|
||||
endif()
|
||||
endmacro()
|
||||
|
|
|
@ -13,34 +13,21 @@ set(XRAY_UNITTEST_CFLAGS
|
|||
|
||||
macro(add_xray_unittest testname)
|
||||
set(XRAY_TEST_ARCH ${XRAY_SUPPORTED_ARCH})
|
||||
if (APPLE)
|
||||
darwin_filter_host_archs(XRAY_SUPPORTED_ARCH)
|
||||
endif()
|
||||
if(UNIX)
|
||||
cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN})
|
||||
set(TEST_OBJECTS)
|
||||
# FIXME: Figure out how to run even just the unit tests on APPLE.
|
||||
if(UNIX AND NOT APPLE)
|
||||
foreach(arch ${XRAY_TEST_ARCH})
|
||||
cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN})
|
||||
set(TEST_OBJECTS)
|
||||
foreach(SOURCE ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE})
|
||||
sanitizer_test_compile(TEST_OBJECTS ${SOURCE} ${arch}
|
||||
DEPS gtest_main xray
|
||||
CFLAGS ${XRAY_UNITTEST_CFLAGS})
|
||||
endforeach()
|
||||
get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
|
||||
set(TEST_DEPS ${TEST_OBJECTS})
|
||||
if(NOT COMPILER_RT_STANDALONE_BUILD)
|
||||
list(APPEND TEST_DEPS gtest_main xray)
|
||||
endif()
|
||||
if(NOT APPLE)
|
||||
add_compiler_rt_test(XRayUnitTests ${testname}-${arch}
|
||||
OBJECTS ${TEST_OBJECTS}
|
||||
DEPS ${TEST_DEPS}
|
||||
LINK_FLAGS ${TARGET_LINK_FLAGS}
|
||||
generate_compiler_rt_tests(TEST_OBJECTS
|
||||
XRayUnitTests "${testname}-${arch}" "${arch}"
|
||||
SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}
|
||||
DEPS gtest_main xray
|
||||
CFLAGS ${XRAY_UNITTEST_CFLAGS}
|
||||
LINK_FLAGS
|
||||
-lstdc++ -lm ${CMAKE_THREAD_LIBS_INIT}
|
||||
-lpthread
|
||||
-L${COMPILER_RT_LIBRARY_OUTPUT_DIR} -lclang_rt.xray-${arch}
|
||||
-ldl -lrt)
|
||||
endif()
|
||||
# FIXME: Figure out how to run even just the unit tests on APPLE.
|
||||
endforeach()
|
||||
endif()
|
||||
endmacro()
|
||||
|
|
Loading…
Reference in New Issue