[libc] Reduce the sizes of some math tests that take longest time.
[llvm-project.git] / libc / test / src / CMakeLists.txt
blob9e6c02c1f9f4b482784f942f8e497ec40c3f6721
1 function(add_fp_unittest name)
2   cmake_parse_arguments(
3     "MATH_UNITTEST"
4     "NEED_MPFR;HERMETIC_TEST_ONLY" # Optional arguments
5     "" # Single value arguments
6     "LINK_LIBRARIES" # 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   endif()
20   if(MATH_UNITTEST_NEED_MPFR)
21     if(MATH_UNITTEST_HERMETIC_TEST_ONLY)
22       message(FATAL "Hermetic math test cannot require MPFR.")
23     endif()
24     set(test_type UNIT_TEST_ONLY)
25     list(APPEND MATH_UNITTEST_LINK_LIBRARIES libcMPFRWrapper libc_math_test_utils -lmpfr -lgmp)
26   endif()
27   list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers)
29   add_libc_unittest(
30     ${name}
31     ${test_type}
32     LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}"
33     "${MATH_UNITTEST_UNPARSED_ARGUMENTS}"
34   )
35 endfunction(add_fp_unittest)
37 add_subdirectory(__support)
38 add_subdirectory(ctype)
39 add_subdirectory(errno)
40 add_subdirectory(fenv)
41 add_subdirectory(math)
42 add_subdirectory(string)
43 add_subdirectory(stdlib)
44 add_subdirectory(inttypes)
45 add_subdirectory(stdio)
46 add_subdirectory(wchar)
48 if(${LIBC_TARGET_OS} STREQUAL "linux")
49   add_subdirectory(fcntl)
50   add_subdirectory(sched)
51   add_subdirectory(sys)
52   add_subdirectory(termios)
53   add_subdirectory(unistd)
54 endif()
56 if(NOT LLVM_LIBC_FULL_BUILD)
57   return()
58 endif()
60 add_subdirectory(dirent)
61 add_subdirectory(assert)
62 add_subdirectory(network)
63 add_subdirectory(setjmp)
64 add_subdirectory(signal)
65 add_subdirectory(spawn)
66 add_subdirectory(time)
68 if(${LIBC_TARGET_OS} STREQUAL "linux")
69   add_subdirectory(pthread)
70 endif()
72 if(LLVM_RUNTIMES_BUILD OR LIBC_HDRGEN_EXE)
73   # The public API test below uses tablegen to generate the test
74   # source file. Since tablegen is not available during a runtimes
75   # build, we will skip the test.
76   # If a different libc-hdrgen binary is being used, then also we
77   # skip the api-test as we cannot generate the test source file.
78   return()
79 endif()
81 set(public_test ${CMAKE_CURRENT_BINARY_DIR}/public_api_test.cpp)
83 set(entrypoints_name_list "")
84 foreach(entry IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
85   get_target_property(entry_name ${entry} "ENTRYPOINT_NAME")
86   list(APPEND entrypoints_name_list ${entry_name})
87 endforeach()
89 # TODO: Remove these when they are added to the TableGen.
90 list(REMOVE_ITEM entrypoints_name_list "__assert_fail" "__errno_location")
91 list(TRANSFORM entrypoints_name_list PREPEND "-e=")
93 file(GLOB spec_files ${LIBC_SOURCE_DIR}/spec/*.td)
95 # Generate api test souce code.
96 add_custom_command(
97   OUTPUT ${public_test}
98   COMMAND $<TARGET_FILE:libc-prototype-testgen> -o ${public_test}
99           ${entrypoints_name_list}
100           -I ${LIBC_SOURCE_DIR}
101           ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td
103   DEPENDS ${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/api.td ${spec_files}
104           libc-prototype-testgen ${TARGET_PUBLIC_HEADERS}
105           ${LIBC_TARGET}
108 add_custom_target(libc-api-test)
109 add_dependencies(check-libc libc-api-test)
111 set(
112   allocator_entrypoints 
113     libc.src.stdlib.malloc
114     libc.src.stdlib.calloc
115     libc.src.stdlib.realloc
116     libc.src.stdlib.aligned_alloc
117     libc.src.stdlib.free
119 set(api-test-entrypoints ${TARGET_LLVMLIBC_ENTRYPOINTS})
120 list(REMOVE_ITEM api-test-entrypoints ${allocator_entrypoints})
121 add_integration_test(
122   api-test
123   SUITE
124     libc-api-test
125   SRCS
126     ${public_test}
127   DEPENDS
128     ${api-test-entrypoints}
131 if(COMPILER_RESOURCE_DIR AND LLVM_LIBC_ENABLE_LINTING)
132   add_custom_target(
133     libc-api-test-tidy
134     VERBATIM
135     COMMAND ${LLVM_LIBC_CLANG_TIDY} --system-headers
136       --checks=-*,llvmlibc-restrict-system-libc-headers
137       "--extra-arg=-resource-dir=${COMPILER_RESOURCE_DIR}"
138       --header-filter=.*
139       --warnings-as-errors=llvmlibc-*
140       "-config={CheckOptions: [{key: llvmlibc-restrict-system-libc-headers.Includes, value: '-*, linux/*, asm/*.h, asm-generic/*.h'}]}"
141       --quiet
142       -p ${PROJECT_BINARY_DIR}
143       ${public_test}
144     DEPENDS
145       clang-tidy ${public_test}
146   )
147   add_dependencies(libc-api-test libc-api-test-tidy)
148 endif()