5 class TestingConfig(object):
7 TestingConfig - Information on the tests inside a suite.
11 def fromdefaults(litConfig
):
13 fromdefaults(litConfig) -> TestingConfig
15 Create a TestingConfig object with default values.
17 # Set the environment based on the command line arguments.
19 "PATH": os
.pathsep
.join(litConfig
.path
+ [os
.environ
.get("PATH", "")]),
20 "LLVM_DISABLE_CRASH_REPORT": "1",
31 "LLVM_SYMBOLIZER_PATH",
33 "ASAN_SYMBOLIZER_PATH",
34 "HWASAN_SYMBOLIZER_PATH",
35 "LSAN_SYMBOLIZER_PATH",
36 "MSAN_SYMBOLIZER_PATH",
37 "TSAN_SYMBOLIZER_PATH",
38 "UBSAN_SYMBOLIZER_PATH",
49 "SANITIZER_IGNORE_CVE_2016_2143",
61 "WindowsSDKLibVersion",
67 if sys
.platform
.startswith("aix"):
68 pass_vars
+= ["LIBPATH"]
69 elif sys
.platform
== "win32":
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
85 environment
["__COMPAT_LAYER"] = "RunAsInvoker"
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.
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(
106 environment
=environment
,
110 test_source_root
=None,
112 available_features
=available_features
,
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
125 # Load the config script data.
131 litConfig
.fatal("unable to load config file: %r" % (path
,))
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
140 exec(compile(data
, path
, "exec"), cfg_globals
, None)
142 litConfig
.note("... loaded config %r" % path
)
144 e
= sys
.exc_info()[1]
145 # We allow normal system exit inside a config file to just
146 # return control without error.
153 "unable to parse config file %r, traceback: %s"
154 % (path
, traceback
.format_exc())
156 self
.finish(litConfig
)
172 limit_to_features
=[],
174 parallelism_group
=None,
175 standalone_tests
=False,
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
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):
205 "recursiveExpansionLimit must be either None or an integer (got <{}>)".format(
209 if isinstance(value
, int) and value
< 0:
211 "recursiveExpansionLimit must be a non-negative integer (got <{}>)".format(
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
)
236 """root attribute - The root configuration for the test suite."""
237 if self
.parent
is None:
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
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
261 return self
.substitution
264 return len(self
.substitution
)
266 def __getitem__(self
, item
):
267 return self
.substitution
.__getitem
__(item
)