xref: /llvm-project/libc/test/include/CMakeLists.txt (revision 5e4b41c1d534c90a4591b840a4f1b2f7bf59279f)
1add_custom_target(libc_include_tests)
2add_dependencies(check-libc libc_include_tests)
3
4add_libc_test(
5  assert_test
6  SUITE
7    libc_include_tests
8  SRCS
9    assert_test.cpp
10  DEPENDS
11    libc.include.llvm-libc-macros.assert_macros
12)
13
14add_libc_test(
15  complex_test
16  SUITE
17    libc_include_tests
18  SRCS
19    complex_test.cpp
20  DEPENDS
21    libc.include.llvm-libc-macros.complex_macros
22)
23
24add_libc_test(
25  sys_queue_test
26  SUITE
27    libc_include_tests
28  SRCS
29    sys/queue_test.cpp
30  DEPENDS
31    libc.include.llvm-libc-macros.sys_queue_macros
32    libc.src.__support.char_vector
33    libc.src.__support.CPP.string
34  COMPILE_OPTIONS
35    # This is needed because the __containerof macro uses statement expression.
36    -Wno-gnu-statement-expression-from-macro-expansion
37)
38
39add_libc_test(
40  stdbit_test
41  SUITE
42    libc_include_tests
43  HDRS
44    stdbit_stub.h
45  SRCS
46    stdbit_test.cpp
47  DEPENDS
48    libc.include.llvm-libc-macros.stdbit_macros
49    libc.include.llvm_libc_common_h
50    libc.include.stdbit
51    # Intentionally do not depend on libc.src.stdbit.*. The include test is
52    # simply testing the macros provided by stdbit.h, not the implementation
53    # of the underlying functions which the type generic macros may dispatch
54    # to.
55)
56add_libc_test(
57  stdbit_c_test
58  C_TEST
59  UNIT_TEST_ONLY
60  SUITE
61    libc_include_tests
62  HDRS
63    stdbit_stub.h
64  SRCS
65    stdbit_test.c
66  COMPILE_OPTIONS
67    -Wall
68    -Werror
69  DEPENDS
70    libc.include.llvm-libc-macros.stdbit_macros
71    libc.include.llvm_libc_common_h
72    libc.include.stdbit
73    libc.src.assert.__assert_fail
74    # Intentionally do not depend on libc.src.stdbit.*. The include test is
75    # simply testing the macros provided by stdbit.h, not the implementation
76    # of the underlying functions which the type generic macros may dispatch
77    # to.
78)
79
80add_libc_test(
81  stdckdint_test
82  SUITE
83    libc_include_tests
84  SRCS
85    stdckdint_test.cpp
86  DEPENDS
87    libc.include.llvm-libc-macros.stdckdint_macros
88)
89
90add_libc_test(
91  issubnormal_test
92  SUITE
93    libc_include_tests
94  SRCS
95    issubnormal_test.cpp
96  DEPENDS
97    libc.include.llvm-libc-macros.math_function_macros
98)
99
100add_libc_test(
101  issubnormalf_test
102  SUITE
103    libc_include_tests
104  SRCS
105    issubnormalf_test.cpp
106  DEPENDS
107    libc.include.llvm-libc-macros.math_function_macros
108)
109
110add_libc_test(
111  issubnormall_test
112  SUITE
113    libc_include_tests
114  SRCS
115    issubnormall_test.cpp
116  DEPENDS
117    libc.include.llvm-libc-macros.math_function_macros
118)
119
120add_libc_test(
121  isnormal_test
122  SUITE
123    libc_include_tests
124  SRCS
125    isnormal_test.cpp
126  DEPENDS
127    libc.include.llvm-libc-macros.math_function_macros
128)
129
130add_libc_test(
131  isnormalf_test
132  SUITE
133    libc_include_tests
134  SRCS
135    isnormalf_test.cpp
136  DEPENDS
137    libc.include.llvm-libc-macros.math_function_macros
138)
139
140add_libc_test(
141  isnormall_test
142  SUITE
143    libc_include_tests
144  SRCS
145    isnormall_test.cpp
146  DEPENDS
147    libc.include.llvm-libc-macros.math_function_macros
148)
149
150add_libc_test(
151  fpclassify_test
152  SUITE
153    libc_include_tests
154  SRCS
155    fpclassify_test.cpp
156  DEPENDS
157    libc.include.llvm-libc-macros.math_function_macros
158)
159
160add_libc_test(
161  fpclassifyf_test
162  SUITE
163    libc_include_tests
164  SRCS
165    fpclassifyf_test.cpp
166  DEPENDS
167    libc.include.llvm-libc-macros.math_function_macros
168)
169
170add_libc_test(
171  fpclassifyl_test
172  SUITE
173    libc_include_tests
174  SRCS
175    fpclassifyl_test.cpp
176  DEPENDS
177    libc.include.llvm-libc-macros.math_function_macros
178)
179
180add_libc_test(
181  iszero_test
182  SUITE
183    libc_include_tests
184  SRCS
185    iszero_test.cpp
186  DEPENDS
187    libc.include.llvm-libc-macros.math_function_macros
188)
189
190add_libc_test(
191  iszerof_test
192  SUITE
193    libc_include_tests
194  SRCS
195    iszerof_test.cpp
196  DEPENDS
197    libc.include.llvm-libc-macros.math_function_macros
198)
199
200add_libc_test(
201  iszerol_test
202  SUITE
203    libc_include_tests
204  SRCS
205    iszerol_test.cpp
206  DEPENDS
207    libc.include.llvm-libc-macros.math_function_macros
208)
209
210add_libc_test(
211  signbit_test
212  SUITE
213    libc_include_tests
214  SRCS
215    signbit_test.cpp
216  DEPENDS
217    libc.include.llvm-libc-macros.math_function_macros
218)
219
220add_libc_test(
221  signbitf_test
222  SUITE
223    libc_include_tests
224  SRCS
225    signbitf_test.cpp
226  DEPENDS
227    libc.include.llvm-libc-macros.math_function_macros
228)
229
230add_libc_test(
231  signbitl_test
232  SUITE
233    libc_include_tests
234  SRCS
235    signbitl_test.cpp
236  DEPENDS
237    libc.include.llvm-libc-macros.math_function_macros
238)
239
240add_libc_test(
241  isnan_test
242  SUITE
243    libc_include_tests
244  SRCS
245    isnan_test.cpp
246  DEPENDS
247    libc.include.llvm-libc-macros.math_function_macros
248)
249
250add_libc_test(
251  isnanf_test
252  SUITE
253    libc_include_tests
254  SRCS
255    isnanf_test.cpp
256  DEPENDS
257    libc.include.llvm-libc-macros.math_function_macros
258)
259
260add_libc_test(
261  isnanl_test
262  SUITE
263    libc_include_tests
264  SRCS
265    isnanl_test.cpp
266  DEPENDS
267    libc.include.llvm-libc-macros.math_function_macros
268)
269
270add_libc_test(
271  isinf_test
272  SUITE
273    libc_include_tests
274  SRCS
275    isinf_test.cpp
276  DEPENDS
277    libc.include.llvm-libc-macros.math_function_macros
278)
279
280add_libc_test(
281  isinff_test
282  SUITE
283    libc_include_tests
284  SRCS
285    isinff_test.cpp
286  DEPENDS
287    libc.include.llvm-libc-macros.math_function_macros
288)
289
290add_libc_test(
291  isinfl_test
292  SUITE
293    libc_include_tests
294  SRCS
295    isinfl_test.cpp
296  DEPENDS
297    libc.include.llvm-libc-macros.math_function_macros
298)
299
300add_libc_test(
301  isfinite_test
302  SUITE
303    libc_include_tests
304  SRCS
305    isfinite_test.cpp
306  DEPENDS
307    libc.include.llvm-libc-macros.math_function_macros
308)
309
310add_libc_test(
311  isfinitef_test
312  SUITE
313    libc_include_tests
314  SRCS
315    isfinitef_test.cpp
316  DEPENDS
317    libc.include.llvm-libc-macros.math_function_macros
318)
319
320add_libc_test(
321  isfinitel_test
322  SUITE
323    libc_include_tests
324  SRCS
325    isfinitel_test.cpp
326  DEPENDS
327    libc.include.llvm-libc-macros.math_function_macros
328)
329
330add_libc_test(
331  signbit_c_test
332  C_TEST
333  UNIT_TEST_ONLY
334  SUITE
335    libc_include_tests
336  SRCS
337    signbit_test.c
338  COMPILE_OPTIONS
339    -Wall
340    -Werror
341  DEPENDS
342    libc.include.llvm-libc-macros.math_function_macros
343)
344
345add_libc_test(
346  isnan_c_test
347  C_TEST
348  UNIT_TEST_ONLY
349  SUITE
350    libc_include_tests
351  SRCS
352    isnan_test.c
353  COMPILE_OPTIONS
354    -Wall
355    -Werror
356  DEPENDS
357    libc.include.llvm-libc-macros.math_function_macros
358)
359
360add_libc_test(
361  isnormal_c_test
362  C_TEST
363  UNIT_TEST_ONLY
364  SUITE
365    libc_include_tests
366  SRCS
367    isnormal_test.c
368  COMPILE_OPTIONS
369    -Wall
370    -Werror
371  DEPENDS
372    libc.include.llvm-libc-macros.math_function_macros
373)
374
375# TODO(https://github.com/llvm/llvm-project/issues/114618): fix linkage failures
376# add_libc_test(
377#   issignaling_c_test
378#   C_TEST
379#   UNIT_TEST_ONLY
380#   SUITE
381#     libc_include_tests
382#   SRCS
383#     issignaling_test.c
384#   COMPILE_OPTIONS
385#     -Wall
386#     -Werror
387#   DEPENDS
388#     libc.include.llvm-libc-macros.math_function_macros
389#     libc.src.math.issignaling
390#     libc.src.math.issignalingf
391#     libc.src.math.issignalingl
392# )
393
394# add_libc_test(
395#   iscanonical_c_test
396#   C_TEST
397#   UNIT_TEST_ONLY
398#   SUITE
399#     libc_include_tests
400#   SRCS
401#     iscanonical_test.c
402#   COMPILE_OPTIONS
403#     -Wall
404#     -Werror
405#   DEPENDS
406#     libc.include.llvm-libc-macros.math_function_macros
407#     libc.src.math.iscanonical
408#     libc.src.math.iscanonicalf
409#     libc.src.math.iscanonicall
410# )
411
412add_libc_test(
413  isinf_c_test
414  C_TEST
415  UNIT_TEST_ONLY
416  SUITE
417    libc_include_tests
418  SRCS
419    isinf_test.c
420  COMPILE_OPTIONS
421    -Wall
422    -Werror
423  DEPENDS
424    libc.include.llvm-libc-macros.math_function_macros
425)
426
427add_libc_test(
428  isfinite_c_test
429  C_TEST
430  UNIT_TEST_ONLY
431  SUITE
432    libc_include_tests
433  SRCS
434    isfinite_test.c
435  COMPILE_OPTIONS
436    -Wall
437    -Werror
438  DEPENDS
439    libc.include.llvm-libc-macros.math_function_macros
440)
441
442add_libc_test(
443  issubnormal_c_test
444  C_TEST
445  UNIT_TEST_ONLY
446  SUITE
447    libc_include_tests
448  SRCS
449    issubnormal_test.c
450  COMPILE_OPTIONS
451    -Wall
452    -Werror
453  DEPENDS
454    libc.include.llvm-libc-macros.math_function_macros
455)
456
457add_libc_test(
458  fpclassify_c_test
459  C_TEST
460  UNIT_TEST_ONLY
461  SUITE
462    libc_include_tests
463  SRCS
464    fpclassify_test.c
465  COMPILE_OPTIONS
466    -Wall
467    -Werror
468  DEPENDS
469    libc.include.llvm-libc-macros.math_function_macros
470)
471
472add_libc_test(
473  iszero_c_test
474  C_TEST
475  UNIT_TEST_ONLY
476  SUITE
477    libc_include_tests
478  SRCS
479    iszero_test.c
480  COMPILE_OPTIONS
481    -Wall
482    -Werror
483  DEPENDS
484    libc.include.llvm-libc-macros.math_function_macros
485)
486
487# Test `#include <...>` of each header in each available language mode.
488# This is gated on -DLLVM_LIBC_BUILD_HEADER_TESTS=ON until all the bugs
489# in headers are fixed so the tests all compile.
490set(TEST_STDC_VERSIONS 89;99;11;17;23)
491set(TEST_STDCXX_VERSIONS 03;11;14;17;20;23;26)
492
493function(add_header_test target_name source_file deps std_mode)
494  if(LLVM_LIBC_BUILD_HEADER_TESTS)
495    add_libc_test(
496      ${target_name}
497      C_TEST
498      HERMETIC_TEST_ONLY
499      SUITE
500	libc_include_tests
501      SRCS
502	${source_file}
503      COMPILE_OPTIONS
504	-Werror
505	-Wsystem-headers
506	-Wall
507	-Wextra
508	-std=${std_mode}
509      DEPENDS
510	${deps}
511    )
512  endif()
513endfunction()
514
515foreach(target ${TARGET_PUBLIC_HEADERS})
516  string(REPLACE "libc.include." "" header ${target})
517  get_target_property(HEADER_NAME ${target} HEADER_NAME)
518
519  set(test_stdc_file "${CMAKE_CURRENT_BINARY_DIR}/${header}_test.c")
520  configure_file(header-test-template.c ${test_stdc_file} @ONLY)
521  foreach(stdc_version ${TEST_STDC_VERSIONS})
522    add_header_test(
523      "${header}_c${stdc_version}_test"
524      ${test_stdc_file}
525      ${target}
526      "c${stdc_version}"
527    )
528    add_header_test(
529      "${header}_gnu${stdc_version}_test"
530      ${test_stdc_file}
531      ${target}
532      "gnu${stdc_version}"
533    )
534  endforeach()
535
536  set(test_stdcxx_file "${CMAKE_CURRENT_BINARY_DIR}/${header}_test.cpp")
537  configure_file(header-test-template.c ${test_stdcxx_file} @ONLY)
538  foreach(stdcxx_version ${TEST_STDCXX_VERSIONS})
539    add_header_test(
540      "${header}_cpp${stdcxx_version}_test"
541      ${test_stdcxx_file}
542      ${target}
543      "c++${stdcxx_version}"
544    )
545    add_header_test(
546      "${header}_gnucpp${stdcxx_version}_test"
547      ${test_stdcxx_file}
548      ${target}
549      "gnu++${stdcxx_version}"
550    )
551  endforeach()
552endforeach()
553