OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 | |
3 """ | |
4 Copyright 2014 Google Inc. | |
5 | |
6 Use of this source code is governed by a BSD-style license that can be | |
7 found in the LICENSE file. | |
8 | |
9 Compare results of two render_pictures runs. | |
10 """ | |
11 | |
12 # System-level imports | |
13 import logging | |
14 import os | |
15 import re | |
16 import sys | |
17 import time | |
18 | |
19 # Imports from within Skia | |
20 # | |
21 # TODO(epoger): Once we move the create_filepath_url() function out of | |
22 # download_actuals into a shared utility module, we won't need to import | |
23 # download_actuals anymore. | |
24 # | |
25 # We need to add the 'gm' directory, so that we can import gm_json.py within | |
26 # that directory. That script allows us to parse the actual-results.json file | |
27 # written out by the GM tool. | |
28 # Make sure that the 'gm' dir is in the PYTHONPATH, but add it at the *end* | |
29 # so any dirs that are already in the PYTHONPATH will be preferred. | |
30 PARENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) | |
31 GM_DIRECTORY = os.path.dirname(PARENT_DIRECTORY) | |
32 TRUNK_DIRECTORY = os.path.dirname(GM_DIRECTORY) | |
33 if GM_DIRECTORY not in sys.path: | |
34 sys.path.append(GM_DIRECTORY) | |
35 import download_actuals | |
36 import gm_json | |
37 import imagediffdb | |
38 import imagepair | |
39 import imagepairset | |
40 import results | |
41 | |
42 # Characters we don't want popping up just anywhere within filenames. | |
43 DISALLOWED_FILEPATH_CHAR_REGEX = re.compile('[^\w\-]') | |
44 | |
45 # URL under which all render_pictures images can be found in Google Storage. | |
46 # TODO(epoger): We're not actually uploading any images there yet! | |
47 BASE_IMAGE_URL = 'http://chromium-skia-gm.commondatastorage.googleapis.com/rende r_pictures/images' | |
rmistry
2014/04/04 14:22:20
Should this be the default value for a parameter i
rmistry
2014/04/04 14:22:20
What do you think about adding this link to global
epoger
2014/04/04 15:31:53
Done.
epoger
2014/04/04 15:31:53
Good idea. Added as a TODO for now.
| |
48 | |
49 | |
50 class RenderedPicturesComparisons(results.BaseComparisons): | |
51 """Loads results from two different render_pictures runs into an ImagePairSet. | |
52 """ | |
53 | |
54 def __init__(self, subdirs, actuals_root, | |
55 generated_images_root=results.DEFAULT_GENERATED_IMAGES_ROOT, | |
56 diff_base_url=None): | |
57 """ | |
58 Args: | |
59 actuals_root: root directory containing all render_pictures-generated | |
60 JSON files | |
61 subdirs: (string, string) tuple; pair of subdirectories within | |
62 actuals_root to compare | |
63 generated_images_root: directory within which to create all pixel diffs; | |
64 if this directory does not yet exist, it will be created | |
65 diff_base_url: base URL within which the client should look for diff | |
66 images; if not specified, defaults to a "file:///" URL representation | |
67 of generated_images_root | |
68 """ | |
69 time_start = int(time.time()) | |
70 self._image_diff_db = imagediffdb.ImageDiffDB(generated_images_root) | |
71 self._diff_base_url = ( | |
72 diff_base_url or | |
73 download_actuals.create_filepath_url(generated_images_root)) | |
74 self._load_result_pairs(actuals_root, subdirs) | |
75 self._timestamp = int(time.time()) | |
76 logging.info('Results complete; took %d seconds.' % | |
77 (self._timestamp - time_start)) | |
78 | |
79 def _load_result_pairs(self, actuals_root, subdirs): | |
80 """Loads all JSON files found within two subdirs in actuals_root, | |
81 compares across those two subdirs, and stores the summary in self._results. | |
82 | |
83 Args: | |
84 actuals_root: root directory containing all render_pictures-generated | |
85 JSON files | |
86 subdirs: (string, string) tuple; pair of subdirectories within | |
87 actuals_root to compare | |
88 """ | |
89 logging.info( | |
90 'Reading actual-results JSON files from %s subdirs within %s...' % ( | |
91 subdirs, actuals_root)) | |
92 subdirA, subdirB = subdirs | |
93 subdirA_builder_dicts = results.BaseComparisons._read_dicts_from_root( | |
94 os.path.join(actuals_root, subdirA)) | |
95 subdirB_builder_dicts = results.BaseComparisons._read_dicts_from_root( | |
96 os.path.join(actuals_root, subdirB)) | |
97 logging.info('Comparing subdirs %s and %s...' % (subdirA, subdirB)) | |
98 | |
99 all_image_pairs = imagepairset.ImagePairSet( | |
100 descriptions=subdirs, | |
101 diff_base_url=self._diff_base_url) | |
102 failing_image_pairs = imagepairset.ImagePairSet( | |
103 descriptions=subdirs, | |
104 diff_base_url=self._diff_base_url) | |
105 | |
106 all_image_pairs.ensure_extra_column_values_in_summary( | |
107 column_id=results.KEY__EXTRACOLUMN__RESULT_TYPE, values=[ | |
108 results.KEY__RESULT_TYPE__FAILED, | |
109 results.KEY__RESULT_TYPE__NOCOMPARISON, | |
110 results.KEY__RESULT_TYPE__SUCCEEDED, | |
111 ]) | |
112 failing_image_pairs.ensure_extra_column_values_in_summary( | |
113 column_id=results.KEY__EXTRACOLUMN__RESULT_TYPE, values=[ | |
114 results.KEY__RESULT_TYPE__FAILED, | |
115 results.KEY__RESULT_TYPE__NOCOMPARISON, | |
116 ]) | |
117 | |
118 builders = sorted(set(subdirA_builder_dicts.keys() + | |
119 subdirB_builder_dicts.keys())) | |
120 num_builders = len(builders) | |
121 builder_num = 0 | |
122 for builder in builders: | |
123 builder_num += 1 | |
124 logging.info('Generating pixel diffs for builder #%d of %d, "%s"...' % | |
125 (builder_num, num_builders, builder)) | |
126 # TODO(epoger): This will fail if we have results for this builder in | |
127 # subdirA but not subdirB (or vice versa). | |
128 subdirA_results = results.BaseComparisons.combine_subdicts( | |
129 subdirA_builder_dicts[builder][gm_json.JSONKEY_ACTUALRESULTS]) | |
130 subdirB_results = results.BaseComparisons.combine_subdicts( | |
131 subdirB_builder_dicts[builder][gm_json.JSONKEY_ACTUALRESULTS]) | |
132 image_names = sorted(set(subdirA_results.keys() + | |
133 subdirB_results.keys())) | |
134 for image_name in image_names: | |
135 # The image name may contain funny characters or be ridiculously long | |
epoger
2014/04/03 22:03:41
Actually, rather than sanitizing/truncating the im
rmistry
2014/04/04 14:22:20
Should we add a TODO here to keep track of this (m
epoger
2014/04/04 15:31:53
Done.
| |
136 # (see https://code.google.com/p/skia/issues/detail?id=2344#c10 ), | |
137 # so make sure we sanitize it before using it in a URL path. | |
138 sanitized_test_name = DISALLOWED_FILEPATH_CHAR_REGEX.sub( | |
139 '_', image_name)[:30] | |
140 | |
141 subdirA_image_relative_url = ( | |
142 results.BaseComparisons._create_relative_url( | |
143 hashtype_and_digest=subdirA_results.get(image_name), | |
144 test_name=sanitized_test_name)) | |
145 subdirB_image_relative_url = ( | |
146 results.BaseComparisons._create_relative_url( | |
147 hashtype_and_digest=subdirB_results.get(image_name), | |
148 test_name=sanitized_test_name)) | |
149 | |
150 # If we have images for at least one of these two subdirs, | |
151 # add them to our list. | |
152 if subdirA_image_relative_url or subdirB_image_relative_url: | |
153 if subdirA_image_relative_url == subdirB_image_relative_url: | |
154 result_type = results.KEY__RESULT_TYPE__SUCCEEDED | |
155 elif not subdirA_image_relative_url: | |
156 result_type = results.KEY__RESULT_TYPE__NOCOMPARISON | |
157 elif not subdirB_image_relative_url: | |
158 result_type = results.KEY__RESULT_TYPE__NOCOMPARISON | |
159 else: | |
160 result_type = results.KEY__RESULT_TYPE__FAILED | |
161 | |
162 extra_columns_dict = { | |
163 results.KEY__EXTRACOLUMN__RESULT_TYPE: result_type, | |
164 results.KEY__EXTRACOLUMN__BUILDER: builder, | |
165 results.KEY__EXTRACOLUMN__TEST: image_name, | |
166 # TODO(epoger): Right now, the client UI crashes if it receives | |
167 # results that do not include a 'config' column. | |
168 # Until we fix that, keep the client happy. | |
169 results.KEY__EXTRACOLUMN__CONFIG: 'TODO', | |
170 } | |
171 | |
172 try: | |
173 image_pair = imagepair.ImagePair( | |
174 image_diff_db=self._image_diff_db, | |
175 base_url=BASE_IMAGE_URL, | |
176 imageA_relative_url=subdirA_image_relative_url, | |
177 imageB_relative_url=subdirB_image_relative_url, | |
178 extra_columns=extra_columns_dict) | |
179 all_image_pairs.add_image_pair(image_pair) | |
180 if result_type != results.KEY__RESULT_TYPE__SUCCEEDED: | |
181 failing_image_pairs.add_image_pair(image_pair) | |
182 except (KeyError, TypeError): | |
183 logging.exception( | |
184 'got exception while creating ImagePair for image_name ' | |
185 '"%s", builder "%s"' % (image_name, builder)) | |
186 | |
187 self._results = { | |
188 results.KEY__HEADER__RESULTS_ALL: all_image_pairs.as_dict(), | |
189 results.KEY__HEADER__RESULTS_FAILURES: failing_image_pairs.as_dict(), | |
190 } | |
191 | |
192 | |
193 # TODO(epoger): Add main() so this can be called by vm_run_skia_try.sh | |
OLD | NEW |