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, 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.debug = debug 36 self.isWindows = bool(isWindows) 37 self.params = dict(params) 38 self.bashPath = None 39 40 self.numErrors = 0 41 self.numWarnings = 0 42 43 self.valgrindArgs = [] 44 self.valgrindTriple = "" 45 if self.useValgrind: 46 self.valgrindTriple = "-vg" 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.valgrindTriple += "_leak" 52 self.valgrindArgs.append('--leak-check=full') 53 else: 54 # The default is 'summary'. 55 self.valgrindArgs.append('--leak-check=no') 56 self.valgrindArgs.extend(self.valgrindUserArgs) 57 58 59 def load_config(self, config, path): 60 """load_config(config, path) - Load a config object from an alternate 61 path.""" 62 from TestingConfig import TestingConfig 63 return TestingConfig.frompath(path, config.parent, self, 64 mustExist = True, 65 config = config) 66 67 def getBashPath(self): 68 """getBashPath - Get the path to 'bash'""" 69 import os, Util 70 71 if self.bashPath is not None: 72 return self.bashPath 73 74 self.bashPath = Util.which('bash', os.pathsep.join(self.path)) 75 if self.bashPath is None: 76 # Check some known paths. 77 for path in ('/bin/bash', '/usr/bin/bash', '/usr/local/bin/bash'): 78 if os.path.exists(path): 79 self.bashPath = path 80 break 81 82 if self.bashPath is None: 83 self.warning("Unable to find 'bash', running Tcl tests internally.") 84 self.bashPath = '' 85 86 return self.bashPath 87 88 def getToolsPath(self, dir, paths, tools): 89 import os, Util 90 if dir is not None and os.path.isabs(dir) and os.path.isdir(dir): 91 if not Util.checkToolsPath(dir, tools): 92 return None 93 else: 94 dir = Util.whichTools(tools, paths) 95 96 # bash 97 self.bashPath = Util.which('bash', dir) 98 if self.bashPath is None: 99 self.note("Unable to find 'bash.exe'.") 100 self.bashPath = '' 101 102 return dir 103 104 def _write_message(self, kind, message): 105 import inspect, os, sys 106 107 # Get the file/line where this message was generated. 108 f = inspect.currentframe() 109 # Step out of _write_message, and then out of wrapper. 110 f = f.f_back.f_back 111 file,line,_,_,_ = inspect.getframeinfo(f) 112 location = '%s:%d' % (os.path.basename(file), line) 113 114 print >>sys.stderr, '%s: %s: %s: %s' % (self.progname, location, 115 kind, message) 116 117 def note(self, message): 118 self._write_message('note', message) 119 120 def warning(self, message): 121 self._write_message('warning', message) 122 self.numWarnings += 1 123 124 def error(self, message): 125 self._write_message('error', message) 126 self.numErrors += 1 127 128 def fatal(self, message): 129 import sys 130 self._write_message('fatal', message) 131 sys.exit(2) 132