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 def __init__(self, progname, path, quiet,
22 useValgrind, valgrindLeakCheck, valgrindArgs,
23 noExecute, debug, isWindows,
24 params, config_prefix = None):
25 # The name of the test runner.
26 self.progname = progname
27 # The items to add to the PATH environment variable.
28 self.path = [str(p) for p in path]
29 self.quiet = bool(quiet)
30 self.useValgrind = bool(useValgrind)
31 self.valgrindLeakCheck = bool(valgrindLeakCheck)
32 self.valgrindUserArgs = list(valgrindArgs)
33 self.noExecute = noExecute
35 self.isWindows = bool(isWindows)
36 self.params = dict(params)
39 # Configuration files to look for when discovering test suites.
40 self.config_prefix = config_prefix or 'lit'
41 self.config_name = '%s.cfg' % (self.config_prefix,)
42 self.site_config_name = '%s.site.cfg' % (self.config_prefix,)
43 self.local_config_name = '%s.local.cfg' % (self.config_prefix,)
48 self.valgrindArgs = []
50 self.valgrindArgs = ['valgrind', '-q', '--run-libc-freeres=no',
51 '--tool=memcheck', '--trace-children=yes',
52 '--error-exitcode=123']
53 if self.valgrindLeakCheck:
54 self.valgrindArgs.append('--leak-check=full')
56 # The default is 'summary'.
57 self.valgrindArgs.append('--leak-check=no')
58 self.valgrindArgs.extend(self.valgrindUserArgs)
61 def load_config(self, config, path):
62 """load_config(config, path) - Load a config object from an alternate
65 self.note('load_config from %r' % path)
66 config.load_from_path(path, self)
69 def getBashPath(self):
70 """getBashPath - Get the path to 'bash'"""
71 if self.bashPath is not None:
74 self.bashPath = lit.util.which('bash', os.pathsep.join(self.path))
75 if self.bashPath is None:
76 self.bashPath = lit.util.which('bash')
78 if self.bashPath is None:
83 def getToolsPath(self, dir, paths, tools):
84 if dir is not None and os.path.isabs(dir) and os.path.isdir(dir):
85 if not lit.util.checkToolsPath(dir, tools):
88 dir = lit.util.whichTools(tools, paths)
91 self.bashPath = lit.util.which('bash', dir)
92 if self.bashPath is None:
97 def _write_message(self, kind, message):
98 # Get the file/line where this message was generated.
99 f = inspect.currentframe()
100 # Step out of _write_message, and then out of wrapper.
102 file,line,_,_,_ = inspect.getframeinfo(f)
103 location = '%s:%d' % (os.path.basename(file), line)
105 sys.stderr.write('%s: %s: %s: %s\n' % (self.progname, location,
108 def note(self, message):
109 self._write_message('note', message)
111 def warning(self, message):
112 self._write_message('warning', message)
113 self.numWarnings += 1
115 def error(self, message):
116 self._write_message('error', message)
119 def fatal(self, message):
120 self._write_message('fatal', message)