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 36 37def find_shlibpath_var(): 38 if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'SunOS']: 39 yield 'LD_LIBRARY_PATH' 40 elif platform.system() == 'Darwin': 41 yield 'DYLD_LIBRARY_PATH' 42 elif platform.system() == 'Windows': 43 yield 'PATH' 44 45 46# Shared library build of LLVM may require LD_LIBRARY_PATH or equivalent. 47if config.shared_libs: 48 for shlibpath_var in find_shlibpath_var(): 49 # In stand-alone build llvm_shlib_dir specifies LLDB's lib directory while 50 # llvm_libs_dir specifies LLVM's lib directory. 51 shlibpath = os.path.pathsep.join( 52 (config.llvm_shlib_dir, config.llvm_libs_dir, 53 config.environment.get(shlibpath_var, ''))) 54 config.environment[shlibpath_var] = shlibpath 55 else: 56 lit_config.warning("unable to inject shared library path on '{}'".format( 57 platform.system())) 58 59# Propagate LLDB_CAPTURE_REPRODUCER 60if 'LLDB_CAPTURE_REPRODUCER' in os.environ: 61 config.environment['LLDB_CAPTURE_REPRODUCER'] = os.environ[ 62 'LLDB_CAPTURE_REPRODUCER'] 63 64# Clean the module caches in the test build directory. This is necessary in an 65# incremental build whenever clang changes underneath, so doing it once per 66# lit.py invocation is close enough. 67for cachedir in [config.clang_module_cache, config.lldb_module_cache]: 68 if os.path.isdir(cachedir): 69 print("Deleting module cache at %s." % cachedir) 70 shutil.rmtree(cachedir) 71 72# Set a default per-test timeout of 10 minutes. Setting a timeout per test 73# requires that killProcessAndChildren() is supported on the platform and 74# lit complains if the value is set but it is not supported. 75supported, errormsg = lit_config.maxIndividualTestTimeIsSupported 76if supported: 77 lit_config.maxIndividualTestTime = 600 78else: 79 lit_config.warning("Could not set a default per-test timeout. " + errormsg) 80 81# Build dotest command. 82dotest_cmd = [config.dotest_path] 83dotest_cmd += ['--arch', config.test_arch] 84dotest_cmd.extend(config.dotest_args_str.split(';')) 85 86# Library path may be needed to locate just-built clang. 87if config.llvm_libs_dir: 88 dotest_cmd += ['--env', 'LLVM_LIBS_DIR=' + config.llvm_libs_dir] 89 90# Forward ASan-specific environment variables to tests, as a test may load an 91# ASan-ified dylib. 92for env_var in ('ASAN_OPTIONS', 'DYLD_INSERT_LIBRARIES'): 93 if env_var in config.environment: 94 dotest_cmd += ['--inferior-env', env_var + '=' + config.environment[env_var]] 95 96if config.lldb_build_directory: 97 dotest_cmd += ['--build-dir', config.lldb_build_directory] 98 99if config.lldb_module_cache: 100 dotest_cmd += ['--lldb-module-cache-dir', config.lldb_module_cache] 101 102if config.clang_module_cache: 103 dotest_cmd += ['--clang-module-cache-dir', config.clang_module_cache] 104 105if config.lldb_executable: 106 dotest_cmd += ['--executable', config.lldb_executable] 107 108if config.test_compiler: 109 dotest_cmd += ['--compiler', config.test_compiler] 110 111if config.dsymutil: 112 dotest_cmd += ['--dsymutil', config.dsymutil] 113 114if config.filecheck: 115 dotest_cmd += ['--filecheck', config.filecheck] 116 117# We don't want to force users passing arguments to lit to use `;` as a 118# separator. We use Python's simple lexical analyzer to turn the args into a 119# list. Pass there arguments last so they can override anything that was 120# already configured. 121if config.dotest_lit_args_str: 122 dotest_cmd.extend(shlex.split(config.dotest_lit_args_str)) 123 124 125# Load LLDB test format. 126sys.path.append(os.path.join(config.lldb_src_root, "test", "API")) 127import lldbtest 128 129# testFormat: The test format to use to interpret tests. 130config.test_format = lldbtest.LLDBTest(dotest_cmd) 131