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.dirname(__file__) 21config.test_exec_root = config.test_source_root 22 23if '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: 27 import subprocess 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 34 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 45# Shared library build of LLVM may require LD_LIBRARY_PATH or equivalent. 46if 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 54 else: 55 lit_config.warning("unable to inject shared library path on '{}'".format( 56 platform.system())) 57 58# Propagate LLDB_CAPTURE_REPRODUCER 59if 'LLDB_CAPTURE_REPRODUCER' in os.environ: 60 config.environment['LLDB_CAPTURE_REPRODUCER'] = os.environ[ 61 'LLDB_CAPTURE_REPRODUCER'] 62 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. 66lldb_repro_mode = lit_config.params.get('lldb-run-with-repro', None) 67if lldb_repro_mode: 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') 73 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. 77for 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) 81 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. 85supported, errormsg = lit_config.maxIndividualTestTimeIsSupported 86if supported: 87 lit_config.maxIndividualTestTime = 600 88else: 89 lit_config.warning("Could not set a default per-test timeout. " + errormsg) 90 91# Build dotest command. 92dotest_cmd = [config.dotest_path] 93dotest_cmd += ['--arch', config.test_arch] 94dotest_cmd.extend(config.dotest_args_str.split(';')) 95 96# Library path may be needed to locate just-built clang. 97if config.llvm_libs_dir: 98 dotest_cmd += ['--env', 'LLVM_LIBS_DIR=' + config.llvm_libs_dir] 99 100# Forward ASan-specific environment variables to tests, as a test may load an 101# ASan-ified dylib. 102for 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]] 105 106if config.lldb_build_directory: 107 dotest_cmd += ['--build-dir', config.lldb_build_directory] 108 109if config.lldb_module_cache: 110 dotest_cmd += ['--lldb-module-cache-dir', config.lldb_module_cache] 111 112if config.clang_module_cache: 113 dotest_cmd += ['--clang-module-cache-dir', config.clang_module_cache] 114 115if config.lldb_executable: 116 dotest_cmd += ['--executable', config.lldb_executable] 117 118if config.test_compiler: 119 dotest_cmd += ['--compiler', config.test_compiler] 120 121if config.dsymutil: 122 dotest_cmd += ['--dsymutil', config.dsymutil] 123 124if config.filecheck: 125 dotest_cmd += ['--filecheck', config.filecheck] 126 127if config.lldb_libs_dir: 128 dotest_cmd += ['--lldb-libs-dir', config.lldb_libs_dir] 129 130if config.enabled_plugins: 131 for plugin in config.enabled_plugins: 132 dotest_cmd += ['--enable-plugin', plugin] 133 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. 138if config.dotest_lit_args_str: 139 dotest_cmd.extend(shlex.split(config.dotest_lit_args_str)) 140 141 142# Load LLDB test format. 143sys.path.append(os.path.join(config.lldb_src_root, "test", "API")) 144import lldbtest 145 146# testFormat: The test format to use to interpret tests. 147config.test_format = lldbtest.LLDBTest(dotest_cmd) 148