Debian Codegraph @

tests/parse_results.py

raw
1 import sys
2 import os
3 import traceback
4 try:
5 import sqlite3
6 except ImportError:
7 import pysqlite2.dbapi2 as sqlite3
8 import re
9 import glob
10
11
12 def parse_stdout(s):
13 argv = re.search('^===ARGV=(.*?)$', s, re.M).group(1)
14 argv = argv.split()
15 testname = argv[-1]
16 del argv[-1]
17 hub = None
18 reactor = None
19 while argv:
20 if argv[0] == '--hub':
21 hub = argv[1]
22 del argv[0]
23 del argv[0]
24 elif argv[0] == '--reactor':
25 reactor = argv[1]
26 del argv[0]
27 del argv[0]
28 else:
29 del argv[0]
30 if reactor is not None:
31 hub += '/%s' % reactor
32 return testname, hub
33
34
35 unittest_delim = '----------------------------------------------------------------------'
36
37
38 def parse_unittest_output(s):
39 s = s[s.rindex(unittest_delim) + len(unittest_delim):]
40 num = int(re.search(r'^Ran (\d+) test.*?$', s, re.M).group(1))
41 ok = re.search('^OK$', s, re.M)
42 error, fail, timeout = 0, 0, 0
43 failed_match = re.search(
44 r'^FAILED \((?:failures=(?P<f>\d+))?,? ?(?:errors=(?P<e>\d+))?\)$', s, re.M)
45 ok_match = re.search('^OK$', s, re.M)
46 if failed_match:
47 assert not ok_match, (ok_match, s)
48 fail = failed_match.group('f')
49 error = failed_match.group('e')
50 fail = int(fail or '0')
51 error = int(error or '0')
52 else:
53 assert ok_match, repr(s)
54 timeout_match = re.search(r'^===disabled because of timeout: (\d+)$', s, re.M)
55 if timeout_match:
56 timeout = int(timeout_match.group(1))
57 return num, error, fail, timeout
58
59
60 def main(db):
61 c = sqlite3.connect(db)
62 c.execute('''create table if not exists parsed_command_record
63 (id integer not null unique,
64 testname text,
65 hub text,
66 runs integer,
67 errors integer,
68 fails integer,
69 timeouts integer,
70 error_names text,
71 fail_names text,
72 timeout_names text)''')
73 c.commit()
74
75 parse_error = 0
76
77 SQL = ('select command_record.id, command, stdout, exitcode from command_record '
78 'where not exists (select * from parsed_command_record where '
79 'parsed_command_record.id=command_record.id)')
80 for row in c.execute(SQL).fetchall():
81 id, command, stdout, exitcode = row
82 try:
83 testname, hub = parse_stdout(stdout)
84 if unittest_delim in stdout:
85 runs, errors, fails, timeouts = parse_unittest_output(stdout)
86 else:
87 if exitcode == 0:
88 runs, errors, fails, timeouts = 1, 0, 0, 0
89 if exitcode == 7:
90 runs, errors, fails, timeouts = 0, 0, 0, 1
91 elif exitcode:
92 runs, errors, fails, timeouts = 1, 1, 0, 0
93 except Exception:
94 parse_error += 1
95 sys.stderr.write('Failed to parse id=%s\n' % id)
96 print(repr(stdout))
97 traceback.print_exc()
98 else:
99 print(id, hub, testname, runs, errors, fails, timeouts)
100 c.execute('insert into parsed_command_record '
101 '(id, testname, hub, runs, errors, fails, timeouts) '
102 'values (?, ?, ?, ?, ?, ?, ?)',
103 (id, testname, hub, runs, errors, fails, timeouts))
104 c.commit()
105
106
107 if __name__ == '__main__':
108 if not sys.argv[1:]:
109 latest_db = sorted(glob.glob('results.*.db'), key=lambda f: os.stat(f).st_mtime)[-1]
110 print(latest_db)
111 sys.argv.append(latest_db)
112 for db in sys.argv[1:]:
113 main(db)
114 exec(open('generate_report.py').read())