commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | """ |
| 4 | Copyright 2014 Google Inc. |
| 5 | |
| 6 | Use of this source code is governed by a BSD-style license that can be |
| 7 | found in the LICENSE file. |
| 8 | |
| 9 | Test the render_pictures binary. |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 10 | """ |
| 11 | |
| 12 | # System-level imports |
| 13 | import json |
| 14 | import os |
| 15 | import shutil |
| 16 | import tempfile |
| 17 | |
| 18 | # Imports from within Skia |
| 19 | import base_unittest |
| 20 | |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 21 | # Maximum length of text diffs to show when tests fail |
| 22 | MAX_DIFF_LENGTH = 30000 |
| 23 | |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 24 | EXPECTED_HEADER_CONTENTS = { |
| 25 | "type" : "ChecksummedImages", |
| 26 | "revision" : 1, |
| 27 | } |
| 28 | |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 115 | |
| 116 | class RenderPicturesTest(base_unittest.TestCase): |
| 117 | |
| 118 | def setUp(self): |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 119 | self._input_skp_dir = tempfile.mkdtemp() |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 120 | self._temp_dir = tempfile.mkdtemp() |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 121 | self.maxDiff = MAX_DIFF_LENGTH |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 122 | |
| 123 | def tearDown(self): |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 124 | shutil.rmtree(self._input_skp_dir) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 125 | shutil.rmtree(self._temp_dir) |
| 126 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 127 | def test_tiled_whole_image(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 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 | """ |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 140 | output_json_path = os.path.join(self._temp_dir, 'output.json') |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 141 | self._generate_skps() |
| 142 | self._run_render_pictures(['-r', self._input_skp_dir, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 143 | '--bbh', 'grid', '256', '256', |
| 144 | '--mode', 'tile', '256', '256', |
| 145 | '--writeJsonSummaryPath', output_json_path, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 146 | '--writePath', self._temp_dir, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 147 | '--writeWholeImage']) |
| 148 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 149 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 150 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 151 | "red.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 152 | "tiled-images": RED_TILES, |
| 153 | "whole-image": RED_WHOLEIMAGE, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 154 | }, |
| 155 | "green.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 156 | "tiled-images": GREEN_TILES, |
| 157 | "whole-image": GREEN_WHOLEIMAGE, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 158 | } |
| 159 | } |
commit-bot@chromium.org | 238771c | 2014-01-15 16:33:31 +0000 | [diff] [blame] | 160 | } |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 161 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 162 | self._assert_directory_contents( |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 163 | self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 164 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 165 | def test_untiled(self): |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 166 | """Run without tiles.""" |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 167 | output_json_path = os.path.join(self._temp_dir, 'output.json') |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 168 | self._generate_skps() |
| 169 | self._run_render_pictures(['-r', self._input_skp_dir, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 170 | '--writePath', self._temp_dir, |
| 171 | '--writeJsonSummaryPath', output_json_path]) |
| 172 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 173 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 174 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 175 | "red.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 176 | "whole-image": RED_WHOLEIMAGE, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 177 | }, |
| 178 | "green.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 179 | "whole-image": GREEN_WHOLEIMAGE, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | } |
| 183 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 184 | self._assert_directory_contents( |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 185 | self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 186 | |
| 187 | def test_untiled_writeChecksumBasedFilenames(self): |
| 188 | """Same as test_untiled, but with --writeChecksumBasedFilenames.""" |
| 189 | output_json_path = os.path.join(self._temp_dir, 'output.json') |
| 190 | self._generate_skps() |
| 191 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 192 | '--writeChecksumBasedFilenames', |
| 193 | '--writePath', self._temp_dir, |
| 194 | '--writeJsonSummaryPath', output_json_path]) |
| 195 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 196 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 197 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 198 | "red.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 199 | # Manually verified: 640x400 red rectangle with black border |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 200 | "whole-image": { |
| 201 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 202 | "checksumValue" : 11092453015575919668, |
| 203 | "comparisonResult" : "no-comparison", |
| 204 | "filepath" : "red_skp/bitmap-64bitMD5_11092453015575919668.png", |
| 205 | }, |
| 206 | }, |
| 207 | "green.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 208 | # Manually verified: 640x400 green rectangle with black border |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 209 | "whole-image": { |
| 210 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 211 | "checksumValue" : 8891695120562235492, |
| 212 | "comparisonResult" : "no-comparison", |
| 213 | "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492.png", |
| 214 | }, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | } |
| 218 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 219 | self._assert_directory_contents(self._temp_dir, [ |
| 220 | 'red_skp', 'green_skp', 'output.json']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 221 | self._assert_directory_contents( |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 222 | os.path.join(self._temp_dir, 'red_skp'), |
| 223 | ['bitmap-64bitMD5_11092453015575919668.png']) |
| 224 | self._assert_directory_contents( |
| 225 | os.path.join(self._temp_dir, 'green_skp'), |
| 226 | ['bitmap-64bitMD5_8891695120562235492.png']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 227 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 228 | def test_untiled_validate(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 229 | """Same as test_untiled, but with --validate.""" |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 230 | output_json_path = os.path.join(self._temp_dir, 'output.json') |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 231 | self._generate_skps() |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 232 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 233 | '--validate', |
| 234 | '--writePath', self._temp_dir, |
| 235 | '--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']) |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 250 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 251 | def test_untiled_without_writePath(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 252 | """Same as test_untiled, but without --writePath.""" |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 253 | output_json_path = os.path.join(self._temp_dir, 'output.json') |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 254 | self._generate_skps() |
| 255 | self._run_render_pictures(['-r', self._input_skp_dir, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 256 | '--writeJsonSummaryPath', output_json_path]) |
| 257 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 258 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 259 | "actual-results" : { |
| 260 | "red.skp": { |
| 261 | "whole-image": RED_WHOLEIMAGE, |
| 262 | }, |
| 263 | "green.skp": { |
| 264 | "whole-image": GREEN_WHOLEIMAGE, |
| 265 | } |
| 266 | } |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 267 | } |
| 268 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 269 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 270 | def test_tiled(self): |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 271 | """Generate individual tiles.""" |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 272 | output_json_path = os.path.join(self._temp_dir, 'output.json') |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 273 | self._generate_skps() |
| 274 | self._run_render_pictures(['-r', self._input_skp_dir, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 275 | '--bbh', 'grid', '256', '256', |
| 276 | '--mode', 'tile', '256', '256', |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 277 | '--writePath', self._temp_dir, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 278 | '--writeJsonSummaryPath', output_json_path]) |
| 279 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 280 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 281 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 282 | "red.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 283 | "tiled-images": RED_TILES, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 284 | }, |
| 285 | "green.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 286 | "tiled-images": GREEN_TILES, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 289 | } |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 290 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 291 | self._assert_directory_contents( |
| 292 | self._temp_dir, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 293 | ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', |
| 294 | 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png', |
| 295 | 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png', |
| 296 | 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png', |
| 297 | 'output.json']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 298 | |
| 299 | def test_tiled_writeChecksumBasedFilenames(self): |
| 300 | """Same as test_tiled, but with --writeChecksumBasedFilenames.""" |
| 301 | output_json_path = os.path.join(self._temp_dir, 'output.json') |
| 302 | self._generate_skps() |
| 303 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 304 | '--bbh', 'grid', '256', '256', |
| 305 | '--mode', 'tile', '256', '256', |
| 306 | '--writeChecksumBasedFilenames', |
| 307 | '--writePath', self._temp_dir, |
| 308 | '--writeJsonSummaryPath', output_json_path]) |
| 309 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 310 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 311 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 312 | "red.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 313 | # Manually verified these 6 images, all 256x256 tiles, |
| 314 | # consistent with a tiled version of the 640x400 red rect |
| 315 | # with black borders. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 316 | "tiled-images": [{ |
| 317 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 318 | "checksumValue" : 5815827069051002745, |
| 319 | "comparisonResult" : "no-comparison", |
| 320 | "filepath" : "red_skp/bitmap-64bitMD5_5815827069051002745.png", |
| 321 | }, { |
| 322 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 323 | "checksumValue" : 9323613075234140270, |
| 324 | "comparisonResult" : "no-comparison", |
| 325 | "filepath" : "red_skp/bitmap-64bitMD5_9323613075234140270.png", |
| 326 | }, { |
| 327 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 328 | "checksumValue" : 16670399404877552232, |
| 329 | "comparisonResult" : "no-comparison", |
| 330 | "filepath" : "red_skp/bitmap-64bitMD5_16670399404877552232.png", |
| 331 | }, { |
| 332 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 333 | "checksumValue" : 2507897274083364964, |
| 334 | "comparisonResult" : "no-comparison", |
| 335 | "filepath" : "red_skp/bitmap-64bitMD5_2507897274083364964.png", |
| 336 | }, { |
| 337 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 338 | "checksumValue" : 7325267995523877959, |
| 339 | "comparisonResult" : "no-comparison", |
| 340 | "filepath" : "red_skp/bitmap-64bitMD5_7325267995523877959.png", |
| 341 | }, { |
| 342 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 343 | "checksumValue" : 2181381724594493116, |
| 344 | "comparisonResult" : "no-comparison", |
| 345 | "filepath" : "red_skp/bitmap-64bitMD5_2181381724594493116.png", |
| 346 | }], |
| 347 | }, |
| 348 | "green.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 349 | # Manually verified these 6 images, all 256x256 tiles, |
| 350 | # consistent with a tiled version of the 640x400 green rect |
| 351 | # with black borders. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 352 | "tiled-images": [{ |
| 353 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 354 | "checksumValue" : 12587324416545178013, |
| 355 | "comparisonResult" : "no-comparison", |
| 356 | "filepath" : "green_skp/bitmap-64bitMD5_12587324416545178013.png", |
| 357 | }, { |
| 358 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 359 | "checksumValue" : 7624374914829746293, |
| 360 | "comparisonResult" : "no-comparison", |
| 361 | "filepath" : "green_skp/bitmap-64bitMD5_7624374914829746293.png", |
| 362 | }, { |
| 363 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 364 | "checksumValue" : 5686489729535631913, |
| 365 | "comparisonResult" : "no-comparison", |
| 366 | "filepath" : "green_skp/bitmap-64bitMD5_5686489729535631913.png", |
| 367 | }, { |
| 368 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 369 | "checksumValue" : 7980646035555096146, |
| 370 | "comparisonResult" : "no-comparison", |
| 371 | "filepath" : "green_skp/bitmap-64bitMD5_7980646035555096146.png", |
| 372 | }, { |
| 373 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 374 | "checksumValue" : 17817086664365875131, |
| 375 | "comparisonResult" : "no-comparison", |
| 376 | "filepath" : "green_skp/bitmap-64bitMD5_17817086664365875131.png", |
| 377 | }, { |
| 378 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 379 | "checksumValue" : 10673669813016809363, |
| 380 | "comparisonResult" : "no-comparison", |
| 381 | "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363.png", |
| 382 | }], |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | } |
| 386 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 387 | self._assert_directory_contents(self._temp_dir, [ |
| 388 | 'red_skp', 'green_skp', 'output.json']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 389 | self._assert_directory_contents( |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 390 | os.path.join(self._temp_dir, 'red_skp'), |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 391 | ['bitmap-64bitMD5_5815827069051002745.png', |
| 392 | 'bitmap-64bitMD5_9323613075234140270.png', |
| 393 | 'bitmap-64bitMD5_16670399404877552232.png', |
| 394 | 'bitmap-64bitMD5_2507897274083364964.png', |
| 395 | 'bitmap-64bitMD5_7325267995523877959.png', |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 396 | 'bitmap-64bitMD5_2181381724594493116.png']) |
| 397 | self._assert_directory_contents( |
| 398 | os.path.join(self._temp_dir, 'green_skp'), |
| 399 | ['bitmap-64bitMD5_12587324416545178013.png', |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 400 | 'bitmap-64bitMD5_7624374914829746293.png', |
| 401 | 'bitmap-64bitMD5_5686489729535631913.png', |
| 402 | 'bitmap-64bitMD5_7980646035555096146.png', |
| 403 | 'bitmap-64bitMD5_17817086664365875131.png', |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 404 | 'bitmap-64bitMD5_10673669813016809363.png']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 405 | |
| 406 | def _run_render_pictures(self, args): |
| 407 | binary = self.find_path_to_program('render_pictures') |
| 408 | return self.run_command([binary, |
| 409 | '--clone', '1', |
| 410 | '--config', '8888', |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 411 | ] + args) |
| 412 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 413 | def _generate_skps(self): |
| 414 | """Runs the skpmaker binary to generate files in self._input_skp_dir.""" |
| 415 | self._run_skpmaker( |
| 416 | output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255) |
| 417 | self._run_skpmaker( |
| 418 | output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255) |
| 419 | |
| 420 | def _run_skpmaker(self, output_path, red=0, green=0, blue=0, |
| 421 | width=640, height=400): |
| 422 | """Runs the skpmaker binary to generate SKP with known characteristics. |
| 423 | |
| 424 | Args: |
| 425 | output_path: Filepath to write the SKP into. |
| 426 | red: Value of red color channel in image, 0-255. |
| 427 | green: Value of green color channel in image, 0-255. |
| 428 | blue: Value of blue color channel in image, 0-255. |
| 429 | width: Width of canvas to create. |
| 430 | height: Height of canvas to create. |
| 431 | """ |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 432 | binary = self.find_path_to_program('skpmaker') |
| 433 | return self.run_command([binary, |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 434 | '--red', str(red), |
| 435 | '--green', str(green), |
| 436 | '--blue', str(blue), |
| 437 | '--width', str(width), |
| 438 | '--height', str(height), |
| 439 | '--writePath', str(output_path), |
| 440 | ]) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 441 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 442 | def _assert_directory_contents(self, dir_path, expected_filenames): |
| 443 | """Asserts that files found in a dir are identical to expected_filenames. |
| 444 | |
| 445 | Args: |
| 446 | dir_path: Path to a directory on local disk. |
| 447 | expected_filenames: Set containing the expected filenames within the dir. |
| 448 | |
| 449 | Raises: |
| 450 | AssertionError: contents of the directory are not identical to |
| 451 | expected_filenames. |
| 452 | """ |
| 453 | self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames)) |
| 454 | |
| 455 | |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 456 | def _assert_json_contents(self, json_path, expected_dict): |
| 457 | """Asserts that contents of a JSON file are identical to expected_dict. |
| 458 | |
| 459 | Args: |
| 460 | json_path: Path to a JSON file. |
| 461 | expected_dict: Dictionary indicating the expected contents of the JSON |
| 462 | file. |
| 463 | |
| 464 | Raises: |
| 465 | AssertionError: contents of the JSON file are not identical to |
| 466 | expected_dict. |
| 467 | """ |
| 468 | file_contents = open(json_path, 'r').read() |
| 469 | actual_dict = json.loads(file_contents) |
| 470 | self.assertEqual(actual_dict, expected_dict) |
| 471 | |
| 472 | |
| 473 | def main(): |
| 474 | base_unittest.main(RenderPicturesTest) |
| 475 | |
| 476 | |
| 477 | if __name__ == '__main__': |
| 478 | main() |