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

Side by Side Diff: tools/tests/render_pictures_test.py

Issue 262453002: reland r14391 ('fix contents of render_pictures JSON summary') (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/render_pictures_main.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 """ 3 """
4 Copyright 2014 Google Inc. 4 Copyright 2014 Google Inc.
5 5
6 Use of this source code is governed by a BSD-style license that can be 6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file. 7 found in the LICENSE file.
8 8
9 Test the render_pictures binary. 9 Test the render_pictures binary.
10 """ 10 """
11 11
12 # System-level imports 12 # System-level imports
13 import json 13 import json
14 import os 14 import os
15 import shutil 15 import shutil
16 import tempfile 16 import tempfile
17 17
18 # Imports from within Skia 18 # Imports from within Skia
19 import base_unittest 19 import base_unittest
20 20
21 # Maximum length of text diffs to show when tests fail 21 # Maximum length of text diffs to show when tests fail
22 MAX_DIFF_LENGTH = 30000 22 MAX_DIFF_LENGTH = 30000
23 23
24 EXPECTED_HEADER_CONTENTS = { 24 EXPECTED_HEADER_CONTENTS = {
25 "type" : "ChecksummedImages", 25 "type" : "ChecksummedImages",
26 "revision" : 1, 26 "revision" : 1,
27 } 27 }
28 28
29 # Manually verified: 640x400 red rectangle with black border
30 RED_WHOLEIMAGE = {
31 "checksumAlgorithm" : "bitmap-64bitMD5",
32 "checksumValue" : 11092453015575919668,
33 "comparisonResult" : "no-comparison",
34 "filepath" : "red_skp.png",
35 }
36
37 # Manually verified: 640x400 green rectangle with black border
38 GREEN_WHOLEIMAGE = {
39 "checksumAlgorithm" : "bitmap-64bitMD5",
40 "checksumValue" : 8891695120562235492,
41 "comparisonResult" : "no-comparison",
42 "filepath" : "green_skp.png",
43 }
44
45 # Manually verified these 6 images, all 256x256 tiles,
46 # consistent with a tiled version of the 640x400 red rect
47 # with black borders.
48 RED_TILES = [{
49 "checksumAlgorithm" : "bitmap-64bitMD5",
50 "checksumValue" : 5815827069051002745,
51 "comparisonResult" : "no-comparison",
52 "filepath" : "red_skp-tile0.png",
53 },{
54 "checksumAlgorithm" : "bitmap-64bitMD5",
55 "checksumValue" : 9323613075234140270,
56 "comparisonResult" : "no-comparison",
57 "filepath" : "red_skp-tile1.png",
58 }, {
59 "checksumAlgorithm" : "bitmap-64bitMD5",
60 "checksumValue" : 16670399404877552232,
61 "comparisonResult" : "no-comparison",
62 "filepath" : "red_skp-tile2.png",
63 }, {
64 "checksumAlgorithm" : "bitmap-64bitMD5",
65 "checksumValue" : 2507897274083364964,
66 "comparisonResult" : "no-comparison",
67 "filepath" : "red_skp-tile3.png",
68 }, {
69 "checksumAlgorithm" : "bitmap-64bitMD5",
70 "checksumValue" : 7325267995523877959,
71 "comparisonResult" : "no-comparison",
72 "filepath" : "red_skp-tile4.png",
73 }, {
74 "checksumAlgorithm" : "bitmap-64bitMD5",
75 "checksumValue" : 2181381724594493116,
76 "comparisonResult" : "no-comparison",
77 "filepath" : "red_skp-tile5.png",
78 }]
79
80 # Manually verified these 6 images, all 256x256 tiles,
81 # consistent with a tiled version of the 640x400 green rect
82 # with black borders.
83 GREEN_TILES = [{
84 "checksumAlgorithm" : "bitmap-64bitMD5",
85 "checksumValue" : 12587324416545178013,
86 "comparisonResult" : "no-comparison",
87 "filepath" : "green_skp-tile0.png",
88 }, {
89 "checksumAlgorithm" : "bitmap-64bitMD5",
90 "checksumValue" : 7624374914829746293,
91 "comparisonResult" : "no-comparison",
92 "filepath" : "green_skp-tile1.png",
93 }, {
94 "checksumAlgorithm" : "bitmap-64bitMD5",
95 "checksumValue" : 5686489729535631913,
96 "comparisonResult" : "no-comparison",
97 "filepath" : "green_skp-tile2.png",
98 }, {
99 "checksumAlgorithm" : "bitmap-64bitMD5",
100 "checksumValue" : 7980646035555096146,
101 "comparisonResult" : "no-comparison",
102 "filepath" : "green_skp-tile3.png",
103 }, {
104 "checksumAlgorithm" : "bitmap-64bitMD5",
105 "checksumValue" : 17817086664365875131,
106 "comparisonResult" : "no-comparison",
107 "filepath" : "green_skp-tile4.png",
108 }, {
109 "checksumAlgorithm" : "bitmap-64bitMD5",
110 "checksumValue" : 10673669813016809363,
111 "comparisonResult" : "no-comparison",
112 "filepath" : "green_skp-tile5.png",
113 }]
114
29 115
30 class RenderPicturesTest(base_unittest.TestCase): 116 class RenderPicturesTest(base_unittest.TestCase):
31 117
32 def setUp(self): 118 def setUp(self):
33 self._input_skp_dir = tempfile.mkdtemp() 119 self._input_skp_dir = tempfile.mkdtemp()
34 self._temp_dir = tempfile.mkdtemp() 120 self._temp_dir = tempfile.mkdtemp()
35 self.maxDiff = MAX_DIFF_LENGTH 121 self.maxDiff = MAX_DIFF_LENGTH
36 122
37 def tearDown(self): 123 def tearDown(self):
38 shutil.rmtree(self._input_skp_dir) 124 shutil.rmtree(self._input_skp_dir)
39 shutil.rmtree(self._temp_dir) 125 shutil.rmtree(self._temp_dir)
40 126
41 def test_tiled_whole_image(self): 127 def test_tiled_whole_image(self):
42 """Run render_pictures with tiles and --writeWholeImage flag.""" 128 """Run render_pictures with tiles and --writeWholeImage flag.
129
130 TODO(epoger): This test generates undesired results! The JSON summary
131 includes both whole-image and tiled-images (as it should), but only
132 whole-images are written out to disk. See http://skbug.com/2463
133
134 TODO(epoger): I noticed that when this is run without --writePath being
135 specified, this test writes red_skp.png and green_skp.png to the current
136 directory. We should fix that... if --writePath is not specified, this
137 probably shouldn't write out red_skp.png and green_skp.png at all!
138 See http://skbug.com/2464
139 """
43 output_json_path = os.path.join(self._temp_dir, 'output.json') 140 output_json_path = os.path.join(self._temp_dir, 'output.json')
44 self._generate_skps() 141 self._generate_skps()
45 # TODO(epoger): I noticed that when this is run without --writePath being
46 # specified, this test writes red_skp.png and green_skp.png to the current
47 # directory. We should fix that... if --writePath is not specified, this
48 # probably shouldn't write out red_skp.png and green_skp.png at all!
49 self._run_render_pictures(['-r', self._input_skp_dir, 142 self._run_render_pictures(['-r', self._input_skp_dir,
50 '--bbh', 'grid', '256', '256', 143 '--bbh', 'grid', '256', '256',
51 '--mode', 'tile', '256', '256', 144 '--mode', 'tile', '256', '256',
52 '--writeJsonSummaryPath', output_json_path, 145 '--writeJsonSummaryPath', output_json_path,
53 '--writePath', self._temp_dir, 146 '--writePath', self._temp_dir,
54 '--writeWholeImage']) 147 '--writeWholeImage'])
55 expected_summary_dict = { 148 expected_summary_dict = {
56 "header" : EXPECTED_HEADER_CONTENTS, 149 "header" : EXPECTED_HEADER_CONTENTS,
57 "actual-results" : { 150 "actual-results" : {
58 "red.skp": { 151 "red.skp": {
59 # Manually verified: 640x400 red rectangle with black border 152 "tiled-images": RED_TILES,
60 "whole-image": { 153 "whole-image": RED_WHOLEIMAGE,
61 "checksumAlgorithm" : "bitmap-64bitMD5",
62 "checksumValue" : 11092453015575919668,
63 "comparisonResult" : "no-comparison",
64 "filepath" : "red_skp.png",
65 },
66 }, 154 },
67 "green.skp": { 155 "green.skp": {
68 # Manually verified: 640x400 green rectangle with black border 156 "tiled-images": GREEN_TILES,
69 "whole-image": { 157 "whole-image": GREEN_WHOLEIMAGE,
70 "checksumAlgorithm" : "bitmap-64bitMD5",
71 "checksumValue" : 8891695120562235492,
72 "comparisonResult" : "no-comparison",
73 "filepath" : "green_skp.png",
74 },
75 } 158 }
76 } 159 }
77 } 160 }
78 self._assert_json_contents(output_json_path, expected_summary_dict) 161 self._assert_json_contents(output_json_path, expected_summary_dict)
79 self._assert_directory_contents( 162 self._assert_directory_contents(
80 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) 163 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json'])
81 164
82 def test_untiled(self): 165 def test_untiled(self):
83 """Run without tiles.""" 166 """Run without tiles."""
84 output_json_path = os.path.join(self._temp_dir, 'output.json') 167 output_json_path = os.path.join(self._temp_dir, 'output.json')
85 self._generate_skps() 168 self._generate_skps()
86 self._run_render_pictures(['-r', self._input_skp_dir, 169 self._run_render_pictures(['-r', self._input_skp_dir,
87 '--writePath', self._temp_dir, 170 '--writePath', self._temp_dir,
88 '--writeJsonSummaryPath', output_json_path]) 171 '--writeJsonSummaryPath', output_json_path])
89 # TODO(epoger): These expectations are the same as for above unittest.
90 # Define the expectations once, and share them.
91 expected_summary_dict = { 172 expected_summary_dict = {
92 "header" : EXPECTED_HEADER_CONTENTS, 173 "header" : EXPECTED_HEADER_CONTENTS,
93 "actual-results" : { 174 "actual-results" : {
94 "red.skp": { 175 "red.skp": {
95 # Manually verified: 640x400 red rectangle with black border 176 "whole-image": RED_WHOLEIMAGE,
96 "whole-image": {
97 "checksumAlgorithm" : "bitmap-64bitMD5",
98 "checksumValue" : 11092453015575919668,
99 "comparisonResult" : "no-comparison",
100 "filepath" : "red_skp.png",
101 },
102 }, 177 },
103 "green.skp": { 178 "green.skp": {
104 # Manually verified: 640x400 green rectangle with black border 179 "whole-image": GREEN_WHOLEIMAGE,
105 "whole-image": {
106 "checksumAlgorithm" : "bitmap-64bitMD5",
107 "checksumValue" : 8891695120562235492,
108 "comparisonResult" : "no-comparison",
109 "filepath" : "green_skp.png",
110 },
111 } 180 }
112 } 181 }
113 } 182 }
114 self._assert_json_contents(output_json_path, expected_summary_dict) 183 self._assert_json_contents(output_json_path, expected_summary_dict)
115 self._assert_directory_contents( 184 self._assert_directory_contents(
116 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) 185 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json'])
117 186
118 def test_untiled_writeChecksumBasedFilenames(self): 187 def test_untiled_writeChecksumBasedFilenames(self):
119 """Same as test_untiled, but with --writeChecksumBasedFilenames.""" 188 """Same as test_untiled, but with --writeChecksumBasedFilenames."""
120 output_json_path = os.path.join(self._temp_dir, 'output.json') 189 output_json_path = os.path.join(self._temp_dir, 'output.json')
(...skipping 29 matching lines...) Expand all
150 self._assert_directory_contents(self._temp_dir, [ 219 self._assert_directory_contents(self._temp_dir, [
151 'red_skp', 'green_skp', 'output.json']) 220 'red_skp', 'green_skp', 'output.json'])
152 self._assert_directory_contents( 221 self._assert_directory_contents(
153 os.path.join(self._temp_dir, 'red_skp'), 222 os.path.join(self._temp_dir, 'red_skp'),
154 ['bitmap-64bitMD5_11092453015575919668.png']) 223 ['bitmap-64bitMD5_11092453015575919668.png'])
155 self._assert_directory_contents( 224 self._assert_directory_contents(
156 os.path.join(self._temp_dir, 'green_skp'), 225 os.path.join(self._temp_dir, 'green_skp'),
157 ['bitmap-64bitMD5_8891695120562235492.png']) 226 ['bitmap-64bitMD5_8891695120562235492.png'])
158 227
159 def test_untiled_validate(self): 228 def test_untiled_validate(self):
160 """Same as test_untiled, but with --validate. 229 """Same as test_untiled, but with --validate."""
161
162 TODO(epoger): This test generates undesired results! The call
163 to render_pictures should succeed, and generate the same output as
164 test_untiled.
165 See https://code.google.com/p/skia/issues/detail?id=2044 ('render_pictures:
166 --validate fails')
167 """
168 output_json_path = os.path.join(self._temp_dir, 'output.json') 230 output_json_path = os.path.join(self._temp_dir, 'output.json')
169 self._generate_skps() 231 self._generate_skps()
170 with self.assertRaises(Exception): 232 self._run_render_pictures(['-r', self._input_skp_dir,
171 self._run_render_pictures(['-r', self._input_skp_dir, 233 '--validate',
172 '--validate', 234 '--writePath', self._temp_dir,
173 '--writePath', self._temp_dir, 235 '--writeJsonSummaryPath', output_json_path])
174 '--writeJsonSummaryPath', output_json_path]) 236 expected_summary_dict = {
237 "header" : EXPECTED_HEADER_CONTENTS,
238 "actual-results" : {
239 "red.skp": {
240 "whole-image": RED_WHOLEIMAGE,
241 },
242 "green.skp": {
243 "whole-image": GREEN_WHOLEIMAGE,
244 }
245 }
246 }
247 self._assert_json_contents(output_json_path, expected_summary_dict)
248 self._assert_directory_contents(
249 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json'])
175 250
176 def test_untiled_without_writePath(self): 251 def test_untiled_without_writePath(self):
177 """Same as test_untiled, but without --writePath. 252 """Same as test_untiled, but without --writePath."""
178
179 TODO(epoger): This test generates undesired results!
180 See https://code.google.com/p/skia/issues/detail?id=2043 ('render_pictures:
181 --writeJsonSummaryPath fails unless --writePath is specified')
182 """
183 output_json_path = os.path.join(self._temp_dir, 'output.json') 253 output_json_path = os.path.join(self._temp_dir, 'output.json')
184 self._generate_skps() 254 self._generate_skps()
185 self._run_render_pictures(['-r', self._input_skp_dir, 255 self._run_render_pictures(['-r', self._input_skp_dir,
186 '--writeJsonSummaryPath', output_json_path]) 256 '--writeJsonSummaryPath', output_json_path])
187 expected_summary_dict = { 257 expected_summary_dict = {
188 "header" : EXPECTED_HEADER_CONTENTS, 258 "header" : EXPECTED_HEADER_CONTENTS,
189 "actual-results" : None, 259 "actual-results" : {
260 "red.skp": {
261 "whole-image": RED_WHOLEIMAGE,
262 },
263 "green.skp": {
264 "whole-image": GREEN_WHOLEIMAGE,
265 }
266 }
190 } 267 }
191 self._assert_json_contents(output_json_path, expected_summary_dict) 268 self._assert_json_contents(output_json_path, expected_summary_dict)
192 269
193 def test_tiled(self): 270 def test_tiled(self):
194 """Generate individual tiles.""" 271 """Generate individual tiles."""
195 output_json_path = os.path.join(self._temp_dir, 'output.json') 272 output_json_path = os.path.join(self._temp_dir, 'output.json')
196 self._generate_skps() 273 self._generate_skps()
197 self._run_render_pictures(['-r', self._input_skp_dir, 274 self._run_render_pictures(['-r', self._input_skp_dir,
198 '--bbh', 'grid', '256', '256', 275 '--bbh', 'grid', '256', '256',
199 '--mode', 'tile', '256', '256', 276 '--mode', 'tile', '256', '256',
200 '--writePath', self._temp_dir, 277 '--writePath', self._temp_dir,
201 '--writeJsonSummaryPath', output_json_path]) 278 '--writeJsonSummaryPath', output_json_path])
202 expected_summary_dict = { 279 expected_summary_dict = {
203 "header" : EXPECTED_HEADER_CONTENTS, 280 "header" : EXPECTED_HEADER_CONTENTS,
204 "actual-results" : { 281 "actual-results" : {
205 "red.skp": { 282 "red.skp": {
206 # Manually verified these 6 images, all 256x256 tiles, 283 "tiled-images": RED_TILES,
207 # consistent with a tiled version of the 640x400 red rect
208 # with black borders.
209 "tiled-images": [{
210 "checksumAlgorithm" : "bitmap-64bitMD5",
211 "checksumValue" : 5815827069051002745,
212 "comparisonResult" : "no-comparison",
213 "filepath" : "red_skp-tile0.png",
214 }, {
215 "checksumAlgorithm" : "bitmap-64bitMD5",
216 "checksumValue" : 9323613075234140270,
217 "comparisonResult" : "no-comparison",
218 "filepath" : "red_skp-tile1.png",
219 }, {
220 "checksumAlgorithm" : "bitmap-64bitMD5",
221 "checksumValue" : 16670399404877552232,
222 "comparisonResult" : "no-comparison",
223 "filepath" : "red_skp-tile2.png",
224 }, {
225 "checksumAlgorithm" : "bitmap-64bitMD5",
226 "checksumValue" : 2507897274083364964,
227 "comparisonResult" : "no-comparison",
228 "filepath" : "red_skp-tile3.png",
229 }, {
230 "checksumAlgorithm" : "bitmap-64bitMD5",
231 "checksumValue" : 7325267995523877959,
232 "comparisonResult" : "no-comparison",
233 "filepath" : "red_skp-tile4.png",
234 }, {
235 "checksumAlgorithm" : "bitmap-64bitMD5",
236 "checksumValue" : 2181381724594493116,
237 "comparisonResult" : "no-comparison",
238 "filepath" : "red_skp-tile5.png",
239 }],
240 }, 284 },
241 "green.skp": { 285 "green.skp": {
242 # Manually verified these 6 images, all 256x256 tiles, 286 "tiled-images": GREEN_TILES,
243 # consistent with a tiled version of the 640x400 green rect
244 # with black borders.
245 "tiled-images": [{
246 "checksumAlgorithm" : "bitmap-64bitMD5",
247 "checksumValue" : 12587324416545178013,
248 "comparisonResult" : "no-comparison",
249 "filepath" : "green_skp-tile0.png",
250 }, {
251 "checksumAlgorithm" : "bitmap-64bitMD5",
252 "checksumValue" : 7624374914829746293,
253 "comparisonResult" : "no-comparison",
254 "filepath" : "green_skp-tile1.png",
255 }, {
256 "checksumAlgorithm" : "bitmap-64bitMD5",
257 "checksumValue" : 5686489729535631913,
258 "comparisonResult" : "no-comparison",
259 "filepath" : "green_skp-tile2.png",
260 }, {
261 "checksumAlgorithm" : "bitmap-64bitMD5",
262 "checksumValue" : 7980646035555096146,
263 "comparisonResult" : "no-comparison",
264 "filepath" : "green_skp-tile3.png",
265 }, {
266 "checksumAlgorithm" : "bitmap-64bitMD5",
267 "checksumValue" : 17817086664365875131,
268 "comparisonResult" : "no-comparison",
269 "filepath" : "green_skp-tile4.png",
270 }, {
271 "checksumAlgorithm" : "bitmap-64bitMD5",
272 "checksumValue" : 10673669813016809363,
273 "comparisonResult" : "no-comparison",
274 "filepath" : "green_skp-tile5.png",
275 }],
276 } 287 }
277 } 288 }
278 } 289 }
279 self._assert_json_contents(output_json_path, expected_summary_dict) 290 self._assert_json_contents(output_json_path, expected_summary_dict)
280 self._assert_directory_contents( 291 self._assert_directory_contents(
281 self._temp_dir, 292 self._temp_dir,
282 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', 293 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png',
283 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png', 294 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png',
284 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png', 295 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png',
285 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png', 296 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png',
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 actual_dict = json.loads(file_contents) 469 actual_dict = json.loads(file_contents)
459 self.assertEqual(actual_dict, expected_dict) 470 self.assertEqual(actual_dict, expected_dict)
460 471
461 472
462 def main(): 473 def main():
463 base_unittest.main(RenderPicturesTest) 474 base_unittest.main(RenderPicturesTest)
464 475
465 476
466 if __name__ == '__main__': 477 if __name__ == '__main__':
467 main() 478 main()
OLDNEW
« no previous file with comments | « tools/render_pictures_main.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698