Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (C) 2014 Google Inc. All rights reserved. | |
| 2 # | |
| 3 # Redistribution and use in source and binary forms, with or without | |
| 4 # modification, are permitted provided that the following conditions are | |
| 5 # met: | |
| 6 # | |
| 7 # * Redistributions of source code must retain the above copyright | |
| 8 # notice, this list of conditions and the following disclaimer. | |
| 9 # * Redistributions in binary form must reproduce the above | |
| 10 # copyright notice, this list of conditions and the following disclaimer | |
| 11 # in the documentation and/or other materials provided with the | |
| 12 # distribution. | |
| 13 # * Neither the name of Google Inc. nor the names of its | |
| 14 # contributors may be used to endorse or promote products derived from | |
| 15 # this software without specific prior written permission. | |
| 16 # | |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 28 | |
| 29 import json | |
| 30 | |
| 31 | |
| 32 class GenerateDashBoard(object): | |
| 33 | |
| 34 def __init__(self, port): | |
| 35 self._port = port | |
| 36 self._filesystem = port.host.filesystem | |
| 37 self._results_directory = self._port.results_directory() | |
| 38 self._release_directory = self._filesystem.dirname(self._results_directo ry) | |
| 39 self._current_result_json_dict = {} | |
| 40 self._old_failing_results_list = [] | |
| 41 self._old_full_results_list = [] | |
| 42 self._final_result = [] | |
| 43 | |
| 44 def _add_individual_result_links(self, results_directories): | |
| 45 archived_results_file_list = [(file + '/results.html') for file in resul ts_directories] | |
| 46 self._current_result_json_dict['result_links'] = archived_results_file_l ist | |
| 47 | |
| 48 def _copy_dashboard_html(self): | |
| 49 dashboard_file = self._filesystem.join(self._results_directory, 'dashboa rd.html') | |
| 50 dashboard_html_file_path = self._filesystem.join(self._port.layout_tests _dir(), 'fast/harness/dashboard.html') | |
| 51 if not self._filesystem.exists(dashboard_file): | |
| 52 if self._filesystem.exists(dashboard_html_file_path): | |
| 53 self._filesystem.copyfile(dashboard_html_file_path, dashboard_fi le) | |
| 54 | |
| 55 def _initialize(self): | |
| 56 file_list = self._filesystem.listdir(self._release_directory) | |
| 57 results_directories = [] | |
| 58 for dir in file_list: | |
| 59 if self._filesystem.isdir(self._filesystem.join(self._release_direct ory, dir)): | |
| 60 results_directories.append(self._filesystem.join(self._release_d irectory, dir)) | |
| 61 results_directories.sort(reverse=True, key=lambda x: self._filesystem.mt ime(x)) | |
| 62 with open(self._filesystem.join(results_directories[0], 'failing_results .json'), "r") as file: | |
| 63 input_json_string = file.readline() | |
| 64 input_json_string = input_json_string[12:-2] # Remove preceeding strin g ADD_RESULTS( and ); at the end | |
| 65 self._current_result_json_dict['tests'] = json.loads(input_json_string)[ "tests"] | |
|
Dirk Pranke
2014/07/22 20:02:05
nit: single quotes in both cases
patro
2014/07/24 09:29:14
Done.
| |
| 66 | |
| 67 # To add hyperlink to individual results.html | |
| 68 self._add_individual_result_links(results_directories) | |
| 69 results_directories = results_directories[1:] | |
| 70 | |
| 71 # Load the remaining stale layout test results Json's to create the dash board | |
| 72 for json_file in results_directories: | |
| 73 with open(self._filesystem.join(json_file, 'failing_results.json'), "r") as file: | |
| 74 json_string = file.readline() | |
| 75 json_string = json_string[12:-2] # Remove preceeding string ADD_RE SULTS( and ); at the end | |
| 76 self._old_failing_results_list.append(json.loads(json_string)) | |
| 77 | |
| 78 with open(self._filesystem.join(json_file, 'full_results.json'), "r" ) as full_file: | |
| 79 json_string_full_result = full_file.readline() | |
| 80 self._old_full_results_list.append(json.loads(json_string_full_resul t)) | |
| 81 self._copy_dashboard_html() | |
| 82 | |
| 83 # To process the final dict | |
| 84 def _get_test_result(self, test_result_data): | |
| 85 actual = test_result_data['actual'] | |
| 86 expected = test_result_data['expected'] | |
| 87 if actual == 'SKIP': | |
| 88 return actual | |
| 89 if actual == expected: | |
| 90 return 'HASSTDERR' if test_result_data.get('has_stderr') == 'true' e lse 'PASS' | |
| 91 else: | |
| 92 return actual | |
| 93 | |
| 94 def _recurse_json_object(self, json_object, key_list): | |
| 95 for key in key_list: | |
| 96 try: | |
| 97 json_object = json_object[key] | |
| 98 except KeyError: | |
| 99 return 'NOTFOUND' | |
| 100 return self._get_test_result(json_object) | |
| 101 | |
| 102 def _process_previous_json_results(self, key_list): | |
| 103 row = [] | |
| 104 length = len(self._old_failing_results_list) | |
| 105 for index in range(0, length): | |
| 106 result = self._recurse_json_object(self._old_failing_results_list[in dex]["tests"], key_list) | |
| 107 if result == 'NOTFOUND': | |
| 108 result = self._recurse_json_object(self._old_full_results_list[i ndex]["tests"], key_list) | |
| 109 row.append(result) | |
| 110 return row | |
| 111 | |
| 112 def _add_archived_results(self, json_object, result): | |
| 113 json_object['archived_results'] = result | |
| 114 | |
| 115 def _process_json_object(self, json_object, keyList): | |
| 116 for key, subdict in json_object.iteritems(): | |
| 117 if type(subdict) == dict: | |
| 118 self._process_json_object(subdict, keyList + [key]) | |
| 119 else: | |
| 120 row = [self._get_test_result(json_object)] | |
| 121 row += self._process_previous_json_results(keyList) | |
| 122 json_object.clear() | |
| 123 self._add_archived_results(json_object, row) | |
| 124 return | |
| 125 | |
| 126 def _process_json_data(self): | |
| 127 for key in self._current_result_json_dict["tests"]: | |
| 128 self._process_json_object(self._current_result_json_dict["tests"][ke y], [key]) | |
| 129 | |
| 130 def generate(self): | |
| 131 self._initialize() | |
| 132 self._process_json_data() | |
| 133 final_json = json.dumps(self._current_result_json_dict) | |
| 134 final_json = 'ADD_RESULTS(' + final_json + ');' | |
| 135 with open(self._filesystem.join(self._results_directory, 'archived_resul ts.json'), "w") as file: | |
| 136 file.write(final_json) | |
| OLD | NEW |