3 Program that parses the autotest results and return a nicely printed final test
6 @copyright: Red Hat 2008-2009
9 def parse_results(text
):
11 Parse text containing Autotest results.
13 @return: A list of result 4-tuples.
19 lines
= text
.splitlines()
22 parts
= line
.split("\t")
24 # Found a START line -- get start time
25 if (line
.startswith("START") and len(parts
) >= 5 and
26 parts
[3].startswith("timestamp")):
27 start_time
= float(parts
[3].split("=")[1])
28 start_time_list
.append(start_time
)
31 # Found an END line -- get end time, name and status
32 elif (line
.startswith("END") and len(parts
) >= 5 and
33 parts
[3].startswith("timestamp")):
34 end_time
= float(parts
[3].split("=")[1])
35 start_time
= start_time_list
.pop()
36 info
= info_list
.pop()
38 test_status
= parts
[0].split()[1]
39 # Remove "kvm." prefix
40 if test_name
.startswith("kvm."):
41 test_name
= test_name
[4:]
42 result_list
.append((test_name
, test_status
,
43 int(end_time
- start_time
), info
))
45 # Found a FAIL/ERROR/GOOD line -- get failure/success info
46 elif (len(parts
) >= 6 and parts
[3].startswith("timestamp") and
47 parts
[4].startswith("localtime")):
48 info_list
[-1] = parts
[5]
53 def print_result(result
, name_width
):
55 Nicely print a single Autotest result.
57 @param result: a 4-tuple
58 @param name_width: test name maximum width
61 format
= "%%-%ds %%-10s %%-8s %%s" % name_width
69 for resfile
in resfiles
:
71 text
= open(resfile
).read()
73 print "Bad result file: %s" % resfile
75 results
= parse_results(text
)
76 result_lists
.append((resfile
, results
))
77 name_width
= max([name_width
] + [len(r
[0]) for r
in results
])
79 print_result(("Test", "Status", "Seconds", "Info"), name_width
)
80 print_result(("----", "------", "-------", "----"), name_width
)
82 for resfile
, results
in result_lists
:
83 print " (Result file: %s)" % resfile
85 print_result(r
, name_width
)
88 if __name__
== "__main__":
91 resfiles
= glob
.glob("../../results/default/status*")
93 if sys
.argv
[1] == "-h" or sys
.argv
[1] == "--help":
94 print "Usage: %s [result files]" % sys
.argv
[0]
96 resfiles
= sys
.argv
[1:]