2 """LitConfig - Configuration data for a 'lit' test runner instance, shared
5 The LitConfig object is also used to communicate with client configuration
6 files, it is always passed in as the global variable 'lit' so that
7 configuration files can access common functionality and internal components
11 # Provide access to Test module.
14 # Provide access to built-in formats.
15 import TestFormats as formats
17 # Provide access to built-in utility functions.
20 def __init__(self, progname, path, quiet,
21 useValgrind, valgrindLeakCheck, valgrindArgs,
22 debug, isWindows, params, config_prefix = None):
23 # The name of the test runner.
24 self.progname = progname
25 # The items to add to the PATH environment variable.
26 self.path = list(map(str, path))
27 self.quiet = bool(quiet)
28 self.useValgrind = bool(useValgrind)
29 self.valgrindLeakCheck = bool(valgrindLeakCheck)
30 self.valgrindUserArgs = list(valgrindArgs)
32 self.isWindows = bool(isWindows)
33 self.params = dict(params)
36 # Configuration files to look for when discovering test suites.
37 self.config_prefix = config_prefix or 'lit'
38 self.config_name = '%s.cfg' % (self.config_prefix,)
39 self.site_config_name = '%s.site.cfg' % (self.config_prefix,)
40 self.local_config_name = '%s.local.cfg' % (self.config_prefix,)
45 self.valgrindArgs = []
47 self.valgrindArgs = ['valgrind', '-q', '--run-libc-freeres=no',
48 '--tool=memcheck', '--trace-children=yes',
49 '--error-exitcode=123']
50 if self.valgrindLeakCheck:
51 self.valgrindArgs.append('--leak-check=full')
53 # The default is 'summary'.
54 self.valgrindArgs.append('--leak-check=no')
55 self.valgrindArgs.extend(self.valgrindUserArgs)
58 def load_config(self, config, path):
59 """load_config(config, path) - Load a config object from an alternate
61 from TestingConfig import TestingConfig
63 self.note('load_config from %r' % path)
64 return TestingConfig.frompath(path, config.parent, self,
68 def getBashPath(self):
69 """getBashPath - Get the path to 'bash'"""
72 if self.bashPath is not None:
75 self.bashPath = Util.which('bash', os.pathsep.join(self.path))
76 if self.bashPath is None:
77 # Check some known paths.
78 for path in ('/bin/bash', '/usr/bin/bash', '/usr/local/bin/bash'):
79 if os.path.exists(path):
83 if self.bashPath is None:
84 self.warning("Unable to find 'bash'.")
89 def getToolsPath(self, dir, paths, tools):
91 if dir is not None and os.path.isabs(dir) and os.path.isdir(dir):
92 if not Util.checkToolsPath(dir, tools):
95 dir = Util.whichTools(tools, paths)
98 self.bashPath = Util.which('bash', dir)
99 if self.bashPath is None:
100 self.note("Unable to find 'bash.exe'.")
105 def _write_message(self, kind, message):
106 import inspect, os, sys
108 # Get the file/line where this message was generated.
109 f = inspect.currentframe()
110 # Step out of _write_message, and then out of wrapper.
112 file,line,_,_,_ = inspect.getframeinfo(f)
113 location = '%s:%d' % (os.path.basename(file), line)
115 print >>sys.stderr, '%s: %s: %s: %s' % (self.progname, location,
118 def note(self, message):
119 self._write_message('note', message)
121 def warning(self, message):
122 self._write_message('warning', message)
123 self.numWarnings += 1
125 def error(self, message):
126 self._write_message('error', message)
129 def fatal(self, message):
131 self._write_message('fatal', message)