3 # Configuration file for the 'lit' test runner.
12 # name: The name of this test suite.
13 config.name = 'lldb-api'
15 # suffixes: A list of file extensions to treat as test files.
16 config.suffixes = ['.py']
18 # test_source_root: The root path where tests are located.
19 # test_exec_root: The root path where tests should be run.
20 config.test_source_root = os.path.dirname(__file__)
21 config.test_exec_root = config.test_source_root
24 def find_sanitizer_runtime(name):
26 resource_dir = subprocess.check_output(
27 [config.cmake_cxx_compiler,
28 '-print-resource-dir']).decode('utf-8').strip()
29 return os.path.join(resource_dir, 'lib', 'darwin', name)
32 def find_shlibpath_var():
33 if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'SunOS']:
34 yield 'LD_LIBRARY_PATH'
35 elif platform.system() == 'Darwin':
36 yield 'DYLD_LIBRARY_PATH'
37 elif platform.system() == 'Windows':
41 if 'Address' in config.llvm_use_sanitizer:
42 config.environment['ASAN_OPTIONS'] = 'detect_stack_use_after_return=1'
43 if 'Darwin' in config.host_os and 'x86' in config.host_triple:
44 config.environment['DYLD_INSERT_LIBRARIES'] = find_sanitizer_runtime(
45 'libclang_rt.asan_osx_dynamic.dylib')
47 if 'Thread' in config.llvm_use_sanitizer:
48 if 'Darwin' in config.host_os and 'x86' in config.host_triple:
49 config.environment['DYLD_INSERT_LIBRARIES'] = find_sanitizer_runtime(
50 'libclang_rt.tsan_osx_dynamic.dylib')
52 # Shared library build of LLVM may require LD_LIBRARY_PATH or equivalent.
53 if config.shared_libs:
54 for shlibpath_var in find_shlibpath_var():
55 # In stand-alone build llvm_shlib_dir specifies LLDB's lib directory while
56 # llvm_libs_dir specifies LLVM's lib directory.
57 shlibpath = os.path.pathsep.join(
58 (config.llvm_shlib_dir, config.llvm_libs_dir,
59 config.environment.get(shlibpath_var, '')))
60 config.environment[shlibpath_var] = shlibpath
62 lit_config.warning("unable to inject shared library path on '{}'".format(
65 # Propagate LLDB_CAPTURE_REPRODUCER
66 if 'LLDB_CAPTURE_REPRODUCER' in os.environ:
67 config.environment['LLDB_CAPTURE_REPRODUCER'] = os.environ[
68 'LLDB_CAPTURE_REPRODUCER']
70 # Support running the test suite under the lldb-repro wrapper. This makes it
71 # possible to capture a test suite run and then rerun all the test from the
72 # just captured reproducer.
73 lldb_repro_mode = lit_config.params.get('lldb-run-with-repro', None)
75 lit_config.note("Running API tests in {} mode.".format(lldb_repro_mode))
76 if lldb_repro_mode == 'capture':
77 config.available_features.add('lldb-repro-capture')
78 elif lldb_repro_mode == 'replay':
79 config.available_features.add('lldb-repro-replay')
81 # Clean the module caches in the test build directory. This is necessary in an
82 # incremental build whenever clang changes underneath, so doing it once per
83 # lit.py invocation is close enough.
84 for cachedir in [config.clang_module_cache, config.lldb_module_cache]:
85 if os.path.isdir(cachedir):
86 print("Deleting module cache at %s." % cachedir)
87 shutil.rmtree(cachedir)
89 # Set a default per-test timeout of 10 minutes. Setting a timeout per test
90 # requires that killProcessAndChildren() is supported on the platform and
91 # lit complains if the value is set but it is not supported.
92 supported, errormsg = lit_config.maxIndividualTestTimeIsSupported
94 lit_config.maxIndividualTestTime = 600
96 lit_config.warning("Could not set a default per-test timeout. " + errormsg)
98 # Build dotest command.
99 dotest_cmd = [config.dotest_path]
100 dotest_cmd += ['--arch', config.test_arch]
101 dotest_cmd.extend(config.dotest_args_str.split(';'))
103 # Library path may be needed to locate just-built clang.
104 if config.llvm_libs_dir:
105 dotest_cmd += ['--env', 'LLVM_LIBS_DIR=' + config.llvm_libs_dir]
107 # Forward ASan-specific environment variables to tests, as a test may load an
109 for env_var in ('ASAN_OPTIONS', 'DYLD_INSERT_LIBRARIES'):
110 if env_var in config.environment:
111 dotest_cmd += ['--inferior-env', env_var + '=' + config.environment[env_var]]
113 if config.lldb_build_directory:
114 dotest_cmd += ['--build-dir', config.lldb_build_directory]
116 if config.lldb_module_cache:
117 dotest_cmd += ['--lldb-module-cache-dir', config.lldb_module_cache]
119 if config.clang_module_cache:
120 dotest_cmd += ['--clang-module-cache-dir', config.clang_module_cache]
122 if config.lldb_executable:
123 dotest_cmd += ['--executable', config.lldb_executable]
125 if config.test_compiler:
126 dotest_cmd += ['--compiler', config.test_compiler]
129 dotest_cmd += ['--dsymutil', config.dsymutil]
132 dotest_cmd += ['--filecheck', config.filecheck]
134 if config.lldb_libs_dir:
135 dotest_cmd += ['--lldb-libs-dir', config.lldb_libs_dir]
137 if 'lldb-repro-capture' in config.available_features or \
138 'lldb-repro-replay' in config.available_features:
139 dotest_cmd += ['--skip-category=lldb-vscode', '--skip-category=std-module']
141 if config.enabled_plugins:
142 for plugin in config.enabled_plugins:
143 dotest_cmd += ['--enable-plugin', plugin]
145 # We don't want to force users passing arguments to lit to use `;` as a
146 # separator. We use Python's simple lexical analyzer to turn the args into a
147 # list. Pass there arguments last so they can override anything that was
148 # already configured.
149 if config.dotest_lit_args_str:
150 dotest_cmd.extend(shlex.split(config.dotest_lit_args_str))
153 # Load LLDB test format.
154 sys.path.append(os.path.join(config.lldb_src_root, "test", "API"))
157 # testFormat: The test format to use to interpret tests.
158 config.test_format = lldbtest.LLDBTest(dotest_cmd)