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 DEFAULT_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(DEFAULT_RESULT_DIR, |
| 27 '2011-08-19-21') |
27 PREV_TIME_FOR_DEBUG = '2011-08-19-11' | 28 PREV_TIME_FOR_DEBUG = '2011-08-19-11' |
28 | 29 |
29 DEFAULT_TEST_GROUP_FILE = os.path.join('testname', 'media.csv') | 30 DEFAULT_TEST_GROUP_FILE = os.path.join('testname', 'media.csv') |
30 DEFAULT_TEST_GROUP_NAME = 'media' | 31 DEFAULT_TEST_GROUP_NAME = 'media' |
31 | 32 |
32 | 33 |
33 def parse_option(): | 34 def parse_option(): |
34 """Parse command-line options using OptionParser. | 35 """Parse command-line options using OptionParser. |
35 | 36 |
36 Returns: | 37 Returns: |
(...skipping 29 matching lines...) Expand all Loading... |
66 dest='test_group_file_location', | 67 dest='test_group_file_location', |
67 help=('Location of the test group file; ' | 68 help=('Location of the test group file; ' |
68 'file is expected to be in CSV format ' | 69 'file is expected to be in CSV format ' |
69 '(default to %default)'), | 70 '(default to %default)'), |
70 default=DEFAULT_TEST_GROUP_FILE) | 71 default=DEFAULT_TEST_GROUP_FILE) |
71 option_parser.add_option('-x', '--test-group-name', | 72 option_parser.add_option('-x', '--test-group-name', |
72 dest='test_group_name', | 73 dest='test_group_name', |
73 help=('Name of test group ' | 74 help=('Name of test group ' |
74 '(default to %default)'), | 75 '(default to %default)'), |
75 default=DEFAULT_TEST_GROUP_NAME) | 76 default=DEFAULT_TEST_GROUP_NAME) |
| 77 option_parser.add_option('-d', '--result-directory-location', |
| 78 dest='result_directory_location', |
| 79 help=('Name of result directory location ' |
| 80 '(default to %default)'), |
| 81 default=DEFAULT_RESULT_DIR) |
76 return option_parser.parse_args()[0] | 82 return option_parser.parse_args()[0] |
77 | 83 |
78 | 84 |
79 def main(): | 85 def main(): |
80 """A main function for the analyzer.""" | 86 """A main function for the analyzer.""" |
81 options = parse_option() | 87 options = parse_option() |
82 start_time = datetime.now() | 88 start_time = datetime.now() |
83 | 89 |
84 # Do the main analysis. | 90 # Do the main analysis. |
85 if not options.debug: | 91 if not options.debug: |
86 layouttests = LayoutTests(csv_file_path=options.test_group_file_location) | 92 layouttests = LayoutTests(csv_file_path=options.test_group_file_location) |
87 analyzer_result_map = layouttest_analyzer_helpers.AnalyzerResultMap( | 93 analyzer_result_map = layouttest_analyzer_helpers.AnalyzerResultMap( |
88 layouttests.JoinWithTestExpectation(TestExpectations())) | 94 layouttests.JoinWithTestExpectation(TestExpectations())) |
89 (prev_time, prev_analyzer_result_map) = ( | 95 (prev_time, prev_analyzer_result_map) = ( |
90 layouttest_analyzer_helpers.FindLatestResult('result')) | 96 layouttest_analyzer_helpers.FindLatestResult('result')) |
91 else: | 97 else: |
92 analyzer_result_map = layouttest_analyzer_helpers.AnalyzerResultMap.Load( | 98 analyzer_result_map = layouttest_analyzer_helpers.AnalyzerResultMap.Load( |
93 CURRENT_RESULT_FILE_FOR_DEBUG) | 99 CURRENT_RESULT_FILE_FOR_DEBUG) |
94 prev_time = PREV_TIME_FOR_DEBUG | 100 prev_time = PREV_TIME_FOR_DEBUG |
95 prev_analyzer_result_map = ( | 101 prev_analyzer_result_map = ( |
96 layouttest_analyzer_helpers.AnalyzerResultMap.Load( | 102 layouttest_analyzer_helpers.AnalyzerResultMap.Load( |
97 os.path.join(RESULT_DIR, prev_time))) | 103 os.path.join(options.result_directory_location, prev_time))) |
98 | 104 |
99 # Read bug annotations and generate an annotation map used for the status | 105 # Read bug annotations and generate an annotation map used for the status |
100 # email. | 106 # email. |
101 anno_map = {} | 107 anno_map = {} |
102 file_object = open(options.bug_annotation_file_location) | 108 file_object = open(options.bug_annotation_file_location) |
103 data = csv.reader(file_object) | 109 data = csv.reader(file_object) |
104 for row in data: | 110 for row in data: |
105 anno_map[row[0]] = row[1] | 111 anno_map[row[0]] = row[1] |
106 file_object.close() | 112 file_object.close() |
107 | 113 |
108 layouttest_analyzer_helpers.SendStatusEmail(prev_time, analyzer_result_map, | 114 layouttest_analyzer_helpers.SendStatusEmail(prev_time, analyzer_result_map, |
109 prev_analyzer_result_map, | 115 prev_analyzer_result_map, |
110 anno_map, | 116 anno_map, |
111 options.receiver_email_address, | 117 options.receiver_email_address, |
112 options.test_group_name) | 118 options.test_group_name) |
113 if not options.debug: | 119 if not options.debug: |
114 # Save the current result. | 120 # Save the current result. |
115 date = start_time.strftime('%Y-%m-%d-%H') | 121 date = start_time.strftime('%Y-%m-%d-%H') |
116 file_path = os.path.join(RESULT_DIR, date) | 122 file_path = os.path.join(options.result_directory_location, date) |
117 analyzer_result_map.Save(file_path) | 123 analyzer_result_map.Save(file_path) |
118 | 124 |
119 # Trend graph update (if specified in the command-line argument). | 125 # Trend graph update (if specified in the command-line argument). |
120 trend_graph = TrendGraph(options.trend_graph_location) | 126 trend_graph = TrendGraph(options.trend_graph_location) |
121 datetime_string = start_time.strftime('%Y,%m,%d,%H,%M,%S') | 127 datetime_string = start_time.strftime('%Y,%m,%d,%H,%M,%S') |
122 # TODO(imasaki): add correct title and text instead of 'undefined'. | 128 # TODO(imasaki): add correct title and text instead of 'undefined'. |
123 data_map = ( | 129 data_map = ( |
124 {'whole': (str(len(analyzer_result_map.result_map['whole'].keys())), | 130 {'whole': (str(len(analyzer_result_map.result_map['whole'].keys())), |
125 'undefined', 'undefined'), | 131 'undefined', 'undefined'), |
126 'skip': (str(len(analyzer_result_map.result_map['skip'].keys())), | 132 'skip': (str(len(analyzer_result_map.result_map['skip'].keys())), |
127 'undefined', 'undefined'), | 133 'undefined', 'undefined'), |
128 'nonskip': (str(len(analyzer_result_map.result_map['nonskip'].keys())), | 134 'nonskip': (str(len(analyzer_result_map.result_map['nonskip'].keys())), |
129 'undefined', 'undefined'), | 135 'undefined', 'undefined'), |
130 'passingrate': (str(analyzer_result_map.GetPassingRate()), | 136 'passingrate': (str(analyzer_result_map.GetPassingRate()), |
131 'undefined', 'undefined')}) | 137 'undefined', 'undefined')}) |
132 trend_graph.Update(datetime_string, data_map) | 138 trend_graph.Update(datetime_string, data_map) |
133 | 139 |
134 | 140 |
135 if '__main__' == __name__: | 141 if '__main__' == __name__: |
136 main() | 142 main() |
OLD | NEW |