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