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# Clean the module caches in the test build directory. This is necessary in an 64# incremental build whenever clang changes underneath, so doing it once per 65# lit.py invocation is close enough. 66for cachedir in [config.clang_module_cache, config.lldb_module_cache]: 67 if os.path.isdir(cachedir): 68 print("Deleting module cache at %s." % cachedir) 69 shutil.rmtree(cachedir) 70 71# Set a default per-test timeout of 10 minutes. Setting a timeout per test 72# requires that killProcessAndChildren() is supported on the platform and 73# lit complains if the value is set but it is not supported. 74supported, errormsg = lit_config.maxIndividualTestTimeIsSupported 75if supported: 76 lit_config.maxIndividualTestTime = 600 77else: 78 lit_config.warning("Could not set a default per-test timeout. " + errormsg) 79 80# Build dotest command. 81dotest_cmd = [config.dotest_path] 82dotest_cmd += ['--arch', config.test_arch] 83dotest_cmd.extend(config.dotest_args_str.split(';')) 84 85# Library path may be needed to locate just-built clang. 86if config.llvm_libs_dir: 87 dotest_cmd += ['--env', 'LLVM_LIBS_DIR=' + config.llvm_libs_dir] 88 89# Forward ASan-specific environment variables to tests, as a test may load an 90# ASan-ified dylib. 91for env_var in ('ASAN_OPTIONS', 'DYLD_INSERT_LIBRARIES'): 92 if env_var in config.environment: 93 dotest_cmd += ['--inferior-env', env_var + '=' + config.environment[env_var]] 94 95if config.lldb_build_directory: 96 dotest_cmd += ['--build-dir', config.lldb_build_directory] 97 98if config.lldb_module_cache: 99 dotest_cmd += ['--lldb-module-cache-dir', config.lldb_module_cache] 100 101if config.clang_module_cache: 102 dotest_cmd += ['--clang-module-cache-dir', config.clang_module_cache] 103 104if config.lldb_executable: 105 dotest_cmd += ['--executable', config.lldb_executable] 106 107if config.test_compiler: 108 dotest_cmd += ['--compiler', config.test_compiler] 109 110if config.dsymutil: 111 dotest_cmd += ['--dsymutil', config.dsymutil] 112 113if config.filecheck: 114 dotest_cmd += ['--filecheck', config.filecheck] 115 116if config.lldb_libs_dir: 117 dotest_cmd += ['--lldb-libs-dir', config.lldb_libs_dir] 118 119# We don't want to force users passing arguments to lit to use `;` as a 120# separator. We use Python's simple lexical analyzer to turn the args into a 121# list. Pass there arguments last so they can override anything that was 122# already configured. 123if config.dotest_lit_args_str: 124 dotest_cmd.extend(shlex.split(config.dotest_lit_args_str)) 125 126 127# Load LLDB test format. 128sys.path.append(os.path.join(config.lldb_src_root, "test", "API")) 129import lldbtest 130 131# testFormat: The test format to use to interpret tests. 132config.test_format = lldbtest.LLDBTest(dotest_cmd) 133