Commit 6a929877 authored by Denis Bilenko's avatar Denis Bilenko

remove test scripts deprecated by testrunner.py

parent 8e88cac9
#!/usr/bin/python
"""Drop the records of the tests that were made against non-clean copy (i.e. with uncommitted changes)
"""
from record_results import get_results_db, sqlite3
if __name__=='__main__':
c = sqlite3.connect(get_results_db())
c.execute('delete from testresult where changeset glob "*+"')
c.commit()
This diff is collapsed.
#!/usr/bin/python
# Copyright (c) 2008-2009 AG Projects
# Author: Denis Bilenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import sys
import traceback
import sqlite3
import re
PARSER_VERSION=1
param_re = re.compile('^===(\w+)=(.*)$', re.M)
def parse_output(s):
argv = re.search('^===ARGV=(.*?)$', s, re.M).group(1)
argv = argv.split()
testname = argv[-1]
params = {'testname': testname}
for m in param_re.finditer(s):
key, val = m.groups()
params[key] = val
return params
greentest_delim = '----------------------------------------------------------------------'
unittest_re = re.compile('^Ran (\d+) test.*?$', re.M)
def parse_greentest_output(s):
s = s[s.rindex(greentest_delim)+len(greentest_delim):]
num = int(unittest_re.search(s).group(1))
ok = re.search('^OK$', s, re.M)
error, fail, timeout = 0, 0, 0
failed_match = re.search(r'^FAILED \((?:failures=(?P<f>\d+))?,? ?(?:errors=(?P<e>\d+))?\)$', s, re.M)
ok_match = re.search('^OK$', s, re.M)
if failed_match:
assert not ok_match, (ok_match, s)
fail = failed_match.group('f')
error = failed_match.group('e')
fail = int(fail or '0')
error = int(error or '0')
else:
assert ok_match, `s`
timeout_match = re.search('^===disabled because of timeout: (\d+)$', s, re.M)
if timeout_match:
timeout = int(timeout_match.group(1))
return num, error, fail, timeout
def main(db, options):
print '%s: parsing output' % db
c = sqlite3.connect(db)
try:
c.execute('''alter table testresult add column parser_version integer default -1''')
c.commit()
except sqlite3.OperationalError, ex:
if 'duplicate column' not in str(ex).lower():
raise
parse_error = 0
SQL = 'select id, command, output, exitcode from testresult'
if not options.redo:
SQL += ' where parser_version!=%s' % PARSER_VERSION
count = 0
try:
for row in c.execute(SQL).fetchall():
id, command, output, exitcode = row
try:
params = parse_output(output)
if greentest_delim in output and unittest_re.search(output) is not None:
runs, errors, fails, timeouts = parse_greentest_output(output)
else:
if exitcode == 0:
runs, errors, fails, timeouts = 1,0,0,0
if exitcode == 7:
runs, errors, fails, timeouts = 0,0,0,1
elif exitcode:
runs, errors, fails, timeouts = 1,1,0,0
except Exception:
traceback.print_exc()
sys.stderr.write('Failed to parse id=%s\n\n' % id)
parse_error += 1
else:
added_columns = set()
params['parser_version'] = PARSER_VERSION
params['runs'] = runs
params['errors'] = errors
params['fails'] = fails
params['timeouts'] = timeouts
items = params.items()
keys = [x[0].lower() for x in items]
values = [x[1] for x in items]
for key in keys:
if key not in added_columns:
added_columns.add(key)
try:
c.execute('''alter table testresult add column %s text''' % key)
c.commit()
except sqlite3.OperationalError, ex:
if 'duplicate column' not in str(ex).lower():
raise
sql = 'update testresult set %s where id=%s' % (', '.join('%s=?' % x for x in keys), id)
c.execute(sql, values)
c.commit()
count += 1
finally:
msg = '%s: %s row%s updated' % (db, count, 's' if count!=1 else '')
if parse_error:
msg += ', %s error%s' % (parse_error, 's' if parse_error!=1 else '')
print msg
return count
if __name__=='__main__':
import optparse
parser = optparse.OptionParser()
parser.add_option('--redo', action='store_true', default=False)
options, args = parser.parse_args()
if not args:
from record_results import get_results_db
db = get_results_db()
args.append(db)
for db in args:
if main(db, options):
import generate_report
generate_report.main(db)
#!/usr/bin/python
# Copyright (c) 2008-2009 AG Projects
# Author: Denis Bilenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""Run the program and record stdout/stderr/exitcode into the database results.rev_changeset.db
Usage: %prog program [args]
"""
import sys
import os
import subprocess
from os.path import abspath, dirname, join, split
try:
import sqlite3
except ImportError:
try:
import pysqlite2.dbapi2 as sqlite3
except ImportError:
sqlite3 = None
print "sqlite3 not installed, won't record the results in the database"
import warnings
from greentest import disabled_marker
warnings.simplefilter('ignore')
path = join(join(*split(dirname(abspath(__file__)))[:-1]), 'testresults')
def get_results_db():
try:
os.makedirs(path)
except OSError:
pass
return join(path, 'results.db')
if sqlite3 is None:
def record(argv, output, returncode):
print output
print 'returncode=%s' % returncode
else:
def record(argv, output, returncode):
print "saving %s bytes of output; returncode=%s" % (len(output), returncode)
path = get_results_db()
c = sqlite3.connect(path)
c.execute('''create table if not exists testresult
(id integer primary key autoincrement,
command text,
output text,
exitcode integer)''')
c.execute('insert into testresult (command, output, exitcode)'
'values (?, ?, ?)', (`argv`, output, returncode))
c.commit()
def main():
argv = sys.argv[1:]
if argv[0]=='-d':
debug = True
del argv[0]
else:
debug = False
arg = ' '.join(argv)
print arg
p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
returncode = p.wait()
output = p.stdout.read()
if not debug:
if returncode==1:
pass
elif returncode==8 and disabled_marker in output:
pass
else:
record(argv, output, returncode)
sys.exit(returncode)
if __name__=='__main__':
main()
#!/usr/bin/python
# Copyright (c) 2008-2009 AG Projects
# Author: Denis Bilenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""Run all the tests"""
import sys
import os
import random
from glob import glob
from optparse import OptionParser
from time import time
import py_compile
COMMAND = sys.executable + ' ./record_results.py ' + sys.executable + ' ./with_timeout.py %(test)s'
PARSE_PERIOD = 10
def w(s):
sys.stderr.write("%s\n" % (s, ))
def enum_tests():
tests = []
tests += glob('test_*.py')
tests += glob('*_test.py')
tests = set(tests) - set(['test_support.py'])
return tests
def cmd(program):
w(program)
res = os.system(program)>>8
w(res)
if res==1:
sys.exit(1)
return res
def main():
global cmd
parser = OptionParser()
parser.add_option('--skip', action='store_true', default=False,
help="Run all the tests except those provided on command line")
parser.add_option('--dry-run', action='store_true', default=False)
options, tests = parser.parse_args()
if options.skip:
tests = enum_tests() - set(tests)
elif not tests:
tests = enum_tests()
tests = list(tests)
random.shuffle(tests)
for test in tests[:]:
try:
py_compile.compile(test, doraise=True)
except py_compile.PyCompileError, ex:
if "SyntaxError: invalid syntax" in str(ex):
print 'skipping %s:\n%s\n' % (test, ex)
tests.remove(test)
else:
raise
print 'tests: %s' % ','.join(tests)
if options.dry_run:
cmd = w
os.system = w
else:
cmd = cmd
last_time = time()
for test in tests:
w(test)
cmd(COMMAND % locals())
if time()-last_time>PARSE_PERIOD:
os.system('./parse_results.py')
last_time = time()
os.system('./parse_results.py')
if __name__=='__main__':
main()
#!/usr/bin/python
# Copyright (c) 2008-2009 AG Projects
# Author: Denis Bilenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
Run Python script in a child process. Kill it after timeout has elapsed.
If the script was running greentest test cases, the timeouted test case is
disabled and the script is restarted.
Usage: %prog [-t TIMEOUT] program.py [args]
If program.py timed out, return 7
If program.py exited with non-zero value, return 8
If program.py exited with zero value after several runs, return 9
If program.py exited with non-zero value after several runs, return 10
"""
import sys
import os
import time
import warnings
if sys.argv[1:2] and sys.argv[1]=='-t':
del sys.argv[1]
TIMEOUT = int(sys.argv[1])
del sys.argv[1]
else:
TIMEOUT = 20
try:
disabled_tests
except NameError:
disabled_tests = []
try:
CURRENT_TEST_FILENAME
except NameError:
warnings.filterwarnings('ignore', 'tmpnam is a potential security risk to your program')
CURRENT_TEST_FILENAME = os.tmpnam()
del warnings.filters[0]
class Alarm(Exception):
pass
def al(*args):
raise Alarm
def _test():
"""
>>> system('./with_timeout.py -t 3 __init__.py')
(0, 0)
>>> system('./with_timeout.py -t 3 /usr/lib/python2.5/BaseHTTPServer.py 0')
(7, 3)
>>> system('./with_timeout.py -t 3 with_timeout.py --selftest1')
(9, 3)
>>> system('./with_timeout.py -t 3 with_timeout.py --selftest2')
(10, 3)
>>> system('./with_timeout.py -t 3 with_timeout.py no_such_file.xxx')
(8, 0)
"""
import doctest
doctest.testmod()
if not sys.argv[1:]:
def system(*args):
start = time.time()
res = os.system(*args)
return res>>8, int(time.time()-start)
#system('./with_timeout.py -t 3 with_timeout.py selftest')
#sys.exit(0)
_test()
sys.exit(__doc__.replace('%prog', sys.argv[0]))
elif sys.argv[1:]==['--selftest1']:
import greentest
class Test(greentest.TestCase):
def test1(self):
pass
def test_long(self):
time.sleep(10)
import test_support
test_support.run_unittest(Test)
sys.exit(0)
elif sys.argv[1:]==['--selftest2']:
import greentest
class Test(greentest.TestCase):
def test_fail(self):
fail
def test_long(self):
time.sleep(10)
import test_support
test_support.run_unittest(Test)
sys.exit(0)
filename = sys.argv[1]
del sys.argv[0]
def execf():
#print 'in execf', disabled_tests
def patch_greentest():
"print test name before it was run and write it pipe"
import greentest
class TestCase(greentest.TestCase):
base = greentest.TestCase
def run(self, result=None):
try:
testMethodName = self._testMethodName
except:
testMethodName = self.__testMethodName
name = "%s.%s" % (self.__class__.__name__, testMethodName)
if name in disabled_tests:
return
print name, ' '
sys.stdout.flush()
file(CURRENT_TEST_FILENAME, 'w').write(name)
try:
return self.base.run(self, result)
finally:
sys.stdout.flush()
try:
os.unlink(CURRENT_TEST_FILENAME)
except:
pass
greentest.TestCase = TestCase
patch_greentest()
execfile(filename, globals())
while True:
#print 'before fork, %s' % disabled_tests
try:
os.unlink(CURRENT_TEST_FILENAME)
except:
pass
child = os.fork()
if child == 0:
print '===PYTHON=%s.%s.%s' % sys.version_info[:3]
print '===ARGV=%s' % ' '.join(sys.argv)
print '===TIMEOUT=%r' % TIMEOUT
import gevent
from gevent import __version__
from gevent import core
print '===VERSION=%s' % __version__
print '===PATH=%s' % gevent.__file__
try:
diffstat = os.popen(r"hg diff 2> /dev/null | diffstat -q").read().strip()
except:
diffstat = None
try:
changeset = os.popen(r"hg log -r tip 2> /dev/null | grep changeset").readlines()[0].replace('changeset:', '').strip().replace(':', '_')
if diffstat:
changeset += '+'
print '===CHANGESET=%s' % changeset
except:
changeset = ''
libevent_version = core.get_version()
if core.get_header_version() != core.get_version() and core.get_header_version() is not None:
libevent_version += '/headers=%s' % core.get_header_version()
print '===LIBEVENT_VERSION=%s' % libevent_version
print '===LIBEVENT_METHOD=%s' % core.get_method()
if diffstat:
print 'Non-clean working directory:'
print '-' * 80
print diffstat
print '-' * 80
sys.stdout.flush()
execf()
break
else:
start = time.time()
import signal
signal.signal(signal.SIGALRM, al)
signal.alarm(TIMEOUT)
pid = None
try:
pid, status = os.waitpid(child, 0)
signal.alarm(0)
except Alarm:
try:
os.kill(child, signal.SIGKILL)
except Exception:
pass
print '\n===%s was killed after %s seconds' % (child, time.time()-start)
sys.stdout.flush()
bad_test = None
try:
bad_test = file(CURRENT_TEST_FILENAME).read()
except IOError:
pass
if bad_test in disabled_tests:
print '\n===%s was disabled but it still managed to fail?!' % bad_test
sys.stdout.flush()
break
if bad_test is None:
sys.exit(7)
print '\n===Trying again, now without %s' % bad_test
sys.stdout.flush()
disabled_tests.append(bad_test)
except:
try:
signal.alarm(0)
except:
pass
try:
os.kill(child, signal.SIGKILL)
except:
pass
raise
else:
print '===%s exited with code %s' % (pid, status)
sys.stdout.flush()
if disabled_tests:
print '\n===disabled because of timeout: %s\n%s\n' % (len(disabled_tests), '\n'.join(disabled_tests))
sys.stdout.flush()
if disabled_tests:
if status:
retcode = 10
else:
retcode = 9
else:
if status:
retcode = 8
else:
retcode = 0
sys.exit(retcode)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment