140 lines · plain
1# -*- Python -*-2 3import os4import platform5import sys6import subprocess7 8import lit.formats9from lit.llvm import llvm_config10 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_root28 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 contain34 # ``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 module41if llvm_config:42 llvm_config.use_default_substitutions()43 llvm_config.with_environment("PYTHONPATH", lit_path, append_path=True)44else:45 config.environment["PYTHONPATH"] = lit_path46# Do not add user-site packages directory to the python search path. This avoids test failures if there's an47# incompatible lit module installed inside the user-site packages directory, as it gets prioritized over the lit48# from the PYTHONPATH.49config.environment["PYTHONNOUSERSITE"] = "1"50 51# Add llvm and lit tools directories if this config is being loaded indirectly.52# In this case, we can also expect llvm_config to have been imported correctly.53for attribute in ("llvm_tools_dir", "lit_tools_dir"):54 directory = getattr(config, attribute, None)55 if directory:56 llvm_config.with_environment("PATH", directory, append_path=True)57 58# This test suite calls %{lit} to test lit's behavior for the sample test59# suites in %{inputs}. This test suite's results are then determined in part60# by %{lit}'s textual output, which includes the output of FileCheck calls61# within %{inputs}'s test suites. Thus, %{lit} clears environment variables62# that can affect FileCheck's output. It also includes "--order=lexical -j1"63# to ensure predictable test order, as it is often required for FileCheck64# matches.65config.substitutions.append(("%{inputs}", "Inputs"))66config.substitutions.append(("%{lit}", "%{lit-no-order-opt} --order=lexical"))67config.substitutions.append(68 (69 "%{lit-no-order-opt}",70 "{env} %{{python}} {lit} -j1".format(71 env="env -u FILECHECK_OPTS", lit=os.path.join(lit_path, "lit.py")72 ),73 )74)75config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))76 77# This diagnostic sometimes appears in windows when using bash as an external78# shell. Ignore it in lit's output where we need to strictly check only the79# relevant output.80config.substitutions.append(81 (82 "%{filter-lit}",83 "grep -v 'bash.exe: warning: could not find /tmp, please create!'",84 )85)86 87# Enable coverage.py reporting, assuming the coverage module has been installed88# and sitecustomize.py in the virtualenv has been modified appropriately.89if lit_config.params.get("check-coverage", None):90 config.environment["COVERAGE_PROCESS_START"] = os.path.join(91 os.path.dirname(__file__), ".coveragerc"92 )93 94# Add a feature to detect if test cancellation is available. Check the ability95# to do cancellation in the same environment as where RUN commands are run.96# The reason is that on most systems cancellation depends on psutil being97# available and RUN commands are run with a cleared PYTHONPATH and user site98# packages disabled.99testing_script_path = "/".join(100 (os.path.dirname(__file__), "check-tested-lit-timeout-ability")101)102proc = subprocess.run(103 [sys.executable, testing_script_path],104 stderr=subprocess.PIPE,105 env=config.environment,106 universal_newlines=True,107)108if proc.returncode == 0:109 config.available_features.add("lit-max-individual-test-time")110else:111 errormsg = proc.stderr112 lit_config.warning(113 "Setting a timeout per test not supported. "114 + errormsg115 + " Some tests will be skipped and the --timeout"116 " command line argument will not work."117 )118 119# When running the lit tests standalone, we want to define the same features120# that the llvm_config defines. This means that the 'system-windows' feature121# (and any others) need to match the names in llvm_config for consistency122if not llvm_config:123 if sys.platform.startswith("win") or sys.platform.startswith("cygwin"):124 config.available_features.add("system-windows")125 if platform.system() == "AIX":126 config.available_features.add("system-aix")127 128# For each of lit's internal shell commands ('env', 'cd', 'diff', etc.), put129# a fake command that always fails at the start of PATH. This helps us check130# that we always use lit's internal version rather than some external version131# that might not be present or behave correctly on all platforms. Don't do132# this for 'echo' because an external version is used when it appears in a133# pipeline. Don't do this for ':' because it doesn't appear to be a valid file134# name under Windows. Don't do this for 'not' because lit uses the external135# 'not' throughout a RUN line that calls 'not --crash'.136test_bin = os.path.join(os.path.dirname(__file__), "Inputs", "fake-externals")137config.environment["PATH"] = os.path.pathsep.join(138 (test_bin, config.environment["PATH"])139)140