1 set(LIBFUZZER_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
2 if (NOT COMPILER_RT_STANDALONE_BUILD)
3 list(APPEND LIBFUZZER_TEST_DEPS fuzzer asan ubsan)
4 if (COMPILER_RT_HAS_MSAN)
5 list(APPEND LIBFUZZER_TEST_DEPS msan)
7 if (COMPILER_RT_HAS_DFSAN)
8 list(APPEND LIBFUZZER_TEST_DEPS dfsan)
10 if(NOT APPLE AND COMPILER_RT_HAS_LLD AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
11 list(APPEND LIBFUZZER_TEST_DEPS lld)
15 set(FUZZER_TEST_ARCH ${FUZZER_SUPPORTED_ARCH})
17 darwin_filter_host_archs(FUZZER_SUPPORTED_ARCH FUZZER_TEST_ARCH)
20 if(COMPILER_RT_INCLUDE_TESTS)
21 list(APPEND LIBFUZZER_TEST_DEPS FuzzerUnitTests)
22 list(APPEND LIBFUZZER_TEST_DEPS FuzzedDataProviderUnitTests)
25 set(LIBFUZZER_TESTSUITES)
27 if(COMPILER_RT_INCLUDE_TESTS)
28 # libFuzzer unit tests.
29 configure_lit_site_cfg(
30 ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in
31 ${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg.py)
32 list(APPEND LIBFUZZER_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit)
35 macro(test_fuzzer stdlib)
36 cmake_parse_arguments(TEST "" "" "DEPS" ${ARGN})
37 string(REPLACE "+" "x" stdlib_name ${stdlib})
38 string(REPLACE "-" ";" stdlib_list ${stdlib_name})
39 set(STDLIB_CAPITALIZED "")
40 foreach(part IN LISTS stdlib_list)
41 string(SUBSTRING ${part} 0 1 first_letter)
42 string(TOUPPER ${first_letter} first_letter)
43 string(REGEX REPLACE "^.(.*)" "${first_letter}\\1" part "${part}")
44 set(STDLIB_CAPITALIZED "${STDLIB_CAPITALIZED}${part}")
46 foreach(arch ${FUZZER_TEST_ARCH})
47 set(LIBFUZZER_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER})
48 get_test_cc_for_arch(${arch} LIBFUZZER_TEST_COMPILER LIBFUZZER_TEST_FLAGS)
50 set(LIBFUZZER_TEST_TARGET_ARCH ${arch})
51 set(LIBFUZZER_TEST_APPLE_PLATFORM "osx")
52 set(LIBFUZZER_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_osx_MIN_VER_FLAG}")
54 set(LIBFUZZER_TEST_STDLIB ${stdlib})
56 string(TOUPPER ${arch} ARCH_UPPER_CASE)
57 set(CONFIG_NAME ${ARCH_UPPER_CASE}${STDLIB_CAPITALIZED}${OS_NAME}Config)
58 set(LIBFUZZER_TEST_CONFIG_SUFFIX "-${arch}-${stdlib_name}-${OS_NAME}")
60 # LIT-based libFuzzer tests.
61 configure_lit_site_cfg(
62 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
63 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
66 list(APPEND LIBFUZZER_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
68 list(APPEND LIBFUZZER_TEST_DEPS ${TEST_DEPS})
73 test_fuzzer("default")
74 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
76 test_fuzzer("libc++" DEPS cxx_shared)
79 test_fuzzer("static-libc++" DEPS cxx_static)
83 if(LIBFUZZER_TESTSUITES)
84 add_lit_testsuite(check-fuzzer "Running libFuzzer tests"
85 ${LIBFUZZER_TESTSUITES}
86 DEPENDS ${LIBFUZZER_TEST_DEPS})
87 set_target_properties(check-fuzzer PROPERTIES FOLDER "Compiler-RT Tests")
91 set(LIBFUZZER_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER})
92 set(FUZZER_APPLE_PLATFORMS ${FUZZER_SUPPORTED_OS})
93 foreach(platform ${FUZZER_APPLE_PLATFORMS})
94 if ("${platform}" STREQUAL "osx")
95 # Skip macOS because it's handled by the code above that builds tests for the host machine.
99 FUZZER_TEST_${platform}_ARCHS
100 FUZZER_SUPPORTED_ARCH
101 DARWIN_${platform}_ARCHS
103 foreach(arch ${FUZZER_TEST_${platform}_ARCHS})
104 get_test_cflags_for_apple_platform(
109 string(TOUPPER "${arch}" ARCH_UPPER_CASE)
110 get_capitalized_apple_platform("${platform}" PLATFORM_CAPITALIZED)
111 set(CONFIG_NAME "${PLATFORM_CAPITALIZED}${ARCH_UPPER_CASE}Config")
112 set(LIBFUZZER_TEST_CONFIG_SUFFIX "-${arch}-${platform}")
113 set(LIBFUZZER_TEST_APPLE_PLATFORM "${platform}")
114 set(LIBFUZZER_TEST_TARGET_ARCH "${arch}")
115 set(LIBFUZZER_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_${platform}_MIN_VER_FLAG}")
116 configure_lit_site_cfg(
117 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
118 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
120 add_lit_testsuite(check-fuzzer-${platform}-${arch} "libFuzzer ${platform} ${arch} tests"
121 EXCLUDE_FROM_CHECK_ALL
122 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
123 DEPENDS ${LIBFUZZER_TEST_DEPS})