1 from __future__ import absolute_import
6 import lit.TestingConfig
10 """LitConfig - Configuration data for a 'lit' test runner instance, shared
13 The LitConfig object is also used to communicate with client configuration
14 files, it is always passed in as the global variable 'lit' so that
15 configuration files can access common functionality and internal components
19 # Provide access to Test module.
22 # Provide access to built-in formats.
23 formats = lit.TestFormats
25 # Provide access to built-in utility functions.
28 def __init__(self, progname, path, quiet,
29 useValgrind, valgrindLeakCheck, valgrindArgs,
30 debug, isWindows, params, config_prefix = None):
31 # The name of the test runner.
32 self.progname = progname
33 # The items to add to the PATH environment variable.
34 self.path = list(map(str, path))
35 self.quiet = bool(quiet)
36 self.useValgrind = bool(useValgrind)
37 self.valgrindLeakCheck = bool(valgrindLeakCheck)
38 self.valgrindUserArgs = list(valgrindArgs)
40 self.isWindows = bool(isWindows)
41 self.params = dict(params)
44 # Configuration files to look for when discovering test suites.
45 self.config_prefix = config_prefix or 'lit'
46 self.config_name = '%s.cfg' % (self.config_prefix,)
47 self.site_config_name = '%s.site.cfg' % (self.config_prefix,)
48 self.local_config_name = '%s.local.cfg' % (self.config_prefix,)
53 self.valgrindArgs = []
55 self.valgrindArgs = ['valgrind', '-q', '--run-libc-freeres=no',
56 '--tool=memcheck', '--trace-children=yes',
57 '--error-exitcode=123']
58 if self.valgrindLeakCheck:
59 self.valgrindArgs.append('--leak-check=full')
61 # The default is 'summary'.
62 self.valgrindArgs.append('--leak-check=no')
63 self.valgrindArgs.extend(self.valgrindUserArgs)
66 def load_config(self, config, path):
67 """load_config(config, path) - Load a config object from an alternate
70 self.note('load_config from %r' % path)
71 return lit.TestingConfig.TestingConfig.frompath(
72 path, config.parent, self, mustExist = True, config = config)
74 def getBashPath(self):
75 """getBashPath - Get the path to 'bash'"""
78 if self.bashPath is not None:
81 self.bashPath = lit.Util.which('bash', os.pathsep.join(self.path))
82 if self.bashPath is None:
83 # Check some known paths.
84 for path in ('/bin/bash', '/usr/bin/bash', '/usr/local/bin/bash'):
85 if os.path.exists(path):
89 if self.bashPath is None:
90 self.warning("Unable to find 'bash'.")
95 def getToolsPath(self, dir, paths, tools):
96 if dir is not None and os.path.isabs(dir) and os.path.isdir(dir):
97 if not lit.Util.checkToolsPath(dir, tools):
100 dir = lit.Util.whichTools(tools, paths)
103 self.bashPath = Util.which('bash', dir)
104 if self.bashPath is None:
105 self.note("Unable to find 'bash.exe'.")
110 def _write_message(self, kind, message):
111 import inspect, os, sys
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):
136 self._write_message('fatal', message)