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
23 if 'Address' in config.llvm_use_sanitizer:
24 config.environment['ASAN_OPTIONS'] = 'detect_stack_use_after_return=1'
25 # macOS flags needed for LLDB built with address sanitizer.
26 if 'Darwin' in config.host_os and 'x86' in config.host_triple:
28 resource_dir = subprocess.check_output(
29 [config.cmake_cxx_compiler,
30 '-print-resource-dir']).decode('utf-8').strip()
31 runtime = os.path.join(resource_dir, 'lib', 'darwin',
32 'libclang_rt.asan_osx_dynamic.dylib')
33 config.environment['DYLD_INSERT_LIBRARIES'] = runtime
36 def find_shlibpath_var():
37 if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'SunOS']:
38 yield 'LD_LIBRARY_PATH'
39 elif platform.system() == 'Darwin':
40 yield 'DYLD_LIBRARY_PATH'
41 elif platform.system() == 'Windows':
45 # Shared library build of LLVM may require LD_LIBRARY_PATH or equivalent.
46 if config.shared_libs:
47 for shlibpath_var in find_shlibpath_var():
48 # In stand-alone build llvm_shlib_dir specifies LLDB's lib directory while
49 # llvm_libs_dir specifies LLVM's lib directory.
50 shlibpath = os.path.pathsep.join(
51 (config.llvm_shlib_dir, config.llvm_libs_dir,
52 config.environment.get(shlibpath_var, '')))
53 config.environment[shlibpath_var] = shlibpath
55 lit_config.warning("unable to inject shared library path on '{}'".format(
58 # Propagate LLDB_CAPTURE_REPRODUCER
59 if 'LLDB_CAPTURE_REPRODUCER' in os.environ:
60 config.environment['LLDB_CAPTURE_REPRODUCER'] = os.environ[
61 'LLDB_CAPTURE_REPRODUCER']
63 # Support running the test suite under the lldb-repro wrapper. This makes it
64 # possible to capture a test suite run and then rerun all the test from the
65 # just captured reproducer.
66 lldb_repro_mode = lit_config.params.get('lldb-run-with-repro', None)
68 lit_config.note("Running API tests in {} mode.".format(lldb_repro_mode))
69 if lldb_repro_mode == 'capture':
70 config.available_features.add('lldb-repro-capture')
71 elif lldb_repro_mode == 'replay':
72 config.available_features.add('lldb-repro-replay')
74 # Clean the module caches in the test build directory. This is necessary in an
75 # incremental build whenever clang changes underneath, so doing it once per
76 # lit.py invocation is close enough.
77 for cachedir in [config.clang_module_cache, config.lldb_module_cache]:
78 if os.path.isdir(cachedir):
79 print("Deleting module cache at %s." % cachedir)
80 shutil.rmtree(cachedir)
82 # Set a default per-test timeout of 10 minutes. Setting a timeout per test
83 # requires that killProcessAndChildren() is supported on the platform and
84 # lit complains if the value is set but it is not supported.
85 supported, errormsg = lit_config.maxIndividualTestTimeIsSupported
87 lit_config.maxIndividualTestTime = 600
89 lit_config.warning("Could not set a default per-test timeout. " + errormsg)
91 # Build dotest command.
92 dotest_cmd = [config.dotest_path]
93 dotest_cmd += ['--arch', config.test_arch]
94 dotest_cmd.extend(config.dotest_args_str.split(';'))
96 # Library path may be needed to locate just-built clang.
97 if config.llvm_libs_dir:
98 dotest_cmd += ['--env', 'LLVM_LIBS_DIR=' + config.llvm_libs_dir]
100 # Forward ASan-specific environment variables to tests, as a test may load an
102 for env_var in ('ASAN_OPTIONS', 'DYLD_INSERT_LIBRARIES'):
103 if env_var in config.environment:
104 dotest_cmd += ['--inferior-env', env_var + '=' + config.environment[env_var]]
106 if config.lldb_build_directory:
107 dotest_cmd += ['--build-dir', config.lldb_build_directory]
109 if config.lldb_module_cache:
110 dotest_cmd += ['--lldb-module-cache-dir', config.lldb_module_cache]
112 if config.clang_module_cache:
113 dotest_cmd += ['--clang-module-cache-dir', config.clang_module_cache]
115 if config.lldb_executable:
116 dotest_cmd += ['--executable', config.lldb_executable]
118 if config.test_compiler:
119 dotest_cmd += ['--compiler', config.test_compiler]
122 dotest_cmd += ['--dsymutil', config.dsymutil]
125 dotest_cmd += ['--filecheck', config.filecheck]
127 if config.lldb_libs_dir:
128 dotest_cmd += ['--lldb-libs-dir', config.lldb_libs_dir]
130 if config.enabled_plugins:
131 for plugin in config.enabled_plugins:
132 dotest_cmd += ['--enable-plugin', plugin]
134 # We don't want to force users passing arguments to lit to use `;` as a
135 # separator. We use Python's simple lexical analyzer to turn the args into a
136 # list. Pass there arguments last so they can override anything that was
137 # already configured.
138 if config.dotest_lit_args_str:
139 dotest_cmd.extend(shlex.split(config.dotest_lit_args_str))
142 # Load LLDB test format.
143 sys.path.append(os.path.join(config.lldb_src_root, "test", "API"))
146 # testFormat: The test format to use to interpret tests.
147 config.test_format = lldbtest.LLDBTest(dotest_cmd)