Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libc / test / src / CMakeLists.txt
blobe121555bd60a9fbce7fbb4b33b5bec6d218277f0
1 function(add_fp_unittest name)
2   cmake_parse_arguments(
3     "MATH_UNITTEST"
4     "NEED_MPFR;UNIT_TEST_ONLY;HERMETIC_TEST_ONLY" # Optional arguments
5     "" # Single value arguments
6     "LINK_LIBRARIES;DEPENDS" # Multi-value arguments
7     ${ARGN}
8   )
10   if(MATH_UNITTEST_NEED_MPFR)
11     if(NOT LIBC_TESTS_CAN_USE_MPFR)
12       message(VERBOSE "Math test ${name} will be skipped as MPFR library is not available.")
13       return()
14     endif()
15   endif()
17   if(MATH_UNITTEST_HERMETIC_TEST_ONLY)
18     set(test_type HERMETIC_TEST_ONLY)
19   elseif(MATH_UNITTEST_UNIT_TEST_ONLY)
20     set(test_type UNIT_TEST_ONLY)
21   endif()
22   if(MATH_UNITTEST_NEED_MPFR)
23     if(MATH_UNITTEST_HERMETIC_TEST_ONLY)
24       message(FATAL_ERROR "Hermetic math test cannot require MPFR.")
25     endif()
26     set(test_type UNIT_TEST_ONLY)
27     list(APPEND MATH_UNITTEST_LINK_LIBRARIES libcMPFRWrapper -lmpfr -lgmp)
28     if(NOT(LIBC_TARGET_OS_IS_DARWIN))
29       # macOS does not have libatomic.
30       list(APPEND MATH_UNITTEST_LINK_LIBRARIES -latomic)
31     endif()
32   endif()
33   list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers)
35   set(deps libc.hdr.math_macros)
36   if(MATH_UNITTEST_DEPENDS)
37     list(APPEND deps ${MATH_UNITTEST_DEPENDS})
38   endif()
40   add_libc_test(
41     ${name}
42     ${test_type}
43     LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}"
44     "${MATH_UNITTEST_UNPARSED_ARGUMENTS}"
45     DEPENDS "${deps}"
46   )
47 endfunction(add_fp_unittest)
49 add_subdirectory(__support)
50 add_subdirectory(complex)
51 add_subdirectory(ctype)
52 add_subdirectory(errno)
53 add_subdirectory(fenv)
54 add_subdirectory(math)
55 add_subdirectory(search)
56 add_subdirectory(stdbit)
57 add_subdirectory(stdfix)
58 add_subdirectory(stdio)
59 add_subdirectory(stdlib)
60 add_subdirectory(string)
61 add_subdirectory(wchar)
63 # Depends on utilities in stdlib
64 add_subdirectory(inttypes)
66 if(${LIBC_TARGET_OS} STREQUAL "linux")
67   add_subdirectory(fcntl)
68   add_subdirectory(sched)
69   add_subdirectory(sys)
70   add_subdirectory(termios)
71   add_subdirectory(unistd)
72 endif()
74 if(NOT LLVM_LIBC_FULL_BUILD)
75   return()
76 endif()
78 add_subdirectory(assert)
79 add_subdirectory(compiler)
80 add_subdirectory(dirent)
81 add_subdirectory(network)
82 add_subdirectory(setjmp)
83 add_subdirectory(signal)
84 add_subdirectory(spawn)
85 add_subdirectory(time)
86 add_subdirectory(locale)
88 if(${LIBC_TARGET_OS} STREQUAL "linux")
89   add_subdirectory(pthread)
90 endif()
92 if(LLVM_RUNTIMES_BUILD OR LIBC_HDRGEN_EXE)
93   # The public API test below uses tablegen to generate the test
94   # source file. Since tablegen is not available during a runtimes
95   # build, we will skip the test.
96   # If a different libc-hdrgen binary is being used, then also we
97   # skip the api-test as we cannot generate the test source file.
98   return()
99 endif()
101 set(public_test ${CMAKE_CURRENT_BINARY_DIR}/public_api_test.cpp)
103 set(entrypoints_name_list "")
104 foreach(entry IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
105   get_target_property(entry_name ${entry} "ENTRYPOINT_NAME")
106   list(APPEND entrypoints_name_list ${entry_name})
107 endforeach()
109 # TODO: Remove these when they are added to the TableGen.
110 list(REMOVE_ITEM entrypoints_name_list "__assert_fail" "__errno_location")
111 list(TRANSFORM entrypoints_name_list PREPEND "-e=")
113 file(GLOB spec_files ${LIBC_SOURCE_DIR}/spec/*.td)
115 # Generate api test souce code.
116 add_custom_command(
117   OUTPUT ${public_test}
118   COMMAND $<TARGET_FILE:libc-prototype-testgen> -o ${public_test}
119           ${entrypoints_name_list}
120           -I ${LIBC_SOURCE_DIR}
121           ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
123   DEPENDS ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td ${spec_files}
124           libc-prototype-testgen ${TARGET_PUBLIC_HEADERS}
125           ${LIBC_TARGET}
128 add_custom_target(libc-api-test)
129 add_dependencies(check-libc libc-api-test)
131 set(
132   allocator_entrypoints
133     libc.src.stdlib.malloc
134     libc.src.stdlib.calloc
135     libc.src.stdlib.realloc
136     libc.src.stdlib.aligned_alloc
137     libc.src.stdlib.free
139 set(api-test-entrypoints ${TARGET_LLVMLIBC_ENTRYPOINTS})
140 list(REMOVE_ITEM api-test-entrypoints ${allocator_entrypoints})
141 add_integration_test(
142   api-test
143   SUITE
144     libc-api-test
145   SRCS
146     ${public_test}
147   DEPENDS
148     ${api-test-entrypoints}
151 if(COMPILER_RESOURCE_DIR AND LLVM_LIBC_ENABLE_LINTING)
152   add_custom_target(
153     libc-api-test-tidy
154     VERBATIM
155     COMMAND ${LLVM_LIBC_CLANG_TIDY} --system-headers
156       --checks=-*,llvmlibc-restrict-system-libc-headers
157       "--extra-arg=-resource-dir=${COMPILER_RESOURCE_DIR}"
158       --header-filter=.*
159       --warnings-as-errors=llvmlibc-*
160       "-config={CheckOptions: [{key: llvmlibc-restrict-system-libc-headers.Includes, value: '-*, linux/*, asm/*.h, asm-generic/*.h'}]}"
161       --quiet
162       -p ${PROJECT_BINARY_DIR}
163       ${public_test}
164     DEPENDS
165       clang-tidy ${public_test}
166   )
167   add_dependencies(libc-api-test libc-api-test-tidy)
168 endif()