blob: 4b11e56ae924a8b1307419c1e3c6b95600ef0af3 [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
19# Imports from within Skia
20import base_unittest
21
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +000022# Maximum length of text diffs to show when tests fail
23MAX_DIFF_LENGTH = 30000
24
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000025EXPECTED_HEADER_CONTENTS = {
26 "type" : "ChecksummedImages",
27 "revision" : 1,
28}
29
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000030# Manually verified: 640x400 red rectangle with black border
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000031# Standard expectations will be set up in such a way that this image fails
32# the comparison.
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000033RED_WHOLEIMAGE = {
34 "checksumAlgorithm" : "bitmap-64bitMD5",
35 "checksumValue" : 11092453015575919668,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000036 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000037 "filepath" : "red_skp.png",
38}
39
40# Manually verified: 640x400 green rectangle with black border
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000041# Standard expectations will be set up in such a way that this image passes
42# the comparison.
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000043GREEN_WHOLEIMAGE = {
44 "checksumAlgorithm" : "bitmap-64bitMD5",
45 "checksumValue" : 8891695120562235492,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000046 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000047 "filepath" : "green_skp.png",
48}
49
50# Manually verified these 6 images, all 256x256 tiles,
51# consistent with a tiled version of the 640x400 red rect
52# with black borders.
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000053# Standard expectations will be set up in such a way that these images fail
54# the comparison.
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000055RED_TILES = [{
56 "checksumAlgorithm" : "bitmap-64bitMD5",
57 "checksumValue" : 5815827069051002745,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000058 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000059 "filepath" : "red_skp-tile0.png",
60},{
61 "checksumAlgorithm" : "bitmap-64bitMD5",
62 "checksumValue" : 9323613075234140270,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000063 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000064 "filepath" : "red_skp-tile1.png",
65}, {
66 "checksumAlgorithm" : "bitmap-64bitMD5",
67 "checksumValue" : 16670399404877552232,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000068 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000069 "filepath" : "red_skp-tile2.png",
70}, {
71 "checksumAlgorithm" : "bitmap-64bitMD5",
72 "checksumValue" : 2507897274083364964,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000073 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000074 "filepath" : "red_skp-tile3.png",
75}, {
76 "checksumAlgorithm" : "bitmap-64bitMD5",
77 "checksumValue" : 7325267995523877959,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000078 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000079 "filepath" : "red_skp-tile4.png",
80}, {
81 "checksumAlgorithm" : "bitmap-64bitMD5",
82 "checksumValue" : 2181381724594493116,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000083 "comparisonResult" : "failed",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000084 "filepath" : "red_skp-tile5.png",
85}]
86
87# Manually verified these 6 images, all 256x256 tiles,
88# consistent with a tiled version of the 640x400 green rect
89# with black borders.
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000090# Standard expectations will be set up in such a way that these images pass
91# the comparison.
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000092GREEN_TILES = [{
93 "checksumAlgorithm" : "bitmap-64bitMD5",
94 "checksumValue" : 12587324416545178013,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +000095 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +000096 "filepath" : "green_skp-tile0.png",
97}, {
98 "checksumAlgorithm" : "bitmap-64bitMD5",
99 "checksumValue" : 7624374914829746293,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000100 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000101 "filepath" : "green_skp-tile1.png",
102}, {
103 "checksumAlgorithm" : "bitmap-64bitMD5",
104 "checksumValue" : 5686489729535631913,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000105 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000106 "filepath" : "green_skp-tile2.png",
107}, {
108 "checksumAlgorithm" : "bitmap-64bitMD5",
109 "checksumValue" : 7980646035555096146,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000110 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000111 "filepath" : "green_skp-tile3.png",
112}, {
113 "checksumAlgorithm" : "bitmap-64bitMD5",
114 "checksumValue" : 17817086664365875131,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000115 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000116 "filepath" : "green_skp-tile4.png",
117}, {
118 "checksumAlgorithm" : "bitmap-64bitMD5",
119 "checksumValue" : 10673669813016809363,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000120 "comparisonResult" : "succeeded",
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000121 "filepath" : "green_skp-tile5.png",
122}]
123
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000124
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000125def modified_dict(input_dict, modification_dict):
126 """Returns a dict, with some modifications applied to it.
127
128 Args:
129 input_dict: a dictionary (which will be copied, not modified in place)
130 modification_dict: a set of key/value pairs to overwrite in the dict
131 """
132 output_dict = input_dict.copy()
133 output_dict.update(modification_dict)
134 return output_dict
135
136
137def modified_list_of_dicts(input_list, modification_dict):
138 """Returns a list of dicts, with some modifications applied to each dict.
139
140 Args:
141 input_list: a list of dictionaries; these dicts will be copied, not
142 modified in place
143 modification_dict: a set of key/value pairs to overwrite in each dict
144 within input_list
145 """
146 output_list = []
147 for input_dict in input_list:
148 output_dict = modified_dict(input_dict, modification_dict)
149 output_list.append(output_dict)
150 return output_list
151
152
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000153class RenderPicturesTest(base_unittest.TestCase):
154
155 def setUp(self):
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000156 self.maxDiff = MAX_DIFF_LENGTH
157 self._expectations_dir = tempfile.mkdtemp()
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000158 self._input_skp_dir = tempfile.mkdtemp()
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000159 self._temp_dir = tempfile.mkdtemp()
160
161 def tearDown(self):
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000162 shutil.rmtree(self._expectations_dir)
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000163 shutil.rmtree(self._input_skp_dir)
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000164 shutil.rmtree(self._temp_dir)
165
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000166 def test_tiled_whole_image(self):
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000167 """Run render_pictures with tiles and --writeWholeImage flag.
168
169 TODO(epoger): This test generates undesired results! The JSON summary
170 includes both whole-image and tiled-images (as it should), but only
171 whole-images are written out to disk. See http://skbug.com/2463
172
173 TODO(epoger): I noticed that when this is run without --writePath being
174 specified, this test writes red_skp.png and green_skp.png to the current
175 directory. We should fix that... if --writePath is not specified, this
176 probably shouldn't write out red_skp.png and green_skp.png at all!
177 See http://skbug.com/2464
178 """
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000179 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000180 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000181 expectations_path = self._create_expectations()
182 self._run_render_pictures([
183 '-r', self._input_skp_dir,
184 '--bbh', 'grid', '256', '256',
185 '--mode', 'tile', '256', '256',
186 '--readJsonSummaryPath', expectations_path,
187 '--writeJsonSummaryPath', output_json_path,
188 '--writePath', self._temp_dir,
189 '--writeWholeImage'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000190 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000191 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000192 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000193 "red.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000194 "tiled-images": RED_TILES,
195 "whole-image": RED_WHOLEIMAGE,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000196 },
197 "green.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000198 "tiled-images": GREEN_TILES,
199 "whole-image": GREEN_WHOLEIMAGE,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000200 }
201 }
commit-bot@chromium.org238771c2014-01-15 16:33:31 +0000202 }
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000203 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000204 self._assert_directory_contents(
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000205 self._temp_dir, ['red_skp.png', 'green_skp.png', 'actuals.json'])
206
207 def test_missing_tile_and_whole_image(self):
208 """test_tiled_whole_image, but missing expectations for some images.
209 """
210 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
211 self._generate_skps()
212 expectations_path = self._create_expectations(missing_some_images=True)
213 self._run_render_pictures([
214 '-r', self._input_skp_dir,
215 '--bbh', 'grid', '256', '256',
216 '--mode', 'tile', '256', '256',
217 '--readJsonSummaryPath', expectations_path,
218 '--writeJsonSummaryPath', output_json_path,
219 '--writePath', self._temp_dir,
220 '--writeWholeImage'])
221 modified_red_tiles = copy.deepcopy(RED_TILES)
222 modified_red_tiles[5]['comparisonResult'] = 'no-comparison'
223 expected_summary_dict = {
224 "header" : EXPECTED_HEADER_CONTENTS,
225 "actual-results" : {
226 "red.skp": {
227 "tiled-images": modified_red_tiles,
228 "whole-image": modified_dict(
229 RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}),
230 },
231 "green.skp": {
232 "tiled-images": GREEN_TILES,
233 "whole-image": GREEN_WHOLEIMAGE,
234 }
235 }
236 }
237 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000238
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000239 def test_untiled(self):
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000240 """Run without tiles."""
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000241 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000242 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000243 expectations_path = self._create_expectations()
244 self._run_render_pictures([
245 '-r', self._input_skp_dir,
246 '--readJsonSummaryPath', expectations_path,
247 '--writePath', self._temp_dir,
248 '--writeJsonSummaryPath', output_json_path])
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000249 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000250 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000251 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000252 "red.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000253 "whole-image": RED_WHOLEIMAGE,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000254 },
255 "green.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000256 "whole-image": GREEN_WHOLEIMAGE,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000257 }
258 }
259 }
260 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000261 self._assert_directory_contents(
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000262 self._temp_dir, ['red_skp.png', 'green_skp.png', 'actuals.json'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000263
264 def test_untiled_writeChecksumBasedFilenames(self):
265 """Same as test_untiled, but with --writeChecksumBasedFilenames."""
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000266 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000267 self._generate_skps()
268 self._run_render_pictures(['-r', self._input_skp_dir,
269 '--writeChecksumBasedFilenames',
270 '--writePath', self._temp_dir,
271 '--writeJsonSummaryPath', output_json_path])
272 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000273 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000274 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000275 "red.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000276 # Manually verified: 640x400 red rectangle with black border
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000277 "whole-image": {
278 "checksumAlgorithm" : "bitmap-64bitMD5",
279 "checksumValue" : 11092453015575919668,
280 "comparisonResult" : "no-comparison",
281 "filepath" : "red_skp/bitmap-64bitMD5_11092453015575919668.png",
282 },
283 },
284 "green.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000285 # Manually verified: 640x400 green rectangle with black border
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000286 "whole-image": {
287 "checksumAlgorithm" : "bitmap-64bitMD5",
288 "checksumValue" : 8891695120562235492,
289 "comparisonResult" : "no-comparison",
290 "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492.png",
291 },
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000292 }
293 }
294 }
295 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000296 self._assert_directory_contents(self._temp_dir, [
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000297 'red_skp', 'green_skp', 'actuals.json'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000298 self._assert_directory_contents(
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000299 os.path.join(self._temp_dir, 'red_skp'),
300 ['bitmap-64bitMD5_11092453015575919668.png'])
301 self._assert_directory_contents(
302 os.path.join(self._temp_dir, 'green_skp'),
303 ['bitmap-64bitMD5_8891695120562235492.png'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000304
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000305 def test_untiled_validate(self):
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000306 """Same as test_untiled, but with --validate."""
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000307 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000308 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000309 expectations_path = self._create_expectations()
310 self._run_render_pictures([
311 '-r', self._input_skp_dir,
312 '--readJsonSummaryPath', expectations_path,
313 '--validate',
314 '--writePath', self._temp_dir,
315 '--writeJsonSummaryPath', output_json_path])
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000316 expected_summary_dict = {
317 "header" : EXPECTED_HEADER_CONTENTS,
318 "actual-results" : {
319 "red.skp": {
320 "whole-image": RED_WHOLEIMAGE,
321 },
322 "green.skp": {
323 "whole-image": GREEN_WHOLEIMAGE,
324 }
325 }
326 }
327 self._assert_json_contents(output_json_path, expected_summary_dict)
328 self._assert_directory_contents(
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000329 self._temp_dir, ['red_skp.png', 'green_skp.png', 'actuals.json'])
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000330
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000331 def test_untiled_without_writePath(self):
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000332 """Same as test_untiled, but without --writePath."""
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000333 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000334 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000335 expectations_path = self._create_expectations()
336 self._run_render_pictures([
337 '-r', self._input_skp_dir,
338 '--readJsonSummaryPath', expectations_path,
339 '--writeJsonSummaryPath', output_json_path])
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000340 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000341 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000342 "actual-results" : {
343 "red.skp": {
344 "whole-image": RED_WHOLEIMAGE,
345 },
346 "green.skp": {
347 "whole-image": GREEN_WHOLEIMAGE,
348 }
349 }
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000350 }
351 self._assert_json_contents(output_json_path, expected_summary_dict)
352
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000353 def test_tiled(self):
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000354 """Generate individual tiles."""
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000355 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000356 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000357 expectations_path = self._create_expectations()
358 self._run_render_pictures([
359 '-r', self._input_skp_dir,
360 '--bbh', 'grid', '256', '256',
361 '--mode', 'tile', '256', '256',
362 '--readJsonSummaryPath', expectations_path,
363 '--writePath', self._temp_dir,
364 '--writeJsonSummaryPath', output_json_path])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000365 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000366 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000367 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000368 "red.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000369 "tiled-images": RED_TILES,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000370 },
371 "green.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000372 "tiled-images": GREEN_TILES,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000373 }
374 }
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000375 }
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000376 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000377 self._assert_directory_contents(
378 self._temp_dir,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000379 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png',
380 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png',
381 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png',
382 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png',
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000383 'actuals.json'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000384
385 def test_tiled_writeChecksumBasedFilenames(self):
386 """Same as test_tiled, but with --writeChecksumBasedFilenames."""
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000387 output_json_path = os.path.join(self._temp_dir, 'actuals.json')
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000388 self._generate_skps()
389 self._run_render_pictures(['-r', self._input_skp_dir,
390 '--bbh', 'grid', '256', '256',
391 '--mode', 'tile', '256', '256',
392 '--writeChecksumBasedFilenames',
393 '--writePath', self._temp_dir,
394 '--writeJsonSummaryPath', output_json_path])
395 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000396 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000397 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000398 "red.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000399 # Manually verified these 6 images, all 256x256 tiles,
400 # consistent with a tiled version of the 640x400 red rect
401 # with black borders.
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000402 "tiled-images": [{
403 "checksumAlgorithm" : "bitmap-64bitMD5",
404 "checksumValue" : 5815827069051002745,
405 "comparisonResult" : "no-comparison",
406 "filepath" : "red_skp/bitmap-64bitMD5_5815827069051002745.png",
407 }, {
408 "checksumAlgorithm" : "bitmap-64bitMD5",
409 "checksumValue" : 9323613075234140270,
410 "comparisonResult" : "no-comparison",
411 "filepath" : "red_skp/bitmap-64bitMD5_9323613075234140270.png",
412 }, {
413 "checksumAlgorithm" : "bitmap-64bitMD5",
414 "checksumValue" : 16670399404877552232,
415 "comparisonResult" : "no-comparison",
416 "filepath" : "red_skp/bitmap-64bitMD5_16670399404877552232.png",
417 }, {
418 "checksumAlgorithm" : "bitmap-64bitMD5",
419 "checksumValue" : 2507897274083364964,
420 "comparisonResult" : "no-comparison",
421 "filepath" : "red_skp/bitmap-64bitMD5_2507897274083364964.png",
422 }, {
423 "checksumAlgorithm" : "bitmap-64bitMD5",
424 "checksumValue" : 7325267995523877959,
425 "comparisonResult" : "no-comparison",
426 "filepath" : "red_skp/bitmap-64bitMD5_7325267995523877959.png",
427 }, {
428 "checksumAlgorithm" : "bitmap-64bitMD5",
429 "checksumValue" : 2181381724594493116,
430 "comparisonResult" : "no-comparison",
431 "filepath" : "red_skp/bitmap-64bitMD5_2181381724594493116.png",
432 }],
433 },
434 "green.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000435 # Manually verified these 6 images, all 256x256 tiles,
436 # consistent with a tiled version of the 640x400 green rect
437 # with black borders.
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000438 "tiled-images": [{
439 "checksumAlgorithm" : "bitmap-64bitMD5",
440 "checksumValue" : 12587324416545178013,
441 "comparisonResult" : "no-comparison",
442 "filepath" : "green_skp/bitmap-64bitMD5_12587324416545178013.png",
443 }, {
444 "checksumAlgorithm" : "bitmap-64bitMD5",
445 "checksumValue" : 7624374914829746293,
446 "comparisonResult" : "no-comparison",
447 "filepath" : "green_skp/bitmap-64bitMD5_7624374914829746293.png",
448 }, {
449 "checksumAlgorithm" : "bitmap-64bitMD5",
450 "checksumValue" : 5686489729535631913,
451 "comparisonResult" : "no-comparison",
452 "filepath" : "green_skp/bitmap-64bitMD5_5686489729535631913.png",
453 }, {
454 "checksumAlgorithm" : "bitmap-64bitMD5",
455 "checksumValue" : 7980646035555096146,
456 "comparisonResult" : "no-comparison",
457 "filepath" : "green_skp/bitmap-64bitMD5_7980646035555096146.png",
458 }, {
459 "checksumAlgorithm" : "bitmap-64bitMD5",
460 "checksumValue" : 17817086664365875131,
461 "comparisonResult" : "no-comparison",
462 "filepath" : "green_skp/bitmap-64bitMD5_17817086664365875131.png",
463 }, {
464 "checksumAlgorithm" : "bitmap-64bitMD5",
465 "checksumValue" : 10673669813016809363,
466 "comparisonResult" : "no-comparison",
467 "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363.png",
468 }],
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000469 }
470 }
471 }
472 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000473 self._assert_directory_contents(self._temp_dir, [
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000474 'red_skp', 'green_skp', 'actuals.json'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000475 self._assert_directory_contents(
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000476 os.path.join(self._temp_dir, 'red_skp'),
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000477 ['bitmap-64bitMD5_5815827069051002745.png',
478 'bitmap-64bitMD5_9323613075234140270.png',
479 'bitmap-64bitMD5_16670399404877552232.png',
480 'bitmap-64bitMD5_2507897274083364964.png',
481 'bitmap-64bitMD5_7325267995523877959.png',
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000482 'bitmap-64bitMD5_2181381724594493116.png'])
483 self._assert_directory_contents(
484 os.path.join(self._temp_dir, 'green_skp'),
485 ['bitmap-64bitMD5_12587324416545178013.png',
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000486 'bitmap-64bitMD5_7624374914829746293.png',
487 'bitmap-64bitMD5_5686489729535631913.png',
488 'bitmap-64bitMD5_7980646035555096146.png',
489 'bitmap-64bitMD5_17817086664365875131.png',
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000490 'bitmap-64bitMD5_10673669813016809363.png'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000491
492 def _run_render_pictures(self, args):
493 binary = self.find_path_to_program('render_pictures')
494 return self.run_command([binary,
495 '--clone', '1',
496 '--config', '8888',
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000497 ] + args)
498
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000499 def _create_expectations(self, missing_some_images=False,
500 rel_path='expectations.json'):
501 """Creates expectations JSON file within self._expectations_dir .
502
503 Args:
504 missing_some_images: (bool) whether to remove expectations for a subset
505 of the images
506 rel_path: (string) relative path within self._expectations_dir to write
507 the expectations into
508
509 Returns: full path to the expectations file created.
510 """
511 expectations_dict = {
512 "header" : EXPECTED_HEADER_CONTENTS,
513 "expected-results" : {
514 # red.skp: these should fail the comparison
515 "red.skp": {
516 "tiled-images": modified_list_of_dicts(
517 RED_TILES, {'checksumValue': 11111}),
518 "whole-image": modified_dict(
519 RED_WHOLEIMAGE, {'checksumValue': 22222}),
520 },
521 # green.skp: these should pass the comparison
522 "green.skp": {
523 "tiled-images": GREEN_TILES,
524 "whole-image": GREEN_WHOLEIMAGE,
525 }
526 }
527 }
528 if missing_some_images:
529 del expectations_dict['expected-results']['red.skp']['whole-image']
530 del expectations_dict['expected-results']['red.skp']['tiled-images'][-1]
531 path = os.path.join(self._expectations_dir, rel_path)
532 with open(path, 'w') as fh:
533 json.dump(expectations_dict, fh)
534 return path
535
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000536 def _generate_skps(self):
537 """Runs the skpmaker binary to generate files in self._input_skp_dir."""
538 self._run_skpmaker(
539 output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255)
540 self._run_skpmaker(
541 output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255)
542
543 def _run_skpmaker(self, output_path, red=0, green=0, blue=0,
544 width=640, height=400):
545 """Runs the skpmaker binary to generate SKP with known characteristics.
546
547 Args:
548 output_path: Filepath to write the SKP into.
549 red: Value of red color channel in image, 0-255.
550 green: Value of green color channel in image, 0-255.
551 blue: Value of blue color channel in image, 0-255.
552 width: Width of canvas to create.
553 height: Height of canvas to create.
554 """
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000555 binary = self.find_path_to_program('skpmaker')
556 return self.run_command([binary,
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000557 '--red', str(red),
558 '--green', str(green),
559 '--blue', str(blue),
560 '--width', str(width),
561 '--height', str(height),
562 '--writePath', str(output_path),
563 ])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000564
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000565 def _assert_directory_contents(self, dir_path, expected_filenames):
566 """Asserts that files found in a dir are identical to expected_filenames.
567
568 Args:
569 dir_path: Path to a directory on local disk.
570 expected_filenames: Set containing the expected filenames within the dir.
571
572 Raises:
573 AssertionError: contents of the directory are not identical to
574 expected_filenames.
575 """
576 self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames))
577
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000578 def _assert_json_contents(self, json_path, expected_dict):
579 """Asserts that contents of a JSON file are identical to expected_dict.
580
581 Args:
582 json_path: Path to a JSON file.
583 expected_dict: Dictionary indicating the expected contents of the JSON
584 file.
585
586 Raises:
587 AssertionError: contents of the JSON file are not identical to
588 expected_dict.
589 """
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000590 prettyprinted_expected_dict = json.dumps(expected_dict, sort_keys=True,
591 indent=2)
592 with open(json_path, 'r') as fh:
593 prettyprinted_json_dict = json.dumps(json.load(fh), sort_keys=True,
594 indent=2)
595 self.assertMultiLineEqual(prettyprinted_expected_dict,
596 prettyprinted_json_dict)
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000597
598
599def main():
600 base_unittest.main(RenderPicturesTest)
601
602
603if __name__ == '__main__':
604 main()