diff options
author | Alexey Samsonov <samsonov@google.com> | 2013-09-11 09:56:33 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2013-09-11 09:56:33 +0000 |
commit | a8b4c3b6809a4cdc10587020b98246c171bc18ee (patch) | |
tree | 71cf4890f4933f77401b22cf5c67caa4bd2fe5f2 /lib/tsan/tests | |
parent | e059bd35a33040c9ecbd291a190449f7a0a6f17f (diff) |
[TSan] Use Clang to compile and link TSan unit tests with TSan runtime
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@190503 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/tsan/tests')
-rw-r--r-- | lib/tsan/tests/CMakeLists.txt | 56 | ||||
-rw-r--r-- | lib/tsan/tests/rtl/CMakeLists.txt | 14 | ||||
-rw-r--r-- | lib/tsan/tests/unit/CMakeLists.txt | 9 | ||||
-rw-r--r-- | lib/tsan/tests/unit/tsan_unit_test_main.cc | 19 |
4 files changed, 72 insertions, 26 deletions
diff --git a/lib/tsan/tests/CMakeLists.txt b/lib/tsan/tests/CMakeLists.txt index 7cc079f3d..f73a89242 100644 --- a/lib/tsan/tests/CMakeLists.txt +++ b/lib/tsan/tests/CMakeLists.txt @@ -3,22 +3,44 @@ include_directories(../rtl) add_custom_target(TsanUnitTests) set_target_properties(TsanUnitTests PROPERTIES FOLDER "TSan unittests") -function(add_tsan_unittest testname) - # Build unit tests only on 64-bit Linux. - if(UNIX AND NOT APPLE - AND CAN_TARGET_x86_64 - AND CMAKE_SIZEOF_VOID_P EQUAL 8 - AND NOT LLVM_BUILD_32_BITS) - add_unittest(TsanUnitTests ${testname} ${ARGN}) - # Link with TSan runtime. - target_link_libraries(${testname} clang_rt.tsan-x86_64) - # Compile tests with the same flags as TSan runtime. - set_target_compile_flags(${testname} ${TSAN_CFLAGS}) - # Link tests with -pie. - set_property(TARGET ${testname} APPEND_STRING - PROPERTY LINK_FLAGS " -pie") + +set(TSAN_UNITTEST_CFLAGS + ${TSAN_CFLAGS} + ${COMPILER_RT_GTEST_INCLUDE_CFLAGS} + -I${COMPILER_RT_SOURCE_DIR}/lib + -I${COMPILER_RT_SOURCE_DIR}/lib/tsan/rtl + -DGTEST_HAS_RTTI=0) + +# tsan_compile(obj_list, source, arch, {headers}) +macro(tsan_compile obj_list source arch) + get_filename_component(basename ${source} NAME) + set(output_obj "${basename}.${arch}.o") + get_target_flags_for_arch(${arch} TARGET_CFLAGS) + clang_compile(${output_obj} ${source} + CFLAGS ${TSAN_UNITTEST_CFLAGS} ${TARGET_CFLAGS} + DEPS gtest ${TSAN_RUNTIME_LIBRARIES} ${ARGN}) + list(APPEND ${obj_list} ${output_obj}) +endmacro() + +macro(add_tsan_unittest testname) + # Build unit tests only for 64-bit Linux. + if(UNIX AND NOT APPLE AND CAN_TARGET_x86_64) + parse_arguments(TEST "SOURCES;HEADERS" "" ${ARGN}) + set(TEST_OBJECTS) + foreach(SOURCE ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}) + tsan_compile(TEST_OBJECTS ${SOURCE} x86_64 ${TEST_HEADERS}) + endforeach() + get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS) + add_compiler_rt_test(TsanUnitTests ${testname} + OBJECTS ${TEST_OBJECTS} + DEPS ${TSAN_RUNTIME_LIBRARIES} ${TEST_OBJECTS} + LINK_FLAGS ${TARGET_LINK_FLAGS} + -fsanitize=thread + -lstdc++ -lm) endif() -endfunction() +endmacro() -add_subdirectory(rtl) -add_subdirectory(unit) +if(COMPILER_RT_CAN_EXECUTE_TESTS) + add_subdirectory(rtl) + add_subdirectory(unit) +endif() diff --git a/lib/tsan/tests/rtl/CMakeLists.txt b/lib/tsan/tests/rtl/CMakeLists.txt index b585660e8..989566d9e 100644 --- a/lib/tsan/tests/rtl/CMakeLists.txt +++ b/lib/tsan/tests/rtl/CMakeLists.txt @@ -1,15 +1,19 @@ -set(TSAN_RTL_TESTS +set(TSAN_RTL_TEST_SOURCES tsan_bench.cc tsan_mop.cc tsan_mutex.cc tsan_posix.cc tsan_string.cc tsan_test.cc - tsan_thread.cc - ) + tsan_thread.cc) if(UNIX AND NOT APPLE) - list(APPEND TSAN_RTL_TESTS tsan_test_util_linux.cc) + list(APPEND TSAN_RTL_TEST_SOURCES tsan_test_util_linux.cc) endif() -add_tsan_unittest(TsanRtlTest ${TSAN_RTL_TESTS}) +set(TSAN_RTL_TEST_HEADERS + tsan_test_util.h) + +add_tsan_unittest(TsanRtlTest + SOURCES ${TSAN_RTL_TEST_SOURCES} + HEADERS ${TSAN_RTL_TEST_HEADERS}) diff --git a/lib/tsan/tests/unit/CMakeLists.txt b/lib/tsan/tests/unit/CMakeLists.txt index 1cd2abe4d..6898f641d 100644 --- a/lib/tsan/tests/unit/CMakeLists.txt +++ b/lib/tsan/tests/unit/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TSAN_UNIT_TESTS +set(TSAN_UNIT_TEST_SOURCES tsan_clock_test.cc tsan_flags_test.cc tsan_mman_test.cc @@ -6,7 +6,8 @@ set(TSAN_UNIT_TESTS tsan_shadow_test.cc tsan_stack_test.cc tsan_sync_test.cc - tsan_vector_test.cc - ) + tsan_unit_test_main.cc + tsan_vector_test.cc) -add_tsan_unittest(TsanUnitTest ${TSAN_UNIT_TESTS}) +add_tsan_unittest(TsanUnitTest + SOURCES ${TSAN_UNIT_TEST_SOURCES}) diff --git a/lib/tsan/tests/unit/tsan_unit_test_main.cc b/lib/tsan/tests/unit/tsan_unit_test_main.cc new file mode 100644 index 000000000..84d94dd03 --- /dev/null +++ b/lib/tsan/tests/unit/tsan_unit_test_main.cc @@ -0,0 +1,19 @@ +//===-- tsan_unit_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 (TSan), a race detector. +// +//===----------------------------------------------------------------------===// +#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(); +} |