OLD | NEW |
---|---|
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 | |
epoger
2014/04/24 20:51:20
This behavior CHANGED with this CL, but it was alr
| |
131 includes both whole-image and tiled-images (as it should), but only | |
132 whole-images are written out to disk. | |
133 | |
134 TODO(epoger): I noticed that when this is run without --writePath being | |
scroggo
2014/04/24 21:15:08
Are there bugs for these TODOs? Should they be ref
epoger
2014/04/25 15:26:43
Now they do, and they are. Good idea, thanks.
| |
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 """ | |
43 output_json_path = os.path.join(self._temp_dir, 'output.json') | 139 output_json_path = os.path.join(self._temp_dir, 'output.json') |
44 self._generate_skps() | 140 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, | 141 self._run_render_pictures(['-r', self._input_skp_dir, |
50 '--bbh', 'grid', '256', '256', | 142 '--bbh', 'grid', '256', '256', |
51 '--mode', 'tile', '256', '256', | 143 '--mode', 'tile', '256', '256', |
52 '--writeJsonSummaryPath', output_json_path, | 144 '--writeJsonSummaryPath', output_json_path, |
53 '--writePath', self._temp_dir, | 145 '--writePath', self._temp_dir, |
54 '--writeWholeImage']) | 146 '--writeWholeImage']) |
55 expected_summary_dict = { | 147 expected_summary_dict = { |
56 "header" : EXPECTED_HEADER_CONTENTS, | 148 "header" : EXPECTED_HEADER_CONTENTS, |
57 "actual-results" : { | 149 "actual-results" : { |
58 "red.skp": { | 150 "red.skp": { |
59 # Manually verified: 640x400 red rectangle with black border | 151 "tiled-images": RED_TILES, |
60 "whole-image": { | 152 "whole-image": RED_WHOLEIMAGE, |
61 "checksumAlgorithm" : "bitmap-64bitMD5", | |
62 "checksumValue" : 11092453015575919668, | |
63 "comparisonResult" : "no-comparison", | |
64 "filepath" : "red_skp.png", | |
65 }, | |
66 }, | 153 }, |
67 "green.skp": { | 154 "green.skp": { |
68 # Manually verified: 640x400 green rectangle with black border | 155 "tiled-images": GREEN_TILES, |
69 "whole-image": { | 156 "whole-image": GREEN_WHOLEIMAGE, |
70 "checksumAlgorithm" : "bitmap-64bitMD5", | |
71 "checksumValue" : 8891695120562235492, | |
72 "comparisonResult" : "no-comparison", | |
73 "filepath" : "green_skp.png", | |
74 }, | |
75 } | 157 } |
76 } | 158 } |
77 } | 159 } |
78 self._assert_json_contents(output_json_path, expected_summary_dict) | 160 self._assert_json_contents(output_json_path, expected_summary_dict) |
161 # The disk contents are not what they should be--we should see all the | |
scroggo
2014/04/24 21:15:08
I suppose this goes with the TODO above?
epoger
2014/04/25 15:26:43
Yes. Removed this redundant comment.
| |
162 # tile images written out, too. | |
79 self._assert_directory_contents( | 163 self._assert_directory_contents( |
80 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) | 164 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) |
81 | 165 |
82 def test_untiled(self): | 166 def test_untiled(self): |
83 """Run without tiles.""" | 167 """Run without tiles.""" |
84 output_json_path = os.path.join(self._temp_dir, 'output.json') | 168 output_json_path = os.path.join(self._temp_dir, 'output.json') |
85 self._generate_skps() | 169 self._generate_skps() |
86 self._run_render_pictures(['-r', self._input_skp_dir, | 170 self._run_render_pictures(['-r', self._input_skp_dir, |
87 '--writePath', self._temp_dir, | 171 '--writePath', self._temp_dir, |
88 '--writeJsonSummaryPath', output_json_path]) | 172 '--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 = { | 173 expected_summary_dict = { |
92 "header" : EXPECTED_HEADER_CONTENTS, | 174 "header" : EXPECTED_HEADER_CONTENTS, |
93 "actual-results" : { | 175 "actual-results" : { |
94 "red.skp": { | 176 "red.skp": { |
95 # Manually verified: 640x400 red rectangle with black border | 177 "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 }, | 178 }, |
103 "green.skp": { | 179 "green.skp": { |
104 # Manually verified: 640x400 green rectangle with black border | 180 "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 } | 181 } |
112 } | 182 } |
113 } | 183 } |
114 self._assert_json_contents(output_json_path, expected_summary_dict) | 184 self._assert_json_contents(output_json_path, expected_summary_dict) |
115 self._assert_directory_contents( | 185 self._assert_directory_contents( |
116 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) | 186 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) |
117 | 187 |
118 def test_untiled_writeChecksumBasedFilenames(self): | 188 def test_untiled_writeChecksumBasedFilenames(self): |
119 """Same as test_untiled, but with --writeChecksumBasedFilenames.""" | 189 """Same as test_untiled, but with --writeChecksumBasedFilenames.""" |
120 output_json_path = os.path.join(self._temp_dir, 'output.json') | 190 output_json_path = os.path.join(self._temp_dir, 'output.json') |
(...skipping 29 matching lines...) Expand all Loading... | |
150 self._assert_directory_contents(self._temp_dir, [ | 220 self._assert_directory_contents(self._temp_dir, [ |
151 'red_skp', 'green_skp', 'output.json']) | 221 'red_skp', 'green_skp', 'output.json']) |
152 self._assert_directory_contents( | 222 self._assert_directory_contents( |
153 os.path.join(self._temp_dir, 'red_skp'), | 223 os.path.join(self._temp_dir, 'red_skp'), |
154 ['bitmap-64bitMD5_11092453015575919668.png']) | 224 ['bitmap-64bitMD5_11092453015575919668.png']) |
155 self._assert_directory_contents( | 225 self._assert_directory_contents( |
156 os.path.join(self._temp_dir, 'green_skp'), | 226 os.path.join(self._temp_dir, 'green_skp'), |
157 ['bitmap-64bitMD5_8891695120562235492.png']) | 227 ['bitmap-64bitMD5_8891695120562235492.png']) |
158 | 228 |
159 def test_untiled_validate(self): | 229 def test_untiled_validate(self): |
160 """Same as test_untiled, but with --validate. | 230 """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: | |
scroggo
2014/04/24 21:15:08
I'm glad to know that using the flag "validate" no
epoger
2014/04/25 15:26:43
Probably so.
This code really should have had uni
| |
166 --validate fails') | |
167 """ | |
168 output_json_path = os.path.join(self._temp_dir, 'output.json') | 231 output_json_path = os.path.join(self._temp_dir, 'output.json') |
169 self._generate_skps() | 232 self._generate_skps() |
170 with self.assertRaises(Exception): | 233 self._run_render_pictures(['-r', self._input_skp_dir, |
171 self._run_render_pictures(['-r', self._input_skp_dir, | 234 '--validate', |
172 '--validate', | 235 '--writePath', self._temp_dir, |
173 '--writePath', self._temp_dir, | 236 '--writeJsonSummaryPath', output_json_path]) |
174 '--writeJsonSummaryPath', output_json_path]) | 237 expected_summary_dict = { |
238 "header" : EXPECTED_HEADER_CONTENTS, | |
239 "actual-results" : { | |
240 "red.skp": { | |
241 "whole-image": RED_WHOLEIMAGE, | |
242 }, | |
243 "green.skp": { | |
244 "whole-image": GREEN_WHOLEIMAGE, | |
245 } | |
246 } | |
247 } | |
248 self._assert_json_contents(output_json_path, expected_summary_dict) | |
249 self._assert_directory_contents( | |
250 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) | |
175 | 251 |
176 def test_untiled_without_writePath(self): | 252 def test_untiled_without_writePath(self): |
177 """Same as test_untiled, but without --writePath. | 253 """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') | 254 output_json_path = os.path.join(self._temp_dir, 'output.json') |
184 self._generate_skps() | 255 self._generate_skps() |
185 self._run_render_pictures(['-r', self._input_skp_dir, | 256 self._run_render_pictures(['-r', self._input_skp_dir, |
186 '--writeJsonSummaryPath', output_json_path]) | 257 '--writeJsonSummaryPath', output_json_path]) |
187 expected_summary_dict = { | 258 expected_summary_dict = { |
188 "header" : EXPECTED_HEADER_CONTENTS, | 259 "header" : EXPECTED_HEADER_CONTENTS, |
189 "actual-results" : None, | 260 "actual-results" : { |
261 "red.skp": { | |
262 "whole-image": RED_WHOLEIMAGE, | |
263 }, | |
264 "green.skp": { | |
265 "whole-image": GREEN_WHOLEIMAGE, | |
266 } | |
267 } | |
190 } | 268 } |
191 self._assert_json_contents(output_json_path, expected_summary_dict) | 269 self._assert_json_contents(output_json_path, expected_summary_dict) |
192 | 270 |
193 def test_tiled(self): | 271 def test_tiled(self): |
194 """Generate individual tiles.""" | 272 """Generate individual tiles.""" |
195 output_json_path = os.path.join(self._temp_dir, 'output.json') | 273 output_json_path = os.path.join(self._temp_dir, 'output.json') |
196 self._generate_skps() | 274 self._generate_skps() |
197 self._run_render_pictures(['-r', self._input_skp_dir, | 275 self._run_render_pictures(['-r', self._input_skp_dir, |
198 '--bbh', 'grid', '256', '256', | 276 '--bbh', 'grid', '256', '256', |
199 '--mode', 'tile', '256', '256', | 277 '--mode', 'tile', '256', '256', |
200 '--writePath', self._temp_dir, | 278 '--writePath', self._temp_dir, |
201 '--writeJsonSummaryPath', output_json_path]) | 279 '--writeJsonSummaryPath', output_json_path]) |
202 expected_summary_dict = { | 280 expected_summary_dict = { |
203 "header" : EXPECTED_HEADER_CONTENTS, | 281 "header" : EXPECTED_HEADER_CONTENTS, |
204 "actual-results" : { | 282 "actual-results" : { |
205 "red.skp": { | 283 "red.skp": { |
206 # Manually verified these 6 images, all 256x256 tiles, | 284 "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 }, | 285 }, |
241 "green.skp": { | 286 "green.skp": { |
242 # Manually verified these 6 images, all 256x256 tiles, | 287 "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 } | 288 } |
277 } | 289 } |
278 } | 290 } |
279 self._assert_json_contents(output_json_path, expected_summary_dict) | 291 self._assert_json_contents(output_json_path, expected_summary_dict) |
280 self._assert_directory_contents( | 292 self._assert_directory_contents( |
281 self._temp_dir, | 293 self._temp_dir, |
282 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', | 294 ['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', | 295 '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', | 296 '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', | 297 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png', |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 actual_dict = json.loads(file_contents) | 470 actual_dict = json.loads(file_contents) |
459 self.assertEqual(actual_dict, expected_dict) | 471 self.assertEqual(actual_dict, expected_dict) |
460 | 472 |
461 | 473 |
462 def main(): | 474 def main(): |
463 base_unittest.main(RenderPicturesTest) | 475 base_unittest.main(RenderPicturesTest) |
464 | 476 |
465 | 477 |
466 if __name__ == '__main__': | 478 if __name__ == '__main__': |
467 main() | 479 main() |
OLD | NEW |