| 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 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 option_parser.add_option('-x', '--test-group-name', | 72 option_parser.add_option('-x', '--test-group-name', |
| 73 dest='test_group_name', | 73 dest='test_group_name', |
| 74 help=('Name of test group ' | 74 help=('Name of test group ' |
| 75 '(default to %default)'), | 75 '(default to %default)'), |
| 76 default=DEFAULT_TEST_GROUP_NAME) | 76 default=DEFAULT_TEST_GROUP_NAME) |
| 77 option_parser.add_option('-d', '--result-directory-location', | 77 option_parser.add_option('-d', '--result-directory-location', |
| 78 dest='result_directory_location', | 78 dest='result_directory_location', |
| 79 help=('Name of result directory location ' | 79 help=('Name of result directory location ' |
| 80 '(default to %default)'), | 80 '(default to %default)'), |
| 81 default=DEFAULT_RESULT_DIR) | 81 default=DEFAULT_RESULT_DIR) |
| 82 option_parser.add_option('-b', '--email-appended-text-file-location', |
| 83 dest='email_appended_text_file_location', |
| 84 help=('File location of the email appended text. ' |
| 85 'The text is appended in the status email. ' |
| 86 '(default to %default and no text is ' |
| 87 'appended in that case.)'), |
| 88 default=None) |
| 82 return option_parser.parse_args()[0] | 89 return option_parser.parse_args()[0] |
| 83 | 90 |
| 84 | 91 |
| 85 def main(): | 92 def main(): |
| 86 """A main function for the analyzer.""" | 93 """A main function for the analyzer.""" |
| 87 options = parse_option() | 94 options = parse_option() |
| 88 start_time = datetime.now() | 95 start_time = datetime.now() |
| 89 | 96 |
| 90 # Do the main analysis. | 97 # Do the main analysis. |
| 91 if not options.debug: | 98 if not options.debug: |
| 92 layouttests = LayoutTests(csv_file_path=options.test_group_file_location) | 99 layouttests = LayoutTests(csv_file_path=options.test_group_file_location) |
| 93 analyzer_result_map = layouttest_analyzer_helpers.AnalyzerResultMap( | 100 analyzer_result_map = layouttest_analyzer_helpers.AnalyzerResultMap( |
| 94 layouttests.JoinWithTestExpectation(TestExpectations())) | 101 layouttests.JoinWithTestExpectation(TestExpectations())) |
| 95 (prev_time, prev_analyzer_result_map) = ( | 102 (prev_time, prev_analyzer_result_map) = ( |
| 96 layouttest_analyzer_helpers.FindLatestResult('result')) | 103 layouttest_analyzer_helpers.FindLatestResult('result')) |
| 97 else: | 104 else: |
| 98 analyzer_result_map = layouttest_analyzer_helpers.AnalyzerResultMap.Load( | 105 analyzer_result_map = layouttest_analyzer_helpers.AnalyzerResultMap.Load( |
| 99 CURRENT_RESULT_FILE_FOR_DEBUG) | 106 CURRENT_RESULT_FILE_FOR_DEBUG) |
| 100 prev_time = PREV_TIME_FOR_DEBUG | 107 prev_time = PREV_TIME_FOR_DEBUG |
| 101 prev_analyzer_result_map = ( | 108 prev_analyzer_result_map = ( |
| 102 layouttest_analyzer_helpers.AnalyzerResultMap.Load( | 109 layouttest_analyzer_helpers.AnalyzerResultMap.Load( |
| 103 os.path.join(options.result_directory_location, prev_time))) | 110 os.path.join(options.result_directory_location, prev_time))) |
| 104 | 111 |
| 105 # Read bug annotations and generate an annotation map used for the status | 112 # Read bug annotations and generate an annotation map used for the status |
| 106 # email. | 113 # email. |
| 107 anno_map = {} | 114 anno_map = {} |
| 108 file_object = open(options.bug_annotation_file_location) | 115 try: |
| 109 data = csv.reader(file_object) | 116 file_object = open(options.bug_annotation_file_location) |
| 110 for row in data: | 117 except IOError: |
| 111 anno_map[row[0]] = row[1] | 118 print 'cannot open annotation file %s. Skipping.' % ( |
| 112 file_object.close() | 119 options.bug_annotation_file_location) |
| 120 else: |
| 121 data = csv.reader(file_object) |
| 122 for row in data: |
| 123 anno_map[row[0]] = row[1] |
| 124 file_object.close() |
| 125 |
| 126 appended_text_to_email = '' |
| 127 if options.email_appended_text_file_location: |
| 128 try: |
| 129 file_object = open(options.email_appended_text_file_location) |
| 130 except IOError: |
| 131 print 'cannot open email appended text file %s. Skipping.' % ( |
| 132 options.email_appended_text_file_location) |
| 133 else: |
| 134 appended_text_to_email = ''.join(file_object.readlines()) |
| 135 file_object.close() |
| 136 |
| 113 | 137 |
| 114 layouttest_analyzer_helpers.SendStatusEmail(prev_time, analyzer_result_map, | 138 layouttest_analyzer_helpers.SendStatusEmail(prev_time, analyzer_result_map, |
| 115 prev_analyzer_result_map, | 139 prev_analyzer_result_map, |
| 116 anno_map, | 140 anno_map, |
| 117 options.receiver_email_address, | 141 options.receiver_email_address, |
| 118 options.test_group_name) | 142 options.test_group_name, |
| 143 appended_text_to_email) |
| 119 if not options.debug: | 144 if not options.debug: |
| 120 # Save the current result. | 145 # Save the current result. |
| 121 date = start_time.strftime('%Y-%m-%d-%H') | 146 date = start_time.strftime('%Y-%m-%d-%H') |
| 122 file_path = os.path.join(options.result_directory_location, date) | 147 file_path = os.path.join(options.result_directory_location, date) |
| 123 analyzer_result_map.Save(file_path) | 148 analyzer_result_map.Save(file_path) |
| 124 | 149 |
| 125 # Trend graph update (if specified in the command-line argument). | 150 # Trend graph update (if specified in the command-line argument). |
| 126 trend_graph = TrendGraph(options.trend_graph_location) | 151 trend_graph = TrendGraph(options.trend_graph_location) |
| 127 datetime_string = start_time.strftime('%Y,%m,%d,%H,%M,%S') | 152 datetime_string = start_time.strftime('%Y,%m,%d,%H,%M,%S') |
| 128 # TODO(imasaki): add correct title and text instead of 'undefined'. | 153 # TODO(imasaki): add correct title and text instead of 'undefined'. |
| 129 data_map = ( | 154 data_map = ( |
| 130 {'whole': (str(len(analyzer_result_map.result_map['whole'].keys())), | 155 {'whole': (str(len(analyzer_result_map.result_map['whole'].keys())), |
| 131 'undefined', 'undefined'), | 156 'undefined', 'undefined'), |
| 132 'skip': (str(len(analyzer_result_map.result_map['skip'].keys())), | 157 'skip': (str(len(analyzer_result_map.result_map['skip'].keys())), |
| 133 'undefined', 'undefined'), | 158 'undefined', 'undefined'), |
| 134 'nonskip': (str(len(analyzer_result_map.result_map['nonskip'].keys())), | 159 'nonskip': (str(len(analyzer_result_map.result_map['nonskip'].keys())), |
| 135 'undefined', 'undefined'), | 160 'undefined', 'undefined'), |
| 136 'passingrate': (str(analyzer_result_map.GetPassingRate()), | 161 'passingrate': (str(analyzer_result_map.GetPassingRate()), |
| 137 'undefined', 'undefined')}) | 162 'undefined', 'undefined')}) |
| 138 trend_graph.Update(datetime_string, data_map) | 163 trend_graph.Update(datetime_string, data_map) |
| 139 | 164 |
| 140 | 165 |
| 141 if '__main__' == __name__: | 166 if '__main__' == __name__: |
| 142 main() | 167 main() |
| OLD | NEW |