improve regression test reports

This commit is contained in:
Arvid Norberg 2013-06-18 03:58:06 +00:00
parent dcfd69fbe3
commit 296c23c26b
1 changed files with 126 additions and 108 deletions

View File

@ -38,6 +38,8 @@ import glob
import json
import yaml
# TODO: different parsers could be run on output from different actions
# if we would use the xml output in stead of stdout/stderr
def style_output(o):
ret = ''
subtle = False
@ -67,63 +69,7 @@ def modification_time(file):
except: pass
return mtime
# TODO: remove this dependency
project_name = ''
try:
cfg = open('.regression.yml', 'r')
except:
print '.regression.yml not found in current directory'
sys.exit(1)
cfg = yaml.load(cfg.read())
if 'project' in cfg:
project_name = cfg['project']
branch_name = 'trunk'
if 'branch' in cfg:
branch_name = cfg['branch'].strip()
print 'branch: %s' % branch_name
os.chdir('regression_tests')
if len(sys.argv) > 1:
latest_rev = int(sys.argv[1])
else:
latest_rev = 0
for rev in os.listdir('.'):
try:
if not rev.startswith('%s-' % branch_name): continue
r = int(rev[len(branch_name)+1:])
if r > latest_rev: latest_rev = r
except: pass
if latest_rev == 0:
print 'no test files found'
sys.exit(1)
print 'latest version: %d' % latest_rev
rev_dir = '%s-%d' % (branch_name, latest_rev)
html_file = '%s.html' % rev_dir
index_mtime = modification_time(html_file)
need_refresh = False
for f in glob.glob(os.path.join(rev_dir, '*.json')):
mtime = modification_time(f)
if mtime > index_mtime:
need_refresh = True
break
if not need_refresh:
print 'all up to date'
sys.exit(0)
def parse_tests(rev_dir):
# this contains mappings from platforms to
# the next layer of dictionaries. The next
@ -181,42 +127,99 @@ for f in glob.glob(os.path.join(rev_dir, '*.json')):
platforms[platform][toolset][features][test_name] = j[cfg]
return (platforms, tests)
# TODO: remove this dependency by encoding it in the output files
project_name = ''
try:
cfg = open('.regression.yml', 'r')
except:
print '.regression.yml not found in current directory'
sys.exit(1)
cfg = yaml.load(cfg.read())
if 'project' in cfg:
project_name = cfg['project']
branch_name = 'trunk'
if 'branch' in cfg:
branch_name = cfg['branch'].strip()
print 'branch: %s' % branch_name
os.chdir('regression_tests')
if len(sys.argv) > 1:
latest_rev = int(sys.argv[1])
else:
latest_rev = 0
for rev in os.listdir('.'):
try:
if not rev.startswith('%s-' % branch_name): continue
r = int(rev[len(branch_name)+1:])
if r > latest_rev: latest_rev = r
except: pass
if latest_rev == 0:
print 'no test files found'
sys.exit(1)
print 'latest version: %d' % latest_rev
html_file = 'index.html'
'''
html_file = '%s.html' % rev_dir
index_mtime = modification_time(html_file)
need_refresh = False
for f in glob.glob(os.path.join(rev_dir, '*.json')):
mtime = modification_time(f)
if mtime > index_mtime:
need_refresh = True
break
if not need_refresh:
print 'all up to date'
sys.exit(0)
'''
html = open(html_file, 'w+')
print >>html, '''<html><head><title>regression tests, %s revision %d</title><style type="text/css">
print >>html, '''<html><head><title>regression tests, %s</title><style type="text/css">
.passed { display: block; width: 8px; height: 1em; background-color: #6f8 }
.failed { display: block; width: 8px; height: 1em; background-color: #f68 }
table { border: 0; border-collapse: collapse; }
h1 { font-size: 15pt; }
th { font-size: 8pt; }
td { border: 0; border-spacing: 0px; padding: 1px 1px 0px 0px; }
.left-head { white-space: nowrap; }
.compile-error { color: #f13; font-weight: bold; }
.compile-warning { color: #cb0; }
.test-error { color: #f13; font-weight: bold; }
.test-pass { color: #1c2; font-weight: bold; }
.subtle { color: #ccc; }
pre { color: #999; }
</style><script type="text/javascript">
var expanded = -1;
function toggle(i) {
if (expanded != -1) document.getElementById(expanded).style.display = 'none';
expanded = i;
document.getElementById(i).style.display = 'block';
}
</script></head><body>''' % (project_name, latest_rev)
</style>
</head><body><h1>%s - %s</h1>''' % (project_name, project_name, branch_name)
print >>html, '<h1>%s revision %d</h1>' % (project_name, latest_rev)
print >>html, '<a href="%s-%d.html">previous</a> <a href="%s-%d.html">next</a><br>' % (branch_name, latest_rev - 1, branch_name, latest_rev + 1)
print >>html, '<table border="1"><tr><th colspan="2" style="border:0;"></th>'
print >>html, '<table border="1">'
details_id = 0
details = []
for r in range(latest_rev, latest_rev - 20, -1):
sys.stdout.write('.')
sys.stdout.flush()
print >>html, '<tr><th colspan="2" style="border:0;">revision %d</th>' % r
rev_dir = '%s-%d' % (branch_name, r)
(platforms, tests) = parse_tests(rev_dir)
for f in tests:
print >>html, '<th colspan="%d">%s</th>' % (len(tests[f]), f)
print >>html, '</tr>'
details_id = 0
details = []
for p in platforms:
print >>html, '<tr><th class="left-head" rowspan="%d">%s</th>' % (len(platforms[p]), p)
idx = 0
@ -227,7 +230,7 @@ for p in platforms:
for t in platforms[p][toolset][f]:
if platforms[p][toolset][f][t][u'status'] == 0: c = 'passed'
else: c = 'failed'
print >>html, '<td title="%s"><a class="%s" href="javascript:toggle(%d)"></a></td>' % ('%s %s' % (t, f), c, details_id)
print >>html, '<td title="%s %s"><a class="%s" href="%s"></a></td>' % (t, f, c, os.path.join('logs', '%d.html' % details_id))
platforms[p][toolset][f][t]['name'] = t
platforms[p][toolset][f][t]['features'] = f
details.append(platforms[p][toolset][f][t])
@ -236,15 +239,30 @@ for p in platforms:
print >>html, '</tr>'
idx += 1
print >>html, '</table>'
print >>html, '</table></body></html>'
html.close()
try: os.mkdir('logs')
except: pass
details_id = 0
for d in details:
print >>html, '<div style="display: none" id="%d"><h3>%s - %s</h3><pre>%s</pre></div>' % \
(details_id, d['name'].encode('utf8'), d['features'].encode('utf-8'), style_output(d['output']).encode('utf-8'))
html = open(os.path.join('logs', '%d.html' % details_id), 'w+')
print >>html, '''<html><head><title>%s - %s</title><style type="text/css">
.compile-error { color: #f13; font-weight: bold; }
.compile-warning { color: #cb0; }
.test-error { color: #f13; font-weight: bold; }
.test-pass { color: #1c2; font-weight: bold; }
.subtle { color: #ccc; }
pre { color: #999; }
</style>
</head><body><h1>%s - %s</h1>''' % (project_name, branch_name, project_name, branch_name)
print >>html, '<h3>%s - %s</h3><pre>%s</pre>' % \
(d['name'].encode('utf8'), d['features'].encode('utf-8'), style_output(d['output']).encode('utf-8'))
details_id += 1
print >>html, '</body></html>'
html.close()
sys.stdout.write('.')
sys.stdout.flush()