1# Test runner infrastructure for Clang. This configures the Clang test trees
2# for use by Lit, and delegates to LLVM's lit test handlers.
3
4if (CMAKE_CFG_INTDIR STREQUAL ".")
5  set(LLVM_BUILD_MODE ".")
6else ()
7  set(LLVM_BUILD_MODE "%(build_mode)s")
8endif ()
9
10string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
11
12llvm_canonicalize_cmake_booleans(
13  CLANG_BUILD_EXAMPLES
14  CLANG_ENABLE_ARCMT
15  CLANG_ENABLE_STATIC_ANALYZER
16  CLANG_SPAWN_CC1
17  ENABLE_BACKTRACES
18  LLVM_ENABLE_NEW_PASS_MANAGER
19  LLVM_ENABLE_ZLIB
20  LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
21  LLVM_ENABLE_PLUGINS
22  LLVM_ENABLE_THREADS)
23
24configure_lit_site_cfg(
25  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
26  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
27  MAIN_CONFIG
28  ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
29  PATHS
30  "LLVM_SOURCE_DIR"
31  "LLVM_BINARY_DIR"
32  "LLVM_TOOLS_DIR"
33  "LLVM_LIBS_DIR"
34  "SHLIBDIR"
35  "LLVM_LIT_TOOLS_DIR"
36  "CLANG_BINARY_DIR"
37  "CLANG_SOURCE_DIR"
38  "CLANG_TOOLS_DIR"
39  )
40
41configure_lit_site_cfg(
42  ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
43  ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py
44  MAIN_CONFIG
45  ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.cfg.py
46  PATHS
47  "LLVM_SOURCE_DIR"
48  "LLVM_BINARY_DIR"
49  "LLVM_TOOLS_DIR"
50  "LLVM_LIBS_DIR"
51  "CLANG_BINARY_DIR"
52  "SHLIBDIR"
53  )
54
55option(CLANG_TEST_USE_VG "Run Clang tests under Valgrind" OFF)
56if(CLANG_TEST_USE_VG)
57  set(CLANG_TEST_EXTRA_ARGS ${CLANG_TEST_EXTRA_ARGS} "--vg")
58endif ()
59
60list(APPEND CLANG_TEST_DEPS
61  apinotes-test
62  c-index-test
63  clang
64  clang-resource-headers
65  clang-format
66  clang-tblgen
67  clang-offload-bundler
68  clang-import-test
69  clang-rename
70  clang-refactor
71  clang-diff
72  clang-scan-deps
73  diagtool
74  hmaptool
75  )
76
77if(CLANG_ENABLE_STATIC_ANALYZER)
78  list(APPEND CLANG_TEST_DEPS
79    clang-check
80    clang-extdef-mapping
81    )
82endif()
83
84if (CLANG_ENABLE_ARCMT)
85  list(APPEND CLANG_TEST_DEPS
86    arcmt-test
87    c-arcmt-test
88  )
89endif ()
90
91if (CLANG_BUILD_EXAMPLES)
92  list(APPEND CLANG_TEST_DEPS
93    Attribute
94    AnnotateFunctions
95    CallSuperAttr
96    clang-interpreter
97    PrintFunctionNames
98    )
99endif ()
100
101set(CLANG_TEST_PARAMS
102  USE_Z3_SOLVER=0
103  )
104
105if( NOT CLANG_BUILT_STANDALONE )
106  list(APPEND CLANG_TEST_DEPS
107    llvm-config
108    FileCheck count not
109    llc
110    llvm-as
111    llvm-bcanalyzer
112    llvm-cat
113    llvm-cxxfilt
114    llvm-dis
115    llvm-dwarfdump
116    llvm-ifs
117    llvm-lto2
118    llvm-modextract
119    llvm-nm
120    llvm-objcopy
121    llvm-objdump
122    llvm-profdata
123    llvm-readelf
124    llvm-readobj
125    llvm-symbolizer
126    opt
127    split-file
128    yaml2obj
129    )
130
131  if(TARGET llvm-lto)
132    list(APPEND CLANG_TEST_DEPS llvm-lto)
133  endif()
134endif()
135
136if (CLANG_ENABLE_STATIC_ANALYZER)
137  if (LLVM_ENABLE_PLUGINS)
138    list(APPEND CLANG_TEST_DEPS
139      SampleAnalyzerPlugin
140      CheckerDependencyHandlingAnalyzerPlugin
141      CheckerOptionHandlingAnalyzerPlugin
142      )
143  endif()
144endif()
145
146# Copy gen_ast_dump_json_test.py to the clang build dir. This allows invoking
147# it without having to pass the --clang= argument
148configure_file(AST/gen_ast_dump_json_test.py
149  ${CLANG_BINARY_DIR}/bin/gen_ast_dump_json_test.py COPYONLY)
150
151add_custom_target(clang-test-depends DEPENDS ${CLANG_TEST_DEPS})
152set_target_properties(clang-test-depends PROPERTIES FOLDER "Clang tests")
153
154add_lit_testsuite(check-clang "Running the Clang regression tests"
155  ${CMAKE_CURRENT_BINARY_DIR}
156  #LIT ${LLVM_LIT}
157  PARAMS ${CLANG_TEST_PARAMS}
158  DEPENDS ${CLANG_TEST_DEPS}
159  ARGS ${CLANG_TEST_EXTRA_ARGS}
160  )
161set_target_properties(check-clang PROPERTIES FOLDER "Clang tests")
162
163add_lit_testsuites(CLANG ${CMAKE_CURRENT_SOURCE_DIR}
164  PARAMS ${CLANG_TEST_PARAMS}
165  DEPENDS ${CLANG_TEST_DEPS}
166)
167
168# Add a legacy target spelling: clang-test
169add_custom_target(clang-test)
170add_dependencies(clang-test check-clang)
171set_target_properties(clang-test PROPERTIES FOLDER "Clang tests")
172
173# FIXME: This logic can be removed once all buildbots have moved
174# debuginfo-test from clang/test to llvm/projects or monorepo.
175if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/debuginfo-tests)
176  message(WARNING "Including debuginfo-tests in clang/test is deprecated.  Move to llvm/projects or use monorepo.")
177  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/debuginfo-tests/CMakeLists.txt)
178    add_subdirectory(debuginfo-tests)
179  endif()
180endif()
181