blob: 5ab9d673bb605477c2bd2f4e1859f254328553f0 [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.org3f045172014-05-15 15:10:48 +0000159 # All output of render_pictures binary will go into this directory.
160 self._output_dir = tempfile.mkdtemp()
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000161
162 def tearDown(self):
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000163 shutil.rmtree(self._expectations_dir)
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000164 shutil.rmtree(self._input_skp_dir)
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000165 shutil.rmtree(self._output_dir)
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000166
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000167 def test_tiled_whole_image(self):
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000168 """Run render_pictures with tiles and --writeWholeImage flag.
169
170 TODO(epoger): This test generates undesired results! The JSON summary
171 includes both whole-image and tiled-images (as it should), but only
172 whole-images are written out to disk. See http://skbug.com/2463
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000173 Once I fix that, I should add a similar test that exercises mismatchPath.
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000174
175 TODO(epoger): I noticed that when this is run without --writePath being
176 specified, this test writes red_skp.png and green_skp.png to the current
177 directory. We should fix that... if --writePath is not specified, this
178 probably shouldn't write out red_skp.png and green_skp.png at all!
179 See http://skbug.com/2464
180 """
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000181 output_json_path = os.path.join(self._output_dir, 'actuals.json')
182 write_path_dir = self.create_empty_dir(
183 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000184 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000185 expectations_path = self._create_expectations()
186 self._run_render_pictures([
187 '-r', self._input_skp_dir,
188 '--bbh', 'grid', '256', '256',
189 '--mode', 'tile', '256', '256',
190 '--readJsonSummaryPath', expectations_path,
191 '--writeJsonSummaryPath', output_json_path,
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000192 '--writePath', write_path_dir,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000193 '--writeWholeImage'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000194 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000195 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000196 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000197 "red.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000198 "tiled-images": RED_TILES,
199 "whole-image": RED_WHOLEIMAGE,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000200 },
201 "green.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000202 "tiled-images": GREEN_TILES,
203 "whole-image": GREEN_WHOLEIMAGE,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000204 }
205 }
commit-bot@chromium.org238771c2014-01-15 16:33:31 +0000206 }
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000207 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000208 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000209 write_path_dir, ['red_skp.png', 'green_skp.png'])
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000210
211 def test_missing_tile_and_whole_image(self):
212 """test_tiled_whole_image, but missing expectations for some images.
213 """
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000214 output_json_path = os.path.join(self._output_dir, 'actuals.json')
215 write_path_dir = self.create_empty_dir(
216 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000217 self._generate_skps()
218 expectations_path = self._create_expectations(missing_some_images=True)
219 self._run_render_pictures([
220 '-r', self._input_skp_dir,
221 '--bbh', 'grid', '256', '256',
222 '--mode', 'tile', '256', '256',
223 '--readJsonSummaryPath', expectations_path,
224 '--writeJsonSummaryPath', output_json_path,
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000225 '--writePath', write_path_dir,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000226 '--writeWholeImage'])
227 modified_red_tiles = copy.deepcopy(RED_TILES)
228 modified_red_tiles[5]['comparisonResult'] = 'no-comparison'
229 expected_summary_dict = {
230 "header" : EXPECTED_HEADER_CONTENTS,
231 "actual-results" : {
232 "red.skp": {
233 "tiled-images": modified_red_tiles,
234 "whole-image": modified_dict(
235 RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}),
236 },
237 "green.skp": {
238 "tiled-images": GREEN_TILES,
239 "whole-image": GREEN_WHOLEIMAGE,
240 }
241 }
242 }
243 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000244
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000245 def test_untiled(self):
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000246 """Run without tiles."""
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000247 output_json_path = os.path.join(self._output_dir, 'actuals.json')
248 write_path_dir = self.create_empty_dir(
249 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000250 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000251 expectations_path = self._create_expectations()
252 self._run_render_pictures([
253 '-r', self._input_skp_dir,
254 '--readJsonSummaryPath', expectations_path,
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000255 '--writePath', write_path_dir,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000256 '--writeJsonSummaryPath', output_json_path])
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000257 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000258 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000259 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000260 "red.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000261 "whole-image": RED_WHOLEIMAGE,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000262 },
263 "green.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000264 "whole-image": GREEN_WHOLEIMAGE,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000265 }
266 }
267 }
268 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000269 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000270 write_path_dir, ['red_skp.png', 'green_skp.png'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000271
272 def test_untiled_writeChecksumBasedFilenames(self):
273 """Same as test_untiled, but with --writeChecksumBasedFilenames."""
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000274 output_json_path = os.path.join(self._output_dir, 'actuals.json')
275 write_path_dir = self.create_empty_dir(
276 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000277 self._generate_skps()
278 self._run_render_pictures(['-r', self._input_skp_dir,
279 '--writeChecksumBasedFilenames',
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000280 '--writePath', write_path_dir,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000281 '--writeJsonSummaryPath', output_json_path])
282 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000283 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000284 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000285 "red.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000286 # Manually verified: 640x400 red rectangle with black border
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000287 "whole-image": {
288 "checksumAlgorithm" : "bitmap-64bitMD5",
289 "checksumValue" : 11092453015575919668,
290 "comparisonResult" : "no-comparison",
291 "filepath" : "red_skp/bitmap-64bitMD5_11092453015575919668.png",
292 },
293 },
294 "green.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000295 # Manually verified: 640x400 green rectangle with black border
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000296 "whole-image": {
297 "checksumAlgorithm" : "bitmap-64bitMD5",
298 "checksumValue" : 8891695120562235492,
299 "comparisonResult" : "no-comparison",
300 "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492.png",
301 },
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000302 }
303 }
304 }
305 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000306 self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000307 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000308 os.path.join(write_path_dir, 'red_skp'),
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000309 ['bitmap-64bitMD5_11092453015575919668.png'])
310 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000311 os.path.join(write_path_dir, 'green_skp'),
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000312 ['bitmap-64bitMD5_8891695120562235492.png'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000313
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000314 def test_untiled_validate(self):
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000315 """Same as test_untiled, but with --validate."""
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000316 output_json_path = os.path.join(self._output_dir, 'actuals.json')
317 write_path_dir = self.create_empty_dir(
318 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000319 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000320 expectations_path = self._create_expectations()
321 self._run_render_pictures([
322 '-r', self._input_skp_dir,
323 '--readJsonSummaryPath', expectations_path,
324 '--validate',
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000325 '--writePath', write_path_dir,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000326 '--writeJsonSummaryPath', output_json_path])
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000327 expected_summary_dict = {
328 "header" : EXPECTED_HEADER_CONTENTS,
329 "actual-results" : {
330 "red.skp": {
331 "whole-image": RED_WHOLEIMAGE,
332 },
333 "green.skp": {
334 "whole-image": GREEN_WHOLEIMAGE,
335 }
336 }
337 }
338 self._assert_json_contents(output_json_path, expected_summary_dict)
339 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000340 write_path_dir, ['red_skp.png', 'green_skp.png'])
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000341
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000342 def test_untiled_without_writePath(self):
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000343 """Same as test_untiled, but without --writePath."""
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000344 output_json_path = os.path.join(self._output_dir, 'actuals.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000345 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000346 expectations_path = self._create_expectations()
347 self._run_render_pictures([
348 '-r', self._input_skp_dir,
349 '--readJsonSummaryPath', expectations_path,
350 '--writeJsonSummaryPath', output_json_path])
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000351 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000352 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000353 "actual-results" : {
354 "red.skp": {
355 "whole-image": RED_WHOLEIMAGE,
356 },
357 "green.skp": {
358 "whole-image": GREEN_WHOLEIMAGE,
359 }
360 }
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000361 }
362 self._assert_json_contents(output_json_path, expected_summary_dict)
363
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000364 def test_tiled(self):
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000365 """Generate individual tiles."""
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000366 output_json_path = os.path.join(self._output_dir, 'actuals.json')
367 write_path_dir = self.create_empty_dir(
368 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000369 self._generate_skps()
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000370 expectations_path = self._create_expectations()
371 self._run_render_pictures([
372 '-r', self._input_skp_dir,
373 '--bbh', 'grid', '256', '256',
374 '--mode', 'tile', '256', '256',
375 '--readJsonSummaryPath', expectations_path,
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000376 '--writePath', write_path_dir,
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000377 '--writeJsonSummaryPath', output_json_path])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000378 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000379 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000380 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000381 "red.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000382 "tiled-images": RED_TILES,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000383 },
384 "green.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000385 "tiled-images": GREEN_TILES,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000386 }
387 }
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000388 }
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000389 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000390 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000391 write_path_dir,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000392 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png',
393 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png',
394 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png',
395 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png',
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000396 ])
397
398 def test_tiled_mismatches(self):
399 """Same as test_tiled, but only write out mismatching images."""
400 output_json_path = os.path.join(self._output_dir, 'actuals.json')
401 mismatch_path_dir = self.create_empty_dir(
402 path=os.path.join(self._output_dir, 'mismatchPath'))
403 self._generate_skps()
404 expectations_path = self._create_expectations()
405 self._run_render_pictures([
406 '-r', self._input_skp_dir,
407 '--bbh', 'grid', '256', '256',
408 '--mode', 'tile', '256', '256',
409 '--readJsonSummaryPath', expectations_path,
410 '--mismatchPath', mismatch_path_dir,
411 '--writeJsonSummaryPath', output_json_path])
412 expected_summary_dict = {
413 "header" : EXPECTED_HEADER_CONTENTS,
414 "actual-results" : {
415 "red.skp": {
416 "tiled-images": RED_TILES,
417 },
418 "green.skp": {
419 "tiled-images": GREEN_TILES,
420 }
421 }
422 }
423 self._assert_json_contents(output_json_path, expected_summary_dict)
424 self._assert_directory_contents(
425 mismatch_path_dir,
426 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png',
427 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png',
428 ])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000429
430 def test_tiled_writeChecksumBasedFilenames(self):
431 """Same as test_tiled, but with --writeChecksumBasedFilenames."""
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000432 output_json_path = os.path.join(self._output_dir, 'actuals.json')
433 write_path_dir = self.create_empty_dir(
434 path=os.path.join(self._output_dir, 'writePath'))
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000435 self._generate_skps()
436 self._run_render_pictures(['-r', self._input_skp_dir,
437 '--bbh', 'grid', '256', '256',
438 '--mode', 'tile', '256', '256',
439 '--writeChecksumBasedFilenames',
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000440 '--writePath', write_path_dir,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000441 '--writeJsonSummaryPath', output_json_path])
442 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000443 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000444 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000445 "red.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000446 # Manually verified these 6 images, all 256x256 tiles,
447 # consistent with a tiled version of the 640x400 red rect
448 # with black borders.
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000449 "tiled-images": [{
450 "checksumAlgorithm" : "bitmap-64bitMD5",
451 "checksumValue" : 5815827069051002745,
452 "comparisonResult" : "no-comparison",
453 "filepath" : "red_skp/bitmap-64bitMD5_5815827069051002745.png",
454 }, {
455 "checksumAlgorithm" : "bitmap-64bitMD5",
456 "checksumValue" : 9323613075234140270,
457 "comparisonResult" : "no-comparison",
458 "filepath" : "red_skp/bitmap-64bitMD5_9323613075234140270.png",
459 }, {
460 "checksumAlgorithm" : "bitmap-64bitMD5",
461 "checksumValue" : 16670399404877552232,
462 "comparisonResult" : "no-comparison",
463 "filepath" : "red_skp/bitmap-64bitMD5_16670399404877552232.png",
464 }, {
465 "checksumAlgorithm" : "bitmap-64bitMD5",
466 "checksumValue" : 2507897274083364964,
467 "comparisonResult" : "no-comparison",
468 "filepath" : "red_skp/bitmap-64bitMD5_2507897274083364964.png",
469 }, {
470 "checksumAlgorithm" : "bitmap-64bitMD5",
471 "checksumValue" : 7325267995523877959,
472 "comparisonResult" : "no-comparison",
473 "filepath" : "red_skp/bitmap-64bitMD5_7325267995523877959.png",
474 }, {
475 "checksumAlgorithm" : "bitmap-64bitMD5",
476 "checksumValue" : 2181381724594493116,
477 "comparisonResult" : "no-comparison",
478 "filepath" : "red_skp/bitmap-64bitMD5_2181381724594493116.png",
479 }],
480 },
481 "green.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000482 # Manually verified these 6 images, all 256x256 tiles,
483 # consistent with a tiled version of the 640x400 green rect
484 # with black borders.
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000485 "tiled-images": [{
486 "checksumAlgorithm" : "bitmap-64bitMD5",
487 "checksumValue" : 12587324416545178013,
488 "comparisonResult" : "no-comparison",
489 "filepath" : "green_skp/bitmap-64bitMD5_12587324416545178013.png",
490 }, {
491 "checksumAlgorithm" : "bitmap-64bitMD5",
492 "checksumValue" : 7624374914829746293,
493 "comparisonResult" : "no-comparison",
494 "filepath" : "green_skp/bitmap-64bitMD5_7624374914829746293.png",
495 }, {
496 "checksumAlgorithm" : "bitmap-64bitMD5",
497 "checksumValue" : 5686489729535631913,
498 "comparisonResult" : "no-comparison",
499 "filepath" : "green_skp/bitmap-64bitMD5_5686489729535631913.png",
500 }, {
501 "checksumAlgorithm" : "bitmap-64bitMD5",
502 "checksumValue" : 7980646035555096146,
503 "comparisonResult" : "no-comparison",
504 "filepath" : "green_skp/bitmap-64bitMD5_7980646035555096146.png",
505 }, {
506 "checksumAlgorithm" : "bitmap-64bitMD5",
507 "checksumValue" : 17817086664365875131,
508 "comparisonResult" : "no-comparison",
509 "filepath" : "green_skp/bitmap-64bitMD5_17817086664365875131.png",
510 }, {
511 "checksumAlgorithm" : "bitmap-64bitMD5",
512 "checksumValue" : 10673669813016809363,
513 "comparisonResult" : "no-comparison",
514 "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363.png",
515 }],
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000516 }
517 }
518 }
519 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000520 self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000521 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000522 os.path.join(write_path_dir, 'red_skp'),
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000523 ['bitmap-64bitMD5_5815827069051002745.png',
524 'bitmap-64bitMD5_9323613075234140270.png',
525 'bitmap-64bitMD5_16670399404877552232.png',
526 'bitmap-64bitMD5_2507897274083364964.png',
527 'bitmap-64bitMD5_7325267995523877959.png',
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000528 'bitmap-64bitMD5_2181381724594493116.png'])
529 self._assert_directory_contents(
commit-bot@chromium.org3f045172014-05-15 15:10:48 +0000530 os.path.join(write_path_dir, 'green_skp'),
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000531 ['bitmap-64bitMD5_12587324416545178013.png',
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000532 'bitmap-64bitMD5_7624374914829746293.png',
533 'bitmap-64bitMD5_5686489729535631913.png',
534 'bitmap-64bitMD5_7980646035555096146.png',
535 'bitmap-64bitMD5_17817086664365875131.png',
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000536 'bitmap-64bitMD5_10673669813016809363.png'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000537
538 def _run_render_pictures(self, args):
539 binary = self.find_path_to_program('render_pictures')
540 return self.run_command([binary,
541 '--clone', '1',
542 '--config', '8888',
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000543 ] + args)
544
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000545 def _create_expectations(self, missing_some_images=False,
546 rel_path='expectations.json'):
547 """Creates expectations JSON file within self._expectations_dir .
548
549 Args:
550 missing_some_images: (bool) whether to remove expectations for a subset
551 of the images
552 rel_path: (string) relative path within self._expectations_dir to write
553 the expectations into
554
555 Returns: full path to the expectations file created.
556 """
557 expectations_dict = {
558 "header" : EXPECTED_HEADER_CONTENTS,
559 "expected-results" : {
560 # red.skp: these should fail the comparison
561 "red.skp": {
562 "tiled-images": modified_list_of_dicts(
563 RED_TILES, {'checksumValue': 11111}),
564 "whole-image": modified_dict(
565 RED_WHOLEIMAGE, {'checksumValue': 22222}),
566 },
567 # green.skp: these should pass the comparison
568 "green.skp": {
569 "tiled-images": GREEN_TILES,
570 "whole-image": GREEN_WHOLEIMAGE,
571 }
572 }
573 }
574 if missing_some_images:
575 del expectations_dict['expected-results']['red.skp']['whole-image']
576 del expectations_dict['expected-results']['red.skp']['tiled-images'][-1]
577 path = os.path.join(self._expectations_dir, rel_path)
578 with open(path, 'w') as fh:
579 json.dump(expectations_dict, fh)
580 return path
581
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000582 def _generate_skps(self):
583 """Runs the skpmaker binary to generate files in self._input_skp_dir."""
584 self._run_skpmaker(
585 output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255)
586 self._run_skpmaker(
587 output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255)
588
589 def _run_skpmaker(self, output_path, red=0, green=0, blue=0,
590 width=640, height=400):
591 """Runs the skpmaker binary to generate SKP with known characteristics.
592
593 Args:
594 output_path: Filepath to write the SKP into.
595 red: Value of red color channel in image, 0-255.
596 green: Value of green color channel in image, 0-255.
597 blue: Value of blue color channel in image, 0-255.
598 width: Width of canvas to create.
599 height: Height of canvas to create.
600 """
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000601 binary = self.find_path_to_program('skpmaker')
602 return self.run_command([binary,
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000603 '--red', str(red),
604 '--green', str(green),
605 '--blue', str(blue),
606 '--width', str(width),
607 '--height', str(height),
608 '--writePath', str(output_path),
609 ])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000610
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000611 def _assert_directory_contents(self, dir_path, expected_filenames):
612 """Asserts that files found in a dir are identical to expected_filenames.
613
614 Args:
615 dir_path: Path to a directory on local disk.
616 expected_filenames: Set containing the expected filenames within the dir.
617
618 Raises:
619 AssertionError: contents of the directory are not identical to
620 expected_filenames.
621 """
622 self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames))
623
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000624 def _assert_json_contents(self, json_path, expected_dict):
625 """Asserts that contents of a JSON file are identical to expected_dict.
626
627 Args:
628 json_path: Path to a JSON file.
629 expected_dict: Dictionary indicating the expected contents of the JSON
630 file.
631
632 Raises:
633 AssertionError: contents of the JSON file are not identical to
634 expected_dict.
635 """
commit-bot@chromium.org205ce482014-05-12 15:37:20 +0000636 prettyprinted_expected_dict = json.dumps(expected_dict, sort_keys=True,
637 indent=2)
638 with open(json_path, 'r') as fh:
639 prettyprinted_json_dict = json.dumps(json.load(fh), sort_keys=True,
640 indent=2)
641 self.assertMultiLineEqual(prettyprinted_expected_dict,
642 prettyprinted_json_dict)
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000643
644
645def main():
646 base_unittest.main(RenderPicturesTest)
647
648
649if __name__ == '__main__':
650 main()