2015-07-11 07:51:30 +02:00
|
|
|
#!/usr/bin/env python
|
2013-06-16 01:25:14 +02:00
|
|
|
|
|
|
|
# Copyright (c) 2013, Arvid Norberg
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in
|
|
|
|
# the documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived
|
|
|
|
# from this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
# this is meant to be run from the root of the repository
|
|
|
|
# the arguments are the boost-build toolsets to use.
|
|
|
|
# these will vary between testers and operating systems
|
|
|
|
# common ones are: clang, darwin, gcc, msvc, icc
|
|
|
|
|
|
|
|
import random
|
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import subprocess
|
|
|
|
import xml.etree.ElementTree as et
|
|
|
|
from datetime import datetime
|
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
import yaml
|
2013-06-21 07:47:30 +02:00
|
|
|
import glob
|
|
|
|
import shutil
|
2013-06-22 19:36:00 +02:00
|
|
|
import traceback
|
2014-01-26 18:31:06 +01:00
|
|
|
import clean
|
2013-06-16 01:25:14 +02:00
|
|
|
|
|
|
|
# the .regression.yml configuration file format looks like this (it's yaml):
|
|
|
|
|
2013-06-16 06:25:43 +02:00
|
|
|
# test_dirs:
|
|
|
|
# - <path-to-test-folder>
|
|
|
|
# - ...
|
2013-06-16 01:25:14 +02:00
|
|
|
#
|
|
|
|
# features:
|
2013-06-16 06:25:43 +02:00
|
|
|
# - <list of boost-built features>
|
|
|
|
# - ...
|
2013-06-16 01:25:14 +02:00
|
|
|
#
|
|
|
|
|
2013-06-16 06:25:43 +02:00
|
|
|
def svn_info():
|
|
|
|
# figure out which revision this is
|
|
|
|
p = subprocess.Popen(['svn', 'info'], stdout=subprocess.PIPE)
|
2013-06-16 01:25:14 +02:00
|
|
|
|
2013-06-16 06:25:43 +02:00
|
|
|
revision = -1
|
|
|
|
author = ''
|
2013-06-16 01:25:14 +02:00
|
|
|
|
|
|
|
for l in p.stdout:
|
2013-06-16 06:25:43 +02:00
|
|
|
if 'Last Changed Rev' in l:
|
|
|
|
revision = int(l.split(':')[1].strip())
|
|
|
|
if 'Last Changed Author' in l:
|
|
|
|
author = l.split(':')[1].strip()
|
|
|
|
|
|
|
|
if revision == -1:
|
|
|
|
print 'Failed to extract subversion revision'
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if author == '':
|
|
|
|
print 'Failed to extract subversion author'
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
return (revision, author)
|
|
|
|
|
2014-01-26 18:31:06 +01:00
|
|
|
def run_tests(toolset, tests, features, options, test_dir, time_limit):
|
2013-06-23 03:34:19 +02:00
|
|
|
assert(type(features) == str)
|
|
|
|
|
2013-06-16 06:25:43 +02:00
|
|
|
xml_file = 'bjam_build.%d.xml' % random.randint(0, 100000)
|
2013-06-20 06:43:45 +02:00
|
|
|
try:
|
2013-06-16 06:25:43 +02:00
|
|
|
|
2013-06-20 06:43:45 +02:00
|
|
|
results = {}
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2013-09-15 14:53:53 +02:00
|
|
|
feature_list = features.split(' ')
|
2013-06-20 06:43:45 +02:00
|
|
|
os.chdir(test_dir)
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2014-03-30 11:11:38 +02:00
|
|
|
c = 0
|
2013-06-20 06:43:45 +02:00
|
|
|
for t in tests:
|
2014-03-30 11:11:38 +02:00
|
|
|
c = c + 1
|
|
|
|
|
2013-10-03 17:47:58 +02:00
|
|
|
options_copy = options[:]
|
|
|
|
if t != '': options_copy.append(t)
|
2013-10-02 18:11:31 +02:00
|
|
|
if t == '':
|
|
|
|
t = os.path.split(os.getcwd())[1]
|
|
|
|
# we can't pass in a launcher when just building, that only
|
|
|
|
# works for actual unit tests
|
2013-10-03 17:47:58 +02:00
|
|
|
if 'launcher=valgrind' in options_copy:
|
|
|
|
options_copy.remove('launcher=valgrind')
|
2014-03-17 00:55:18 +01:00
|
|
|
cmdline = ['bjam', '--out-xml=%s' % xml_file, '-l%d' % time_limit, \
|
|
|
|
'-q', '--abbreviate-paths', toolset] + options_copy + feature_list
|
2014-07-06 21:18:00 +02:00
|
|
|
# print 'calling ', cmdline
|
2013-10-02 18:11:31 +02:00
|
|
|
|
2013-09-15 14:53:53 +02:00
|
|
|
p = subprocess.Popen(cmdline, stdout=subprocess.PIPE, cwd=test_dir)
|
2013-06-20 06:43:45 +02:00
|
|
|
output = ''
|
|
|
|
for l in p.stdout:
|
2015-01-16 05:57:58 +01:00
|
|
|
if 'launcher=valgrind' in options_copy and l.startswith('chase_cuOff'):
|
|
|
|
continue
|
2013-06-20 06:43:45 +02:00
|
|
|
output += l.decode('latin-1')
|
2014-03-30 11:11:38 +02:00
|
|
|
sys.stdout.write('.')
|
|
|
|
sys.stdout.flush()
|
2013-06-20 06:43:45 +02:00
|
|
|
p.wait()
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2013-06-20 06:43:45 +02:00
|
|
|
# parse out the toolset version from the xml file
|
|
|
|
compiler = ''
|
|
|
|
compiler_version = ''
|
|
|
|
command = ''
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2013-06-20 06:43:45 +02:00
|
|
|
# make this parse the actual test to pick up the time
|
|
|
|
# spent runnin the test
|
|
|
|
try:
|
|
|
|
dom = et.parse(xml_file)
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2013-06-20 06:43:45 +02:00
|
|
|
command = dom.find('./command').text
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2013-06-20 06:43:45 +02:00
|
|
|
prop = dom.findall('./action/properties/property')
|
|
|
|
for a in prop:
|
|
|
|
name = a.attrib['name']
|
|
|
|
if name == 'toolset':
|
|
|
|
compiler = a.text
|
|
|
|
if compiler_version != '': break
|
|
|
|
if name.startswith('toolset-') and name.endswith(':version'):
|
|
|
|
compiler_version = a.text
|
|
|
|
if compiler != '': break
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2013-06-20 06:43:45 +02:00
|
|
|
if compiler != '' and compiler_version != '':
|
|
|
|
toolset = compiler + '-' + compiler_version
|
|
|
|
except: pass
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2013-06-20 06:43:45 +02:00
|
|
|
r = { 'status': p.returncode, 'output': output, 'command': command }
|
|
|
|
results[t + '|' + features] = r
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2014-03-30 11:11:38 +02:00
|
|
|
if p.returncode != 0:
|
2014-03-31 08:43:29 +02:00
|
|
|
# if the build or test failed, print out the
|
|
|
|
# important parts
|
2014-03-30 11:11:38 +02:00
|
|
|
sys.stdout.write('\n')
|
2014-03-31 08:43:29 +02:00
|
|
|
print command
|
|
|
|
for l in output:
|
|
|
|
if 'error: ' in l or \
|
|
|
|
': fatal error: ' in l or \
|
|
|
|
'failed to write output file' in l or \
|
|
|
|
': error C' in l or \
|
|
|
|
'undefined reference to ' in l or \
|
|
|
|
' error LNK' in l or \
|
|
|
|
'TEST_CHECK' in l or \
|
|
|
|
'TEST_EQUAL_ERROR' in l or \
|
|
|
|
'"ERROR: "' in l or \
|
|
|
|
l.startswith('EXIT STATUS: ') or \
|
|
|
|
' second time limit exceeded' in l or \
|
|
|
|
l.startswith('signal: SIG') or \
|
|
|
|
'jump or move depends on uninitialised value(s)' in l or \
|
|
|
|
'Invalid read of size' in l or \
|
|
|
|
'Invalid write of size' in l or \
|
|
|
|
'Use of uninitialised value of size' in l or \
|
|
|
|
'Uninitialised byte(s) found during' in l or \
|
|
|
|
'points to uninitialised byte(s)' in l:
|
|
|
|
print l
|
2014-03-30 11:11:38 +02:00
|
|
|
|
|
|
|
print '\n%s - %d / %d' % (toolset, c, len(tests))
|
2013-06-20 06:43:45 +02:00
|
|
|
|
2013-06-22 19:36:00 +02:00
|
|
|
except Exception, e:
|
2013-06-21 04:15:47 +02:00
|
|
|
# need this to make child processes exit
|
2013-06-22 19:36:00 +02:00
|
|
|
print 'exiting test process: ', traceback.format_exc()
|
2013-06-21 04:15:47 +02:00
|
|
|
sys.exit(1)
|
2013-06-20 06:43:45 +02:00
|
|
|
finally:
|
2013-06-16 06:25:43 +02:00
|
|
|
try: os.unlink(xml_file)
|
|
|
|
except: pass
|
|
|
|
|
|
|
|
return (toolset, results)
|
|
|
|
|
|
|
|
def print_usage():
|
2014-02-03 04:23:17 +01:00
|
|
|
print '''usage: run_tests.py [options] bjam-toolset [bjam-toolset...] [bjam-option...]
|
2013-06-16 06:25:43 +02:00
|
|
|
options:
|
|
|
|
-j<n> use n parallel processes
|
|
|
|
-h prints this message and exits
|
2013-06-18 07:38:09 +02:00
|
|
|
-i build incrementally (i.e. don't clean between checkouts)
|
2013-09-03 03:57:43 +02:00
|
|
|
-valgrind run tests with valgrind (requires valgrind to be installed)
|
2013-06-16 06:25:43 +02:00
|
|
|
'''
|
|
|
|
|
2013-06-16 22:37:54 +02:00
|
|
|
def main(argv):
|
2013-06-16 06:25:43 +02:00
|
|
|
|
|
|
|
toolsets = []
|
|
|
|
|
2013-06-18 07:38:09 +02:00
|
|
|
incremental = False
|
2013-06-16 06:25:43 +02:00
|
|
|
|
2013-09-03 03:57:43 +02:00
|
|
|
test_dirs = []
|
2014-03-17 00:55:18 +01:00
|
|
|
build_dirs = []
|
2013-09-03 03:57:43 +02:00
|
|
|
configs = []
|
2015-08-09 01:18:05 +02:00
|
|
|
options = ['preserve-test-targets=on']
|
2013-09-03 03:57:43 +02:00
|
|
|
time_limit = 1200
|
|
|
|
|
2013-06-16 22:37:54 +02:00
|
|
|
for arg in argv:
|
2013-06-16 06:25:43 +02:00
|
|
|
if arg[0] == '-':
|
|
|
|
if arg[1] == 'j':
|
|
|
|
num_processes = int(arg[2:])
|
2014-03-30 11:11:38 +02:00
|
|
|
options.append('-j%d' % num_processes)
|
2013-06-16 06:25:43 +02:00
|
|
|
elif arg[1] == 'h':
|
|
|
|
print_usage()
|
|
|
|
sys.exit(1)
|
2013-06-18 07:38:09 +02:00
|
|
|
elif arg[1] == 'i':
|
|
|
|
incremental = True
|
2013-09-03 03:57:43 +02:00
|
|
|
elif arg[1:] == 'valgrind':
|
|
|
|
options.append('launcher=valgrind')
|
2013-06-16 06:25:43 +02:00
|
|
|
else:
|
|
|
|
print 'unknown option: %s' % arg
|
|
|
|
print_usage()
|
|
|
|
sys.exit(1)
|
2014-02-03 04:23:17 +01:00
|
|
|
elif '=' in arg:
|
|
|
|
options.append(arg)
|
2013-06-16 06:25:43 +02:00
|
|
|
else:
|
|
|
|
toolsets.append(arg)
|
|
|
|
|
|
|
|
if toolsets == []:
|
|
|
|
print_usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
2014-01-26 18:31:06 +01:00
|
|
|
if not incremental:
|
|
|
|
print 'cleaning repo'
|
|
|
|
clean.clean()
|
|
|
|
|
2013-06-16 06:25:43 +02:00
|
|
|
try:
|
|
|
|
cfg = open('.regression.yml', 'r')
|
|
|
|
except:
|
2013-06-20 05:20:02 +02:00
|
|
|
print '.regression.yml not found in current directory'
|
2013-06-16 06:25:43 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
cfg = yaml.load(cfg.read())
|
|
|
|
|
|
|
|
if 'test_dirs' in cfg:
|
|
|
|
for d in cfg['test_dirs']:
|
2013-09-15 14:53:53 +02:00
|
|
|
test_dirs.append(os.path.abspath(d))
|
2014-03-17 00:55:18 +01:00
|
|
|
|
|
|
|
if 'build_dirs' in cfg:
|
|
|
|
for d in cfg['build_dirs']:
|
|
|
|
build_dirs.append(os.path.abspath(d))
|
|
|
|
test_dirs.append(os.path.abspath(d))
|
|
|
|
|
|
|
|
if len(build_dirs) == 0 and len(test_dirs) == 0:
|
|
|
|
print 'no test or build directory specified by .regression.yml'
|
2013-06-16 06:25:43 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
configs = []
|
|
|
|
if 'features' in cfg:
|
|
|
|
for d in cfg['features']:
|
|
|
|
configs.append(d)
|
|
|
|
else:
|
2013-06-23 03:34:19 +02:00
|
|
|
configs = ['']
|
2013-06-16 06:25:43 +02:00
|
|
|
|
2014-03-17 00:55:18 +01:00
|
|
|
build_configs = []
|
|
|
|
if 'build_features' in cfg:
|
|
|
|
for d in cfg['build_features']:
|
|
|
|
build_configs.append(d)
|
|
|
|
|
2013-06-20 05:20:02 +02:00
|
|
|
clean_files = []
|
|
|
|
if 'clean' in cfg:
|
|
|
|
clean_files = cfg['clean']
|
|
|
|
|
2013-06-17 03:30:45 +02:00
|
|
|
branch_name = 'trunk'
|
|
|
|
if 'branch' in cfg:
|
|
|
|
branch_name = cfg['branch']
|
|
|
|
|
2013-06-17 08:54:00 +02:00
|
|
|
if 'time_limit' in cfg:
|
|
|
|
time_limit = int(cfg['time_limit'])
|
|
|
|
|
2013-09-04 07:52:43 +02:00
|
|
|
# it takes a bit longer to run in valgrind
|
|
|
|
if 'launcher=valgrind' in options:
|
2014-03-17 00:55:18 +01:00
|
|
|
time_limit *= 7
|
2013-09-04 07:52:43 +02:00
|
|
|
|
2013-06-16 06:25:43 +02:00
|
|
|
architecture = platform.machine()
|
|
|
|
build_platform = platform.system() + '-' + platform.release()
|
|
|
|
|
|
|
|
revision, author = svn_info()
|
|
|
|
|
|
|
|
timestamp = datetime.now()
|
|
|
|
|
2013-06-17 03:30:45 +02:00
|
|
|
print '%s-%d - %s - %s' % (branch_name, revision, author, timestamp)
|
2013-06-16 06:25:43 +02:00
|
|
|
|
2013-06-16 22:37:54 +02:00
|
|
|
print 'toolsets: %s' % ' '.join(toolsets)
|
|
|
|
# print 'configs: %s' % '|'.join(configs)
|
2013-06-16 06:25:43 +02:00
|
|
|
|
2013-06-17 00:51:03 +02:00
|
|
|
current_dir = os.getcwd()
|
2013-06-16 06:25:43 +02:00
|
|
|
|
2013-06-17 00:51:03 +02:00
|
|
|
try:
|
|
|
|
rev_dir = os.path.join(current_dir, 'regression_tests')
|
|
|
|
try: os.mkdir(rev_dir)
|
|
|
|
except: pass
|
2013-06-17 03:30:45 +02:00
|
|
|
rev_dir = os.path.join(rev_dir, '%s-%d' % (branch_name, revision))
|
2013-06-17 00:51:03 +02:00
|
|
|
try: os.mkdir(rev_dir)
|
|
|
|
except: pass
|
2013-06-16 06:25:43 +02:00
|
|
|
|
2014-03-30 11:11:38 +02:00
|
|
|
for toolset in toolsets:
|
|
|
|
results = {}
|
|
|
|
for test_dir in test_dirs:
|
|
|
|
print 'running tests from "%s" in %s' % (test_dir, branch_name)
|
|
|
|
os.chdir(test_dir)
|
|
|
|
test_dir = os.getcwd()
|
|
|
|
|
|
|
|
# figure out which tests are exported by this Jamfile
|
|
|
|
p = subprocess.Popen(['bjam', '--dump-tests', 'non-existing-target'], stdout=subprocess.PIPE, cwd=test_dir)
|
|
|
|
|
|
|
|
tests = []
|
|
|
|
|
|
|
|
output = ''
|
|
|
|
for l in p.stdout:
|
|
|
|
output += l
|
|
|
|
if not 'boost-test(RUN)' in l: continue
|
|
|
|
test_name = os.path.split(l.split(' ')[1][1:-1])[1]
|
|
|
|
tests.append(test_name)
|
|
|
|
print 'found %d tests' % len(tests)
|
|
|
|
if len(tests) == 0:
|
|
|
|
tests = ['']
|
2013-06-17 00:51:03 +02:00
|
|
|
|
2014-03-17 00:55:18 +01:00
|
|
|
additional_configs = []
|
|
|
|
if test_dir in build_dirs:
|
|
|
|
additional_configs = build_configs
|
2013-09-22 15:47:33 +02:00
|
|
|
|
2014-03-17 00:55:18 +01:00
|
|
|
futures = []
|
|
|
|
for features in configs + additional_configs:
|
2014-03-30 11:11:38 +02:00
|
|
|
(compiler, r) = run_tests(toolset, tests, features, options, test_dir, time_limit)
|
|
|
|
results.update(r)
|
2014-03-17 00:55:18 +01:00
|
|
|
|
2013-06-18 04:30:41 +02:00
|
|
|
print ''
|
|
|
|
|
2013-06-20 05:20:02 +02:00
|
|
|
if len(clean_files) > 0:
|
2013-06-23 03:34:19 +02:00
|
|
|
print 'deleting ',
|
2013-06-20 05:20:02 +02:00
|
|
|
for filt in clean_files:
|
2014-03-30 11:11:38 +02:00
|
|
|
for f in glob.glob(os.path.join(test_dir, filt)):
|
2014-01-26 18:31:06 +01:00
|
|
|
# a precaution to make sure a malicious repo
|
2013-06-20 05:20:02 +02:00
|
|
|
# won't clean things outside of the test directory
|
|
|
|
if not os.path.abspath(f).startswith(test_dir): continue
|
2013-06-23 03:34:19 +02:00
|
|
|
print '%s ' % f,
|
|
|
|
try: shutil.rmtree(f)
|
|
|
|
except: pass
|
|
|
|
print ''
|
2013-09-15 14:53:53 +02:00
|
|
|
|
|
|
|
# each file contains a full set of tests for one speific toolset and platform
|
|
|
|
try:
|
|
|
|
f = open(os.path.join(rev_dir, build_platform + '#' + toolset + '.json'), 'w+')
|
2014-03-30 22:13:42 +02:00
|
|
|
except IOError, e:
|
|
|
|
print e
|
2013-09-15 14:53:53 +02:00
|
|
|
rev_dir = os.path.join(current_dir, 'regression_tests')
|
|
|
|
try: os.mkdir(rev_dir)
|
|
|
|
except: pass
|
|
|
|
rev_dir = os.path.join(rev_dir, '%s-%d' % (branch_name, revision))
|
|
|
|
try: os.mkdir(rev_dir)
|
|
|
|
except: pass
|
|
|
|
f = open(os.path.join(rev_dir, build_platform + '#' + toolset + '.json'), 'w+')
|
|
|
|
|
2014-03-30 11:11:38 +02:00
|
|
|
print >>f, json.dumps(results)
|
2013-09-15 14:53:53 +02:00
|
|
|
f.close()
|
|
|
|
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2013-06-17 00:51:03 +02:00
|
|
|
finally:
|
|
|
|
# always restore current directory
|
2013-06-22 22:32:17 +02:00
|
|
|
try:
|
|
|
|
os.chdir(current_dir)
|
|
|
|
except: pass
|
2013-06-16 06:25:43 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2013-06-16 22:37:54 +02:00
|
|
|
main(sys.argv[1:])
|
2013-06-16 01:25:14 +02:00
|
|
|
|