Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 1 | #!/usr/bin/python2 |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2010 Google Inc. All Rights Reserved. |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 4 | """Script to summarize the results of various log files.""" |
| 5 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 6 | from __future__ import print_function |
| 7 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 8 | __author__ = 'raymes@google.com (Raymes Khoury)' |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 9 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 10 | from cros_utils import command_executer |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame] | 11 | import os |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 12 | import sys |
asharif | 60d7b43 | 2013-02-15 08:56:05 +0000 | [diff] [blame] | 13 | import re |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 14 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 15 | RESULTS_DIR = 'results' |
| 16 | RESULTS_FILE = RESULTS_DIR + '/results.csv' |
| 17 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 18 | # pylint: disable=anomalous-backslash-in-string |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame] | 19 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 20 | class DejaGNUSummarizer(object): |
| 21 | """DejaGNU Summarizer Class""" |
| 22 | |
| 23 | def __int__(self): |
| 24 | pass |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 25 | |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 26 | def Matches(self, log_file): |
| 27 | for log_line in log_file: |
| 28 | if log_line.find("""tests ===""") > -1: |
| 29 | return True |
| 30 | return False |
| 31 | |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame] | 32 | def Summarize(self, log_file, filename): |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 33 | result = '' |
| 34 | pass_statuses = ['PASS', 'XPASS'] |
| 35 | fail_statuses = ['FAIL', 'XFAIL', 'UNSUPPORTED'] |
raymes | b7b6a40 | 2013-02-15 05:21:00 +0000 | [diff] [blame] | 36 | name_count = {} |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 37 | for line in log_file: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 38 | line = line.strip().split(':') |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 39 | if len(line) > 1 and (line[0] in pass_statuses or |
| 40 | line[0] in fail_statuses): |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 41 | test_name = (':'.join(line[1:])).replace('\t', ' ').strip() |
raymes | b7b6a40 | 2013-02-15 05:21:00 +0000 | [diff] [blame] | 42 | count = name_count.get(test_name, 0) + 1 |
| 43 | name_count[test_name] = count |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 44 | test_name = '%s (%s)' % (test_name, str(count)) |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 45 | if line[0] in pass_statuses: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 46 | test_result = 'pass' |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 47 | else: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 48 | test_result = 'fail' |
| 49 | result += '%s\t%s\t%s\n' % (test_name, test_result, filename) |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 50 | return result |
| 51 | |
asharif | 60d7b43 | 2013-02-15 08:56:05 +0000 | [diff] [blame] | 52 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 53 | class PerflabSummarizer(object): |
| 54 | """Perflab Summarizer class""" |
| 55 | |
| 56 | def __init__(self): |
| 57 | pass |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 58 | |
asharif | 60d7b43 | 2013-02-15 08:56:05 +0000 | [diff] [blame] | 59 | def Matches(self, log_file): |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 60 | p = re.compile('METRIC isolated \w+') |
asharif | 60d7b43 | 2013-02-15 08:56:05 +0000 | [diff] [blame] | 61 | for log_line in log_file: |
| 62 | if p.search(log_line): |
| 63 | return True |
| 64 | return False |
| 65 | |
| 66 | def Summarize(self, log_file, filename): |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 67 | result = '' |
asharif | 60d7b43 | 2013-02-15 08:56:05 +0000 | [diff] [blame] | 68 | p = re.compile("METRIC isolated (\w+) .*\['(.*?)'\]") |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 69 | log_file_lines = '\n'.join(log_file) |
asharif | 60d7b43 | 2013-02-15 08:56:05 +0000 | [diff] [blame] | 70 | matches = p.findall(log_file_lines) |
| 71 | for match in matches: |
| 72 | if len(match) != 2: |
| 73 | continue |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 74 | result += '%s\t%s\t%s\n' % (match[0], match[1], filename) |
asharif | 60d7b43 | 2013-02-15 08:56:05 +0000 | [diff] [blame] | 75 | return result |
| 76 | |
| 77 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 78 | class AutoTestSummarizer(object): |
| 79 | """AutoTest Summarizer class""" |
| 80 | |
| 81 | def __init__(self): |
| 82 | pass |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 83 | |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 84 | def Matches(self, log_file): |
| 85 | for log_line in log_file: |
| 86 | if log_line.find("""Installing autotest on""") > -1: |
| 87 | return True |
| 88 | return False |
| 89 | |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame] | 90 | def Summarize(self, log_file, filename): |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 91 | result = '' |
| 92 | pass_statuses = ['PASS'] |
| 93 | fail_statuses = ['FAIL'] |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 94 | for line in log_file: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 95 | line = line.strip().split(' ') |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 96 | if len(line) > 1 and (line[-1].strip() in pass_statuses or |
| 97 | line[-1].strip() in fail_statuses): |
| 98 | test_name = (line[0].strip()) |
| 99 | if line[-1].strip() in pass_statuses: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 100 | test_result = 'pass' |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 101 | else: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 102 | test_result = 'fail' |
| 103 | result += '%s\t%s\t%s\n' % (test_name, test_result, filename) |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 104 | return result |
| 105 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 106 | |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 107 | def Usage(): |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 108 | print('Usage: %s log_file' % sys.argv[0]) |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 109 | sys.exit(1) |
| 110 | |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 111 | |
raymes | 85ef5db | 2013-02-15 05:20:49 +0000 | [diff] [blame] | 112 | def SummarizeFile(filename): |
asharif | 60d7b43 | 2013-02-15 08:56:05 +0000 | [diff] [blame] | 113 | summarizers = [DejaGNUSummarizer(), AutoTestSummarizer(), PerflabSummarizer()] |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 114 | inp = open(filename, 'rb') |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame] | 115 | executer = command_executer.GetCommandExecuter() |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 116 | for summarizer in summarizers: |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 117 | inp.seek(0) |
| 118 | if summarizer.Matches(inp): |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame] | 119 | executer.CopyFiles(filename, RESULTS_DIR, recursive=False) |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 120 | inp.seek(0) |
| 121 | result = summarizer.Summarize(inp, os.path.basename(filename)) |
| 122 | inp.close() |
raymes | 85ef5db | 2013-02-15 05:20:49 +0000 | [diff] [blame] | 123 | return result |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 124 | inp.close() |
raymes | 85ef5db | 2013-02-15 05:20:49 +0000 | [diff] [blame] | 125 | return None |
| 126 | |
| 127 | |
| 128 | def Main(argv): |
| 129 | if len(argv) != 2: |
| 130 | Usage() |
| 131 | filename = argv[1] |
| 132 | |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame] | 133 | executer = command_executer.GetCommandExecuter() |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 134 | executer.RunCommand('mkdir -p %s' % RESULTS_DIR) |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame] | 135 | summary = SummarizeFile(filename) |
asharif | 60d7b43 | 2013-02-15 08:56:05 +0000 | [diff] [blame] | 136 | if summary is not None: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 137 | output = open(RESULTS_FILE, 'a') |
| 138 | output.write(summary.strip() + '\n') |
asharif | 60d7b43 | 2013-02-15 08:56:05 +0000 | [diff] [blame] | 139 | output.close() |
asharif | 2198c51 | 2013-02-15 09:21:35 +0000 | [diff] [blame] | 140 | return 0 |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 141 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 142 | |
| 143 | if __name__ == '__main__': |
asharif | 2198c51 | 2013-02-15 09:21:35 +0000 | [diff] [blame] | 144 | retval = Main(sys.argv) |
| 145 | sys.exit(retval) |