Home | History | Annotate | Download | only in tests
      1 include(CheckCXXCompilerFlag)
      2 include(CompilerRTCompile)
      3 include(CompilerRTLink)
      4 
      5 include_directories(..)
      6 include_directories(../..)
      7 
      8 set(LSAN_TESTS_SRC
      9   lsan_dummy_unittest.cc)
     10 
     11 set(LSAN_TESTS_CFLAGS
     12   ${LSAN_CFLAGS}
     13   ${COMPILER_RT_GTEST_INCLUDE_CFLAGS}
     14   -I${COMPILER_RT_SOURCE_DIR}/lib
     15   -I${LSAN_SRC_DIR})
     16 
     17 set(LSAN_TEST_LINK_FLAGS_COMMON
     18   -lstdc++ -ldl -lpthread -lm)
     19 
     20 add_custom_target(LsanUnitTests)
     21 set_target_properties(LsanUnitTests PROPERTIES
     22   FOLDER "LSan unit tests")
     23 
     24 # Compile source for the given architecture, using compiler
     25 # options in ${ARGN}, and add it to the object list.
     26 macro(lsan_compile obj_list source arch)
     27   get_filename_component(basename ${source} NAME)
     28   set(output_obj "${basename}.${arch}.o")
     29   get_target_flags_for_arch(${arch} TARGET_CFLAGS)
     30   clang_compile(${output_obj} ${source}
     31                 CFLAGS ${ARGN} ${TARGET_CFLAGS}
     32                 DEPS gtest ${LSAN_RUNTIME_LIBRARIES})
     33   list(APPEND ${obj_list} ${output_obj})
     34 endmacro()
     35 
     36 function(add_lsan_test test_suite test_name arch)
     37   get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
     38   add_compiler_rt_test(${test_suite} ${test_name}
     39                        OBJECTS ${ARGN}
     40                        DEPS ${LSAN_RUNTIME_LIBRARIES} ${ARGN}
     41                        LINK_FLAGS ${LSAN_TEST_LINK_FLAGS_COMMON}
     42                                   ${TARGET_LINK_FLAGS})
     43 endfunction()
     44 
     45 macro(add_lsan_tests_for_arch arch)
     46   set(LSAN_TESTS_OBJ)
     47   set(LSAN_TEST_SOURCES ${LSAN_TESTS_SRC}
     48                         ${COMPILER_RT_GTEST_SOURCE})
     49   foreach(source ${LSAN_TEST_SOURCES})
     50     lsan_compile(LSAN_TESTS_OBJ ${source} ${arch} ${LSAN_TESTS_CFLAGS})
     51   endforeach()
     52   add_lsan_test(LsanUnitTests Lsan-${arch}-Test ${arch} ${LSAN_TESTS_OBJ})
     53 endmacro()
     54 
     55 # Build tests for 64-bit Linux only.
     56 if(UNIX AND NOT APPLE AND CAN_TARGET_x86_64)
     57   add_lsan_tests_for_arch(x86_64)
     58 endif()
     59