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 | |
| 14 | # tsan_compile(obj_list, source, arch, {headers}) |
| 15 | macro(tsan_compile obj_list source arch) |
| 16 | get_filename_component(basename ${source} NAME) |
| 17 | set(output_obj "${basename}.${arch}.o") |
| 18 | get_target_flags_for_arch(${arch} TARGET_CFLAGS) |
| 19 | clang_compile(${output_obj} ${source} |
| 20 | CFLAGS ${TSAN_UNITTEST_CFLAGS} ${TARGET_CFLAGS} |
| 21 | DEPS gtest ${TSAN_RUNTIME_LIBRARIES} ${ARGN}) |
| 22 | list(APPEND ${obj_list} ${output_obj}) |
| 23 | endmacro() |
| 24 | |
| 25 | macro(add_tsan_unittest testname) |
| 26 | # Build unit tests only for 64-bit Linux. |
| 27 | if(UNIX AND NOT APPLE AND CAN_TARGET_x86_64) |
| 28 | parse_arguments(TEST "SOURCES;HEADERS" "" ${ARGN}) |
| 29 | set(TEST_OBJECTS) |
| 30 | foreach(SOURCE ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE}) |
| 31 | tsan_compile(TEST_OBJECTS ${SOURCE} x86_64 ${TEST_HEADERS}) |
| 32 | endforeach() |
| 33 | get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS) |
| 34 | add_compiler_rt_test(TsanUnitTests ${testname} |
| 35 | OBJECTS ${TEST_OBJECTS} |
| 36 | DEPS ${TSAN_RUNTIME_LIBRARIES} ${TEST_OBJECTS} |
| 37 | LINK_FLAGS ${TARGET_LINK_FLAGS} |
| 38 | -fsanitize=thread |
| 39 | -lstdc++ -lm) |
| 40 | endif() |
| 41 | endmacro() |
| 42 | |
| 43 | if(COMPILER_RT_CAN_EXECUTE_TESTS) |
| 44 | add_subdirectory(rtl) |
| 45 | add_subdirectory(unit) |
| 46 | endif() |