1# -*- Python -*- 2 3import os 4import platform 5import sys 6import subprocess 7 8import lit.formats 9from lit.llvm import llvm_config 10 11# Configuration file for the 'lit' test runner. 12 13# name: The name of this test suite. 14config.name = "lit" 15 16# testFormat: The test format to use to interpret tests. 17config.test_format = lit.formats.ShTest(execute_external=False) 18 19# suffixes: A list of file extensions to treat as test files. 20config.suffixes = [".py"] 21 22# excludes: A list of individual files to exclude. 23config.excludes = ["Inputs"] 24 25# test_source_root: The root path where tests are located. 26config.test_source_root = os.path.dirname(__file__) 27config.test_exec_root = config.test_source_root 28 29config.target_triple = "(unused)" 30 31llvm_src_root = getattr(config, "llvm_src_root", None) 32if llvm_src_root: 33 # ``test_source_root`` may be in LLVM's binary build directory which does not contain 34 # ``lit.py``, so use `llvm_src_root` instead. 35 lit_path = os.path.join(llvm_src_root, "utils", "lit") 36else: 37 lit_path = os.path.join(config.test_source_root, "..") 38lit_path = os.path.abspath(lit_path) 39 40# Required because some tests import the lit module 41if llvm_config: 42 llvm_config.with_environment("PYTHONPATH", lit_path, append_path=True) 43else: 44 config.environment["PYTHONPATH"] = lit_path 45# Do not add user-site packages directory to the python search path. This avoids test failures if there's an 46# incompatible lit module installed inside the user-site packages directory, as it gets prioritized over the lit 47# from the PYTHONPATH. 48config.environment["PYTHONNOUSERSITE"] = "1" 49 50# Add llvm and lit tools directories if this config is being loaded indirectly. 51# In this case, we can also expect llvm_config to have been imported correctly. 52for attribute in ("llvm_tools_dir", "lit_tools_dir"): 53 directory = getattr(config, attribute, None) 54 if directory: 55 llvm_config.with_environment("PATH", directory, append_path=True) 56 57# This test suite calls %{lit} to test lit's behavior for the sample test 58# suites in %{inputs}. This test suite's results are then determined in part 59# by %{lit}'s textual output, which includes the output of FileCheck calls 60# within %{inputs}'s test suites. Thus, %{lit} clears environment variables 61# that can affect FileCheck's output. It also includes "--order=lexical -j1" 62# to ensure predictable test order, as it is often required for FileCheck 63# matches. 64config.substitutions.append(("%{inputs}", "Inputs")) 65config.substitutions.append(("%{lit}", "%{lit-no-order-opt} --order=lexical")) 66config.substitutions.append( 67 ( 68 "%{lit-no-order-opt}", 69 "{env} %{{python}} {lit} -j1".format( 70 env="env -u FILECHECK_OPTS", lit=os.path.join(lit_path, "lit.py") 71 ), 72 ) 73) 74config.substitutions.append(("%{python}", '"%s"' % (sys.executable))) 75 76# This diagnostic sometimes appears in windows when using bash as an external 77# shell. Ignore it in lit's output where we need to strictly check only the 78# relevant output. 79config.substitutions.append( 80 ( 81 "%{filter-lit}", 82 "grep -v 'bash.exe: warning: could not find /tmp, please create!'", 83 ) 84) 85 86# Enable coverage.py reporting, assuming the coverage module has been installed 87# and sitecustomize.py in the virtualenv has been modified appropriately. 88if lit_config.params.get("check-coverage", None): 89 config.environment["COVERAGE_PROCESS_START"] = os.path.join( 90 os.path.dirname(__file__), ".coveragerc" 91 ) 92 93# Add a feature to detect if test cancellation is available. Check the ability 94# to do cancellation in the same environment as where RUN commands are run. 95# The reason is that on most systems cancellation depends on psutil being 96# available and RUN commands are run with a cleared PYTHONPATH and user site 97# packages disabled. 98testing_script_path = "/".join( 99 (os.path.dirname(__file__), "check-tested-lit-timeout-ability") 100) 101proc = subprocess.run( 102 [sys.executable, testing_script_path], 103 stderr=subprocess.PIPE, 104 env=config.environment, 105 universal_newlines=True, 106) 107if proc.returncode == 0: 108 config.available_features.add("lit-max-individual-test-time") 109else: 110 errormsg = proc.stderr 111 lit_config.warning( 112 "Setting a timeout per test not supported. " 113 + errormsg 114 + " Some tests will be skipped and the --timeout" 115 " command line argument will not work." 116 ) 117 118# When running the lit tests standalone, we want to define the same features 119# that the llvm_config defines. This means that the 'system-windows' feature 120# (and any others) need to match the names in llvm_config for consistency 121if not llvm_config: 122 if sys.platform.startswith("win") or sys.platform.startswith("cygwin"): 123 config.available_features.add("system-windows") 124 if platform.system() == "AIX": 125 config.available_features.add("system-aix") 126 127# For each of lit's internal shell commands ('env', 'cd', 'diff', etc.), put 128# a fake command that always fails at the start of PATH. This helps us check 129# that we always use lit's internal version rather than some external version 130# that might not be present or behave correctly on all platforms. Don't do 131# this for 'echo' because an external version is used when it appears in a 132# pipeline. Don't do this for ':' because it doesn't appear to be a valid file 133# name under Windows. Don't do this for 'not' because lit uses the external 134# 'not' throughout a RUN line that calls 'not --crash'. 135test_bin = os.path.join(os.path.dirname(__file__), "Inputs", "fake-externals") 136config.environment["PATH"] = os.path.pathsep.join( 137 (test_bin, config.environment["PATH"]) 138) 139