Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / fuzzer / CMakeLists.txt
blobf0ba087a1b3260365df754489f89b9e8e3d3c850
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)
6   endif()
7   if (COMPILER_RT_HAS_DFSAN)
8     list(APPEND LIBFUZZER_TEST_DEPS dfsan)
9   endif()
10   if(NOT APPLE AND COMPILER_RT_HAS_LLD AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
11     list(APPEND LIBFUZZER_TEST_DEPS lld)
12   endif()
13 endif()
15 set(FUZZER_TEST_ARCH ${FUZZER_SUPPORTED_ARCH})
16 if (APPLE)
17   darwin_filter_host_archs(FUZZER_SUPPORTED_ARCH FUZZER_TEST_ARCH)
18 endif()
20 if(COMPILER_RT_INCLUDE_TESTS)
21   list(APPEND LIBFUZZER_TEST_DEPS FuzzerUnitTests)
22   list(APPEND LIBFUZZER_TEST_DEPS FuzzedDataProviderUnitTests)
23 endif()
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)
33 endif()
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}")
45   endforeach()
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
64       )
66     list(APPEND LIBFUZZER_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
67     if(TEST_DEPS)
68       list(APPEND LIBFUZZER_TEST_DEPS ${TEST_DEPS})
69     endif()
70   endforeach()
71 endmacro()
73 test_fuzzer("default")
74 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
75   if(TARGET cxx_shared)
76     test_fuzzer("libc++" DEPS cxx_shared)
77   endif()
78   if(TARGET cxx_static)
79     test_fuzzer("static-libc++" DEPS cxx_static)
80   endif()
81 endif()
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")
88 endif()
90 if (APPLE)
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.
96       continue()
97     endif()
98     list_intersect(
99       FUZZER_TEST_${platform}_ARCHS
100       FUZZER_SUPPORTED_ARCH
101       DARWIN_${platform}_ARCHS
102     )
103     foreach(arch ${FUZZER_TEST_${platform}_ARCHS})
104       get_test_cflags_for_apple_platform(
105         "${platform}"
106         "${arch}"
107         LIBFUZZER_TEST_FLAGS
108         )
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
119         )
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})
124     endforeach()
125   endforeach()
126 endif()