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 | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 29 | |
| 30 | class RenderPicturesTest(base_unittest.TestCase): |
| 31 | |
| 32 | def setUp(self): |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 33 | self._input_skp_dir = tempfile.mkdtemp() |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 34 | self._temp_dir = tempfile.mkdtemp() |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 35 | self.maxDiff = MAX_DIFF_LENGTH |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 36 | |
| 37 | def tearDown(self): |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 38 | shutil.rmtree(self._input_skp_dir) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 39 | shutil.rmtree(self._temp_dir) |
| 40 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 41 | def test_tiled_whole_image(self): |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 42 | """Run render_pictures with tiles and --writeWholeImage flag.""" |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 43 | 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] | 44 | self._generate_skps() |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 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! |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 49 | self._run_render_pictures(['-r', self._input_skp_dir, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 50 | '--bbh', 'grid', '256', '256', |
| 51 | '--mode', 'tile', '256', '256', |
| 52 | '--writeJsonSummaryPath', output_json_path, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 53 | '--writePath', self._temp_dir, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 54 | '--writeWholeImage']) |
| 55 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 56 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 57 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 58 | "red.skp": { |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 59 | # Manually verified: 640x400 red rectangle with black border |
| 60 | "whole-image": { |
| 61 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 62 | "checksumValue" : 11092453015575919668, |
| 63 | "comparisonResult" : "no-comparison", |
| 64 | "filepath" : "red_skp.png", |
| 65 | }, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 66 | }, |
| 67 | "green.skp": { |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 68 | # Manually verified: 640x400 green rectangle with black border |
| 69 | "whole-image": { |
| 70 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 71 | "checksumValue" : 8891695120562235492, |
| 72 | "comparisonResult" : "no-comparison", |
| 73 | "filepath" : "green_skp.png", |
| 74 | }, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
commit-bot@chromium.org | 238771c | 2014-01-15 16:33:31 +0000 | [diff] [blame] | 77 | } |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 78 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 79 | self._assert_directory_contents( |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 80 | 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] | 81 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 82 | def test_untiled(self): |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 83 | """Run without tiles.""" |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 84 | 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] | 85 | self._generate_skps() |
| 86 | self._run_render_pictures(['-r', self._input_skp_dir, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 87 | '--writePath', self._temp_dir, |
| 88 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 89 | # TODO(epoger): These expectations are the same as for above unittest. |
| 90 | # Define the expectations once, and share them. |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 91 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 92 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 93 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 94 | "red.skp": { |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 95 | # Manually verified: 640x400 red rectangle with black border |
| 96 | "whole-image": { |
| 97 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 98 | "checksumValue" : 11092453015575919668, |
| 99 | "comparisonResult" : "no-comparison", |
| 100 | "filepath" : "red_skp.png", |
| 101 | }, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 102 | }, |
| 103 | "green.skp": { |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 104 | # Manually verified: 640x400 green rectangle with black border |
| 105 | "whole-image": { |
| 106 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 107 | "checksumValue" : 8891695120562235492, |
| 108 | "comparisonResult" : "no-comparison", |
| 109 | "filepath" : "green_skp.png", |
| 110 | }, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | } |
| 114 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 115 | self._assert_directory_contents( |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 116 | 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] | 117 | |
| 118 | def test_untiled_writeChecksumBasedFilenames(self): |
| 119 | """Same as test_untiled, but with --writeChecksumBasedFilenames.""" |
| 120 | output_json_path = os.path.join(self._temp_dir, 'output.json') |
| 121 | self._generate_skps() |
| 122 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 123 | '--writeChecksumBasedFilenames', |
| 124 | '--writePath', self._temp_dir, |
| 125 | '--writeJsonSummaryPath', output_json_path]) |
| 126 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 127 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 128 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 129 | "red.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 130 | # Manually verified: 640x400 red rectangle with black border |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 131 | "whole-image": { |
| 132 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 133 | "checksumValue" : 11092453015575919668, |
| 134 | "comparisonResult" : "no-comparison", |
| 135 | "filepath" : "red_skp/bitmap-64bitMD5_11092453015575919668.png", |
| 136 | }, |
| 137 | }, |
| 138 | "green.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 139 | # Manually verified: 640x400 green rectangle with black border |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 140 | "whole-image": { |
| 141 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 142 | "checksumValue" : 8891695120562235492, |
| 143 | "comparisonResult" : "no-comparison", |
| 144 | "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492.png", |
| 145 | }, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | } |
| 149 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 150 | self._assert_directory_contents(self._temp_dir, [ |
| 151 | 'red_skp', 'green_skp', 'output.json']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 152 | self._assert_directory_contents( |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 153 | os.path.join(self._temp_dir, 'red_skp'), |
| 154 | ['bitmap-64bitMD5_11092453015575919668.png']) |
| 155 | self._assert_directory_contents( |
| 156 | os.path.join(self._temp_dir, 'green_skp'), |
| 157 | ['bitmap-64bitMD5_8891695120562235492.png']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 158 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 159 | def test_untiled_validate(self): |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 160 | """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 | """ |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 168 | 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] | 169 | self._generate_skps() |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 170 | with self.assertRaises(Exception): |
| 171 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 172 | '--validate', |
| 173 | '--writePath', self._temp_dir, |
| 174 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 175 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 176 | def test_untiled_without_writePath(self): |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 177 | """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 | """ |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 183 | 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] | 184 | self._generate_skps() |
| 185 | self._run_render_pictures(['-r', self._input_skp_dir, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 186 | '--writeJsonSummaryPath', output_json_path]) |
| 187 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 188 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 189 | "actual-results" : None, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 190 | } |
| 191 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 192 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 193 | def test_tiled(self): |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 194 | """Generate individual tiles.""" |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 195 | 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] | 196 | self._generate_skps() |
| 197 | self._run_render_pictures(['-r', self._input_skp_dir, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 198 | '--bbh', 'grid', '256', '256', |
| 199 | '--mode', 'tile', '256', '256', |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 200 | '--writePath', self._temp_dir, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 201 | '--writeJsonSummaryPath', output_json_path]) |
| 202 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 203 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 204 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 205 | "red.skp": { |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 206 | # Manually verified these 6 images, all 256x256 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 | }], |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 240 | }, |
| 241 | "green.skp": { |
commit-bot@chromium.org | cced37d | 2014-04-28 14:07:10 +0000 | [diff] [blame] | 242 | # Manually verified these 6 images, all 256x256 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 | }], |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 276 | } |
| 277 | } |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 278 | } |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 279 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 280 | self._assert_directory_contents( |
| 281 | self._temp_dir, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 282 | ['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', |
| 284 | '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', |
| 286 | 'output.json']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 287 | |
| 288 | def test_tiled_writeChecksumBasedFilenames(self): |
| 289 | """Same as test_tiled, but with --writeChecksumBasedFilenames.""" |
| 290 | output_json_path = os.path.join(self._temp_dir, 'output.json') |
| 291 | self._generate_skps() |
| 292 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 293 | '--bbh', 'grid', '256', '256', |
| 294 | '--mode', 'tile', '256', '256', |
| 295 | '--writeChecksumBasedFilenames', |
| 296 | '--writePath', self._temp_dir, |
| 297 | '--writeJsonSummaryPath', output_json_path]) |
| 298 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 299 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 300 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 301 | "red.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 302 | # Manually verified these 6 images, all 256x256 tiles, |
| 303 | # consistent with a tiled version of the 640x400 red rect |
| 304 | # with black borders. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 305 | "tiled-images": [{ |
| 306 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 307 | "checksumValue" : 5815827069051002745, |
| 308 | "comparisonResult" : "no-comparison", |
| 309 | "filepath" : "red_skp/bitmap-64bitMD5_5815827069051002745.png", |
| 310 | }, { |
| 311 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 312 | "checksumValue" : 9323613075234140270, |
| 313 | "comparisonResult" : "no-comparison", |
| 314 | "filepath" : "red_skp/bitmap-64bitMD5_9323613075234140270.png", |
| 315 | }, { |
| 316 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 317 | "checksumValue" : 16670399404877552232, |
| 318 | "comparisonResult" : "no-comparison", |
| 319 | "filepath" : "red_skp/bitmap-64bitMD5_16670399404877552232.png", |
| 320 | }, { |
| 321 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 322 | "checksumValue" : 2507897274083364964, |
| 323 | "comparisonResult" : "no-comparison", |
| 324 | "filepath" : "red_skp/bitmap-64bitMD5_2507897274083364964.png", |
| 325 | }, { |
| 326 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 327 | "checksumValue" : 7325267995523877959, |
| 328 | "comparisonResult" : "no-comparison", |
| 329 | "filepath" : "red_skp/bitmap-64bitMD5_7325267995523877959.png", |
| 330 | }, { |
| 331 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 332 | "checksumValue" : 2181381724594493116, |
| 333 | "comparisonResult" : "no-comparison", |
| 334 | "filepath" : "red_skp/bitmap-64bitMD5_2181381724594493116.png", |
| 335 | }], |
| 336 | }, |
| 337 | "green.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 338 | # Manually verified these 6 images, all 256x256 tiles, |
| 339 | # consistent with a tiled version of the 640x400 green rect |
| 340 | # with black borders. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 341 | "tiled-images": [{ |
| 342 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 343 | "checksumValue" : 12587324416545178013, |
| 344 | "comparisonResult" : "no-comparison", |
| 345 | "filepath" : "green_skp/bitmap-64bitMD5_12587324416545178013.png", |
| 346 | }, { |
| 347 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 348 | "checksumValue" : 7624374914829746293, |
| 349 | "comparisonResult" : "no-comparison", |
| 350 | "filepath" : "green_skp/bitmap-64bitMD5_7624374914829746293.png", |
| 351 | }, { |
| 352 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 353 | "checksumValue" : 5686489729535631913, |
| 354 | "comparisonResult" : "no-comparison", |
| 355 | "filepath" : "green_skp/bitmap-64bitMD5_5686489729535631913.png", |
| 356 | }, { |
| 357 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 358 | "checksumValue" : 7980646035555096146, |
| 359 | "comparisonResult" : "no-comparison", |
| 360 | "filepath" : "green_skp/bitmap-64bitMD5_7980646035555096146.png", |
| 361 | }, { |
| 362 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 363 | "checksumValue" : 17817086664365875131, |
| 364 | "comparisonResult" : "no-comparison", |
| 365 | "filepath" : "green_skp/bitmap-64bitMD5_17817086664365875131.png", |
| 366 | }, { |
| 367 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 368 | "checksumValue" : 10673669813016809363, |
| 369 | "comparisonResult" : "no-comparison", |
| 370 | "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363.png", |
| 371 | }], |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | } |
| 375 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 376 | self._assert_directory_contents(self._temp_dir, [ |
| 377 | 'red_skp', 'green_skp', 'output.json']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 378 | self._assert_directory_contents( |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 379 | os.path.join(self._temp_dir, 'red_skp'), |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 380 | ['bitmap-64bitMD5_5815827069051002745.png', |
| 381 | 'bitmap-64bitMD5_9323613075234140270.png', |
| 382 | 'bitmap-64bitMD5_16670399404877552232.png', |
| 383 | 'bitmap-64bitMD5_2507897274083364964.png', |
| 384 | 'bitmap-64bitMD5_7325267995523877959.png', |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 385 | 'bitmap-64bitMD5_2181381724594493116.png']) |
| 386 | self._assert_directory_contents( |
| 387 | os.path.join(self._temp_dir, 'green_skp'), |
| 388 | ['bitmap-64bitMD5_12587324416545178013.png', |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 389 | 'bitmap-64bitMD5_7624374914829746293.png', |
| 390 | 'bitmap-64bitMD5_5686489729535631913.png', |
| 391 | 'bitmap-64bitMD5_7980646035555096146.png', |
| 392 | 'bitmap-64bitMD5_17817086664365875131.png', |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 393 | 'bitmap-64bitMD5_10673669813016809363.png']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 394 | |
| 395 | def _run_render_pictures(self, args): |
| 396 | binary = self.find_path_to_program('render_pictures') |
| 397 | return self.run_command([binary, |
| 398 | '--clone', '1', |
| 399 | '--config', '8888', |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 400 | ] + args) |
| 401 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 402 | def _generate_skps(self): |
| 403 | """Runs the skpmaker binary to generate files in self._input_skp_dir.""" |
| 404 | self._run_skpmaker( |
| 405 | output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255) |
| 406 | self._run_skpmaker( |
| 407 | output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255) |
| 408 | |
| 409 | def _run_skpmaker(self, output_path, red=0, green=0, blue=0, |
| 410 | width=640, height=400): |
| 411 | """Runs the skpmaker binary to generate SKP with known characteristics. |
| 412 | |
| 413 | Args: |
| 414 | output_path: Filepath to write the SKP into. |
| 415 | red: Value of red color channel in image, 0-255. |
| 416 | green: Value of green color channel in image, 0-255. |
| 417 | blue: Value of blue color channel in image, 0-255. |
| 418 | width: Width of canvas to create. |
| 419 | height: Height of canvas to create. |
| 420 | """ |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 421 | binary = self.find_path_to_program('skpmaker') |
| 422 | return self.run_command([binary, |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 423 | '--red', str(red), |
| 424 | '--green', str(green), |
| 425 | '--blue', str(blue), |
| 426 | '--width', str(width), |
| 427 | '--height', str(height), |
| 428 | '--writePath', str(output_path), |
| 429 | ]) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 430 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 431 | def _assert_directory_contents(self, dir_path, expected_filenames): |
| 432 | """Asserts that files found in a dir are identical to expected_filenames. |
| 433 | |
| 434 | Args: |
| 435 | dir_path: Path to a directory on local disk. |
| 436 | expected_filenames: Set containing the expected filenames within the dir. |
| 437 | |
| 438 | Raises: |
| 439 | AssertionError: contents of the directory are not identical to |
| 440 | expected_filenames. |
| 441 | """ |
| 442 | self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames)) |
| 443 | |
| 444 | |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 445 | def _assert_json_contents(self, json_path, expected_dict): |
| 446 | """Asserts that contents of a JSON file are identical to expected_dict. |
| 447 | |
| 448 | Args: |
| 449 | json_path: Path to a JSON file. |
| 450 | expected_dict: Dictionary indicating the expected contents of the JSON |
| 451 | file. |
| 452 | |
| 453 | Raises: |
| 454 | AssertionError: contents of the JSON file are not identical to |
| 455 | expected_dict. |
| 456 | """ |
| 457 | file_contents = open(json_path, 'r').read() |
| 458 | actual_dict = json.loads(file_contents) |
| 459 | self.assertEqual(actual_dict, expected_dict) |
| 460 | |
| 461 | |
| 462 | def main(): |
| 463 | base_unittest.main(RenderPicturesTest) |
| 464 | |
| 465 | |
| 466 | if __name__ == '__main__': |
| 467 | main() |