1class LitConfig: 2 """LitConfig - Configuration data for a 'lit' test runner instance, shared 3 across all tests. 4 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 8 easily. 9 """ 10 11 # Provide access to Test module. 12 import Test 13 14 # Provide access to built-in formats. 15 import LitFormats as formats 16 17 # Provide access to built-in utility functions. 18 import Util as util 19 20 def __init__(self, progname, path, quiet, 21 useValgrind, valgrindLeakCheck, valgrindArgs, 22 useTclAsSh, 23 noExecute, ignoreStdErr, debug, isWindows, 24 params): 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 36 self.debug = debug 37 self.isWindows = bool(isWindows) 38 self.params = dict(params) 39 self.bashPath = None 40 41 self.numErrors = 0 42 self.numWarnings = 0 43 44 self.valgrindArgs = [] 45 self.valgrindTriple = "" 46 if self.useValgrind: 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') 54 else: 55 # The default is 'summary'. 56 self.valgrindArgs.append('--leak-check=no') 57 self.valgrindArgs.extend(self.valgrindUserArgs) 58 59 60 def load_config(self, config, path): 61 """load_config(config, path) - Load a config object from an alternate 62 path.""" 63 from TestingConfig import TestingConfig 64 if self.debug: 65 self.note('load_config from %r' % path) 66 return TestingConfig.frompath(path, config.parent, self, 67 mustExist = True, 68 config = config) 69 70 def getBashPath(self): 71 """getBashPath - Get the path to 'bash'""" 72 import os, Util 73 74 if self.bashPath is not None: 75 return self.bashPath 76 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): 82 self.bashPath = path 83 break 84 85 if self.bashPath is None: 86 self.warning("Unable to find 'bash', running Tcl tests internally.") 87 self.bashPath = '' 88 89 return self.bashPath 90 91 def getToolsPath(self, dir, paths, tools): 92 import os, Util 93 if dir is not None and os.path.isabs(dir) and os.path.isdir(dir): 94 if not Util.checkToolsPath(dir, tools): 95 return None 96 else: 97 dir = Util.whichTools(tools, paths) 98 99 # bash 100 self.bashPath = Util.which('bash', dir) 101 if self.bashPath is None: 102 self.note("Unable to find 'bash.exe'.") 103 self.bashPath = '' 104 105 return dir 106 107 def _write_message(self, kind, message): 108 import inspect, os, sys 109 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. 113 f = f.f_back.f_back 114 file,line,_,_,_ = inspect.getframeinfo(f) 115 location = '%s:%d' % (os.path.basename(file), line) 116 117 print >>sys.stderr, '%s: %s: %s: %s' % (self.progname, location, 118 kind, message) 119 120 def note(self, message): 121 self._write_message('note', message) 122 123 def warning(self, message): 124 self._write_message('warning', message) 125 self.numWarnings += 1 126 127 def error(self, message): 128 self._write_message('error', message) 129 self.numErrors += 1 130 131 def fatal(self, message): 132 import sys 133 self._write_message('fatal', message) 134 sys.exit(2) 135