lmr | 6f669ce | 2009-05-31 19:02:42 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | """ |
| 3 | Program that parses the autotest results and return a nicely printed final test |
| 4 | result. |
| 5 | |
| 6 | @copyright: Red Hat 2008-2009 |
| 7 | """ |
| 8 | |
| 9 | def parse_results(text): |
| 10 | """Parse text containing Autotest results and return a list of result 4-tuples.""" |
| 11 | result_list = [] |
| 12 | start_time_list = [] |
| 13 | info_list = [] |
| 14 | |
| 15 | lines = text.splitlines() |
| 16 | for line in lines: |
| 17 | line = line.strip() |
| 18 | parts = line.split("\t") |
| 19 | |
| 20 | # Found a START line -- get start time |
| 21 | if line.startswith("START") and len(parts) >= 5 and parts[3].startswith("timestamp"): |
| 22 | start_time = float(parts[3].split('=')[1]) |
| 23 | start_time_list.append(start_time) |
| 24 | info_list.append("") |
| 25 | |
| 26 | # Found an END line -- get end time, name and status |
| 27 | elif line.startswith("END") and len(parts) >= 5 and parts[3].startswith("timestamp"): |
| 28 | end_time = float(parts[3].split('=')[1]) |
| 29 | start_time = start_time_list.pop() |
| 30 | info = info_list.pop() |
| 31 | test_name = parts[2] |
| 32 | test_status = parts[0].split()[1] |
lmr | fc0e141 | 2009-06-10 20:03:26 +0000 | [diff] [blame] | 33 | # Remove 'kvm.' prefix |
| 34 | if test_name.startswith("kvm."): |
| 35 | test_name = test_name.split("kvm.")[1] |
lmr | 6f669ce | 2009-05-31 19:02:42 +0000 | [diff] [blame] | 36 | result_list.append((test_name, test_status, int(end_time - start_time), info)) |
| 37 | |
| 38 | # Found a FAIL/ERROR/GOOD line -- get failure/success info |
| 39 | elif len(parts) >= 6 and parts[3].startswith("timestamp") and parts[4].startswith("localtime"): |
| 40 | info_list[-1] = parts[5] |
| 41 | |
| 42 | return result_list |
| 43 | |
| 44 | |
| 45 | def print_result(result): |
| 46 | """Nicely print a single Autotest result. |
| 47 | |
| 48 | result -- a 4-tuple |
| 49 | """ |
| 50 | if result: |
| 51 | print '%-48s\t\t%s\t%s\t%s' % tuple(map(str, result)) |
| 52 | |
| 53 | |
| 54 | def main(resfile): |
| 55 | print_result(('test', 'status', 'seconds', 'info')) |
| 56 | print_result(('----', '------', '-------', '----')) |
| 57 | |
| 58 | f = file(resfile) |
| 59 | text = f.read() |
| 60 | f.close() |
| 61 | |
| 62 | results = parse_results(text) |
| 63 | map(print_result, results) |
| 64 | |
| 65 | |
| 66 | if __name__ == '__main__': |
| 67 | import sys, os |
| 68 | |
| 69 | resfile = '../../results/default/status' |
| 70 | if len(sys.argv) == 2: |
| 71 | resfile = sys.argv[1] |
| 72 | if resfile == '-h' or resfile == '--help' or len(sys.argv) > 2: |
| 73 | print 'usage: %s [ <resfile> ]' % sys.argv[0] |
| 74 | sys.exit(0) |
| 75 | if not os.path.exists(resfile): |
| 76 | print 'Bad result file: %s' % resfile |
| 77 | sys.exit(1) |
| 78 | main(resfile) |