Commit f5da3456 authored by Denis Bilenko's avatar Denis Bilenko

test: store output and parsed results in the same table; rename column stdout -> output

- add column parser_version
- parse_results: print number of columns updated
parent 52e546dd
...@@ -71,7 +71,7 @@ th.row ...@@ -71,7 +71,7 @@ th.row
def make_table(database, row, column): def make_table(database, row, column):
c = sqlite3.connect(database) c = sqlite3.connect(database)
res = c.execute(('select * from parsed_command_record join command_record on parsed_command_record.id=command_record.id ')) res = c.execute(('select * from testresult where output!=""'))
columns = [x[0].lower() for x in res.description] columns = [x[0].lower() for x in res.description]
table = {} table = {}
row_set = set() row_set = set()
...@@ -194,7 +194,7 @@ class TestResult: ...@@ -194,7 +194,7 @@ class TestResult:
if self.id is None: if self.id is None:
valign = 'bottom' valign = 'bottom'
else: else:
text = '<a class="x" href="%s.txt">%s</a>' % (self.id, text) text = '<a class="x" href="output-%s.txt">%s</a>' % (self.id, text)
valign = 'center' valign = 'center'
return '<td align=center valign=%s bgcolor=%s>%s</td>' % (valign, self.color(), text) return '<td align=center valign=%s bgcolor=%s>%s</td>' % (valign, self.color(), text)
...@@ -280,10 +280,12 @@ def format_html(table, common_fields): ...@@ -280,10 +280,12 @@ def format_html(table, common_fields):
def generate_raw_results(path, database): def generate_raw_results(path, database):
c = sqlite3.connect(database) c = sqlite3.connect(database)
res = c.execute('select id, stdout from command_record').fetchall() res = c.execute('select id, output from testresult').fetchall()
for id, out in res: for id, out in res:
file(os.path.join(path, '%s.txt' % id), 'w').write(out.encode('utf-8')) filename = os.path.join(path, 'output-%s.txt' % id)
sys.stderr.write('.') if not os.path.exists(filename):
file(filename, 'w').write(out.encode('utf-8'))
sys.stderr.write('.')
sys.stderr.write('\n') sys.stderr.write('\n')
def main(db): def main(db):
......
...@@ -25,9 +25,10 @@ import traceback ...@@ -25,9 +25,10 @@ import traceback
import sqlite3 import sqlite3
import re import re
PARSER_VERSION=1
param_re = re.compile('^===(\w+)=(.*)$', re.M) param_re = re.compile('^===(\w+)=(.*)$', re.M)
def parse_stdout(s): def parse_output(s):
argv = re.search('^===ARGV=(.*?)$', s, re.M).group(1) argv = re.search('^===ARGV=(.*?)$', s, re.M).group(1)
argv = argv.split() argv = argv.split()
testname = argv[-1] testname = argv[-1]
...@@ -63,56 +64,64 @@ def parse_greentest_output(s): ...@@ -63,56 +64,64 @@ def parse_greentest_output(s):
def main(db, options): def main(db, options):
print '%s: parsing output' % db print '%s: parsing output' % db
c = sqlite3.connect(db) c = sqlite3.connect(db)
c.execute('''create table if not exists parsed_command_record (id integer not null unique)''') try:
c.commit() 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 parse_error = 0
SQL = 'select command_record.id, command, stdout, exitcode from command_record' SQL = 'select id, command, output, exitcode from testresult'
if not options.redo: if not options.redo:
SQL += ' where not exists (select * from parsed_command_record where parsed_command_record.id=command_record.id)' SQL += ' where parser_version!=%s' % PARSER_VERSION
for row in c.execute(SQL).fetchall(): count = 0
id, command, stdout, exitcode = row try:
try: for row in c.execute(SQL).fetchall():
params = parse_stdout(stdout) id, command, output, exitcode = row
if greentest_delim in stdout and unittest_re.search(stdout) is not None: try:
runs, errors, fails, timeouts = parse_greentest_output(stdout) 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:
parse_error += 1
sys.stderr.write('Failed to parse id=%s\n' % id)
print repr(output)
traceback.print_exc()
else: else:
if exitcode == 0: added_columns = set()
runs, errors, fails, timeouts = 1,0,0,0 #print id, runs, errors, fails, timeouts, params
if exitcode == 7: params['parser_version'] = PARSER_VERSION
runs, errors, fails, timeouts = 0,0,0,1 params['runs'] = runs
elif exitcode: params['errors'] = errors
runs, errors, fails, timeouts = 1,1,0,0 params['fails'] = fails
except Exception: params['timeouts'] = timeouts
parse_error += 1 items = params.items()
sys.stderr.write('Failed to parse id=%s\n' % id) keys = [x[0].lower() for x in items]
print repr(stdout) values = [x[1] for x in items]
traceback.print_exc() for key in keys:
else: if key not in added_columns:
added_columns = set() added_columns.add(key)
#print id, runs, errors, fails, timeouts, params try:
params['id'] = id c.execute('''alter table testresult add column %s text''' % key)
params['runs'] = runs c.commit()
params['errors'] = errors except sqlite3.OperationalError, ex:
params['fails'] = fails if 'duplicate column' not in str(ex).lower():
params['timeouts'] = timeouts raise
items = params.items() sql = 'update testresult set %s where id=%s' % (', '.join('%s=?' % x for x in keys), id)
keys = [x[0].lower() for x in items] c.execute(sql, values)
values = [x[1] for x in items] c.commit()
for key in keys: count += 1
if key not in added_columns: finally:
added_columns.add(key) print '%s rows updated' % count
try:
c.execute('''alter table parsed_command_record add column %s text''' % key)
c.commit()
except sqlite3.OperationalError, ex:
if 'duplicate column' not in str(ex).lower():
raise
sql = 'insert or replace into parsed_command_record (%s) values (%s)' % (', '.join(keys), ', '.join(['?']*len(items)))
#print sql
c.execute(sql, values)
c.commit()
if __name__=='__main__': if __name__=='__main__':
import optparse import optparse
......
...@@ -45,16 +45,16 @@ def get_results_db(): ...@@ -45,16 +45,16 @@ def get_results_db():
pass pass
return join(path, 'results.db') return join(path, 'results.db')
def record(argv, stdout, returncode): def record(argv, output, returncode):
path = get_results_db() path = get_results_db()
c = sqlite3.connect(path) c = sqlite3.connect(path)
c.execute('''create table if not exists command_record c.execute('''create table if not exists testresult
(id integer primary key autoincrement, (id integer primary key autoincrement,
command text, command text,
stdout text, output text,
exitcode integer)''') exitcode integer)''')
c.execute('insert into command_record (command, stdout, exitcode)' c.execute('insert into testresult (command, output, exitcode)'
'values (?, ?, ?)', (`argv`, stdout, returncode)) 'values (?, ?, ?)', (`argv`, output, returncode))
c.commit() c.commit()
def main(): def main():
...@@ -69,14 +69,14 @@ def main(): ...@@ -69,14 +69,14 @@ def main():
print arg print arg
returncode = os.system(arg)>>8 returncode = os.system(arg)>>8
print arg, 'finished with code', returncode print arg, 'finished with code', returncode
stdout = codecs.open(output_name, mode='r', encoding='utf-8', errors='replace').read().replace('\x00', '?') output = codecs.open(output_name, mode='r', encoding='utf-8', errors='replace').read().replace('\x00', '?')
if not debug: if not debug:
if returncode==1: if returncode==1:
pass pass
elif returncode==8 and disabled_marker in stdout: elif returncode==8 and disabled_marker in output:
pass pass
else: else:
record(argv, stdout, returncode) record(argv, output, returncode)
os.unlink(output_name) os.unlink(output_name)
sys.exit(returncode) sys.exit(returncode)
......
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