1 from __future__ import absolute_import
8 import lit.TestingConfig
12 """LitConfig - Configuration data for a 'lit' test runner instance, shared
15 The LitConfig object is also used to communicate with client configuration
16 files, it is always passed in as the global variable 'lit' so that
17 configuration files can access common functionality and internal components
21 # Provide access to Test module.
24 # Provide access to built-in formats.
25 formats = lit.TestFormats
27 # Provide access to built-in utility functions.
30 def __init__(self, progname, path, quiet,
31 useValgrind, valgrindLeakCheck, valgrindArgs,
32 noExecute, debug, isWindows,
33 params, config_prefix = None):
34 # The name of the test runner.
35 self.progname = progname
36 # The items to add to the PATH environment variable.
37 self.path = [str(p) for p in path]
38 self.quiet = bool(quiet)
39 self.useValgrind = bool(useValgrind)
40 self.valgrindLeakCheck = bool(valgrindLeakCheck)
41 self.valgrindUserArgs = list(valgrindArgs)
42 self.noExecute = noExecute
44 self.isWindows = bool(isWindows)
45 self.params = dict(params)
48 # Configuration files to look for when discovering test suites.
49 self.config_prefix = config_prefix or 'lit'
50 self.config_name = '%s.cfg' % (self.config_prefix,)
51 self.site_config_name = '%s.site.cfg' % (self.config_prefix,)
52 self.local_config_name = '%s.local.cfg' % (self.config_prefix,)
57 self.valgrindArgs = []
59 self.valgrindArgs = ['valgrind', '-q', '--run-libc-freeres=no',
60 '--tool=memcheck', '--trace-children=yes',
61 '--error-exitcode=123']
62 if self.valgrindLeakCheck:
63 self.valgrindArgs.append('--leak-check=full')
65 # The default is 'summary'.
66 self.valgrindArgs.append('--leak-check=no')
67 self.valgrindArgs.extend(self.valgrindUserArgs)
70 def load_config(self, config, path):
71 """load_config(config, path) - Load a config object from an alternate
74 self.note('load_config from %r' % path)
75 config.load_from_path(path, self)
78 def getBashPath(self):
79 """getBashPath - Get the path to 'bash'"""
80 if self.bashPath is not None:
83 self.bashPath = lit.Util.which('bash', os.pathsep.join(self.path))
84 if self.bashPath is None:
85 # Check some known paths.
86 for path in ('/bin/bash', '/usr/bin/bash', '/usr/local/bin/bash'):
87 if os.path.exists(path):
91 if self.bashPath is None:
92 self.warning("Unable to find 'bash'.")
97 def getToolsPath(self, dir, paths, tools):
98 if dir is not None and os.path.isabs(dir) and os.path.isdir(dir):
99 if not lit.Util.checkToolsPath(dir, tools):
102 dir = lit.Util.whichTools(tools, paths)
105 self.bashPath = lit.Util.which('bash', dir)
106 if self.bashPath is None:
107 self.note("Unable to find 'bash.exe'.")
112 def _write_message(self, kind, message):
113 # Get the file/line where this message was generated.
114 f = inspect.currentframe()
115 # Step out of _write_message, and then out of wrapper.
117 file,line,_,_,_ = inspect.getframeinfo(f)
118 location = '%s:%d' % (os.path.basename(file), line)
120 sys.stderr.write('%s: %s: %s: %s\n' % (self.progname, location,
123 def note(self, message):
124 self._write_message('note', message)
126 def warning(self, message):
127 self._write_message('warning', message)
128 self.numWarnings += 1
130 def error(self, message):
131 self._write_message('error', message)
134 def fatal(self, message):
135 self._write_message('fatal', message)