Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: Tools/Scripts/webkitpy/layout_tests/generate_results_dashboard.py

Issue 339623002: Added support for versioning of layout test results of run-webkit-tests runs (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressing comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright (C) 2010 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 import logging
31 import string
32
33 from webkitpy.layout_tests.port import configuration_options, platform_options
Dirk Pranke 2014/07/15 20:50:01 Do you need this import? I don't think so; you pro
patro 2014/07/16 14:37:37 Done.
34
35 _log = logging.getLogger(__name__)
36
37
38 class GenerateDashBoard(object):
39
40 "A class for generating the Dashboard from the list of archived results"
Dirk Pranke 2014/07/15 20:50:01 This docstring doesn't tell us much; I'd probably
patro 2014/07/16 14:37:36 Done.
41
42 def __init__(self, port):
43 self._port = port
44 self._filesystem = port.host.filesystem
45 self._results_directory = self._port.results_directory()
46 self._release_directory = self._filesystem.join(self._filesystem.dirname (self._results_directory), '')
Dirk Pranke 2014/07/15 20:50:00 You don't need the .join() here; dirname() gives y
patro 2014/07/16 14:37:36 Renaming it to self._results_directory_path Yes i
47 self._input_json_data = ""
Dirk Pranke 2014/07/15 20:50:01 Is this supposed to be a string or a dict? Why not
patro 2014/07/16 14:37:37 It is a dict. Renaming it ro self._current_result_
Dirk Pranke 2014/07/16 19:32:44 If it's a dict, why are you assigning a string to
48 self._old_failing_results_list = []
49 self._old_full_results_list = []
50 self._final_result = []
51
52 def _add_individual_result_links(self, file_list):
Dirk Pranke 2014/07/15 20:50:00 this is actually a list of directories, not a list
patro 2014/07/16 14:37:37 Done.
53 file_list = [(file + '/results.html') for file in file_list]
54 self._input_json_data['result_links'] = file_list
55
56 def _copy_dashboard_html(self):
57 dashboard_file = self._filesystem.join(self._release_directory, 'dashboa rd.html')
58 dashboard_html_file_path = self._filesystem.join(self._port.layout_tests _dir(), 'fast/harness/dashboard.html')
59 if ~(self._filesystem.exists(dashboard_file)):
Dirk Pranke 2014/07/15 20:50:01 this should be 'if not self._filesystem.exists(das
patro 2014/07/16 14:37:36 Done.
60 if self._filesystem.exists(dashboard_html_file_path):
61 self._filesystem.copyfile(dashboard_html_file_path, dashboard_fi le)
62
63 def _initialize(self):
64 file_list = self._filesystem.listdir(self._release_directory)
65 json_file_list = []
Dirk Pranke 2014/07/15 20:50:01 json_file_list isn't a list of json files, it's a
patro 2014/07/16 14:37:36 Done.
66 for dir in file_list:
67 if self._filesystem.isdir(self._filesystem.join(self._release_direct ory, dir)):
68 json_file_list.append(self._filesystem.join(self._release_direct ory, dir))
69 json_file_list.sort(reverse=True)
70 #Read the current Layout Test Results
Dirk Pranke 2014/07/15 20:50:00 if you are going to add comments, add a blank line
patro 2014/07/16 14:37:37 Done.
71 with open(self._filesystem.join(json_file_list[0], 'failing_results.json '), "r") as file:
72 input_json_string = file.readline()
73 input_json_string = input_json_string[12:-2] # Remove preceeding strin g ADD_RESULTS( and ); at the end
Dirk Pranke 2014/07/15 20:50:01 I would extract lines 71-73 into a routine and reu
74 self._input_json_data = json.loads(input_json_string)
75 #To add hyperlink to individual results.html
76 self._add_individual_result_links(json_file_list)
77 json_file_list = json_file_list[1:]
78 #Load the remaining stale layout test results Json's to create the dashb oard
79 for json_file in json_file_list:
80 with open(self._filesystem.join(json_file, 'failing_results.json'), "r") as file:
81 json_string = file.readline()
82 json_string = json_string[12:-2] # Remove preceeding string ADD_RE SULTS( and ); at the end
83 self._old_failing_results_list.append(json.loads(json_string))
84
85 with open(self._filesystem.join(json_file, 'full_results.json'), "r" ) as full_file:
86 json_string_full_result = full_file.readline()
87 self._old_full_results_list.append(json.loads(json_string_full_resul t))
88 self._copy_dashboard_html()
89
90 #To safely get the value if key doesn't exit then it is a syntax error
91 def _get_value(self, json_object, key):
92 try:
93 value = json_object[key]
94 return value
95 except KeyError, e:
96 print("Syntax error: Could not find the key ", key)
97 exit()
Dirk Pranke 2014/07/15 20:50:01 printing an error and calling exit is actually les
patro 2014/07/16 14:37:36 Done.
98
99 #To process the final dict
100 def _process_json_result(self, json_object):
Dirk Pranke 2014/07/15 20:50:01 what are you 'processing' here? can you use a more
patro 2014/07/16 14:37:36 Done.
101 actual = self._get_value(json_object, "actual")
Dirk Pranke 2014/07/15 20:50:01 just use actual = json_object['actual'] here and a
patro 2014/07/16 14:37:36 Done.
102 expected = self._get_value(json_object, "expected")
103 if actual == 'SKIP':
104 return actual
105 if actual == expected:
106 hasStderr = 'false'
107 try:
108 hasStderr = json_object["has_stderr"]
109 except KeyError, e:
110 pass
Dirk Pranke 2014/07/15 20:50:00 You can replace lines 107-110 with hasStderr = js
patro 2014/07/16 14:37:37 Done.
111 if hasStderr == 'true':
112 return 'HASSTDERR'
113 return 'PASS'
114 else:
115 return actual
116
117 def _recurse_json_object(self, json_object, key_list):
118 for key in key_list:
119 try:
120 json_object = json_object[key]
121 except KeyError:
122 return 'NOTFOUND'
123 return self._process_json_result(json_object)
124
125 def _process_previous_json_results(self, key_list):
126 row = []
127 length = len(self._old_failing_results_list)
128 for index in range(0, length - 1):
129 result = self._recurse_json_object(self._old_failing_results_list[in dex]["tests"], key_list)
130 if result == 'NOTFOUND':
131 result = self._recurse_json_object(self._old_full_results_list[i ndex]["tests"], key_list)
132 row.append(result)
133 return row
134
135 def _add_archived_results(self, json_object, result):
136 json_object['archived_results'] = result
137
138 def _process_json_object(self, json_object, keyList):
139 flag = 0
140 for key, subdict in json_object.iteritems():
141 if type(subdict) == dict:
142 self._process_json_object(subdict, keyList + [key])
143 else:
144 flag = 1
145 break
146 if flag == 1:
147 row = [self._process_json_result(json_object)]
148 row += self._process_previous_json_results(keyList)
149 self._add_archived_results(json_object, row)
Dirk Pranke 2014/07/15 20:50:01 just replace line 144 with lines 147-149 and repla
patro 2014/07/16 14:37:37 Done.
150
151 def _process_json_data(self):
152 for key in self._input_json_data["tests"]:
153 self._process_json_object(self._input_json_data["tests"][key], [key] )
154
155 def generate(self):
156 self._initialize()
157 self._process_json_data()
158 final_json = json.dumps(self._input_json_data)
159 final_json = 'ADD_RESULTS(' + final_json + ');'
160 with open(self._filesystem.join(self._release_directory, 'archived_resul ts.json'), "w") as file:
161 file.write(final_json)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698