| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Main functions for the Layout Test Analyzer module.""" | 6 """Main functions for the Layout Test Analyzer module.""" |
| 7 | 7 |
| 8 import csv | 8 import csv |
| 9 from datetime import datetime | 9 from datetime import datetime |
| 10 import optparse | 10 import optparse |
| 11 import os | 11 import os |
| 12 import pickle | 12 import pickle |
| 13 import time | 13 import time |
| 14 | 14 |
| 15 | 15 |
| 16 from layouttests import LayoutTests | 16 from layouttests import LayoutTests |
| 17 import layouttest_analyzer_helpers | 17 import layouttest_analyzer_helpers |
| 18 from test_expectations import TestExpectations | 18 from test_expectations import TestExpectations |
| 19 from trend_graph import TrendGraph | 19 from trend_graph import TrendGraph |
| 20 | 20 |
| 21 # Predefined result directory. | 21 # Predefined result directory. |
| 22 RESULT_DIR = 'result' | 22 RESULT_DIR = 'result' |
| 23 DEFAULT_ANNO_FILE = os.path.join('anno', 'anno.csv') | 23 DEFAULT_ANNO_FILE = os.path.join('anno', 'anno.csv') |
| 24 DEFAULT_GRAPH_FILE = os.path.join('graph', 'graph.html') | 24 DEFAULT_GRAPH_FILE = os.path.join('graph', 'graph.html') |
| 25 # Predefined result files for debug. | 25 # Predefined result files for debug. |
| 26 CURRENT_RESULT_FILE_FOR_DEBUG = os.path.join(RESULT_DIR, '2011-08-19-21') | 26 CURRENT_RESULT_FILE_FOR_DEBUG = os.path.join(RESULT_DIR, '2011-08-19-21') |
| 27 PREV_TIME_FOR_DEBUG = '2011-08-19-11' | 27 PREV_TIME_FOR_DEBUG = '2011-08-19-11' |
| 28 | 28 |
| 29 DEFAULT_TEST_GROUP_FILE = os.path.join('testname', 'media.csv') |
| 30 DEFAULT_TEST_GROUP_NAME = 'media' |
| 31 |
| 29 | 32 |
| 30 def parse_option(): | 33 def parse_option(): |
| 31 """Parse command-line options using OptionParser. | 34 """Parse command-line options using OptionParser. |
| 32 | 35 |
| 33 Returns: | 36 Returns: |
| 34 an object containing all command-line option information. | 37 an object containing all command-line option information. |
| 35 """ | 38 """ |
| 36 option_parser = optparse.OptionParser() | 39 option_parser = optparse.OptionParser() |
| 37 | 40 |
| 38 option_parser.add_option('-r', '--receiver-email-address', | 41 option_parser.add_option('-r', '--receiver-email-address', |
| 39 dest='receiver_email_address', | 42 dest='receiver_email_address', |
| 40 help=('receiver\'s email adddress (defaults to ' | 43 help=('receiver\'s email adddress (defaults to ' |
| 41 '%default'), | 44 '%default'), |
| 42 default='imasaki@chromium.org') | 45 default='imasaki@chromium.org') |
| 43 option_parser.add_option('-g', '--debug-mode', dest='debug', | 46 option_parser.add_option('-g', '--debug-mode', dest='debug', |
| 44 help=('Debug mode is used when you want to debug ' | 47 help=('Debug mode is used when you want to debug ' |
| 45 'the analyzer by using local file rather ' | 48 'the analyzer by using local file rather ' |
| 46 'than getting data from SVN. This shortens ' | 49 'than getting data from SVN. This shortens ' |
| 47 'the debugging time (off by default)'), | 50 'the debugging time (off by default)'), |
| 48 action='store_true', default=False) | 51 action='store_true', default=False) |
| 49 option_parser.add_option('-t', '--trend-graph-location', | 52 option_parser.add_option('-t', '--trend-graph-location', |
| 50 dest='trend_graph_location', | 53 dest='trend_graph_location', |
| 51 help=('trend graph location ', | 54 help=('Location of the bug trend file; ' |
| 55 'file is expected to be in Google ' |
| 56 'Visualization API trend-line format ' |
| 52 '(defaults to %default)'), | 57 '(defaults to %default)'), |
| 53 default=DEFAULT_GRAPH_FILE) | 58 default=DEFAULT_GRAPH_FILE) |
| 54 option_parser.add_option('-a', '--bug-anno-file-location', | 59 option_parser.add_option('-a', '--bug-anno-file-location', |
| 55 dest='bug_annotation_file_location', | 60 dest='bug_annotation_file_location', |
| 56 help=('Location of the bug annotation file; ' | 61 help=('Location of the bug annotation file; ' |
| 57 'file is expected to be in CSV format ' | 62 'file is expected to be in CSV format ' |
| 58 '(default to %default)'), | 63 '(default to %default)'), |
| 59 default=DEFAULT_ANNO_FILE) | 64 default=DEFAULT_ANNO_FILE) |
| 65 option_parser.add_option('-n', '--test-group-file-location', |
| 66 dest='test_group_file_location', |
| 67 help=('Location of the test group file; ' |
| 68 'file is expected to be in CSV format ' |
| 69 '(default to %default)'), |
| 70 default=DEFAULT_TEST_GROUP_FILE) |
| 71 option_parser.add_option('-x', '--test-group-name', |
| 72 dest='test_group_name', |
| 73 help=('Name of test group ' |
| 74 '(default to %default)'), |
| 75 default=DEFAULT_TEST_GROUP_NAME) |
| 60 return option_parser.parse_args()[0] | 76 return option_parser.parse_args()[0] |
| 61 | 77 |
| 62 | 78 |
| 63 def main(): | 79 def main(): |
| 64 """A main function for the analyzer.""" | 80 """A main function for the analyzer.""" |
| 65 options = parse_option() | 81 options = parse_option() |
| 66 start_time = datetime.now() | 82 start_time = datetime.now() |
| 67 | 83 |
| 68 # Do the main analysis. | 84 # Do the main analysis. |
| 69 if not options.debug: | 85 if not options.debug: |
| 70 layouttests = LayoutTests(csv_file_path=os.path.join('testname', | 86 layouttests = LayoutTests(csv_file_path=options.test_group_file_location) |
| 71 'media.csv')) | |
| 72 analyzer_result_map = layouttest_analyzer_helpers.AnalyzerResultMap( | 87 analyzer_result_map = layouttest_analyzer_helpers.AnalyzerResultMap( |
| 73 layouttests.JoinWithTestExpectation(TestExpectations())) | 88 layouttests.JoinWithTestExpectation(TestExpectations())) |
| 74 (prev_time, prev_analyzer_result_map) = ( | 89 (prev_time, prev_analyzer_result_map) = ( |
| 75 layouttest_analyzer_helpers.FindLatestResult('result')) | 90 layouttest_analyzer_helpers.FindLatestResult('result')) |
| 76 else: | 91 else: |
| 77 analyzer_result_map = layouttest_analyzer_helpers.AnalyzerResultMap.Load( | 92 analyzer_result_map = layouttest_analyzer_helpers.AnalyzerResultMap.Load( |
| 78 CURRENT_RESULT_FILE_FOR_DEBUG) | 93 CURRENT_RESULT_FILE_FOR_DEBUG) |
| 79 prev_time = PREV_TIME_FOR_DEBUG | 94 prev_time = PREV_TIME_FOR_DEBUG |
| 80 prev_analyzer_result_map = ( | 95 prev_analyzer_result_map = ( |
| 81 layouttest_analyzer_helpers.AnalyzerResultMap.Load( | 96 layouttest_analyzer_helpers.AnalyzerResultMap.Load( |
| 82 os.path.join(RESULT_DIR, prev_time))) | 97 os.path.join(RESULT_DIR, prev_time))) |
| 83 | 98 |
| 84 # Read bug annotations and generate an annotation map used for the status | 99 # Read bug annotations and generate an annotation map used for the status |
| 85 # email. | 100 # email. |
| 86 anno_map = {} | 101 anno_map = {} |
| 87 file_object = open(options.bug_annotation_file_location) | 102 file_object = open(options.bug_annotation_file_location) |
| 88 data = csv.reader(file_object) | 103 data = csv.reader(file_object) |
| 89 for row in data: | 104 for row in data: |
| 90 anno_map[row[0]] = row[1] | 105 anno_map[row[0]] = row[1] |
| 91 file_object.close() | 106 file_object.close() |
| 92 | 107 |
| 93 layouttest_analyzer_helpers.SendStatusEmail(prev_time, analyzer_result_map, | 108 layouttest_analyzer_helpers.SendStatusEmail(prev_time, analyzer_result_map, |
| 94 prev_analyzer_result_map, | 109 prev_analyzer_result_map, |
| 95 anno_map, | 110 anno_map, |
| 96 options.receiver_email_address) | 111 options.receiver_email_address, |
| 112 options.test_group_name) |
| 97 if not options.debug: | 113 if not options.debug: |
| 98 # Save the current result. | 114 # Save the current result. |
| 99 date = start_time.strftime('%Y-%m-%d-%H') | 115 date = start_time.strftime('%Y-%m-%d-%H') |
| 100 file_path = os.path.join(RESULT_DIR, date) | 116 file_path = os.path.join(RESULT_DIR, date) |
| 101 analyzer_result_map.Save(file_path) | 117 analyzer_result_map.Save(file_path) |
| 102 | 118 |
| 103 # Trend graph update (if specified in the command-line argument). | 119 # Trend graph update (if specified in the command-line argument). |
| 104 trend_graph = TrendGraph(options.trend_graph_location) | 120 trend_graph = TrendGraph(options.trend_graph_location) |
| 105 datetime_string = start_time.strftime('%Y,%m,%d,%H,%M,%S') | 121 datetime_string = start_time.strftime('%Y,%m,%d,%H,%M,%S') |
| 106 # TODO(imasaki): add correct title and text instead of 'undefined'. | 122 # TODO(imasaki): add correct title and text instead of 'undefined'. |
| 107 data_map = ( | 123 data_map = ( |
| 108 {'whole': (str(len(analyzer_result_map.result_map['whole'].keys())), | 124 {'whole': (str(len(analyzer_result_map.result_map['whole'].keys())), |
| 109 'undefined', 'undefined'), | 125 'undefined', 'undefined'), |
| 110 'skip': (str(len(analyzer_result_map.result_map['skip'].keys())), | 126 'skip': (str(len(analyzer_result_map.result_map['skip'].keys())), |
| 111 'undefined', 'undefined'), | 127 'undefined', 'undefined'), |
| 112 'nonskip': (str(len(analyzer_result_map.result_map['nonskip'].keys())), | 128 'nonskip': (str(len(analyzer_result_map.result_map['nonskip'].keys())), |
| 113 'undefined', 'undefined'), | 129 'undefined', 'undefined'), |
| 114 'passingrate': (str(analyzer_result_map.GetPassingRate()), | 130 'passingrate': (str(analyzer_result_map.GetPassingRate()), |
| 115 'undefined', 'undefined')}) | 131 'undefined', 'undefined')}) |
| 116 trend_graph.Update(datetime_string, data_map) | 132 trend_graph.Update(datetime_string, data_map) |
| 117 | 133 |
| 118 | 134 |
| 119 if '__main__' == __name__: | 135 if '__main__' == __name__: |
| 120 main() | 136 main() |
| OLD | NEW |