9 from lit.llvm import llvm_config
11 # Configuration file for the 'lit' test runner.
13 # name: The name of this test suite.
16 # testFormat: The test format to use to interpret tests.
17 config.test_format = lit.formats.ShTest(execute_external=False)
19 # suffixes: A list of file extensions to treat as test files.
20 config.suffixes = [".py"]
22 # excludes: A list of individual files to exclude.
23 config.excludes = ["Inputs"]
25 # test_source_root: The root path where tests are located.
26 config.test_source_root = os.path.dirname(__file__)
27 config.test_exec_root = config.test_source_root
29 config.target_triple = "(unused)"
31 llvm_src_root = getattr(config, "llvm_src_root", None)
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")
37 lit_path = os.path.join(config.test_source_root, "..")
38 lit_path = os.path.abspath(lit_path)
40 # Required because some tests import the lit module
42 llvm_config.with_environment("PYTHONPATH", lit_path, append_path=True)
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.
48 config.environment["PYTHONNOUSERSITE"] = "1"
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.
52 for attribute in ("llvm_tools_dir", "lit_tools_dir"):
53 directory = getattr(config, attribute, None)
55 llvm_config.with_environment("PATH", directory, append_path=True)
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
64 config.substitutions.append(("%{inputs}", "Inputs"))
65 config.substitutions.append(("%{lit}", "%{lit-no-order-opt} --order=lexical"))
66 config.substitutions.append(
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")
74 config.substitutions.append(("%{python}", '"%s"' % (sys.executable)))
76 # Enable coverage.py reporting, assuming the coverage module has been installed
77 # and sitecustomize.py in the virtualenv has been modified appropriately.
78 if lit_config.params.get("check-coverage", None):
79 config.environment["COVERAGE_PROCESS_START"] = os.path.join(
80 os.path.dirname(__file__), ".coveragerc"
83 # Add a feature to detect if test cancellation is available. Check the ability
84 # to do cancellation in the same environment as where RUN commands are run.
85 # The reason is that on most systems cancellation depends on psutil being
86 # available and RUN commands are run with a cleared PYTHONPATH and user site
88 testing_script_path = "/".join(
89 (os.path.dirname(__file__), "check-tested-lit-timeout-ability")
91 proc = subprocess.run(
92 [sys.executable, testing_script_path],
93 stderr=subprocess.PIPE,
94 env=config.environment,
95 universal_newlines=True,
97 if proc.returncode == 0:
98 config.available_features.add("lit-max-individual-test-time")
100 errormsg = proc.stderr
102 "Setting a timeout per test not supported. "
104 + " Some tests will be skipped and the --timeout"
105 " command line argument will not work."
108 # When running the lit tests standalone, we want to define the same features
109 # that the llvm_config defines. This means that the 'system-windows' feature
110 # (and any others) need to match the names in llvm_config for consistency
112 if sys.platform.startswith("win") or sys.platform.startswith("cygwin"):
113 config.available_features.add("system-windows")
114 if platform.system() == "AIX":
115 config.available_features.add("system-aix")
117 # For each of lit's internal shell commands ('env', 'cd', 'diff', etc.), put
118 # a fake command that always fails at the start of PATH. This helps us check
119 # that we always use lit's internal version rather than some external version
120 # that might not be present or behave correctly on all platforms. Don't do
121 # this for 'echo' because an external version is used when it appears in a
122 # pipeline. Don't do this for ':' because it doesn't appear to be a valid file
123 # name under Windows. Don't do this for 'not' because lit uses the external
124 # 'not' throughout a RUN line that calls 'not --crash'.
125 test_bin = os.path.join(os.path.dirname(__file__), "Inputs", "fake-externals")
126 config.environment["PATH"] = os.path.pathsep.join(
127 (test_bin, config.environment["PATH"])