From c20f5d2246ad445a91cd4e190502b7909700cb86 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 27 Dec 2012 13:19:23 +0000 Subject: [PATCH] Define COMPILER_RT_CAN_EXECUTE_TESTS variable on platforms where we can produce working binaries and use it in build rules for sanitizers tests llvm-svn: 171160 --- compiler-rt/CMakeLists.txt | 9 ++++++ compiler-rt/lib/asan/CMakeLists.txt | 3 -- compiler-rt/lib/asan/lit_tests/CMakeLists.txt | 12 ++------ compiler-rt/lib/asan/tests/CMakeLists.txt | 6 +--- compiler-rt/lib/msan/tests/CMakeLists.txt | 27 +++++++++--------- .../lib/sanitizer_common/tests/CMakeLists.txt | 28 ++++++++++--------- compiler-rt/lib/tsan/lit_tests/CMakeLists.txt | 8 +++--- .../lib/ubsan/lit_tests/CMakeLists.txt | 6 ++-- 8 files changed, 47 insertions(+), 52 deletions(-) diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index 8574cdc245fe..0c9f2a624b8e 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -66,6 +66,15 @@ try_compile(CAN_TARGET_I386 ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE32} COMPILE_DEFINITIONS "${TARGET_I386_CFLAGS}" CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${TARGET_I386_CFLAGS}") +# We only support running instrumented tests when we're not cross compiling +# and target a unix-like system. On Android we define the rules for building +# unit tests, but don't execute them. +if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND UNIX AND NOT ANDROID) + set(COMPILER_RT_CAN_EXECUTE_TESTS TRUE) +else() + set(COMPILER_RT_CAN_EXECUTE_TESTS FALSE) +endif() + function(filter_available_targets out_var) set(archs) foreach(arch ${ARGN}) diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt index 0f561e6cb6c5..2a27da9dc61a 100644 --- a/compiler-rt/lib/asan/CMakeLists.txt +++ b/compiler-rt/lib/asan/CMakeLists.txt @@ -129,7 +129,4 @@ if(LLVM_INCLUDE_TESTS) add_subdirectory(tests) endif() -# ASan output tests. -# FIXME: move all output tests from output_tests/ to lit_tests/ and get rid -# of the first directory. add_subdirectory(lit_tests) diff --git a/compiler-rt/lib/asan/lit_tests/CMakeLists.txt b/compiler-rt/lib/asan/lit_tests/CMakeLists.txt index afe76a98d7b2..1609032d4670 100644 --- a/compiler-rt/lib/asan/lit_tests/CMakeLists.txt +++ b/compiler-rt/lib/asan/lit_tests/CMakeLists.txt @@ -11,9 +11,8 @@ configure_lit_site_cfg( ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg ) -if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}") - # Run ASan output tests only if we're not cross-compiling, - # and can be sure that clang would produce working binaries. +if(COMPILER_RT_CAN_EXECUTE_TESTS) + # Run ASan tests only if we're sure we may produce working binaries. set(ASAN_TEST_DEPS clang clang-headers FileCheck count not llvm-nm llvm-symbolizer ${ASAN_RUNTIME_LIBRARIES} @@ -30,11 +29,4 @@ if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}") DEPENDS ${ASAN_TEST_DEPS} ) set_target_properties(check-asan PROPERTIES FOLDER "ASan tests") -elseif(LLVM_INCLUDE_TESTS) - # Otherwise run only ASan unit tests. - add_lit_testsuite(check-asan "Running the AddressSanitizer unit tests" - ${CMAKE_CURRENT_BINARY_DIR}/Unit - DEPENDS AsanUnitTests - ) - set_target_properties(check-asan PROPERTIES FOLDER "ASan unit tests") endif() diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt index 33b3c58421e4..0cfb767f64a6 100644 --- a/compiler-rt/lib/asan/tests/CMakeLists.txt +++ b/compiler-rt/lib/asan/tests/CMakeLists.txt @@ -153,11 +153,7 @@ macro(add_asan_tests_for_arch arch) ${ASAN_BENCHMARKS_OBJECTS} ${ASAN_INST_GTEST}) endmacro() -# We only support building instrumented tests when we're not cross compiling -# and targeting a unix-like system where we can predict viable compilation and -# linking strategies. -# We use a different approach to build these tests for Android. See below. -if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND UNIX AND NOT ANDROID) +if(COMPILER_RT_CAN_EXECUTE_TESTS) if(CAN_TARGET_X86_64) add_asan_tests_for_arch(x86_64) endif() diff --git a/compiler-rt/lib/msan/tests/CMakeLists.txt b/compiler-rt/lib/msan/tests/CMakeLists.txt index 1c8e2c9e191e..d6df41c0be0b 100644 --- a/compiler-rt/lib/msan/tests/CMakeLists.txt +++ b/compiler-rt/lib/msan/tests/CMakeLists.txt @@ -147,21 +147,20 @@ macro(add_msan_tests_for_arch arch) ${MSAN_INST_LIBCXX} ${MSANDR_TEST_SO}) endmacro() -if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND UNIX AND NOT ANDROID - AND EXISTS ${MSAN_LIBCXX_PATH}/) +if(COMPILER_RT_CAN_EXECUTE_TESTS AND EXISTS ${MSAN_LIBCXX_PATH}/) if(CAN_TARGET_X86_64) add_msan_tests_for_arch(x86_64) endif() + + # 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-msan "Running MemorySanitizer unittests" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS MsanUnitTests + ) + set_target_properties(check-msan PROPERTIES FOLDER "MemorySanitizer unittests") endif() - -# 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-msan "Running MemorySanitizer unittests" - ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS MsanUnitTests - ) -set_target_properties(check-msan PROPERTIES FOLDER "MemorySanitizer unittests") diff --git a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt index fa1d7ca020fd..0cedeb58231d 100644 --- a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt +++ b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt @@ -75,7 +75,9 @@ macro(add_sanitizer_tests_for_arch arch) LINK_FLAGS ${SANITIZER_TEST_LINK_FLAGS}) endmacro() -if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND UNIX AND NOT ANDROID) +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. if(APPLE) add_sanitizer_common_lib("RTSanitizerCommon.test.osx" $) @@ -95,16 +97,16 @@ if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND UNIX AND NOT ANDROID) if(CAN_TARGET_I386) add_sanitizer_tests_for_arch(i386) endif() + + # 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") endif() - -# 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/compiler-rt/lib/tsan/lit_tests/CMakeLists.txt b/compiler-rt/lib/tsan/lit_tests/CMakeLists.txt index 6dc90e2367f9..ff2508dd75af 100644 --- a/compiler-rt/lib/tsan/lit_tests/CMakeLists.txt +++ b/compiler-rt/lib/tsan/lit_tests/CMakeLists.txt @@ -8,9 +8,8 @@ configure_lit_site_cfg( ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg ) -if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}") - # Run TSan output tests only if we're not cross-compiling, - # and can be sure that clang would produce working binaries. +if(COMPILER_RT_CAN_EXECUTE_TESTS) + # Run TSan output tests only if we're sure we can produce working binaries. set(TSAN_TEST_DEPS clang clang-headers FileCheck count not llvm-symbolizer ${TSAN_RUNTIME_LIBRARIES} @@ -28,7 +27,8 @@ if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}") ) set_target_properties(check-tsan PROPERTIES FOLDER "TSan unittests") elseif(LLVM_INCLUDE_TESTS) - # Otherwise run only TSan unit tests. + # Otherwise run only TSan unit tests (they are linked using the + # host compiler). add_lit_testsuite(check-tsan "Running ThreadSanitizer tests" ${CMAKE_CURRENT_BINARY_DIR}/Unit DEPENDS TsanUnitTests llvm-symbolizer) diff --git a/compiler-rt/lib/ubsan/lit_tests/CMakeLists.txt b/compiler-rt/lib/ubsan/lit_tests/CMakeLists.txt index 67d786dd9597..565c523ceb49 100644 --- a/compiler-rt/lib/ubsan/lit_tests/CMakeLists.txt +++ b/compiler-rt/lib/ubsan/lit_tests/CMakeLists.txt @@ -3,9 +3,9 @@ configure_lit_site_cfg( ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg ) -if("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}") - # Run UBSan output tests only if we're not cross-compiling, - # and can be sure that clang would produce working binaries. +if(COMPILER_RT_CAN_EXECUTE_TESTS) + # Run UBSan output tests only if we're sure that clang would produce + # working binaries. set(UBSAN_TEST_DEPS clang clang-headers FileCheck count not ${UBSAN_RUNTIME_LIBRARIES}