Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / utils / lit / lit / TestingConfig.py
blobeb9f8de2a7f960ceacf550dce61b238a370679d1
1 import os
2 import sys
5 class TestingConfig(object):
6 """
7 TestingConfig - Information on the tests inside a suite.
8 """
10 @staticmethod
11 def fromdefaults(litConfig):
12 """
13 fromdefaults(litConfig) -> TestingConfig
15 Create a TestingConfig object with default values.
16 """
17 # Set the environment based on the command line arguments.
18 environment = {
19 "PATH": os.pathsep.join(litConfig.path + [os.environ.get("PATH", "")]),
20 "LLVM_DISABLE_CRASH_REPORT": "1",
23 pass_vars = [
24 "LIBRARY_PATH",
25 "LD_LIBRARY_PATH",
26 "SYSTEMROOT",
27 "TERM",
28 "CLANG",
29 "LLDB",
30 "LD_PRELOAD",
31 "LLVM_SYMBOLIZER_PATH",
32 "LLVM_PROFILE_FILE",
33 "ASAN_SYMBOLIZER_PATH",
34 "HWASAN_SYMBOLIZER_PATH",
35 "LSAN_SYMBOLIZER_PATH",
36 "MSAN_SYMBOLIZER_PATH",
37 "TSAN_SYMBOLIZER_PATH",
38 "UBSAN_SYMBOLIZER_PATH",
39 "ASAN_OPTIONS",
40 "LSAN_OPTIONS",
41 "HWASAN_OPTIONS",
42 "MSAN_OPTIONS",
43 "TSAN_OPTIONS",
44 "UBSAN_OPTIONS",
45 "ADB",
46 "ADB_SERVER_SOCKET",
47 "ANDROID_SERIAL",
48 "SSH_AUTH_SOCK",
49 "SANITIZER_IGNORE_CVE_2016_2143",
50 "TMPDIR",
51 "TMP",
52 "TEMP",
53 "TEMPDIR",
54 "AVRLIT_BOARD",
55 "AVRLIT_PORT",
56 "FILECHECK_OPTS",
57 "VCINSTALLDIR",
58 "VCToolsinstallDir",
59 "VSINSTALLDIR",
60 "WindowsSdkDir",
61 "WindowsSDKLibVersion",
62 "SOURCE_DATE_EPOCH",
63 "GTEST_FILTER",
64 "DFLTCC",
67 if sys.platform.startswith("aix"):
68 pass_vars += ["LIBPATH"]
69 elif sys.platform == "win32":
70 pass_vars += [
71 "COMSPEC",
72 "INCLUDE",
73 "LIB",
74 "PATHEXT",
75 "USERPROFILE",
77 environment["PYTHONBUFFERED"] = "1"
78 # Avoid Windows heuristics which try to detect potential installer
79 # programs (which may need to run with elevated privileges) and ask
80 # if the user wants to run them in that way. This heuristic may
81 # match for executables containing the substrings "patch" (which is
82 # a substring of "dispatch"), "update", "setup", etc. Set this
83 # environment variable indicating that we want to execute them with
84 # the current user.
85 environment["__COMPAT_LAYER"] = "RunAsInvoker"
87 for var in pass_vars:
88 val = os.environ.get(var, "")
89 # Check for empty string as some variables such as LD_PRELOAD cannot be empty
90 # ('') for OS's such as OpenBSD.
91 if val:
92 environment[var] = val
94 # Set the default available features based on the LitConfig.
95 available_features = []
96 if litConfig.useValgrind:
97 available_features.append("valgrind")
98 if litConfig.valgrindLeakCheck:
99 available_features.append("vg_leak")
101 return TestingConfig(
102 None,
103 name="<unnamed>",
104 suffixes=set(),
105 test_format=None,
106 environment=environment,
107 substitutions=[],
108 unsupported=False,
109 test_exec_root=None,
110 test_source_root=None,
111 excludes=[],
112 available_features=available_features,
113 pipefail=True,
114 standalone_tests=False,
117 def load_from_path(self, path, litConfig):
119 load_from_path(path, litConfig)
121 Load the configuration module at the provided path into the given config
122 object.
125 # Load the config script data.
126 data = None
127 f = open(path)
128 try:
129 data = f.read()
130 except:
131 litConfig.fatal("unable to load config file: %r" % (path,))
132 f.close()
134 # Execute the config script to initialize the object.
135 cfg_globals = dict(globals())
136 cfg_globals["config"] = self
137 cfg_globals["lit_config"] = litConfig
138 cfg_globals["__file__"] = path
139 try:
140 exec(compile(data, path, "exec"), cfg_globals, None)
141 if litConfig.debug:
142 litConfig.note("... loaded config %r" % path)
143 except SystemExit:
144 e = sys.exc_info()[1]
145 # We allow normal system exit inside a config file to just
146 # return control without error.
147 if e.args:
148 raise
149 except:
150 import traceback
152 litConfig.fatal(
153 "unable to parse config file %r, traceback: %s"
154 % (path, traceback.format_exc())
156 self.finish(litConfig)
158 def __init__(
159 self,
160 parent,
161 name,
162 suffixes,
163 test_format,
164 environment,
165 substitutions,
166 unsupported,
167 test_exec_root,
168 test_source_root,
169 excludes,
170 available_features,
171 pipefail,
172 limit_to_features=[],
173 is_early=False,
174 parallelism_group=None,
175 standalone_tests=False,
177 self.parent = parent
178 self.name = str(name)
179 self.suffixes = set(suffixes)
180 self.test_format = test_format
181 self.environment = dict(environment)
182 self.substitutions = list(substitutions)
183 self.unsupported = unsupported
184 self.test_exec_root = test_exec_root
185 self.test_source_root = test_source_root
186 self.excludes = set(excludes)
187 self.available_features = set(available_features)
188 self.pipefail = pipefail
189 self.standalone_tests = standalone_tests
190 # This list is used by TestRunner.py to restrict running only tests that
191 # require one of the features in this list if this list is non-empty.
192 # Configurations can set this list to restrict the set of tests to run.
193 self.limit_to_features = set(limit_to_features)
194 self.parallelism_group = parallelism_group
195 self._recursiveExpansionLimit = None
197 @property
198 def recursiveExpansionLimit(self):
199 return self._recursiveExpansionLimit
201 @recursiveExpansionLimit.setter
202 def recursiveExpansionLimit(self, value):
203 if value is not None and not isinstance(value, int):
204 raise ValueError(
205 "recursiveExpansionLimit must be either None or an integer (got <{}>)".format(
206 value
209 if isinstance(value, int) and value < 0:
210 raise ValueError(
211 "recursiveExpansionLimit must be a non-negative integer (got <{}>)".format(
212 value
215 self._recursiveExpansionLimit = value
217 def finish(self, litConfig):
218 """finish() - Finish this config object, after loading is complete."""
220 self.name = str(self.name)
221 self.suffixes = set(self.suffixes)
222 self.environment = dict(self.environment)
223 self.substitutions = list(self.substitutions)
224 if self.test_exec_root is not None:
225 # FIXME: This should really only be suite in test suite config
226 # files. Should we distinguish them?
227 self.test_exec_root = str(self.test_exec_root)
228 if self.test_source_root is not None:
229 # FIXME: This should really only be suite in test suite config
230 # files. Should we distinguish them?
231 self.test_source_root = str(self.test_source_root)
232 self.excludes = set(self.excludes)
234 @property
235 def root(self):
236 """root attribute - The root configuration for the test suite."""
237 if self.parent is None:
238 return self
239 else:
240 return self.parent.root
243 class SubstituteCaptures:
245 Helper class to indicate that the substitutions contains backreferences.
247 This can be used as the following in lit.cfg to mark subsitutions as having
248 back-references::
250 config.substutions.append(('\b[^ ]*.cpp', SubstituteCaptures('\0.txt')))
254 def __init__(self, substitution):
255 self.substitution = substitution
257 def replace(self, pattern, replacement):
258 return self.substitution
260 def __str__(self):
261 return self.substitution
263 def __len__(self):
264 return len(self.substitution)
266 def __getitem__(self, item):
267 return self.substitution.__getitem__(item)