[compiler-rt] r190503 - [TSan] Use Clang to compile and link TSan unit tests with TSan runtime
Alexey Samsonov
samsonov at google.com
Wed Sep 11 02:56:33 PDT 2013
Author: samsonov
Date: Wed Sep 11 04:56:33 2013
New Revision: 190503
URL: http://llvm.org/viewvc/llvm-project?rev=190503&view=rev
Log:
[TSan] Use Clang to compile and link TSan unit tests with TSan runtime
Added:
compiler-rt/trunk/lib/tsan/tests/unit/tsan_unit_test_main.cc
Modified:
compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt
compiler-rt/trunk/lib/tsan/tests/rtl/CMakeLists.txt
compiler-rt/trunk/lib/tsan/tests/unit/CMakeLists.txt
Modified: compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt?rev=190503&r1=190502&r2=190503&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt Wed Sep 11 04:56:33 2013
@@ -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()
Modified: compiler-rt/trunk/lib/tsan/tests/rtl/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/CMakeLists.txt?rev=190503&r1=190502&r2=190503&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/tests/rtl/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/tsan/tests/rtl/CMakeLists.txt Wed Sep 11 04:56:33 2013
@@ -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})
Modified: compiler-rt/trunk/lib/tsan/tests/unit/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/CMakeLists.txt?rev=190503&r1=190502&r2=190503&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/tests/unit/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/tsan/tests/unit/CMakeLists.txt Wed Sep 11 04:56:33 2013
@@ -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})
Added: compiler-rt/trunk/lib/tsan/tests/unit/tsan_unit_test_main.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_unit_test_main.cc?rev=190503&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/tests/unit/tsan_unit_test_main.cc (added)
+++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_unit_test_main.cc Wed Sep 11 04:56:33 2013
@@ -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();
+}
More information about the llvm-commits
mailing list