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 return TestingConfig.frompath(path, config.parent, self, 65 mustExist = True, 66 config = config) 67 68 def getBashPath(self): 69 """getBashPath - Get the path to 'bash'""" 70 import os, Util 71 72 if self.bashPath is not None: 73 return self.bashPath 74 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): 80 self.bashPath = path 81 break 82 83 if self.bashPath is None: 84 self.warning("Unable to find 'bash', running Tcl tests internally.") 85 self.bashPath = '' 86 87 return self.bashPath 88 89 def getToolsPath(self, dir, paths, tools): 90 import os, Util 91 if dir is not None and os.path.isabs(dir) and os.path.isdir(dir): 92 if not Util.checkToolsPath(dir, tools): 93 return None 94 else: 95 dir = Util.whichTools(tools, paths) 96 97 # bash 98 self.bashPath = Util.which('bash', dir) 99 if self.bashPath is None: 100 self.note("Unable to find 'bash.exe'.") 101 self.bashPath = '' 102 103 return dir 104 105 def _write_message(self, kind, message): 106 import inspect, os, sys 107 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. 111 f = f.f_back.f_back 112 file,line,_,_,_ = inspect.getframeinfo(f) 113 location = '%s:%d' % (os.path.basename(file), line) 114 115 print >>sys.stderr, '%s: %s: %s: %s' % (self.progname, location, 116 kind, message) 117 118 def note(self, message): 119 self._write_message('note', message) 120 121 def warning(self, message): 122 self._write_message('warning', message) 123 self.numWarnings += 1 124 125 def error(self, message): 126 self._write_message('error', message) 127 self.numErrors += 1 128 129 def fatal(self, message): 130 import sys 131 self._write_message('fatal', message) 132 sys.exit(2) 133