[libc] Switch to using the generic `<gpuintrin.h>` implementations (#121810)
[llvm-project.git] / compiler-rt / test / fuzzer / CMakeLists.txt
blob51021e2dc2d9955e0408bb707d21d57b493f1195
1 set(LIBFUZZER_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS} fuzzer)
2 if (COMPILER_RT_HAS_UBSAN)
3   list(APPEND LIBFUZZER_TEST_DEPS ubsan)
4 endif()
5 if (COMPILER_RT_HAS_ASAN)
6   list(APPEND LIBFUZZER_TEST_DEPS asan)
7 endif()
8 if (COMPILER_RT_HAS_MSAN)
9   list(APPEND LIBFUZZER_TEST_DEPS msan)
10 endif()
11 if (COMPILER_RT_HAS_DFSAN)
12   list(APPEND LIBFUZZER_TEST_DEPS dfsan)
13 endif()
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)
17   endif()
18 endif()
20 set(FUZZER_TEST_ARCH ${FUZZER_SUPPORTED_ARCH})
21 if (APPLE)
22   darwin_filter_host_archs(FUZZER_SUPPORTED_ARCH FUZZER_TEST_ARCH)
23 endif()
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}")
46   endforeach()
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
65       )
67     list(APPEND LIBFUZZER_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
68     if(TEST_DEPS)
69       list(APPEND LIBFUZZER_TEST_DEPS ${TEST_DEPS})
70     endif()
71   endforeach()
72 endmacro()
74 test_fuzzer("default")
75 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
76   if(LIBCXX_ENABLE_SHARED)
77     test_fuzzer("libc++" DEPS cxx_shared)
78   endif()
79   if(LIBCXX_ENABLE_STATIC)
80     test_fuzzer("static-libc++" DEPS cxx_static)
81   endif()
82 endif()
84 if(LIBFUZZER_TESTSUITES)
85   add_lit_testsuite(check-fuzzer "Running libFuzzer tests"
86     ${LIBFUZZER_TESTSUITES}
87     DEPENDS ${LIBFUZZER_TEST_DEPS})
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()