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