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 LitFormats as formats
17 # Provide access to built-in utility functions.
20 def __init__(self, progname, path, quiet,
21 useValgrind, valgrindLeakCheck, valgrindArgs,
23 noExecute, ignoreStdErr, debug, isWindows,
25 # The name of the test runner.
26 self.progname = progname
27 # The items to add to the PATH environment variable.
28 self.path = list(map(str, path))
29 self.quiet = bool(quiet)
30 self.useValgrind = bool(useValgrind)
31 self.valgrindLeakCheck = bool(valgrindLeakCheck)
32 self.valgrindUserArgs = list(valgrindArgs)
33 self.useTclAsSh = bool(useTclAsSh)
34 self.noExecute = noExecute
35 self.ignoreStdErr = ignoreStdErr
37 self.isWindows = bool(isWindows)
38 self.params = dict(params)
44 self.valgrindArgs = []
45 self.valgrindTriple = ""
47 self.valgrindTriple = "-vg"
48 self.valgrindArgs = ['valgrind', '-q', '--run-libc-freeres=no',
49 '--tool=memcheck', '--trace-children=yes',
50 '--error-exitcode=123']
51 if self.valgrindLeakCheck:
52 self.valgrindTriple += "_leak"
53 self.valgrindArgs.append('--leak-check=full')
55 # The default is 'summary'.
56 self.valgrindArgs.append('--leak-check=no')
57 self.valgrindArgs.extend(self.valgrindUserArgs)
60 def load_config(self, config, path):
61 """load_config(config, path) - Load a config object from an alternate
63 from TestingConfig import TestingConfig
65 self.note('load_config from %r' % path)
66 return TestingConfig.frompath(path, config.parent, self,
70 def getBashPath(self):
71 """getBashPath - Get the path to 'bash'"""
74 if self.bashPath is not None:
77 self.bashPath = Util.which('bash', os.pathsep.join(self.path))
78 if self.bashPath is None:
79 # Check some known paths.
80 for path in ('/bin/bash', '/usr/bin/bash', '/usr/local/bin/bash'):
81 if os.path.exists(path):
85 if self.bashPath is None:
86 self.warning("Unable to find 'bash', running Tcl tests internally.")
91 def getToolsPath(self, dir, paths, tools):
93 if dir is not None and os.path.isabs(dir) and os.path.isdir(dir):
94 if not Util.checkToolsPath(dir, tools):
97 dir = Util.whichTools(tools, paths)
100 self.bashPath = Util.which('bash', dir)
101 if self.bashPath is None:
102 self.note("Unable to find 'bash.exe'.")
107 def _write_message(self, kind, message):
108 import inspect, os, sys
110 # Get the file/line where this message was generated.
111 f = inspect.currentframe()
112 # Step out of _write_message, and then out of wrapper.
114 file,line,_,_,_ = inspect.getframeinfo(f)
115 location = '%s:%d' % (os.path.basename(file), line)
117 print >>sys.stderr, '%s: %s: %s: %s' % (self.progname, location,
120 def note(self, message):
121 self._write_message('note', message)
123 def warning(self, message):
124 self._write_message('warning', message)
125 self.numWarnings += 1
127 def error(self, message):
128 self._write_message('error', message)
131 def fatal(self, message):
133 self._write_message('fatal', message)