diff projects/compiler-rt/test/fuzzer/CMakeLists.txt @ 131:f476a9ba4795

http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
author mir3636
date Fri, 16 Feb 2018 21:02:11 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/projects/compiler-rt/test/fuzzer/CMakeLists.txt	Fri Feb 16 21:02:11 2018 +0900
@@ -0,0 +1,72 @@
+set(LIBFUZZER_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
+list(REMOVE_ITEM LIBFUZZER_TEST_DEPS SanitizerLintCheck)
+if (NOT COMPILER_RT_STANDALONE_BUILD)
+  list(APPEND LIBFUZZER_TEST_DEPS fuzzer asan ubsan)
+endif()
+
+if(COMPILER_RT_INCLUDE_TESTS)
+  list(APPEND LIBFUZZER_TEST_DEPS FuzzerUnitTests)
+endif()
+
+set(EXCLUDE_FROM_ALL ON)
+
+add_custom_target(check-fuzzer)
+
+if(COMPILER_RT_INCLUDE_TESTS)
+  # libFuzzer unit tests.
+  configure_lit_site_cfg(
+    ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.in
+    ${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg)
+  add_lit_testsuite(check-fuzzer-unit "Running Fuzzer unit tests"
+    ${CMAKE_CURRENT_BINARY_DIR}/unit
+    DEPENDS ${LIBFUZZER_TEST_DEPS})
+  set_target_properties(check-fuzzer-unit PROPERTIES FOLDER "Compiler-RT Tests")
+  add_dependencies(check-fuzzer check-fuzzer-unit)
+endif()
+
+macro(test_fuzzer stdlib)
+  cmake_parse_arguments(TEST "" "" "DEPS" ${ARGN})
+  string(REPLACE "+" "x" stdlib_name ${stdlib})
+  string(REPLACE "-" ";" stdlib_list ${stdlib_name})
+  set(STDLIB_CAPITALIZED "")
+  foreach(part IN LISTS stdlib_list)
+    string(SUBSTRING ${part} 0 1 first_letter)
+    string(TOUPPER ${first_letter} first_letter)
+    string(REGEX REPLACE "^.(.*)" "${first_letter}\\1" part "${part}")
+    set(STDLIB_CAPITALIZED "${STDLIB_CAPITALIZED}${part}")
+  endforeach()
+  foreach(arch ${FUZZER_SUPPORTED_ARCH})
+    set(LIBFUZZER_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER})
+    get_test_cc_for_arch(${arch} LIBFUZZER_TEST_COMPILER LIBFUZZER_TEST_FLAGS)
+
+    set(LIBFUZZER_TEST_STDLIB ${stdlib})
+
+    string(TOUPPER ${arch} ARCH_UPPER_CASE)
+    set(CONFIG_NAME ${ARCH_UPPER_CASE}${STDLIB_CAPITALIZED}${OS_NAME}Config)
+
+    # LIT-based libFuzzer tests.
+    configure_lit_site_cfg(
+      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
+      )
+
+    add_lit_testsuite(check-fuzzer-${stdlib_name} "Running Fuzzer ${stdlib} tests"
+      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}
+      DEPENDS ${LIBFUZZER_TEST_DEPS})
+    if(TEST_DEPS)
+      add_dependencies(check-fuzzer-${stdlib_name} ${TEST_DEPS})
+    endif()
+    set_target_properties(check-fuzzer-${stdlib_name} PROPERTIES FOLDER "Compiler-RT Tests")
+    add_dependencies(check-fuzzer check-fuzzer-${stdlib_name})
+  endforeach()
+endmacro()
+
+test_fuzzer("default")
+if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
+  if(TARGET cxx_shared)
+    test_fuzzer("libc++" DEPS cxx_shared)
+  endif()
+  if(TARGET cxx_static)
+    test_fuzzer("static-libc++" DEPS cxx_static)
+  endif()
+endif()