Alien-SVN
view release on metacpan or search on metacpan
src/subversion/build/run_tests.py view on Meta::CPAN
def _get_term_width():
'Attempt to discern the width of the terminal'
# This may not work on all platforms, in which case the default of 80
# characters is used. Improvements welcomed.
def ioctl_GWINSZ(fd):
try:
import fcntl, termios, struct, os
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
except:
return None
return cr
cr = None
if not cr:
try:
cr = (os.environ['SVN_MAKE_CHECK_LINES'],
os.environ['SVN_MAKE_CHECK_COLUMNS'])
except:
cr = None
if not cr:
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
if not cr:
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd)
os.close(fd)
except:
pass
if not cr:
try:
cr = (os.environ['LINES'], os.environ['COLUMNS'])
except:
cr = None
if not cr:
# Default
if sys.platform == 'win32':
cr = (25, 79)
else:
cr = (25, 80)
return int(cr[1])
class TestHarness:
'''Test harness for Subversion tests.
'''
def __init__(self, abs_srcdir, abs_builddir, logfile, faillogfile,
base_url=None, fs_type=None, http_library=None,
server_minor_version=None, verbose=None,
cleanup=None, enable_sasl=None, parallel=None, config_file=None,
fsfs_sharding=None, fsfs_packing=None,
list_tests=None, svn_bin=None, mode_filter=None,
milestone_filter=None, set_log_level=None, ssl_cert=None,
http_proxy=None):
'''Construct a TestHarness instance.
ABS_SRCDIR and ABS_BUILDDIR are the source and build directories.
LOGFILE is the name of the log file. If LOGFILE is None, let tests
print their output to stdout and stderr, and don't print a summary
at the end (since there's no log file to analyze).
BASE_URL is the base url for DAV tests.
FS_TYPE is the FS type for repository creation.
HTTP_LIBRARY is the HTTP library for DAV-based communications.
SERVER_MINOR_VERSION is the minor version of the server being tested.
SVN_BIN is the path where the svn binaries are installed.
MODE_FILTER restricts the TestHarness to tests with the expected mode
XFail, Skip, Pass, or All tests (default). MILESTONE_FILTER is a
string representation of a valid regular expression pattern; when used
in conjunction with LIST_TESTS, the only tests that are listed are
those with an associated issue in the tracker which has a target
milestone that matches the regex.
'''
self.srcdir = abs_srcdir
self.builddir = abs_builddir
self.logfile = logfile
self.faillogfile = faillogfile
self.base_url = base_url
self.fs_type = fs_type
self.http_library = http_library
self.server_minor_version = server_minor_version
# If you change the below condition then change in
# ../subversion/tests/cmdline/svntest/main.py too.
if server_minor_version is not None:
if int(server_minor_version) not in range(3, 1+SVN_VER_MINOR):
sys.stderr.write("Test harness only supports server minor versions 3-%d\n"
% SVN_VER_MINOR)
sys.exit(1)
self.verbose = verbose
self.cleanup = cleanup
self.enable_sasl = enable_sasl
self.parallel = parallel
self.fsfs_sharding = fsfs_sharding
self.fsfs_packing = fsfs_packing
if fsfs_packing is not None and fsfs_sharding is None:
raise Exception('--fsfs-packing requires --fsfs-sharding')
self.config_file = None
if config_file is not None:
self.config_file = os.path.abspath(config_file)
self.list_tests = list_tests
self.milestone_filter = milestone_filter
self.set_log_level = set_log_level
self.svn_bin = svn_bin
self.mode_filter = mode_filter
self.log = None
self.ssl_cert = ssl_cert
self.http_proxy = http_proxy
if not sys.stdout.isatty() or sys.platform == 'win32':
TextColors.disable()
def run(self, list):
'''Run all test programs given in LIST. Print a summary of results, if
there is a log file. Return zero iff all test programs passed.'''
self._open_log('w')
failed = 0
for cnt, prog in enumerate(list):
failed = self._run_test(prog, cnt, len(list)) or failed
if self.log is None:
return failed
# Open the log in binary mode because it can contain binary data
# from diff_tests.py's testing of svnpatch. This may prevent
# readlines() from reading the whole log because it thinks it
# has encountered the EOF marker.
self._open_log('rb')
log_lines = self.log.readlines()
# Remove \r characters introduced by opening the log as binary
if sys.platform == 'win32':
log_lines = [x.replace('\r', '') for x in log_lines]
# Print the results, from least interesting to most interesting.
# Helper for Work-In-Progress indications for XFAIL tests.
wimptag = ' [[WIMP: '
def printxfail(x):
wip = x.find(wimptag)
if 0 > wip:
sys.stdout.write(x)
else:
sys.stdout.write('%s\n [[%s'
% (x[:wip], x[wip + len(wimptag):]))
if self.list_tests:
passed = [x for x in log_lines if x[8:13] == ' ']
src/subversion/build/run_tests.py view on Meta::CPAN
if not self.log is None:
self.log.close()
self.log = None
def _run_c_test(self, prog, test_nums, dot_count):
'Run a c test, escaping parameters as required.'
progdir, progbase = os.path.split(prog)
if self.list_tests and self.milestone_filter:
print 'WARNING: --milestone-filter option does not currently work with C tests'
if os.access(progbase, os.X_OK):
progname = './' + progbase
cmdline = [progname,
'--srcdir=' + os.path.join(self.srcdir, progdir)]
if self.config_file is not None:
cmdline.append('--config-file=' + self.config_file)
else:
print("Don't know what to do about " + progbase)
sys.exit(1)
if self.verbose is not None:
cmdline.append('--verbose')
if self.cleanup is not None:
cmdline.append('--cleanup')
if self.fs_type is not None:
cmdline.append('--fs-type=' + self.fs_type)
if self.server_minor_version is not None:
cmdline.append('--server-minor-version=' + self.server_minor_version)
if self.list_tests is not None:
cmdline.append('--list')
if self.mode_filter is not None:
cmdline.append('--mode-filter=' + self.mode_filter)
if test_nums:
test_nums = test_nums.split(',')
cmdline.extend(test_nums)
if test_nums:
total = len(test_nums)
else:
total_cmdline = [cmdline[0], '--list']
prog = subprocess.Popen(total_cmdline, stdout=subprocess.PIPE)
lines = prog.stdout.readlines()
total = len(lines) - 2
# This has to be class-scoped for use in the progress_func()
self.dots_written = 0
def progress_func(completed):
if not self.log or self.dots_written >= dot_count:
return
dots = (completed * dot_count) / total
if dots > dot_count:
dots = dot_count
dots_to_write = dots - self.dots_written
os.write(sys.stdout.fileno(), '.' * dots_to_write)
self.dots_written = dots
tests_completed = 0
prog = subprocess.Popen(cmdline, stdout=subprocess.PIPE,
stderr=self.log)
line = prog.stdout.readline()
while line:
if sys.platform == 'win32':
# Remove CRs inserted because we parse the output as binary.
line = line.replace('\r', '')
# If using --log-to-stdout self.log in None.
if self.log:
self.log.write(line)
if line.startswith('PASS') or line.startswith('FAIL') \
or line.startswith('XFAIL') or line.startswith('XPASS') \
or line.startswith('SKIP'):
tests_completed += 1
progress_func(tests_completed)
line = prog.stdout.readline()
# If we didn't run any tests, still print out the dots
if not tests_completed:
os.write(sys.stdout.fileno(), '.' * dot_count)
prog.wait()
return prog.returncode
def _run_py_test(self, prog, test_nums, dot_count):
'Run a python test, passing parameters as needed.'
progdir, progbase = os.path.split(prog)
old_path = sys.path[:]
sys.path = [progdir] + sys.path
try:
prog_mod = imp.load_module(progbase[:-3], open(prog, 'r'), prog,
('.py', 'U', imp.PY_SOURCE))
except:
print("Don't know what to do about " + progbase)
sys.exit(1)
import svntest.main
# set up our options
svntest.main.create_default_options()
if self.base_url is not None:
svntest.main.options.test_area_url = self.base_url
if self.enable_sasl is not None:
svntest.main.options.enable_sasl = True
if self.parallel is not None:
svntest.main.options.parallel = svntest.main.default_num_threads
if self.config_file is not None:
svntest.main.options.config_file = self.config_file
if self.verbose is not None:
svntest.main.options.verbose = True
if self.cleanup is not None:
svntest.main.options.cleanup = True
if self.fs_type is not None:
svntest.main.options.fs_type = self.fs_type
if self.http_library is not None:
svntest.main.options.http_library = self.http_library
if self.server_minor_version is not None:
svntest.main.options.server_minor_version = int(self.server_minor_version)
if self.list_tests is not None:
svntest.main.options.list_tests = True
if self.milestone_filter is not None:
svntest.main.options.milestone_filter = self.milestone_filter
if self.set_log_level is not None:
# Somehow the logger is not setup correctly from win-tests.py, so
# setting the log level would fail. ### Please fix
if svntest.main.logger is None:
import logging
svntest.main.logger = logging.getLogger()
svntest.main.logger.setLevel(self.set_log_level)
if self.svn_bin is not None:
svntest.main.options.svn_bin = self.svn_bin
if self.fsfs_sharding is not None:
svntest.main.options.fsfs_sharding = int(self.fsfs_sharding)
if self.fsfs_packing is not None:
svntest.main.options.fsfs_packing = self.fsfs_packing
if self.mode_filter is not None:
svntest.main.options.mode_filter = self.mode_filter
if self.ssl_cert is not None:
svntest.main.options.ssl_cert = self.ssl_cert
if self.http_proxy is not None:
svntest.main.options.http_proxy = self.http_proxy
svntest.main.options.srcdir = self.srcdir
# setup the output pipes
if self.log:
sys.stdout.flush()
sys.stderr.flush()
self.log.flush()
old_stdout = os.dup(sys.stdout.fileno())
old_stderr = os.dup(sys.stderr.fileno())
os.dup2(self.log.fileno(), sys.stdout.fileno())
os.dup2(self.log.fileno(), sys.stderr.fileno())
# These have to be class-scoped for use in the progress_func()
self.dots_written = 0
self.progress_lock = threading.Lock()
def progress_func(completed, total):
"""Report test suite progress. Can be called from multiple threads
in parallel mode."""
if not self.log:
return
dots = (completed * dot_count) / total
if dots > dot_count:
dots = dot_count
self.progress_lock.acquire()
if self.dots_written < dot_count:
dots_to_write = dots - self.dots_written
self.dots_written = dots
os.write(old_stdout, '.' * dots_to_write)
self.progress_lock.release()
serial_only = hasattr(prog_mod, 'serial_only') and prog_mod.serial_only
# run the tests
svntest.testcase.TextColors.disable()
if self.list_tests:
prog_f = None
else:
prog_f = progress_func
if test_nums:
test_selection = [test_nums]
else:
test_selection = []
try:
failed = svntest.main.execute_tests(prog_mod.test_list,
serial_only=serial_only,
test_name=progbase,
progress_func=prog_f,
test_selection=test_selection)
except svntest.Failure:
if self.log:
os.write(old_stdout, '.' * dot_count)
failed = True
# restore some values
sys.path = old_path
if self.log:
sys.stdout.flush()
sys.stderr.flush()
os.dup2(old_stdout, sys.stdout.fileno())
os.dup2(old_stderr, sys.stderr.fileno())
os.close(old_stdout)
os.close(old_stderr)
return failed
def _run_test(self, prog, test_nr, total_tests):
"Run a single test. Return the test's exit code."
if self.log:
log = self.log
else:
log = sys.stdout
test_nums = None
if '#' in prog:
prog, test_nums = prog.split('#')
progdir, progbase = os.path.split(prog)
if self.log:
# Using write here because we don't want even a trailing space
test_info = '[%s/%d] %s' % (str(test_nr + 1).zfill(len(str(total_tests))),
total_tests, progbase)
if self.list_tests:
sys.stdout.write('Listing tests in %s' % (test_info, ))
else:
sys.stdout.write('%s' % (test_info, ))
sys.stdout.flush()
else:
# ### Hack for --log-to-stdout to work (but not print any dots).
test_info = ''
if self.list_tests:
log.write('LISTING: %s\n' % progbase)
else:
log.write('START: %s\n' % progbase)
log.flush()
start_time = datetime.now()
progabs = os.path.abspath(os.path.join(self.srcdir, prog))
old_cwd = os.getcwd()
line_length = _get_term_width()
dots_needed = line_length \
- len(test_info) \
- len('success')
try:
os.chdir(progdir)
if progbase[-3:] == '.py':
failed = self._run_py_test(progabs, test_nums, dots_needed)
else:
failed = self._run_c_test(prog, test_nums, dots_needed)
except:
os.chdir(old_cwd)
raise
else:
os.chdir(old_cwd)
# We always return 1 for failed tests. Some other failure than 1
# probably means the test didn't run at all and probably didn't
# output any failure info. In that case, log a generic failure message.
# ### Even if failure==1 it could be that the test didn't run at all.
( run in 0.847 second using v1.01-cache-2.11-cpan-524268b4103 )