blob: 67d7e9a418b84c9a60410d49cbb0c1977a552a0c [file] [log] [blame]
Caroline Tice88272d42016-01-13 09:48:29 -08001#!/usr/bin/python2
raymesf12f79d2013-02-15 05:16:01 +00002#
3# Copyright 2010 Google Inc. All Rights Reserved.
raymesf12f79d2013-02-15 05:16:01 +00004"""Script to summarize the results of various log files."""
5
Caroline Tice88272d42016-01-13 09:48:29 -08006from __future__ import print_function
7
Luis Lozanof2a3ef42015-12-15 13:49:30 -08008__author__ = 'raymes@google.com (Raymes Khoury)'
raymesf12f79d2013-02-15 05:16:01 +00009
Caroline Tice88272d42016-01-13 09:48:29 -080010from cros_utils import command_executer
raymes6eece822013-02-15 05:53:31 +000011import os
raymesf12f79d2013-02-15 05:16:01 +000012import sys
asharif60d7b432013-02-15 08:56:05 +000013import re
raymesf12f79d2013-02-15 05:16:01 +000014
Luis Lozanof2a3ef42015-12-15 13:49:30 -080015RESULTS_DIR = 'results'
16RESULTS_FILE = RESULTS_DIR + '/results.csv'
17
Caroline Tice88272d42016-01-13 09:48:29 -080018# pylint: disable=anomalous-backslash-in-string
raymes6eece822013-02-15 05:53:31 +000019
Caroline Tice88272d42016-01-13 09:48:29 -080020class DejaGNUSummarizer(object):
21 """DejaGNU Summarizer Class"""
22
23 def __int__(self):
24 pass
Luis Lozanof2a3ef42015-12-15 13:49:30 -080025
raymesf12f79d2013-02-15 05:16:01 +000026 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
raymes6eece822013-02-15 05:53:31 +000032 def Summarize(self, log_file, filename):
Luis Lozanof2a3ef42015-12-15 13:49:30 -080033 result = ''
34 pass_statuses = ['PASS', 'XPASS']
35 fail_statuses = ['FAIL', 'XFAIL', 'UNSUPPORTED']
raymesb7b6a402013-02-15 05:21:00 +000036 name_count = {}
raymesf12f79d2013-02-15 05:16:01 +000037 for line in log_file:
Luis Lozanof2a3ef42015-12-15 13:49:30 -080038 line = line.strip().split(':')
raymesf12f79d2013-02-15 05:16:01 +000039 if len(line) > 1 and (line[0] in pass_statuses or
40 line[0] in fail_statuses):
Luis Lozanof2a3ef42015-12-15 13:49:30 -080041 test_name = (':'.join(line[1:])).replace('\t', ' ').strip()
raymesb7b6a402013-02-15 05:21:00 +000042 count = name_count.get(test_name, 0) + 1
43 name_count[test_name] = count
Luis Lozanof2a3ef42015-12-15 13:49:30 -080044 test_name = '%s (%s)' % (test_name, str(count))
raymesf12f79d2013-02-15 05:16:01 +000045 if line[0] in pass_statuses:
Luis Lozanof2a3ef42015-12-15 13:49:30 -080046 test_result = 'pass'
raymesf12f79d2013-02-15 05:16:01 +000047 else:
Luis Lozanof2a3ef42015-12-15 13:49:30 -080048 test_result = 'fail'
49 result += '%s\t%s\t%s\n' % (test_name, test_result, filename)
raymesf12f79d2013-02-15 05:16:01 +000050 return result
51
asharif60d7b432013-02-15 08:56:05 +000052
Caroline Tice88272d42016-01-13 09:48:29 -080053class PerflabSummarizer(object):
54 """Perflab Summarizer class"""
55
56 def __init__(self):
57 pass
Luis Lozanof2a3ef42015-12-15 13:49:30 -080058
asharif60d7b432013-02-15 08:56:05 +000059 def Matches(self, log_file):
Luis Lozanof2a3ef42015-12-15 13:49:30 -080060 p = re.compile('METRIC isolated \w+')
asharif60d7b432013-02-15 08:56:05 +000061 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 Lozanof2a3ef42015-12-15 13:49:30 -080067 result = ''
asharif60d7b432013-02-15 08:56:05 +000068 p = re.compile("METRIC isolated (\w+) .*\['(.*?)'\]")
Luis Lozanof2a3ef42015-12-15 13:49:30 -080069 log_file_lines = '\n'.join(log_file)
asharif60d7b432013-02-15 08:56:05 +000070 matches = p.findall(log_file_lines)
71 for match in matches:
72 if len(match) != 2:
73 continue
Caroline Tice88272d42016-01-13 09:48:29 -080074 result += '%s\t%s\t%s\n' % (match[0], match[1], filename)
asharif60d7b432013-02-15 08:56:05 +000075 return result
76
77
Caroline Tice88272d42016-01-13 09:48:29 -080078class AutoTestSummarizer(object):
79 """AutoTest Summarizer class"""
80
81 def __init__(self):
82 pass
Luis Lozanof2a3ef42015-12-15 13:49:30 -080083
raymesf12f79d2013-02-15 05:16:01 +000084 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
raymes6eece822013-02-15 05:53:31 +000090 def Summarize(self, log_file, filename):
Luis Lozanof2a3ef42015-12-15 13:49:30 -080091 result = ''
92 pass_statuses = ['PASS']
93 fail_statuses = ['FAIL']
raymesf12f79d2013-02-15 05:16:01 +000094 for line in log_file:
Luis Lozanof2a3ef42015-12-15 13:49:30 -080095 line = line.strip().split(' ')
raymesf12f79d2013-02-15 05:16:01 +000096 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 Lozanof2a3ef42015-12-15 13:49:30 -0800100 test_result = 'pass'
raymesf12f79d2013-02-15 05:16:01 +0000101 else:
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800102 test_result = 'fail'
103 result += '%s\t%s\t%s\n' % (test_name, test_result, filename)
raymesf12f79d2013-02-15 05:16:01 +0000104 return result
105
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800106
raymesf12f79d2013-02-15 05:16:01 +0000107def Usage():
Caroline Tice88272d42016-01-13 09:48:29 -0800108 print('Usage: %s log_file' % sys.argv[0])
raymesf12f79d2013-02-15 05:16:01 +0000109 sys.exit(1)
110
raymesf12f79d2013-02-15 05:16:01 +0000111
raymes85ef5db2013-02-15 05:20:49 +0000112def SummarizeFile(filename):
asharif60d7b432013-02-15 08:56:05 +0000113 summarizers = [DejaGNUSummarizer(), AutoTestSummarizer(), PerflabSummarizer()]
Caroline Tice88272d42016-01-13 09:48:29 -0800114 inp = open(filename, 'rb')
raymes6eece822013-02-15 05:53:31 +0000115 executer = command_executer.GetCommandExecuter()
raymesf12f79d2013-02-15 05:16:01 +0000116 for summarizer in summarizers:
Caroline Tice88272d42016-01-13 09:48:29 -0800117 inp.seek(0)
118 if summarizer.Matches(inp):
raymes6eece822013-02-15 05:53:31 +0000119 executer.CopyFiles(filename, RESULTS_DIR, recursive=False)
Caroline Tice88272d42016-01-13 09:48:29 -0800120 inp.seek(0)
121 result = summarizer.Summarize(inp, os.path.basename(filename))
122 inp.close()
raymes85ef5db2013-02-15 05:20:49 +0000123 return result
Caroline Tice88272d42016-01-13 09:48:29 -0800124 inp.close()
raymes85ef5db2013-02-15 05:20:49 +0000125 return None
126
127
128def Main(argv):
129 if len(argv) != 2:
130 Usage()
131 filename = argv[1]
132
raymes6eece822013-02-15 05:53:31 +0000133 executer = command_executer.GetCommandExecuter()
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800134 executer.RunCommand('mkdir -p %s' % RESULTS_DIR)
raymes6eece822013-02-15 05:53:31 +0000135 summary = SummarizeFile(filename)
asharif60d7b432013-02-15 08:56:05 +0000136 if summary is not None:
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800137 output = open(RESULTS_FILE, 'a')
138 output.write(summary.strip() + '\n')
asharif60d7b432013-02-15 08:56:05 +0000139 output.close()
asharif2198c512013-02-15 09:21:35 +0000140 return 0
raymesf12f79d2013-02-15 05:16:01 +0000141
Luis Lozanof2a3ef42015-12-15 13:49:30 -0800142
143if __name__ == '__main__':
asharif2198c512013-02-15 09:21:35 +0000144 retval = Main(sys.argv)
145 sys.exit(retval)