Alexey Samsonov | f548ef8 | 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 | f548ef8 | 2012-09-17 10:02:17 +0000 | [diff] [blame] | 6 | |
Alexey Samsonov | a8b4c3b | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 7 | set(TSAN_UNITTEST_CFLAGS |
| 8 | ${TSAN_CFLAGS} |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 9 | ${COMPILER_RT_TEST_CFLAGS} |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 10 | ${COMPILER_RT_GTEST_CFLAGS} |
Alexey Samsonov | a8b4c3b | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 11 | -I${COMPILER_RT_SOURCE_DIR}/lib |
| 12 | -I${COMPILER_RT_SOURCE_DIR}/lib/tsan/rtl |
| 13 | -DGTEST_HAS_RTTI=0) |
| 14 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 15 | set(TSAN_RTL_HEADERS) |
| 16 | foreach (header ${TSAN_HEADERS}) |
| 17 | list(APPEND TSAN_RTL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../${header}) |
| 18 | endforeach() |
| 19 | |
Alexey Samsonov | a8b4c3b | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 20 | # tsan_compile(obj_list, source, arch, {headers}) |
| 21 | macro(tsan_compile obj_list source arch) |
| 22 | get_filename_component(basename ${source} NAME) |
| 23 | set(output_obj "${basename}.${arch}.o") |
| 24 | get_target_flags_for_arch(${arch} TARGET_CFLAGS) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 25 | set(COMPILE_DEPS ${TSAN_RTL_HEADERS} ${ARGN}) |
| 26 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
| 27 | list(APPEND COMPILE_DEPS gtest tsan) |
| 28 | endif() |
Alexey Samsonov | a8b4c3b | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 29 | clang_compile(${output_obj} ${source} |
| 30 | CFLAGS ${TSAN_UNITTEST_CFLAGS} ${TARGET_CFLAGS} |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 31 | DEPS ${COMPILE_DEPS}) |
Alexey Samsonov | a8b4c3b | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 32 | list(APPEND ${obj_list} ${output_obj}) |
| 33 | endmacro() |
| 34 | |
| 35 | macro(add_tsan_unittest testname) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 36 | set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH}) |
| 37 | if(APPLE) |
| 38 | darwin_filter_host_archs(TSAN_SUPPORTED_ARCH TSAN_TEST_ARCH) |
| 39 | endif() |
| 40 | if(UNIX) |
| 41 | foreach(arch ${TSAN_TEST_ARCH}) |
| 42 | cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN}) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 43 | set(TEST_OBJECTS) |
| 44 | foreach(SOURCE ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}) |
| 45 | tsan_compile(TEST_OBJECTS ${SOURCE} ${arch} ${TEST_HEADERS}) |
| 46 | endforeach() |
| 47 | get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS) |
| 48 | set(TEST_DEPS ${TEST_OBJECTS}) |
| 49 | if(NOT COMPILER_RT_STANDALONE_BUILD) |
| 50 | list(APPEND TEST_DEPS tsan) |
| 51 | endif() |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 52 | if(NOT APPLE) |
| 53 | # FIXME: Looks like we should link TSan with just-built runtime, |
| 54 | # and not rely on -fsanitize=thread, as these tests are essentially |
| 55 | # unit tests. |
| 56 | add_compiler_rt_test(TsanUnitTests ${testname} |
| 57 | OBJECTS ${TEST_OBJECTS} |
| 58 | DEPS ${TEST_DEPS} |
| 59 | LINK_FLAGS ${TARGET_LINK_FLAGS} |
| 60 | -fsanitize=thread |
| 61 | -lstdc++ -lm) |
| 62 | else() |
| 63 | set(TSAN_TEST_RUNTIME_OBJECTS |
| 64 | $<TARGET_OBJECTS:RTTsan_dynamic.osx> |
| 65 | $<TARGET_OBJECTS:RTInterception.osx> |
| 66 | $<TARGET_OBJECTS:RTSanitizerCommon.osx> |
| 67 | $<TARGET_OBJECTS:RTSanitizerCommonLibc.osx> |
| 68 | $<TARGET_OBJECTS:RTUbsan.osx>) |
| 69 | set(TSAN_TEST_RUNTIME RTTsanTest.${testname}.${arch}) |
| 70 | add_library(${TSAN_TEST_RUNTIME} STATIC ${TSAN_TEST_RUNTIME_OBJECTS}) |
| 71 | set_target_properties(${TSAN_TEST_RUNTIME} PROPERTIES |
| 72 | ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
| 73 | list(APPEND TEST_OBJECTS lib${TSAN_TEST_RUNTIME}.a) |
| 74 | list(APPEND TEST_DEPS ${TSAN_TEST_RUNTIME}) |
| 75 | # Intentionally do *not* link with `-fsanitize=thread`. We already link |
| 76 | # against a static version of the runtime, and we don't want the dynamic |
| 77 | # one. |
| 78 | add_compiler_rt_test(TsanUnitTests "${testname}-${arch}-Test" |
| 79 | OBJECTS ${TEST_OBJECTS} |
| 80 | DEPS ${TEST_DEPS} |
| 81 | LINK_FLAGS ${TARGET_LINK_FLAGS} |
| 82 | -lc++) |
| 83 | endif() |
Alexey Samsonov | a8b4c3b | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 84 | endforeach() |
Alexey Samsonov | a8b4c3b | 2013-09-11 09:56:33 +0000 | [diff] [blame] | 85 | endif() |
| 86 | endmacro() |
| 87 | |
| 88 | if(COMPILER_RT_CAN_EXECUTE_TESTS) |
| 89 | add_subdirectory(rtl) |
| 90 | add_subdirectory(unit) |
| 91 | endif() |