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 return lit.TestingConfig.TestingConfig.frompath(path, config, self)
77 def getBashPath(self):
78 """getBashPath - Get the path to 'bash'"""
79 if self.bashPath is not None:
82 self.bashPath = lit.Util.which('bash', os.pathsep.join(self.path))
83 if self.bashPath is None:
84 # Check some known paths.
85 for path in ('/bin/bash', '/usr/bin/bash', '/usr/local/bin/bash'):
86 if os.path.exists(path):
90 if self.bashPath is None:
91 self.warning("Unable to find 'bash'.")
96 def getToolsPath(self, dir, paths, tools):
97 if dir is not None and os.path.isabs(dir) and os.path.isdir(dir):
98 if not lit.Util.checkToolsPath(dir, tools):
101 dir = lit.Util.whichTools(tools, paths)
104 self.bashPath = lit.Util.which('bash', dir)
105 if self.bashPath is None:
106 self.note("Unable to find 'bash.exe'.")
111 def _write_message(self, kind, message):
112 # Get the file/line where this message was generated.
113 f = inspect.currentframe()
114 # Step out of _write_message, and then out of wrapper.
116 file,line,_,_,_ = inspect.getframeinfo(f)
117 location = '%s:%d' % (os.path.basename(file), line)
119 sys.stderr.write('%s: %s: %s: %s\n' % (self.progname, location,
122 def note(self, message):
123 self._write_message('note', message)
125 def warning(self, message):
126 self._write_message('warning', message)
127 self.numWarnings += 1
129 def error(self, message):
130 self._write_message('error', message)
133 def fatal(self, message):
134 self._write_message('fatal', message)