[clang-tidy][NFC]remove deps of clang in clang tidy test (#116588)
[llvm-project.git] / mlir / test / lit.cfg.py
blob9b429b424d35753d6a86d3a6923df1469f1add4a
1 # -*- Python -*-
3 import os
4 import platform
5 import re
6 import subprocess
7 import tempfile
9 import lit.formats
10 import lit.util
12 from lit.llvm import llvm_config
13 from lit.llvm.subst import ToolSubst
14 from lit.llvm.subst import FindTool
16 # Configuration file for the 'lit' test runner.
18 # name: The name of this test suite.
19 config.name = "MLIR"
21 # TODO: Consolidate the logic for turning on the internal shell by default for all LLVM test suites.
22 # See https://github.com/llvm/llvm-project/issues/106636 for more details.
24 # We prefer the lit internal shell which provides a better user experience on failures
25 # unless the user explicitly disables it with LIT_USE_INTERNAL_SHELL=0 env var.
26 use_lit_shell = True
27 lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")
28 if lit_shell_env:
29 use_lit_shell = lit.util.pythonize_bool(lit_shell_env)
31 config.test_format = lit.formats.ShTest(execute_external=not use_lit_shell)
33 # suffixes: A list of file extensions to treat as test files.
34 config.suffixes = [
35 ".td",
36 ".mlir",
37 ".toy",
38 ".ll",
39 ".tc",
40 ".py",
41 ".yaml",
42 ".test",
43 ".pdll",
44 ".c",
47 # test_source_root: The root path where tests are located.
48 config.test_source_root = os.path.dirname(__file__)
50 # test_exec_root: The root path where tests should be run.
51 config.test_exec_root = os.path.join(config.mlir_obj_root, "test")
53 config.substitutions.append(("%PATH%", config.environment["PATH"]))
54 config.substitutions.append(("%shlibext", config.llvm_shlib_ext))
55 config.substitutions.append(("%llvm_src_root", config.llvm_src_root))
56 config.substitutions.append(("%mlir_src_root", config.mlir_src_root))
57 config.substitutions.append(("%host_cxx", config.host_cxx))
58 config.substitutions.append(("%host_cc", config.host_cc))
61 # Searches for a runtime library with the given name and returns the found path.
62 # Correctly handles the platforms shared library directory and naming conventions.
63 def find_runtime(name):
64 path = ""
65 for prefix in ["", "lib"]:
66 path = os.path.join(
67 config.llvm_shlib_dir, f"{prefix}{name}{config.llvm_shlib_ext}"
69 if os.path.isfile(path):
70 break
71 return path
74 # Searches for a runtime library with the given name and returns a tool
75 # substitution of the same name and the found path.
76 def add_runtime(name):
77 return ToolSubst(f"%{name}", find_runtime(name))
80 llvm_config.with_system_environment(["HOME", "INCLUDE", "LIB", "TMP", "TEMP"])
82 llvm_config.use_default_substitutions()
84 # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
85 # subdirectories contain auxiliary inputs for various tests in their parent
86 # directories.
87 config.excludes = [
88 "Inputs",
89 "CMakeLists.txt",
90 "README.txt",
91 "LICENSE.txt",
92 "lit.cfg.py",
93 "lit.site.cfg.py",
96 # Tweak the PATH to include the tools dir.
97 llvm_config.with_environment("PATH", config.mlir_tools_dir, append_path=True)
98 llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)
100 tool_dirs = [config.mlir_tools_dir, config.llvm_tools_dir]
101 tools = [
102 "mlir-tblgen",
103 "mlir-translate",
104 "mlir-lsp-server",
105 "mlir-capi-execution-engine-test",
106 "mlir-capi-ir-test",
107 "mlir-capi-irdl-test",
108 "mlir-capi-llvm-test",
109 "mlir-capi-pass-test",
110 "mlir-capi-pdl-test",
111 "mlir-capi-quant-test",
112 "mlir-capi-rewrite-test",
113 "mlir-capi-sparse-tensor-test",
114 "mlir-capi-transform-test",
115 "mlir-capi-transform-interpreter-test",
116 "mlir-capi-translation-test",
117 "mlir-cpu-runner",
118 add_runtime("mlir_runner_utils"),
119 add_runtime("mlir_c_runner_utils"),
120 add_runtime("mlir_async_runtime"),
121 add_runtime("mlir_float16_utils"),
122 "mlir-linalg-ods-yaml-gen",
123 "mlir-reduce",
124 "mlir-pdll",
125 "not",
128 if config.enable_vulkan_runner:
129 tools.extend([add_runtime("vulkan-runtime-wrappers")])
131 if config.enable_rocm_runner:
132 tools.extend([add_runtime("mlir_rocm_runtime")])
134 if config.enable_cuda_runner:
135 tools.extend([add_runtime("mlir_cuda_runtime")])
137 if config.enable_sycl_runner:
138 tools.extend([add_runtime("mlir_sycl_runtime")])
140 if config.enable_spirv_cpu_runner:
141 tools.extend([add_runtime("mlir_spirv_cpu_runtime")])
143 if config.mlir_run_arm_sve_tests or config.mlir_run_arm_sme_tests:
144 tools.extend([add_runtime("mlir_arm_runner_utils")])
146 if config.mlir_run_arm_sme_tests:
147 config.substitutions.append(
149 "%arm_sme_abi_shlib",
150 # Use passed Arm SME ABI routines, if not present default to stubs.
151 config.arm_sme_abi_routines_shlib or find_runtime("mlir_arm_sme_abi_stubs"),
155 # The following tools are optional
156 tools.extend(
158 ToolSubst("toyc-ch1", unresolved="ignore"),
159 ToolSubst("toyc-ch2", unresolved="ignore"),
160 ToolSubst("toyc-ch3", unresolved="ignore"),
161 ToolSubst("toyc-ch4", unresolved="ignore"),
162 ToolSubst("toyc-ch5", unresolved="ignore"),
163 ToolSubst("toyc-ch6", unresolved="ignore"),
164 ToolSubst("toyc-ch7", unresolved="ignore"),
165 ToolSubst("transform-opt-ch2", unresolved="ignore"),
166 ToolSubst("transform-opt-ch3", unresolved="ignore"),
167 ToolSubst("transform-opt-ch4", unresolved="ignore"),
168 ToolSubst("mlir-transform-opt", unresolved="ignore"),
169 ToolSubst("%mlir_lib_dir", config.mlir_lib_dir, unresolved="ignore"),
170 ToolSubst("%mlir_src_dir", config.mlir_src_root, unresolved="ignore"),
174 python_executable = config.python_executable
175 # Python configuration with sanitizer requires some magic preloading. This will only work on clang/linux.
176 # TODO: detect Darwin/Windows situation (or mark these tests as unsupported on these platforms).
177 if "asan" in config.available_features and "Linux" in config.host_os:
178 python_executable = f"LD_PRELOAD=$({config.host_cxx} -print-file-name=libclang_rt.asan-{config.host_arch}.so) {config.python_executable}"
179 # On Windows the path to python could contains spaces in which case it needs to be provided in quotes.
180 # This is the equivalent of how %python is setup in llvm/utils/lit/lit/llvm/config.py.
181 elif "Windows" in config.host_os:
182 python_executable = '"%s"' % (python_executable)
183 tools.extend(
185 ToolSubst("%PYTHON", python_executable, unresolved="ignore"),
189 if "MLIR_OPT_CHECK_IR_ROUNDTRIP" in os.environ:
190 tools.extend(
192 ToolSubst("mlir-opt", "mlir-opt --verify-roundtrip", unresolved="fatal"),
195 else:
196 tools.extend(["mlir-opt"])
198 llvm_config.add_tool_substitutions(tools, tool_dirs)
201 # FileCheck -enable-var-scope is enabled by default in MLIR test
202 # This option avoids to accidentally reuse variable across -LABEL match,
203 # it can be explicitly opted-in by prefixing the variable name with $
204 config.environment["FILECHECK_OPTS"] = "-enable-var-scope --allow-unused-prefixes=false"
206 # Add the python path for both the source and binary tree.
207 # Note that presently, the python sources come from the source tree and the
208 # binaries come from the build tree. This should be unified to the build tree
209 # by copying/linking sources to build.
210 if config.enable_bindings_python:
211 config.environment["PYTHONPATH"] = os.getenv("MLIR_LIT_PYTHONPATH", "")
212 llvm_config.with_environment(
213 "PYTHONPATH",
215 os.path.join(config.mlir_obj_root, "python_packages", "mlir_core"),
216 os.path.join(config.mlir_obj_root, "python_packages", "mlir_test"),
218 append_path=True,
221 if config.enable_assertions:
222 config.available_features.add("asserts")
223 else:
224 config.available_features.add("noasserts")
227 def have_host_jit_feature_support(feature_name):
228 mlir_cpu_runner_exe = lit.util.which("mlir-cpu-runner", config.mlir_tools_dir)
230 if not mlir_cpu_runner_exe:
231 return False
233 try:
234 mlir_cpu_runner_cmd = subprocess.Popen(
235 [mlir_cpu_runner_exe, "--host-supports-" + feature_name],
236 stdout=subprocess.PIPE,
238 except OSError:
239 print("could not exec mlir-cpu-runner")
240 return False
242 mlir_cpu_runner_out = mlir_cpu_runner_cmd.stdout.read().decode("ascii")
243 mlir_cpu_runner_cmd.wait()
245 return "true" in mlir_cpu_runner_out
248 if have_host_jit_feature_support("jit"):
249 config.available_features.add("host-supports-jit")
251 if config.run_nvptx_tests:
252 config.available_features.add("host-supports-nvptx")
254 if config.run_rocm_tests:
255 config.available_features.add("host-supports-amdgpu")
257 if config.arm_emulator_executable:
258 config.available_features.add("arm-emulator")