from __future__ import absolute_import
import inspect
import os
import platform
import sys
import lit.Test
import lit.formats
import lit.TestingConfig
import lit.util
class LitConfig(object):
def __init__(self, progname, path, quiet,
useValgrind, valgrindLeakCheck, valgrindArgs,
noExecute, debug, isWindows, order,
params, config_prefix = None,
maxIndividualTestTime = 0,
parallelism_groups = {},
echo_all_commands = False):
self.progname = progname
self.path = [str(p) for p in path]
self.quiet = bool(quiet)
self.useValgrind = bool(useValgrind)
self.valgrindLeakCheck = bool(valgrindLeakCheck)
self.valgrindUserArgs = list(valgrindArgs)
self.noExecute = noExecute
self.debug = debug
self.isWindows = bool(isWindows)
self.order = order
self.params = dict(params)
self.bashPath = None
self.config_prefix = config_prefix or 'lit'
self.suffixes = ['cfg.py', 'cfg']
self.config_names = ['%s.%s' % (self.config_prefix,x) for x in self.suffixes]
self.site_config_names = ['%s.site.%s' % (self.config_prefix,x) for x in self.suffixes]
self.local_config_names = ['%s.local.%s' % (self.config_prefix,x) for x in self.suffixes]
self.numErrors = 0
self.numWarnings = 0
self.valgrindArgs = []
if self.useValgrind:
self.valgrindArgs = ['valgrind', '-q', '--run-libc-freeres=no',
'--tool=memcheck', '--trace-children=yes',
'--error-exitcode=123']
if self.valgrindLeakCheck:
self.valgrindArgs.append('--leak-check=full')
else:
self.valgrindArgs.append('--leak-check=no')
self.valgrindArgs.extend(self.valgrindUserArgs)
self.maxIndividualTestTime = maxIndividualTestTime
self.parallelism_groups = parallelism_groups
self.echo_all_commands = echo_all_commands
@property
def maxIndividualTestTime(self):
return self._maxIndividualTestTime
@property
def maxIndividualTestTimeIsSupported(self):
return lit.util.killProcessAndChildrenIsSupported()
@maxIndividualTestTime.setter
def maxIndividualTestTime(self, value):
if not isinstance(value, int):
self.fatal('maxIndividualTestTime must set to a value of type int.')
self._maxIndividualTestTime = value
if self.maxIndividualTestTime > 0:
supported, errormsg = self.maxIndividualTestTimeIsSupported
if not supported:
self.fatal('Setting a timeout per test not supported. ' +
errormsg)
elif self.maxIndividualTestTime < 0:
self.fatal('The timeout per test must be >= 0 seconds')
def load_config(self, config, path):
if self.debug:
self.note('load_config from %r' % path)
config.load_from_path(path, self)
return config
def getBashPath(self):
if self.bashPath is not None:
return self.bashPath
self.bashPath = lit.util.which('bash', os.pathsep.join(self.path))
if self.bashPath is None:
self.bashPath = lit.util.which('bash')
if self.bashPath is None:
self.bashPath = ''
if self.isWindows and self.bashPath:
command = [self.bashPath, '-c',
'[[ -f "%s" ]]' % self.bashPath.replace('\\', '\\\\')]
_, _, exitCode = lit.util.executeCommand(command)
if exitCode:
self.note('bash command failed: %s' % (
' '.join('"%s"' % c for c in command)))
self.bashPath = ''
if not self.bashPath:
self.warning('Unable to find a usable version of bash.')
return self.bashPath
def getToolsPath(self, dir, paths, tools):
if dir is not None and os.path.isabs(dir) and os.path.isdir(dir):
if not lit.util.checkToolsPath(dir, tools):
return None
else:
dir = lit.util.whichTools(tools, paths)
self.bashPath = lit.util.which('bash', dir)
if self.bashPath is None:
self.bashPath = ''
return dir
def _write_message(self, kind, message):
f = inspect.currentframe()
f = f.f_back.f_back
file = os.path.abspath(inspect.getsourcefile(f))
line = inspect.getlineno(f)
sys.stderr.write('%s: %s:%d: %s: %s\n' % (self.progname, file, line,
kind, message))
if self.isWindows:
sys.stderr.flush()
def substitute(self, string):
try:
return string % self.params
except KeyError as e:
key, = e.args
self.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (
key,key))
def note(self, message):
if not self.quiet:
self._write_message('note', message)
def warning(self, message):
if not self.quiet:
self._write_message('warning', message)
self.numWarnings += 1
def error(self, message):
self._write_message('error', message)
self.numErrors += 1
def fatal(self, message):
self._write_message('fatal', message)
sys.exit(2)