[AMDGPU] Add True16 register classes.
[llvm-project.git] / lldb / test / API / lit.cfg.py
blobc306c5b3c0ec0c619287edc526472d0a0c43c6e7
1 # -*- Python -*-
3 # Configuration file for the 'lit' test runner.
5 import os
6 import platform
7 import shlex
8 import shutil
9 import subprocess
11 import lit.formats
13 # name: The name of this test suite.
14 config.name = "lldb-api"
16 # suffixes: A list of file extensions to treat as test files.
17 config.suffixes = [".py"]
19 # test_source_root: The root path where tests are located.
20 config.test_source_root = os.path.dirname(__file__)
22 # test_exec_root: The root path where tests should be run.
23 config.test_exec_root = os.path.join(config.lldb_obj_root, "test", "API")
26 def mkdir_p(path):
27 import errno
29 try:
30 os.makedirs(path)
31 except OSError as e:
32 if e.errno != errno.EEXIST:
33 raise
34 if not os.path.isdir(path):
35 raise OSError(errno.ENOTDIR, "%s is not a directory" % path)
38 def find_sanitizer_runtime(name):
39 resource_dir = (
40 subprocess.check_output([config.cmake_cxx_compiler, "-print-resource-dir"])
41 .decode("utf-8")
42 .strip()
44 return os.path.join(resource_dir, "lib", "darwin", name)
47 def find_shlibpath_var():
48 if platform.system() in ["Linux", "FreeBSD", "NetBSD", "SunOS"]:
49 yield "LD_LIBRARY_PATH"
50 elif platform.system() == "Darwin":
51 yield "DYLD_LIBRARY_PATH"
52 elif platform.system() == "Windows":
53 yield "PATH"
56 # On macOS, we can't do the DYLD_INSERT_LIBRARIES trick with a shim python
57 # binary as the ASan interceptors get loaded too late. Also, when SIP is
58 # enabled, we can't inject libraries into system binaries at all, so we need a
59 # copy of the "real" python to work with.
60 def find_python_interpreter():
61 # Avoid doing any work if we already copied the binary.
62 copied_python = os.path.join(config.lldb_build_directory, "copied-python")
63 if os.path.isfile(copied_python):
64 return copied_python
66 # Find the "real" python binary.
67 real_python = (
68 subprocess.check_output(
70 config.python_executable,
71 os.path.join(
72 os.path.dirname(os.path.realpath(__file__)),
73 "get_darwin_real_python.py",
77 .decode("utf-8")
78 .strip()
81 shutil.copy(real_python, copied_python)
83 # Now make sure the copied Python works. The Python in Xcode has a relative
84 # RPATH and cannot be copied.
85 try:
86 # We don't care about the output, just make sure it runs.
87 subprocess.check_output([copied_python, "-V"], stderr=subprocess.STDOUT)
88 except subprocess.CalledProcessError:
89 # The copied Python didn't work. Assume we're dealing with the Python
90 # interpreter in Xcode. Given that this is not a system binary SIP
91 # won't prevent us form injecting the interceptors so we get away with
92 # not copying the executable.
93 os.remove(copied_python)
94 return real_python
96 # The copied Python works.
97 return copied_python
100 def is_configured(attr):
101 """Return the configuration attribute if it exists and None otherwise.
103 This allows us to check if the attribute exists before trying to access it."""
104 return getattr(config, attr, None)
107 def delete_module_cache(path):
108 """Clean the module caches in the test build directory.
110 This is necessary in an incremental build whenever clang changes underneath,
111 so doing it once per lit.py invocation is close enough."""
112 if os.path.isdir(path):
113 lit_config.note("Deleting module cache at %s." % path)
114 shutil.rmtree(path)
117 if is_configured("llvm_use_sanitizer"):
118 if "Address" in config.llvm_use_sanitizer:
119 config.environment["ASAN_OPTIONS"] = "detect_stack_use_after_return=1"
120 if "Darwin" in config.host_os:
121 config.environment["DYLD_INSERT_LIBRARIES"] = find_sanitizer_runtime(
122 "libclang_rt.asan_osx_dynamic.dylib"
125 if "Thread" in config.llvm_use_sanitizer:
126 config.environment["TSAN_OPTIONS"] = "halt_on_error=1"
127 if "Darwin" in config.host_os:
128 config.environment["DYLD_INSERT_LIBRARIES"] = find_sanitizer_runtime(
129 "libclang_rt.tsan_osx_dynamic.dylib"
132 if "DYLD_INSERT_LIBRARIES" in config.environment and platform.system() == "Darwin":
133 config.python_executable = find_python_interpreter()
135 # Shared library build of LLVM may require LD_LIBRARY_PATH or equivalent.
136 if is_configured("shared_libs"):
137 for shlibpath_var in find_shlibpath_var():
138 # In stand-alone build llvm_shlib_dir specifies LLDB's lib directory while
139 # llvm_libs_dir specifies LLVM's lib directory.
140 shlibpath = os.path.pathsep.join(
142 config.llvm_shlib_dir,
143 config.llvm_libs_dir,
144 config.environment.get(shlibpath_var, ""),
147 config.environment[shlibpath_var] = shlibpath
148 else:
149 lit_config.warning(
150 "unable to inject shared library path on '{}'".format(platform.system())
153 lldb_use_simulator = lit_config.params.get("lldb-run-with-simulator", None)
154 if lldb_use_simulator:
155 if lldb_use_simulator == "ios":
156 lit_config.note("Running API tests on iOS simulator")
157 config.available_features.add("lldb-simulator-ios")
158 elif lldb_use_simulator == "watchos":
159 lit_config.note("Running API tests on watchOS simulator")
160 config.available_features.add("lldb-simulator-watchos")
161 elif lldb_use_simulator == "tvos":
162 lit_config.note("Running API tests on tvOS simulator")
163 config.available_features.add("lldb-simulator-tvos")
164 else:
165 lit_config.error("Unknown simulator id '{}'".format(lldb_use_simulator))
167 # Set a default per-test timeout of 10 minutes. Setting a timeout per test
168 # requires that killProcessAndChildren() is supported on the platform and
169 # lit complains if the value is set but it is not supported.
170 supported, errormsg = lit_config.maxIndividualTestTimeIsSupported
171 if supported:
172 lit_config.maxIndividualTestTime = 600
173 else:
174 lit_config.warning("Could not set a default per-test timeout. " + errormsg)
176 # Build dotest command.
177 dotest_cmd = [os.path.join(config.lldb_src_root, "test", "API", "dotest.py")]
179 if is_configured("dotest_common_args_str"):
180 dotest_cmd.extend(config.dotest_common_args_str.split(";"))
182 # Library path may be needed to locate just-built clang and libcxx.
183 if is_configured("llvm_libs_dir"):
184 dotest_cmd += ["--env", "LLVM_LIBS_DIR=" + config.llvm_libs_dir]
186 # Include path may be needed to locate just-built libcxx.
187 if is_configured("llvm_include_dir"):
188 dotest_cmd += ["--env", "LLVM_INCLUDE_DIR=" + config.llvm_include_dir]
190 # This path may be needed to locate required llvm tools
191 if is_configured("llvm_tools_dir"):
192 dotest_cmd += ["--env", "LLVM_TOOLS_DIR=" + config.llvm_tools_dir]
194 # If we have a just-built libcxx, prefer it over the system one.
195 if is_configured("has_libcxx") and config.has_libcxx:
196 if platform.system() != "Windows":
197 if is_configured("libcxx_include_dir") and is_configured("libcxx_libs_dir"):
198 dotest_cmd += ["--libcxx-include-dir", config.libcxx_include_dir]
199 if is_configured("libcxx_include_target_dir"):
200 dotest_cmd += [
201 "--libcxx-include-target-dir",
202 config.libcxx_include_target_dir,
204 dotest_cmd += ["--libcxx-library-dir", config.libcxx_libs_dir]
206 # Forward ASan-specific environment variables to tests, as a test may load an
207 # ASan-ified dylib.
208 for env_var in ("ASAN_OPTIONS", "DYLD_INSERT_LIBRARIES"):
209 if env_var in config.environment:
210 dotest_cmd += ["--inferior-env", env_var + "=" + config.environment[env_var]]
212 if is_configured("test_arch"):
213 dotest_cmd += ["--arch", config.test_arch]
215 if is_configured("lldb_build_directory"):
216 dotest_cmd += ["--build-dir", config.lldb_build_directory]
218 if is_configured("lldb_module_cache"):
219 delete_module_cache(config.lldb_module_cache)
220 dotest_cmd += ["--lldb-module-cache-dir", config.lldb_module_cache]
222 if is_configured("clang_module_cache"):
223 delete_module_cache(config.clang_module_cache)
224 dotest_cmd += ["--clang-module-cache-dir", config.clang_module_cache]
226 if is_configured("lldb_executable"):
227 dotest_cmd += ["--executable", config.lldb_executable]
229 if is_configured("test_compiler"):
230 dotest_cmd += ["--compiler", config.test_compiler]
232 if is_configured("dsymutil"):
233 dotest_cmd += ["--dsymutil", config.dsymutil]
235 if is_configured("llvm_tools_dir"):
236 dotest_cmd += ["--llvm-tools-dir", config.llvm_tools_dir]
238 if is_configured("server"):
239 dotest_cmd += ["--server", config.server]
241 if is_configured("lldb_libs_dir"):
242 dotest_cmd += ["--lldb-libs-dir", config.lldb_libs_dir]
244 if is_configured("lldb_framework_dir"):
245 dotest_cmd += ["--framework", config.lldb_framework_dir]
247 if (
248 "lldb-repro-capture" in config.available_features
249 or "lldb-repro-replay" in config.available_features
251 dotest_cmd += ["--skip-category=lldb-vscode", "--skip-category=std-module"]
253 if "lldb-simulator-ios" in config.available_features:
254 dotest_cmd += ["--apple-sdk", "iphonesimulator", "--platform-name", "ios-simulator"]
255 elif "lldb-simulator-watchos" in config.available_features:
256 dotest_cmd += [
257 "--apple-sdk",
258 "watchsimulator",
259 "--platform-name",
260 "watchos-simulator",
262 elif "lldb-simulator-tvos" in config.available_features:
263 dotest_cmd += [
264 "--apple-sdk",
265 "appletvsimulator",
266 "--platform-name",
267 "tvos-simulator",
270 if is_configured("enabled_plugins"):
271 for plugin in config.enabled_plugins:
272 dotest_cmd += ["--enable-plugin", plugin]
274 # `dotest` args come from three different sources:
275 # 1. Derived by CMake based on its configs (LLDB_TEST_COMMON_ARGS), which end
276 # up in `dotest_common_args_str`.
277 # 2. CMake user parameters (LLDB_TEST_USER_ARGS), which end up in
278 # `dotest_user_args_str`.
279 # 3. With `llvm-lit "--param=dotest-args=..."`, which end up in
280 # `dotest_lit_args_str`.
281 # Check them in this order, so that more specific overrides are visited last.
282 # In particular, (1) is visited at the top of the file, since the script
283 # derives other information from it.
285 if is_configured("dotest_user_args_str"):
286 dotest_cmd.extend(config.dotest_user_args_str.split(";"))
288 if is_configured("dotest_lit_args_str"):
289 # We don't want to force users passing arguments to lit to use `;` as a
290 # separator. We use Python's simple lexical analyzer to turn the args into a
291 # list. Pass there arguments last so they can override anything that was
292 # already configured.
293 dotest_cmd.extend(shlex.split(config.dotest_lit_args_str))
295 # Load LLDB test format.
296 sys.path.append(os.path.join(config.lldb_src_root, "test", "API"))
297 import lldbtest
299 # testFormat: The test format to use to interpret tests.
300 config.test_format = lldbtest.LLDBTest(dotest_cmd)
302 # Propagate TERM or default to vt100.
303 config.environment["TERM"] = os.getenv("TERM", default="vt100")
305 # Propagate FREEBSD_LEGACY_PLUGIN
306 if "FREEBSD_LEGACY_PLUGIN" in os.environ:
307 config.environment["FREEBSD_LEGACY_PLUGIN"] = os.environ["FREEBSD_LEGACY_PLUGIN"]
309 # Propagate XDG_CACHE_HOME
310 if "XDG_CACHE_HOME" in os.environ:
311 config.environment["XDG_CACHE_HOME"] = os.environ["XDG_CACHE_HOME"]