1# -*- Python -*-
2
3# Configuration file for the 'lit' test runner.
4
5import os
6import platform
7import shlex
8import shutil
9
10import lit.formats
11
12# name: The name of this test suite.
13config.name = 'lldb-api'
14
15# suffixes: A list of file extensions to treat as test files.
16config.suffixes = ['.py']
17
18# test_source_root: The root path where tests are located.
19# test_exec_root: The root path where tests should be run.
20config.test_source_root = os.path.join(config.lldb_src_root, 'packages',
21                                       'Python', 'lldbsuite', 'test')
22config.test_exec_root = config.test_source_root
23
24if 'Address' in config.llvm_use_sanitizer:
25  config.environment['ASAN_OPTIONS'] = 'detect_stack_use_after_return=1'
26  # macOS flags needed for LLDB built with address sanitizer.
27  if 'Darwin' in config.host_os and 'x86' in config.host_triple:
28    import subprocess
29    resource_dir = subprocess.check_output(
30        [config.cmake_cxx_compiler,
31         '-print-resource-dir']).decode('utf-8').strip()
32    runtime = os.path.join(resource_dir, 'lib', 'darwin',
33                           'libclang_rt.asan_osx_dynamic.dylib')
34    config.environment['DYLD_INSERT_LIBRARIES'] = runtime
35
36def 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':
42    yield 'PATH'
43
44# Shared library build of LLVM may require LD_LIBRARY_PATH or equivalent.
45if config.shared_libs:
46  for shlibpath_var in find_shlibpath_var():
47    # In stand-alone build llvm_shlib_dir specifies LLDB's lib directory while
48    # llvm_libs_dir specifies LLVM's lib directory.
49    shlibpath = os.path.pathsep.join(
50        (config.llvm_shlib_dir, config.llvm_libs_dir,
51         config.environment.get(shlibpath_var, '')))
52    config.environment[shlibpath_var] = shlibpath
53  else:
54    lit_config.warning("unable to inject shared library path on '{}'".format(
55        platform.system()))
56
57# Clean the module caches in the test build directory. This is necessary in an
58# incremental build whenever clang changes underneath, so doing it once per
59# lit.py invocation is close enough.
60for cachedir in [config.clang_module_cache, config.lldb_module_cache]:
61  if os.path.isdir(cachedir):
62    print("Deleting module cache at %s."%cachedir)
63    shutil.rmtree(cachedir)
64
65# Set a default per-test timeout of 10 minutes. Setting a timeout per test
66# requires that killProcessAndChildren() is supported on the platform and
67# lit complains if the value is set but it is not supported.
68supported, errormsg = lit_config.maxIndividualTestTimeIsSupported
69if supported:
70  lit_config.maxIndividualTestTime = 600
71else:
72  lit_config.warning("Could not set a default per-test timeout. " + errormsg)
73
74# Build dotest command.
75dotest_cmd = [config.dotest_path]
76dotest_cmd.extend(config.dotest_args_str.split(';'))
77
78# We don't want to force users passing arguments to lit to use `;` as a
79# separator. We use Python's simple lexical analyzer to turn the args into a
80# list.
81if config.dotest_lit_args_str:
82  dotest_cmd.extend(shlex.split(config.dotest_lit_args_str))
83
84# Library path may be needed to locate just-built clang.
85if config.llvm_libs_dir:
86  dotest_cmd += ['--env', 'LLVM_LIBS_DIR=' + config.llvm_libs_dir]
87
88if config.lldb_build_directory:
89  dotest_cmd += ['--build-dir', config.lldb_build_directory]
90
91if config.lldb_module_cache:
92  dotest_cmd += ['--lldb-module-cache-dir', config.lldb_module_cache]
93
94if config.clang_module_cache:
95  dotest_cmd += ['--clang-module-cache-dir', config.clang_module_cache]
96
97# Load LLDB test format.
98sys.path.append(os.path.join(config.lldb_src_root, "test", "API"))
99import lldbtest
100
101# testFormat: The test format to use to interpret tests.
102config.test_format = lldbtest.LLDBTest(dotest_cmd)
103