| Alexey Samsonov | 0fa3ea6 | 2012-09-17 10:02:17 +0000 | [diff] [blame] | 1 | include_directories(../rtl) | 
|  | 2 |  | 
|  | 3 | add_custom_target(TsanUnitTests) | 
|  | 4 | set_target_properties(TsanUnitTests PROPERTIES | 
|  | 5 | FOLDER "TSan unittests") | 
| Alexey Samsonov | 0fa3ea6 | 2012-09-17 10:02:17 +0000 | [diff] [blame] | 6 |  | 
| Alexey Samsonov | e99a0b9 | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 7 | set(TSAN_UNITTEST_CFLAGS | 
|  | 8 | ${TSAN_CFLAGS} | 
|  | 9 | ${COMPILER_RT_GTEST_INCLUDE_CFLAGS} | 
|  | 10 | -I${COMPILER_RT_SOURCE_DIR}/lib | 
|  | 11 | -I${COMPILER_RT_SOURCE_DIR}/lib/tsan/rtl | 
|  | 12 | -DGTEST_HAS_RTTI=0) | 
|  | 13 |  | 
| Alexey Samsonov | 11705b2 | 2014-02-20 12:03:56 +0000 | [diff] [blame^] | 14 | set(TSAN_RTL_HEADERS) | 
|  | 15 | foreach (header ${TSAN_HEADERS}) | 
|  | 16 | list(APPEND TSAN_RTL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../${header}) | 
|  | 17 | endforeach() | 
|  | 18 |  | 
| Alexey Samsonov | e99a0b9 | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 19 | # tsan_compile(obj_list, source, arch, {headers}) | 
|  | 20 | macro(tsan_compile obj_list source arch) | 
|  | 21 | get_filename_component(basename ${source} NAME) | 
|  | 22 | set(output_obj "${basename}.${arch}.o") | 
|  | 23 | get_target_flags_for_arch(${arch} TARGET_CFLAGS) | 
| Alexey Samsonov | 11705b2 | 2014-02-20 12:03:56 +0000 | [diff] [blame^] | 24 | set(COMPILE_DEPS ${TSAN_RTL_HEADERS} ${ARGN}) | 
|  | 25 | if(NOT COMPILER_RT_STANDALONE_BUILD) | 
|  | 26 | list(APPEND COMPILE_DEPS gtest tsan) | 
|  | 27 | endif() | 
| Alexey Samsonov | e99a0b9 | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 28 | clang_compile(${output_obj} ${source} | 
|  | 29 | CFLAGS ${TSAN_UNITTEST_CFLAGS} ${TARGET_CFLAGS} | 
| Alexey Samsonov | 11705b2 | 2014-02-20 12:03:56 +0000 | [diff] [blame^] | 30 | DEPS ${COMPILE_DEPS}) | 
| Alexey Samsonov | e99a0b9 | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 31 | list(APPEND ${obj_list} ${output_obj}) | 
|  | 32 | endmacro() | 
|  | 33 |  | 
|  | 34 | macro(add_tsan_unittest testname) | 
|  | 35 | # Build unit tests only for 64-bit Linux. | 
|  | 36 | if(UNIX AND NOT APPLE AND CAN_TARGET_x86_64) | 
|  | 37 | parse_arguments(TEST "SOURCES;HEADERS" "" ${ARGN}) | 
|  | 38 | set(TEST_OBJECTS) | 
|  | 39 | foreach(SOURCE ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}) | 
|  | 40 | tsan_compile(TEST_OBJECTS ${SOURCE} x86_64 ${TEST_HEADERS}) | 
|  | 41 | endforeach() | 
|  | 42 | get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS) | 
| Alexey Samsonov | 11705b2 | 2014-02-20 12:03:56 +0000 | [diff] [blame^] | 43 | set(TEST_DEPS ${TEST_OBJECTS}) | 
|  | 44 | if(NOT COMPILER_RT_STANDALONE_BUILD) | 
|  | 45 | list(APPEND TEST_DEPS tsan) | 
|  | 46 | endif() | 
|  | 47 | # FIXME: Looks like we should link TSan with just-built runtime, | 
|  | 48 | # and not rely on -fsanitize=thread, as these tests are essentially | 
|  | 49 | # unit tests. | 
| Alexey Samsonov | e99a0b9 | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 50 | add_compiler_rt_test(TsanUnitTests ${testname} | 
|  | 51 | OBJECTS ${TEST_OBJECTS} | 
| Alexey Samsonov | 11705b2 | 2014-02-20 12:03:56 +0000 | [diff] [blame^] | 52 | DEPS ${TEST_DEPS} | 
| Alexey Samsonov | e99a0b9 | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 53 | LINK_FLAGS ${TARGET_LINK_FLAGS} | 
|  | 54 | -fsanitize=thread | 
|  | 55 | -lstdc++ -lm) | 
|  | 56 | endif() | 
|  | 57 | endmacro() | 
|  | 58 |  | 
|  | 59 | if(COMPILER_RT_CAN_EXECUTE_TESTS) | 
|  | 60 | add_subdirectory(rtl) | 
|  | 61 | add_subdirectory(unit) | 
|  | 62 | endif() |