blob: 1fdeb10f677164679c9462c393e1685ae806ec63 [file] [log] [blame]
commit-bot@chromium.org11f15622014-01-07 17:03:40 +00001#!/usr/bin/python
2
3"""
4Copyright 2014 Google Inc.
5
6Use of this source code is governed by a BSD-style license that can be
7found in the LICENSE file.
8
9Test the render_pictures binary.
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000010"""
11
12# System-level imports
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000013import copy
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000014import json
15import os
16import shutil
17import tempfile
18
epoger66ed8dc2014-07-17 12:54:16 -070019# Must fix up PYTHONPATH before importing from within Skia
20import fix_pythonpath # pylint: disable=W0611
21
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000022# Imports from within Skia
23import base_unittest
epoger66ed8dc2014-07-17 12:54:16 -070024import find_run_binary
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000025
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +000026# Maximum length of text diffs to show when tests fail
27MAX_DIFF_LENGTH = 30000
28
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000029EXPECTED_HEADER_CONTENTS = {
30 "type" : "ChecksummedImages",
31 "revision" : 1,
32}
33
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000034# Manually verified: 640x400 red rectangle with black border
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000035# Standard expectations will be set up in such a way that this image fails
36# the comparison.
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000037RED_WHOLEIMAGE = {
38 "checksumAlgorithm" : "bitmap-64bitMD5",
39 "checksumValue" : 11092453015575919668,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000040 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000041 "filepath" : "red_skp.png",
42}
43
44# Manually verified: 640x400 green rectangle with black border
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000045# Standard expectations will be set up in such a way that this image passes
46# the comparison.
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000047GREEN_WHOLEIMAGE = {
48 "checksumAlgorithm" : "bitmap-64bitMD5",
49 "checksumValue" : 8891695120562235492,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000050 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000051 "filepath" : "green_skp.png",
52}
53
54# Manually verified these 6 images, all 256x256 tiles,
55# consistent with a tiled version of the 640x400 red rect
56# with black borders.
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000057# Standard expectations will be set up in such a way that these images fail
58# the comparison.
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000059RED_TILES = [{
60 "checksumAlgorithm" : "bitmap-64bitMD5",
61 "checksumValue" : 5815827069051002745,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000062 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000063 "filepath" : "red_skp-tile0.png",
64},{
65 "checksumAlgorithm" : "bitmap-64bitMD5",
66 "checksumValue" : 9323613075234140270,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000067 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000068 "filepath" : "red_skp-tile1.png",
69}, {
70 "checksumAlgorithm" : "bitmap-64bitMD5",
71 "checksumValue" : 16670399404877552232,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000072 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000073 "filepath" : "red_skp-tile2.png",
74}, {
75 "checksumAlgorithm" : "bitmap-64bitMD5",
76 "checksumValue" : 2507897274083364964,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000077 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000078 "filepath" : "red_skp-tile3.png",
79}, {
80 "checksumAlgorithm" : "bitmap-64bitMD5",
81 "checksumValue" : 7325267995523877959,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000082 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000083 "filepath" : "red_skp-tile4.png",
84}, {
85 "checksumAlgorithm" : "bitmap-64bitMD5",
86 "checksumValue" : 2181381724594493116,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000087 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000088 "filepath" : "red_skp-tile5.png",
89}]
90
91# Manually verified these 6 images, all 256x256 tiles,
92# consistent with a tiled version of the 640x400 green rect
93# with black borders.
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000094# Standard expectations will be set up in such a way that these images pass
95# the comparison.
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000096GREEN_TILES = [{
97 "checksumAlgorithm" : "bitmap-64bitMD5",
98 "checksumValue" : 12587324416545178013,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000099 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000100 "filepath" : "green_skp-tile0.png",
101}, {
102 "checksumAlgorithm" : "bitmap-64bitMD5",
103 "checksumValue" : 7624374914829746293,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000104 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000105 "filepath" : "green_skp-tile1.png",
106}, {
107 "checksumAlgorithm" : "bitmap-64bitMD5",
108 "checksumValue" : 5686489729535631913,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000109 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000110 "filepath" : "green_skp-tile2.png",
111}, {
112 "checksumAlgorithm" : "bitmap-64bitMD5",
113 "checksumValue" : 7980646035555096146,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000114 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000115 "filepath" : "green_skp-tile3.png",
116}, {
117 "checksumAlgorithm" : "bitmap-64bitMD5",
118 "checksumValue" : 17817086664365875131,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000119 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000120 "filepath" : "green_skp-tile4.png",
121}, {
122 "checksumAlgorithm" : "bitmap-64bitMD5",
123 "checksumValue" : 10673669813016809363,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000124 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000125 "filepath" : "green_skp-tile5.png",
126}]
127
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000128
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000129def modified_dict(input_dict, modification_dict):
130 """Returns a dict, with some modifications applied to it.
131
132 Args:
133 input_dict: a dictionary (which will be copied, not modified in place)
134 modification_dict: a set of key/value pairs to overwrite in the dict
135 """
136 output_dict = input_dict.copy()
137 output_dict.update(modification_dict)
138 return output_dict
139
140
141def modified_list_of_dicts(input_list, modification_dict):
142 """Returns a list of dicts, with some modifications applied to each dict.
143
144 Args:
145 input_list: a list of dictionaries; these dicts will be copied, not
146 modified in place
147 modification_dict: a set of key/value pairs to overwrite in each dict
148 within input_list
149 """
150 output_list = []
151 for input_dict in input_list:
152 output_dict = modified_dict(input_dict, modification_dict)
153 output_list.append(output_dict)
154 return output_list
155
156
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000157class RenderPicturesTest(base_unittest.TestCase):
158
159 def setUp(self):
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000160 self.maxDiff = MAX_DIFF_LENGTH
161 self._expectations_dir = tempfile.mkdtemp()
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000162 self._input_skp_dir = tempfile.mkdtemp()
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000163 # All output of render_pictures binary will go into this directory.
164 self._output_dir = tempfile.mkdtemp()
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000165
166 def tearDown(self):
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000167 shutil.rmtree(self._expectations_dir)
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000168 shutil.rmtree(self._input_skp_dir)
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000169 shutil.rmtree(self._output_dir)
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000170
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000171 def test_tiled_whole_image(self):
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000172 """Run render_pictures with tiles and --writeWholeImage flag.
173
174 TODO(epoger): This test generates undesired results! The JSON summary
175 includes both whole-image and tiled-images (as it should), but only
176 whole-images are written out to disk. See http://skbug.com/2463
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000177 Once I fix that, I should add a similar test that exercises mismatchPath.
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000178
179 TODO(epoger): I noticed that when this is run without --writePath being
180 specified, this test writes red_skp.png and green_skp.png to the current
181 directory. We should fix that... if --writePath is not specified, this
182 probably shouldn't write out red_skp.png and green_skp.png at all!
183 See http://skbug.com/2464
184 """
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000185 output_json_path = os.path.join(self._output_dir, 'actuals.json')
186 write_path_dir = self.create_empty_dir(
187 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000188 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000189 expectations_path = self._create_expectations()
190 self._run_render_pictures([
191 '-r', self._input_skp_dir,
192 '--bbh', 'grid', '256', '256',
193 '--mode', 'tile', '256', '256',
194 '--readJsonSummaryPath', expectations_path,
195 '--writeJsonSummaryPath', output_json_path,
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000196 '--writePath', write_path_dir,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000197 '--writeWholeImage'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000198 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000199 "header" : EXPECTED_HEADER_CONTENTS,
epogerb492c6f2014-08-14 07:32:49 -0700200 "descriptions" : None,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000201 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000202 "red.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000203 "tiled-images": RED_TILES,
204 "whole-image": RED_WHOLEIMAGE,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000205 },
206 "green.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000207 "tiled-images": GREEN_TILES,
208 "whole-image": GREEN_WHOLEIMAGE,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000209 }
210 }
commit-bot@chromium.org238771c2014-01-15 16:33:31 +0000211 }
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000212 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000213 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000214 write_path_dir, ['red_skp.png', 'green_skp.png'])
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000215
216 def test_missing_tile_and_whole_image(self):
217 """test_tiled_whole_image, but missing expectations for some images.
218 """
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000219 output_json_path = os.path.join(self._output_dir, 'actuals.json')
220 write_path_dir = self.create_empty_dir(
221 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000222 self._generate_skps()
223 expectations_path = self._create_expectations(missing_some_images=True)
224 self._run_render_pictures([
225 '-r', self._input_skp_dir,
226 '--bbh', 'grid', '256', '256',
227 '--mode', 'tile', '256', '256',
228 '--readJsonSummaryPath', expectations_path,
229 '--writeJsonSummaryPath', output_json_path,
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000230 '--writePath', write_path_dir,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000231 '--writeWholeImage'])
232 modified_red_tiles = copy.deepcopy(RED_TILES)
233 modified_red_tiles[5]['comparisonResult'] = 'no-comparison'
234 expected_summary_dict = {
235 "header" : EXPECTED_HEADER_CONTENTS,
epogerb492c6f2014-08-14 07:32:49 -0700236 "descriptions" : None,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000237 "actual-results" : {
238 "red.skp": {
239 "tiled-images": modified_red_tiles,
240 "whole-image": modified_dict(
241 RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}),
242 },
243 "green.skp": {
244 "tiled-images": GREEN_TILES,
245 "whole-image": GREEN_WHOLEIMAGE,
246 }
247 }
248 }
249 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000250
commit-bot@chromium.orgabeb9582014-05-19 15:25:10 +0000251 def _test_untiled(self, expectations_path=None, expected_summary_dict=None,
252 additional_args=None):
253 """Base for multiple tests without tiles.
254
255 Args:
256 expectations_path: path we should pass using --readJsonSummaryPath, or
257 None if we should create the default expectations file
258 expected_summary_dict: dict we should compare against the output actual
259 results summary, or None if we should use a default comparison dict
260 additional_args: array of command-line args to add when we run
261 render_pictures
262 """
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000263 output_json_path = os.path.join(self._output_dir, 'actuals.json')
264 write_path_dir = self.create_empty_dir(
265 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000266 self._generate_skps()
commit-bot@chromium.orgabeb9582014-05-19 15:25:10 +0000267 if expectations_path == None:
268 expectations_path = self._create_expectations()
269 args = [
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000270 '-r', self._input_skp_dir,
271 '--readJsonSummaryPath', expectations_path,
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000272 '--writePath', write_path_dir,
commit-bot@chromium.orgabeb9582014-05-19 15:25:10 +0000273 '--writeJsonSummaryPath', output_json_path,
274 ]
275 if additional_args:
276 args.extend(additional_args)
277 self._run_render_pictures(args)
278 if expected_summary_dict == None:
279 expected_summary_dict = {
280 "header" : EXPECTED_HEADER_CONTENTS,
epogerb492c6f2014-08-14 07:32:49 -0700281 "descriptions" : None,
commit-bot@chromium.orgabeb9582014-05-19 15:25:10 +0000282 "actual-results" : {
283 "red.skp": {
284 "whole-image": RED_WHOLEIMAGE,
285 },
286 "green.skp": {
287 "whole-image": GREEN_WHOLEIMAGE,
288 }
289 }
290 }
291 self._assert_json_contents(output_json_path, expected_summary_dict)
292 self._assert_directory_contents(
293 write_path_dir, ['red_skp.png', 'green_skp.png'])
294
295 def test_untiled(self):
296 """Basic test without tiles."""
297 self._test_untiled()
298
299 def test_untiled_empty_expectations_file(self):
300 """Same as test_untiled, but with an empty expectations file."""
301 expectations_path = os.path.join(self._expectations_dir, 'empty')
epoger66ed8dc2014-07-17 12:54:16 -0700302 with open(expectations_path, 'w'):
commit-bot@chromium.orgabeb9582014-05-19 15:25:10 +0000303 pass
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000304 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000305 "header" : EXPECTED_HEADER_CONTENTS,
epogerb492c6f2014-08-14 07:32:49 -0700306 "descriptions" : None,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000307 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000308 "red.skp": {
commit-bot@chromium.orgabeb9582014-05-19 15:25:10 +0000309 "whole-image": modified_dict(
310 RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}),
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000311 },
312 "green.skp": {
commit-bot@chromium.orgabeb9582014-05-19 15:25:10 +0000313 "whole-image": modified_dict(
314 GREEN_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}),
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000315 }
316 }
317 }
commit-bot@chromium.orgabeb9582014-05-19 15:25:10 +0000318 self._test_untiled(expectations_path=expectations_path,
319 expected_summary_dict=expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000320
321 def test_untiled_writeChecksumBasedFilenames(self):
322 """Same as test_untiled, but with --writeChecksumBasedFilenames."""
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000323 output_json_path = os.path.join(self._output_dir, 'actuals.json')
324 write_path_dir = self.create_empty_dir(
325 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000326 self._generate_skps()
epogerb492c6f2014-08-14 07:32:49 -0700327 self._run_render_pictures([
328 '-r', self._input_skp_dir,
329 '--descriptions', 'builder=builderName', 'renderMode=renderModeName',
330 '--writeChecksumBasedFilenames',
331 '--writePath', write_path_dir,
332 '--writeJsonSummaryPath', output_json_path,
333 ])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000334 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000335 "header" : EXPECTED_HEADER_CONTENTS,
epogerb492c6f2014-08-14 07:32:49 -0700336 "descriptions" : {
337 "builder": "builderName",
338 "renderMode": "renderModeName",
339 },
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000340 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000341 "red.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000342 # Manually verified: 640x400 red rectangle with black border
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000343 "whole-image": {
344 "checksumAlgorithm" : "bitmap-64bitMD5",
345 "checksumValue" : 11092453015575919668,
346 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700347 "filepath" :
348 "red_skp/bitmap-64bitMD5_11092453015575919668.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000349 },
350 },
351 "green.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000352 # Manually verified: 640x400 green rectangle with black border
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000353 "whole-image": {
354 "checksumAlgorithm" : "bitmap-64bitMD5",
355 "checksumValue" : 8891695120562235492,
356 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700357 "filepath" :
358 "green_skp/bitmap-64bitMD5_8891695120562235492.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000359 },
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000360 }
361 }
362 }
363 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000364 self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000365 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000366 os.path.join(write_path_dir, 'red_skp'),
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000367 ['bitmap-64bitMD5_11092453015575919668.png'])
368 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000369 os.path.join(write_path_dir, 'green_skp'),
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000370 ['bitmap-64bitMD5_8891695120562235492.png'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000371
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000372 def test_untiled_validate(self):
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000373 """Same as test_untiled, but with --validate."""
commit-bot@chromium.orgabeb9582014-05-19 15:25:10 +0000374 self._test_untiled(additional_args=['--validate'])
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000375
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000376 def test_untiled_without_writePath(self):
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000377 """Same as test_untiled, but without --writePath."""
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000378 output_json_path = os.path.join(self._output_dir, 'actuals.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000379 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000380 expectations_path = self._create_expectations()
381 self._run_render_pictures([
382 '-r', self._input_skp_dir,
383 '--readJsonSummaryPath', expectations_path,
384 '--writeJsonSummaryPath', output_json_path])
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000385 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000386 "header" : EXPECTED_HEADER_CONTENTS,
epogerb492c6f2014-08-14 07:32:49 -0700387 "descriptions" : None,
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000388 "actual-results" : {
389 "red.skp": {
390 "whole-image": RED_WHOLEIMAGE,
391 },
392 "green.skp": {
393 "whole-image": GREEN_WHOLEIMAGE,
394 }
395 }
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000396 }
397 self._assert_json_contents(output_json_path, expected_summary_dict)
398
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000399 def test_tiled(self):
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000400 """Generate individual tiles."""
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000401 output_json_path = os.path.join(self._output_dir, 'actuals.json')
402 write_path_dir = self.create_empty_dir(
403 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000404 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000405 expectations_path = self._create_expectations()
406 self._run_render_pictures([
407 '-r', self._input_skp_dir,
408 '--bbh', 'grid', '256', '256',
409 '--mode', 'tile', '256', '256',
410 '--readJsonSummaryPath', expectations_path,
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000411 '--writePath', write_path_dir,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000412 '--writeJsonSummaryPath', output_json_path])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000413 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000414 "header" : EXPECTED_HEADER_CONTENTS,
epogerb492c6f2014-08-14 07:32:49 -0700415 "descriptions" : None,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000416 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000417 "red.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000418 "tiled-images": RED_TILES,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000419 },
420 "green.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000421 "tiled-images": GREEN_TILES,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000422 }
423 }
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000424 }
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000425 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000426 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000427 write_path_dir,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000428 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png',
429 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png',
430 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png',
431 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png',
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000432 ])
433
434 def test_tiled_mismatches(self):
435 """Same as test_tiled, but only write out mismatching images."""
436 output_json_path = os.path.join(self._output_dir, 'actuals.json')
437 mismatch_path_dir = self.create_empty_dir(
438 path=os.path.join(self._output_dir, 'mismatchPath'))
439 self._generate_skps()
440 expectations_path = self._create_expectations()
441 self._run_render_pictures([
442 '-r', self._input_skp_dir,
443 '--bbh', 'grid', '256', '256',
444 '--mode', 'tile', '256', '256',
445 '--readJsonSummaryPath', expectations_path,
446 '--mismatchPath', mismatch_path_dir,
447 '--writeJsonSummaryPath', output_json_path])
448 expected_summary_dict = {
449 "header" : EXPECTED_HEADER_CONTENTS,
epogerb492c6f2014-08-14 07:32:49 -0700450 "descriptions" : None,
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000451 "actual-results" : {
452 "red.skp": {
453 "tiled-images": RED_TILES,
454 },
455 "green.skp": {
456 "tiled-images": GREEN_TILES,
457 }
458 }
459 }
460 self._assert_json_contents(output_json_path, expected_summary_dict)
461 self._assert_directory_contents(
462 mismatch_path_dir,
463 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png',
464 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png',
465 ])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000466
467 def test_tiled_writeChecksumBasedFilenames(self):
468 """Same as test_tiled, but with --writeChecksumBasedFilenames."""
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000469 output_json_path = os.path.join(self._output_dir, 'actuals.json')
470 write_path_dir = self.create_empty_dir(
471 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000472 self._generate_skps()
473 self._run_render_pictures(['-r', self._input_skp_dir,
474 '--bbh', 'grid', '256', '256',
475 '--mode', 'tile', '256', '256',
476 '--writeChecksumBasedFilenames',
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000477 '--writePath', write_path_dir,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000478 '--writeJsonSummaryPath', output_json_path])
479 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000480 "header" : EXPECTED_HEADER_CONTENTS,
epogerb492c6f2014-08-14 07:32:49 -0700481 "descriptions" : None,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000482 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000483 "red.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000484 # Manually verified these 6 images, all 256x256 tiles,
485 # consistent with a tiled version of the 640x400 red rect
486 # with black borders.
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000487 "tiled-images": [{
488 "checksumAlgorithm" : "bitmap-64bitMD5",
489 "checksumValue" : 5815827069051002745,
490 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700491 "filepath" :
492 "red_skp/bitmap-64bitMD5_5815827069051002745.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000493 }, {
494 "checksumAlgorithm" : "bitmap-64bitMD5",
495 "checksumValue" : 9323613075234140270,
496 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700497 "filepath" :
498 "red_skp/bitmap-64bitMD5_9323613075234140270.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000499 }, {
500 "checksumAlgorithm" : "bitmap-64bitMD5",
501 "checksumValue" : 16670399404877552232,
502 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700503 "filepath" :
504 "red_skp/bitmap-64bitMD5_16670399404877552232.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000505 }, {
506 "checksumAlgorithm" : "bitmap-64bitMD5",
507 "checksumValue" : 2507897274083364964,
508 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700509 "filepath" :
510 "red_skp/bitmap-64bitMD5_2507897274083364964.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000511 }, {
512 "checksumAlgorithm" : "bitmap-64bitMD5",
513 "checksumValue" : 7325267995523877959,
514 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700515 "filepath" :
516 "red_skp/bitmap-64bitMD5_7325267995523877959.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000517 }, {
518 "checksumAlgorithm" : "bitmap-64bitMD5",
519 "checksumValue" : 2181381724594493116,
520 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700521 "filepath" :
522 "red_skp/bitmap-64bitMD5_2181381724594493116.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000523 }],
524 },
525 "green.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000526 # Manually verified these 6 images, all 256x256 tiles,
527 # consistent with a tiled version of the 640x400 green rect
528 # with black borders.
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000529 "tiled-images": [{
530 "checksumAlgorithm" : "bitmap-64bitMD5",
531 "checksumValue" : 12587324416545178013,
532 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700533 "filepath" :
534 "green_skp/bitmap-64bitMD5_12587324416545178013.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000535 }, {
536 "checksumAlgorithm" : "bitmap-64bitMD5",
537 "checksumValue" : 7624374914829746293,
538 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700539 "filepath" :
540 "green_skp/bitmap-64bitMD5_7624374914829746293.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000541 }, {
542 "checksumAlgorithm" : "bitmap-64bitMD5",
543 "checksumValue" : 5686489729535631913,
544 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700545 "filepath" :
546 "green_skp/bitmap-64bitMD5_5686489729535631913.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000547 }, {
548 "checksumAlgorithm" : "bitmap-64bitMD5",
549 "checksumValue" : 7980646035555096146,
550 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700551 "filepath" :
552 "green_skp/bitmap-64bitMD5_7980646035555096146.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000553 }, {
554 "checksumAlgorithm" : "bitmap-64bitMD5",
555 "checksumValue" : 17817086664365875131,
556 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700557 "filepath" :
558 "green_skp/bitmap-64bitMD5_17817086664365875131.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000559 }, {
560 "checksumAlgorithm" : "bitmap-64bitMD5",
561 "checksumValue" : 10673669813016809363,
562 "comparisonResult" : "no-comparison",
epoger66ed8dc2014-07-17 12:54:16 -0700563 "filepath" :
564 "green_skp/bitmap-64bitMD5_10673669813016809363.png",
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000565 }],
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000566 }
567 }
568 }
569 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000570 self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000571 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000572 os.path.join(write_path_dir, 'red_skp'),
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000573 ['bitmap-64bitMD5_5815827069051002745.png',
574 'bitmap-64bitMD5_9323613075234140270.png',
575 'bitmap-64bitMD5_16670399404877552232.png',
576 'bitmap-64bitMD5_2507897274083364964.png',
577 'bitmap-64bitMD5_7325267995523877959.png',
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000578 'bitmap-64bitMD5_2181381724594493116.png'])
579 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000580 os.path.join(write_path_dir, 'green_skp'),
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000581 ['bitmap-64bitMD5_12587324416545178013.png',
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000582 'bitmap-64bitMD5_7624374914829746293.png',
583 'bitmap-64bitMD5_5686489729535631913.png',
584 'bitmap-64bitMD5_7980646035555096146.png',
585 'bitmap-64bitMD5_17817086664365875131.png',
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000586 'bitmap-64bitMD5_10673669813016809363.png'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000587
588 def _run_render_pictures(self, args):
epoger66ed8dc2014-07-17 12:54:16 -0700589 binary = find_run_binary.find_path_to_program('render_pictures')
590 return find_run_binary.run_command(
591 [binary, '--config', '8888'] + args)
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000592
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000593 def _create_expectations(self, missing_some_images=False,
594 rel_path='expectations.json'):
595 """Creates expectations JSON file within self._expectations_dir .
596
597 Args:
598 missing_some_images: (bool) whether to remove expectations for a subset
599 of the images
600 rel_path: (string) relative path within self._expectations_dir to write
601 the expectations into
602
603 Returns: full path to the expectations file created.
604 """
605 expectations_dict = {
606 "header" : EXPECTED_HEADER_CONTENTS,
epogerb492c6f2014-08-14 07:32:49 -0700607 "descriptions" : None,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000608 "expected-results" : {
609 # red.skp: these should fail the comparison
610 "red.skp": {
611 "tiled-images": modified_list_of_dicts(
612 RED_TILES, {'checksumValue': 11111}),
613 "whole-image": modified_dict(
614 RED_WHOLEIMAGE, {'checksumValue': 22222}),
615 },
616 # green.skp: these should pass the comparison
617 "green.skp": {
618 "tiled-images": GREEN_TILES,
619 "whole-image": GREEN_WHOLEIMAGE,
620 }
621 }
622 }
623 if missing_some_images:
624 del expectations_dict['expected-results']['red.skp']['whole-image']
625 del expectations_dict['expected-results']['red.skp']['tiled-images'][-1]
626 path = os.path.join(self._expectations_dir, rel_path)
627 with open(path, 'w') as fh:
628 json.dump(expectations_dict, fh)
629 return path
630
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000631 def _generate_skps(self):
632 """Runs the skpmaker binary to generate files in self._input_skp_dir."""
633 self._run_skpmaker(
634 output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255)
635 self._run_skpmaker(
636 output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255)
637
638 def _run_skpmaker(self, output_path, red=0, green=0, blue=0,
639 width=640, height=400):
640 """Runs the skpmaker binary to generate SKP with known characteristics.
641
642 Args:
643 output_path: Filepath to write the SKP into.
644 red: Value of red color channel in image, 0-255.
645 green: Value of green color channel in image, 0-255.
646 blue: Value of blue color channel in image, 0-255.
647 width: Width of canvas to create.
648 height: Height of canvas to create.
649 """
epoger66ed8dc2014-07-17 12:54:16 -0700650 binary = find_run_binary.find_path_to_program('skpmaker')
651 return find_run_binary.run_command([
652 binary,
653 '--red', str(red),
654 '--green', str(green),
655 '--blue', str(blue),
656 '--width', str(width),
657 '--height', str(height),
658 '--writePath', str(output_path),
659 ])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000660
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000661 def _assert_directory_contents(self, dir_path, expected_filenames):
662 """Asserts that files found in a dir are identical to expected_filenames.
663
664 Args:
665 dir_path: Path to a directory on local disk.
666 expected_filenames: Set containing the expected filenames within the dir.
667
668 Raises:
669 AssertionError: contents of the directory are not identical to
670 expected_filenames.
671 """
672 self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames))
673
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000674 def _assert_json_contents(self, json_path, expected_dict):
675 """Asserts that contents of a JSON file are identical to expected_dict.
676
677 Args:
678 json_path: Path to a JSON file.
679 expected_dict: Dictionary indicating the expected contents of the JSON
680 file.
681
682 Raises:
683 AssertionError: contents of the JSON file are not identical to
684 expected_dict.
685 """
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000686 prettyprinted_expected_dict = json.dumps(expected_dict, sort_keys=True,
687 indent=2)
688 with open(json_path, 'r') as fh:
689 prettyprinted_json_dict = json.dumps(json.load(fh), sort_keys=True,
690 indent=2)
691 self.assertMultiLineEqual(prettyprinted_expected_dict,
692 prettyprinted_json_dict)
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000693
694
695def main():
696 base_unittest.main(RenderPicturesTest)
697
698
699if __name__ == '__main__':
700 main()