1 set(LIBFUZZER_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS} fuzzer)
2 if (COMPILER_RT_HAS_UBSAN)
3 list(APPEND LIBFUZZER_TEST_DEPS ubsan)
5 if (COMPILER_RT_HAS_ASAN)
6 list(APPEND LIBFUZZER_TEST_DEPS asan)
8 if (COMPILER_RT_HAS_MSAN)
9 list(APPEND LIBFUZZER_TEST_DEPS msan)
11 if (COMPILER_RT_HAS_DFSAN)
12 list(APPEND LIBFUZZER_TEST_DEPS dfsan)
14 if (NOT COMPILER_RT_STANDALONE_BUILD)
15 if(NOT APPLE AND COMPILER_RT_HAS_LLD AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
16 list(APPEND LIBFUZZER_TEST_DEPS lld)
20 set(FUZZER_TEST_ARCH ${FUZZER_SUPPORTED_ARCH})
22 darwin_filter_host_archs(FUZZER_SUPPORTED_ARCH FUZZER_TEST_ARCH)
25 list(APPEND LIBFUZZER_TEST_DEPS FuzzerUnitTests)
26 list(APPEND LIBFUZZER_TEST_DEPS FuzzedDataProviderUnitTests)
28 set(LIBFUZZER_TESTSUITES)
30 # libFuzzer unit tests.
31 configure_lit_site_cfg(
32 ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in
33 ${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg.py)
34 list(APPEND LIBFUZZER_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit)
36 macro(test_fuzzer stdlib)
37 cmake_parse_arguments(TEST "" "" "DEPS" ${ARGN})
38 string(REPLACE "+" "x" stdlib_name ${stdlib})
39 string(REPLACE "-" ";" stdlib_list ${stdlib_name})
40 set(STDLIB_CAPITALIZED "")
41 foreach(part IN LISTS stdlib_list)
42 string(SUBSTRING ${part} 0 1 first_letter)
43 string(TOUPPER ${first_letter} first_letter)
44 string(REGEX REPLACE "^.(.*)" "${first_letter}\\1" part "${part}")
45 set(STDLIB_CAPITALIZED "${STDLIB_CAPITALIZED}${part}")
47 foreach(arch ${FUZZER_TEST_ARCH})
48 set(LIBFUZZER_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER})
49 get_test_cc_for_arch(${arch} LIBFUZZER_TEST_COMPILER LIBFUZZER_TEST_FLAGS)
51 set(LIBFUZZER_TEST_TARGET_ARCH ${arch})
52 set(LIBFUZZER_TEST_APPLE_PLATFORM "osx")
53 set(LIBFUZZER_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_osx_MIN_VER_FLAG}")
55 set(LIBFUZZER_TEST_STDLIB ${stdlib})
57 string(TOUPPER ${arch} ARCH_UPPER_CASE)
58 set(CONFIG_NAME ${ARCH_UPPER_CASE}${STDLIB_CAPITALIZED}${OS_NAME}Config)
59 set(LIBFUZZER_TEST_CONFIG_SUFFIX "-${arch}-${stdlib_name}-${OS_NAME}")
61 # LIT-based libFuzzer tests.
62 configure_lit_site_cfg(
63 ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
64 ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
67 list(APPEND LIBFUZZER_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
69 list(APPEND LIBFUZZER_TEST_DEPS ${TEST_DEPS})
74 test_fuzzer("default")
75 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
76 if(LIBCXX_ENABLE_SHARED)
77 test_fuzzer("libc++" DEPS cxx_shared)
79 if(LIBCXX_ENABLE_STATIC)
80 test_fuzzer("static-libc++" DEPS cxx_static)
84 if(LIBFUZZER_TESTSUITES)
85 add_lit_testsuite(check-fuzzer "Running libFuzzer tests"
86 ${LIBFUZZER_TESTSUITES}
87 DEPENDS ${LIBFUZZER_TEST_DEPS})
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})