raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 1 | #!/usr/bin/python2.6 |
| 2 | # |
| 3 | # Copyright 2010 Google Inc. All Rights Reserved. |
| 4 | |
| 5 | """Script to summarize the results of various log files.""" |
| 6 | |
| 7 | __author__ = "raymes@google.com (Raymes Khoury)" |
| 8 | |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame^] | 9 | from utils import command_executer |
| 10 | import os |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 11 | import sys |
| 12 | |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame^] | 13 | RESULTS_DIR = "results" |
| 14 | RESULTS_FILE = RESULTS_DIR + "/results.csv" |
| 15 | |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 16 | class DejaGNUSummarizer: |
| 17 | def Matches(self, log_file): |
| 18 | for log_line in log_file: |
| 19 | if log_line.find("""tests ===""") > -1: |
| 20 | return True |
| 21 | return False |
| 22 | |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame^] | 23 | def Summarize(self, log_file, filename): |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 24 | result = "" |
| 25 | pass_statuses = ["PASS", "XPASS"] |
raymes | b7b6a40 | 2013-02-15 05:21:00 +0000 | [diff] [blame] | 26 | fail_statuses = ["FAIL", "XFAIL", "UNSUPPORTED"] |
| 27 | name_count = {} |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 28 | for line in log_file: |
| 29 | line = line.strip().split(":") |
| 30 | if len(line) > 1 and (line[0] in pass_statuses or |
| 31 | line[0] in fail_statuses): |
| 32 | test_name = (":".join(line[1:])).replace("\t", " ").strip() |
raymes | b7b6a40 | 2013-02-15 05:21:00 +0000 | [diff] [blame] | 33 | count = name_count.get(test_name, 0) + 1 |
| 34 | name_count[test_name] = count |
| 35 | test_name = "%s (%s)" % (test_name, str(count)) |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 36 | if line[0] in pass_statuses: |
| 37 | test_result = "pass" |
| 38 | else: |
| 39 | test_result = "fail" |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame^] | 40 | result += "%s\t%s\t%s\n" % (test_name, test_result, filename) |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 41 | return result |
| 42 | |
| 43 | class AutoTestSummarizer: |
| 44 | def Matches(self, log_file): |
| 45 | for log_line in log_file: |
| 46 | if log_line.find("""Installing autotest on""") > -1: |
| 47 | return True |
| 48 | return False |
| 49 | |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame^] | 50 | def Summarize(self, log_file, filename): |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 51 | result = "" |
| 52 | pass_statuses = ["PASS"] |
| 53 | fail_statuses = ["FAIL"] |
| 54 | for line in log_file: |
| 55 | line = line.strip().split(" ") |
| 56 | if len(line) > 1 and (line[-1].strip() in pass_statuses or |
| 57 | line[-1].strip() in fail_statuses): |
| 58 | test_name = (line[0].strip()) |
| 59 | if line[-1].strip() in pass_statuses: |
| 60 | test_result = "pass" |
| 61 | else: |
| 62 | test_result = "fail" |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame^] | 63 | result += "%s\t%s\t%s\n" % (test_name, test_result, filename) |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 64 | return result |
| 65 | |
| 66 | def Usage(): |
| 67 | print "Usage: %s log_file" % sys.argv[0] |
| 68 | sys.exit(1) |
| 69 | |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 70 | |
raymes | 85ef5db | 2013-02-15 05:20:49 +0000 | [diff] [blame] | 71 | def SummarizeFile(filename): |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 72 | summarizers = [DejaGNUSummarizer(), AutoTestSummarizer()] |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame^] | 73 | input = open(filename, 'rb') |
| 74 | executer = command_executer.GetCommandExecuter() |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 75 | for summarizer in summarizers: |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame^] | 76 | input.seek(0) |
| 77 | if summarizer.Matches(input): |
| 78 | executer.CopyFiles(filename, RESULTS_DIR, recursive=False) |
| 79 | input.seek(0) |
| 80 | result = summarizer.Summarize(input, os.path.basename(filename)) |
| 81 | input.close() |
raymes | 85ef5db | 2013-02-15 05:20:49 +0000 | [diff] [blame] | 82 | return result |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame^] | 83 | input.close() |
raymes | 85ef5db | 2013-02-15 05:20:49 +0000 | [diff] [blame] | 84 | return None |
| 85 | |
| 86 | |
| 87 | def Main(argv): |
| 88 | if len(argv) != 2: |
| 89 | Usage() |
| 90 | filename = argv[1] |
| 91 | |
raymes | 6eece82 | 2013-02-15 05:53:31 +0000 | [diff] [blame^] | 92 | executer = command_executer.GetCommandExecuter() |
| 93 | executer.RunCommand("mkdir -p %s" % RESULTS_DIR) |
| 94 | summary = SummarizeFile(filename) |
| 95 | output = open(RESULTS_FILE, "a") |
| 96 | output.write(summary.strip() + "\n") |
| 97 | output.close() |
raymes | f12f79d | 2013-02-15 05:16:01 +0000 | [diff] [blame] | 98 | |
| 99 | if __name__ == "__main__": |
| 100 | Main(sys.argv) |
| 101 | |