forked from avocado-framework/avocado-vt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_autotest_results.py
105 lines (85 loc) · 3.16 KB
/
scan_autotest_results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""
Program that parses the autotest results and return a nicely printed final test
result.
:copyright: Red Hat 2008-2009
"""
def parse_results(text):
"""
Parse text containing Autotest results.
:return: A list of result 4-tuples.
"""
result_list = []
start_time_list = []
info_list = []
lines = text.splitlines()
for line in lines:
line = line.strip()
parts = line.split("\t")
# Found a START line -- get start time
if (line.startswith("START") and len(parts) >= 5 and
parts[3].startswith("timestamp")):
start_time = float(parts[3].split("=")[1])
start_time_list.append(start_time)
info_list.append("")
# Found an END line -- get end time, name and status
elif (line.startswith("END") and len(parts) >= 5 and
parts[3].startswith("timestamp")):
end_time = float(parts[3].split("=")[1])
start_time = start_time_list.pop()
info = info_list.pop()
test_name = parts[2]
test_status = parts[0].split()[1]
# Remove "kvm." prefix
if test_name.startswith("kvm."):
test_name = test_name[4:]
result_list.append((test_name, test_status,
int(end_time - start_time), info))
# Found a FAIL/ERROR/GOOD line -- get failure/success info
elif (len(parts) >= 6 and parts[3].startswith("timestamp") and
parts[4].startswith("localtime")):
info_list[-1] = parts[5]
return result_list
def print_result(result, name_width):
"""
Nicely print a single Autotest result.
:param result: a 4-tuple
:param name_width: test name maximum width
"""
if result:
format = "%%-%ds %%-10s %%-8s %%s" % name_width
print format % result
def main(resfiles):
result_lists = []
name_width = 40
for resfile in resfiles:
try:
text = open(resfile).read()
except IOError as e:
if e.errno == 21: # Directory
continue
else:
print "Bad result file: %s, errno = %d" % (resfile, e.errno)
continue
results = parse_results(text)
result_lists.append((resfile, results))
name_width = max([name_width] + [len(r[0]) for r in results])
print_result(("Test", "Status", "Seconds", "Info"), name_width)
print_result(("----", "------", "-------", "----"), name_width)
for resfile, results in result_lists:
if len(results):
print " (Result file: %s)" % resfile
for r in results:
print_result(r, name_width)
if __name__ == "__main__":
import sys
import glob
import os
dirname = os.path.dirname(sys.modules[__name__].__file__)
CLIENT_DIR = os.path.abspath(os.path.join(dirname, ".."))
resfiles = glob.glob(os.path.join(CLIENT_DIR, 'results', '*', 'status*'))
if len(sys.argv) > 1:
if sys.argv[1] == "-h" or sys.argv[1] == "--help":
print "Usage: %s [result files]" % sys.argv[0]
sys.exit(0)
resfiles = sys.argv[1:]
main(resfiles)