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 |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 13 | import copy |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 14 | import json |
| 15 | import os |
| 16 | import shutil |
| 17 | import tempfile |
| 18 | |
| 19 | # Imports from within Skia |
| 20 | import base_unittest |
| 21 | |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 22 | # Maximum length of text diffs to show when tests fail |
| 23 | MAX_DIFF_LENGTH = 30000 |
| 24 | |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 25 | EXPECTED_HEADER_CONTENTS = { |
| 26 | "type" : "ChecksummedImages", |
| 27 | "revision" : 1, |
| 28 | } |
| 29 | |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 30 | # Manually verified: 640x400 red rectangle with black border |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 31 | # Standard expectations will be set up in such a way that this image fails |
| 32 | # the comparison. |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 33 | RED_WHOLEIMAGE = { |
| 34 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 35 | "checksumValue" : 11092453015575919668, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 36 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 37 | "filepath" : "red_skp.png", |
| 38 | } |
| 39 | |
| 40 | # Manually verified: 640x400 green rectangle with black border |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 41 | # Standard expectations will be set up in such a way that this image passes |
| 42 | # the comparison. |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 43 | GREEN_WHOLEIMAGE = { |
| 44 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 45 | "checksumValue" : 8891695120562235492, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 46 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 47 | "filepath" : "green_skp.png", |
| 48 | } |
| 49 | |
| 50 | # Manually verified these 6 images, all 256x256 tiles, |
| 51 | # consistent with a tiled version of the 640x400 red rect |
| 52 | # with black borders. |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 53 | # Standard expectations will be set up in such a way that these images fail |
| 54 | # the comparison. |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 55 | RED_TILES = [{ |
| 56 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 57 | "checksumValue" : 5815827069051002745, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 58 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 59 | "filepath" : "red_skp-tile0.png", |
| 60 | },{ |
| 61 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 62 | "checksumValue" : 9323613075234140270, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 63 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 64 | "filepath" : "red_skp-tile1.png", |
| 65 | }, { |
| 66 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 67 | "checksumValue" : 16670399404877552232, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 68 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 69 | "filepath" : "red_skp-tile2.png", |
| 70 | }, { |
| 71 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 72 | "checksumValue" : 2507897274083364964, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 73 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 74 | "filepath" : "red_skp-tile3.png", |
| 75 | }, { |
| 76 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 77 | "checksumValue" : 7325267995523877959, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 78 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 79 | "filepath" : "red_skp-tile4.png", |
| 80 | }, { |
| 81 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 82 | "checksumValue" : 2181381724594493116, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 83 | "comparisonResult" : "failed", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 84 | "filepath" : "red_skp-tile5.png", |
| 85 | }] |
| 86 | |
| 87 | # Manually verified these 6 images, all 256x256 tiles, |
| 88 | # consistent with a tiled version of the 640x400 green rect |
| 89 | # with black borders. |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 90 | # Standard expectations will be set up in such a way that these images pass |
| 91 | # the comparison. |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 92 | GREEN_TILES = [{ |
| 93 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 94 | "checksumValue" : 12587324416545178013, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 95 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 96 | "filepath" : "green_skp-tile0.png", |
| 97 | }, { |
| 98 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 99 | "checksumValue" : 7624374914829746293, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 100 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 101 | "filepath" : "green_skp-tile1.png", |
| 102 | }, { |
| 103 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 104 | "checksumValue" : 5686489729535631913, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 105 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 106 | "filepath" : "green_skp-tile2.png", |
| 107 | }, { |
| 108 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 109 | "checksumValue" : 7980646035555096146, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 110 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 111 | "filepath" : "green_skp-tile3.png", |
| 112 | }, { |
| 113 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 114 | "checksumValue" : 17817086664365875131, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 115 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 116 | "filepath" : "green_skp-tile4.png", |
| 117 | }, { |
| 118 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 119 | "checksumValue" : 10673669813016809363, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 120 | "comparisonResult" : "succeeded", |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 121 | "filepath" : "green_skp-tile5.png", |
| 122 | }] |
| 123 | |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 124 | |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 125 | def modified_dict(input_dict, modification_dict): |
| 126 | """Returns a dict, with some modifications applied to it. |
| 127 | |
| 128 | Args: |
| 129 | input_dict: a dictionary (which will be copied, not modified in place) |
| 130 | modification_dict: a set of key/value pairs to overwrite in the dict |
| 131 | """ |
| 132 | output_dict = input_dict.copy() |
| 133 | output_dict.update(modification_dict) |
| 134 | return output_dict |
| 135 | |
| 136 | |
| 137 | def modified_list_of_dicts(input_list, modification_dict): |
| 138 | """Returns a list of dicts, with some modifications applied to each dict. |
| 139 | |
| 140 | Args: |
| 141 | input_list: a list of dictionaries; these dicts will be copied, not |
| 142 | modified in place |
| 143 | modification_dict: a set of key/value pairs to overwrite in each dict |
| 144 | within input_list |
| 145 | """ |
| 146 | output_list = [] |
| 147 | for input_dict in input_list: |
| 148 | output_dict = modified_dict(input_dict, modification_dict) |
| 149 | output_list.append(output_dict) |
| 150 | return output_list |
| 151 | |
| 152 | |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 153 | class RenderPicturesTest(base_unittest.TestCase): |
| 154 | |
| 155 | def setUp(self): |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 156 | self.maxDiff = MAX_DIFF_LENGTH |
| 157 | self._expectations_dir = tempfile.mkdtemp() |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 158 | self._input_skp_dir = tempfile.mkdtemp() |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 159 | self._temp_dir = tempfile.mkdtemp() |
| 160 | |
| 161 | def tearDown(self): |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 162 | shutil.rmtree(self._expectations_dir) |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 163 | shutil.rmtree(self._input_skp_dir) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 164 | shutil.rmtree(self._temp_dir) |
| 165 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 166 | def test_tiled_whole_image(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 167 | """Run render_pictures with tiles and --writeWholeImage flag. |
| 168 | |
| 169 | TODO(epoger): This test generates undesired results! The JSON summary |
| 170 | includes both whole-image and tiled-images (as it should), but only |
| 171 | whole-images are written out to disk. See http://skbug.com/2463 |
| 172 | |
| 173 | TODO(epoger): I noticed that when this is run without --writePath being |
| 174 | specified, this test writes red_skp.png and green_skp.png to the current |
| 175 | directory. We should fix that... if --writePath is not specified, this |
| 176 | probably shouldn't write out red_skp.png and green_skp.png at all! |
| 177 | See http://skbug.com/2464 |
| 178 | """ |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 179 | output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 180 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 181 | expectations_path = self._create_expectations() |
| 182 | self._run_render_pictures([ |
| 183 | '-r', self._input_skp_dir, |
| 184 | '--bbh', 'grid', '256', '256', |
| 185 | '--mode', 'tile', '256', '256', |
| 186 | '--readJsonSummaryPath', expectations_path, |
| 187 | '--writeJsonSummaryPath', output_json_path, |
| 188 | '--writePath', self._temp_dir, |
| 189 | '--writeWholeImage']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 190 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 191 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 192 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 193 | "red.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 194 | "tiled-images": RED_TILES, |
| 195 | "whole-image": RED_WHOLEIMAGE, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 196 | }, |
| 197 | "green.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 198 | "tiled-images": GREEN_TILES, |
| 199 | "whole-image": GREEN_WHOLEIMAGE, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 200 | } |
| 201 | } |
commit-bot@chromium.org | 238771c | 2014-01-15 16:33:31 +0000 | [diff] [blame] | 202 | } |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 203 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 204 | self._assert_directory_contents( |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 205 | self._temp_dir, ['red_skp.png', 'green_skp.png', 'actuals.json']) |
| 206 | |
| 207 | def test_missing_tile_and_whole_image(self): |
| 208 | """test_tiled_whole_image, but missing expectations for some images. |
| 209 | """ |
| 210 | output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
| 211 | self._generate_skps() |
| 212 | expectations_path = self._create_expectations(missing_some_images=True) |
| 213 | self._run_render_pictures([ |
| 214 | '-r', self._input_skp_dir, |
| 215 | '--bbh', 'grid', '256', '256', |
| 216 | '--mode', 'tile', '256', '256', |
| 217 | '--readJsonSummaryPath', expectations_path, |
| 218 | '--writeJsonSummaryPath', output_json_path, |
| 219 | '--writePath', self._temp_dir, |
| 220 | '--writeWholeImage']) |
| 221 | modified_red_tiles = copy.deepcopy(RED_TILES) |
| 222 | modified_red_tiles[5]['comparisonResult'] = 'no-comparison' |
| 223 | expected_summary_dict = { |
| 224 | "header" : EXPECTED_HEADER_CONTENTS, |
| 225 | "actual-results" : { |
| 226 | "red.skp": { |
| 227 | "tiled-images": modified_red_tiles, |
| 228 | "whole-image": modified_dict( |
| 229 | RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), |
| 230 | }, |
| 231 | "green.skp": { |
| 232 | "tiled-images": GREEN_TILES, |
| 233 | "whole-image": GREEN_WHOLEIMAGE, |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 238 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 239 | def test_untiled(self): |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 240 | """Run without tiles.""" |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 241 | output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 242 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 243 | expectations_path = self._create_expectations() |
| 244 | self._run_render_pictures([ |
| 245 | '-r', self._input_skp_dir, |
| 246 | '--readJsonSummaryPath', expectations_path, |
| 247 | '--writePath', self._temp_dir, |
| 248 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 249 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 250 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 251 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 252 | "red.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 253 | "whole-image": RED_WHOLEIMAGE, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 254 | }, |
| 255 | "green.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 256 | "whole-image": GREEN_WHOLEIMAGE, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | } |
| 260 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 261 | self._assert_directory_contents( |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 262 | self._temp_dir, ['red_skp.png', 'green_skp.png', 'actuals.json']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 263 | |
| 264 | def test_untiled_writeChecksumBasedFilenames(self): |
| 265 | """Same as test_untiled, but with --writeChecksumBasedFilenames.""" |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 266 | output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 267 | self._generate_skps() |
| 268 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 269 | '--writeChecksumBasedFilenames', |
| 270 | '--writePath', self._temp_dir, |
| 271 | '--writeJsonSummaryPath', output_json_path]) |
| 272 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 273 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 274 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 275 | "red.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 276 | # Manually verified: 640x400 red rectangle with black border |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 277 | "whole-image": { |
| 278 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 279 | "checksumValue" : 11092453015575919668, |
| 280 | "comparisonResult" : "no-comparison", |
| 281 | "filepath" : "red_skp/bitmap-64bitMD5_11092453015575919668.png", |
| 282 | }, |
| 283 | }, |
| 284 | "green.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 285 | # Manually verified: 640x400 green rectangle with black border |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 286 | "whole-image": { |
| 287 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 288 | "checksumValue" : 8891695120562235492, |
| 289 | "comparisonResult" : "no-comparison", |
| 290 | "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492.png", |
| 291 | }, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | } |
| 295 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 296 | self._assert_directory_contents(self._temp_dir, [ |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 297 | 'red_skp', 'green_skp', 'actuals.json']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 298 | self._assert_directory_contents( |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 299 | os.path.join(self._temp_dir, 'red_skp'), |
| 300 | ['bitmap-64bitMD5_11092453015575919668.png']) |
| 301 | self._assert_directory_contents( |
| 302 | os.path.join(self._temp_dir, 'green_skp'), |
| 303 | ['bitmap-64bitMD5_8891695120562235492.png']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 304 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 305 | def test_untiled_validate(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 306 | """Same as test_untiled, but with --validate.""" |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 307 | output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 308 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 309 | expectations_path = self._create_expectations() |
| 310 | self._run_render_pictures([ |
| 311 | '-r', self._input_skp_dir, |
| 312 | '--readJsonSummaryPath', expectations_path, |
| 313 | '--validate', |
| 314 | '--writePath', self._temp_dir, |
| 315 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 316 | expected_summary_dict = { |
| 317 | "header" : EXPECTED_HEADER_CONTENTS, |
| 318 | "actual-results" : { |
| 319 | "red.skp": { |
| 320 | "whole-image": RED_WHOLEIMAGE, |
| 321 | }, |
| 322 | "green.skp": { |
| 323 | "whole-image": GREEN_WHOLEIMAGE, |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 328 | self._assert_directory_contents( |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 329 | self._temp_dir, ['red_skp.png', 'green_skp.png', 'actuals.json']) |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 330 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 331 | def test_untiled_without_writePath(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 332 | """Same as test_untiled, but without --writePath.""" |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 333 | output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 334 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 335 | expectations_path = self._create_expectations() |
| 336 | self._run_render_pictures([ |
| 337 | '-r', self._input_skp_dir, |
| 338 | '--readJsonSummaryPath', expectations_path, |
| 339 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 340 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 341 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 342 | "actual-results" : { |
| 343 | "red.skp": { |
| 344 | "whole-image": RED_WHOLEIMAGE, |
| 345 | }, |
| 346 | "green.skp": { |
| 347 | "whole-image": GREEN_WHOLEIMAGE, |
| 348 | } |
| 349 | } |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 350 | } |
| 351 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 352 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 353 | def test_tiled(self): |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 354 | """Generate individual tiles.""" |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 355 | output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 356 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 357 | expectations_path = self._create_expectations() |
| 358 | self._run_render_pictures([ |
| 359 | '-r', self._input_skp_dir, |
| 360 | '--bbh', 'grid', '256', '256', |
| 361 | '--mode', 'tile', '256', '256', |
| 362 | '--readJsonSummaryPath', expectations_path, |
| 363 | '--writePath', self._temp_dir, |
| 364 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 365 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 366 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 367 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 368 | "red.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 369 | "tiled-images": RED_TILES, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 370 | }, |
| 371 | "green.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 372 | "tiled-images": GREEN_TILES, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 373 | } |
| 374 | } |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 375 | } |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 376 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 377 | self._assert_directory_contents( |
| 378 | self._temp_dir, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 379 | ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', |
| 380 | 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png', |
| 381 | 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png', |
| 382 | 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png', |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 383 | 'actuals.json']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 384 | |
| 385 | def test_tiled_writeChecksumBasedFilenames(self): |
| 386 | """Same as test_tiled, but with --writeChecksumBasedFilenames.""" |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 387 | output_json_path = os.path.join(self._temp_dir, 'actuals.json') |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 388 | self._generate_skps() |
| 389 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 390 | '--bbh', 'grid', '256', '256', |
| 391 | '--mode', 'tile', '256', '256', |
| 392 | '--writeChecksumBasedFilenames', |
| 393 | '--writePath', self._temp_dir, |
| 394 | '--writeJsonSummaryPath', output_json_path]) |
| 395 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 396 | "header" : EXPECTED_HEADER_CONTENTS, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 397 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 398 | "red.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 399 | # Manually verified these 6 images, all 256x256 tiles, |
| 400 | # consistent with a tiled version of the 640x400 red rect |
| 401 | # with black borders. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 402 | "tiled-images": [{ |
| 403 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 404 | "checksumValue" : 5815827069051002745, |
| 405 | "comparisonResult" : "no-comparison", |
| 406 | "filepath" : "red_skp/bitmap-64bitMD5_5815827069051002745.png", |
| 407 | }, { |
| 408 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 409 | "checksumValue" : 9323613075234140270, |
| 410 | "comparisonResult" : "no-comparison", |
| 411 | "filepath" : "red_skp/bitmap-64bitMD5_9323613075234140270.png", |
| 412 | }, { |
| 413 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 414 | "checksumValue" : 16670399404877552232, |
| 415 | "comparisonResult" : "no-comparison", |
| 416 | "filepath" : "red_skp/bitmap-64bitMD5_16670399404877552232.png", |
| 417 | }, { |
| 418 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 419 | "checksumValue" : 2507897274083364964, |
| 420 | "comparisonResult" : "no-comparison", |
| 421 | "filepath" : "red_skp/bitmap-64bitMD5_2507897274083364964.png", |
| 422 | }, { |
| 423 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 424 | "checksumValue" : 7325267995523877959, |
| 425 | "comparisonResult" : "no-comparison", |
| 426 | "filepath" : "red_skp/bitmap-64bitMD5_7325267995523877959.png", |
| 427 | }, { |
| 428 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 429 | "checksumValue" : 2181381724594493116, |
| 430 | "comparisonResult" : "no-comparison", |
| 431 | "filepath" : "red_skp/bitmap-64bitMD5_2181381724594493116.png", |
| 432 | }], |
| 433 | }, |
| 434 | "green.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 435 | # Manually verified these 6 images, all 256x256 tiles, |
| 436 | # consistent with a tiled version of the 640x400 green rect |
| 437 | # with black borders. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 438 | "tiled-images": [{ |
| 439 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 440 | "checksumValue" : 12587324416545178013, |
| 441 | "comparisonResult" : "no-comparison", |
| 442 | "filepath" : "green_skp/bitmap-64bitMD5_12587324416545178013.png", |
| 443 | }, { |
| 444 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 445 | "checksumValue" : 7624374914829746293, |
| 446 | "comparisonResult" : "no-comparison", |
| 447 | "filepath" : "green_skp/bitmap-64bitMD5_7624374914829746293.png", |
| 448 | }, { |
| 449 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 450 | "checksumValue" : 5686489729535631913, |
| 451 | "comparisonResult" : "no-comparison", |
| 452 | "filepath" : "green_skp/bitmap-64bitMD5_5686489729535631913.png", |
| 453 | }, { |
| 454 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 455 | "checksumValue" : 7980646035555096146, |
| 456 | "comparisonResult" : "no-comparison", |
| 457 | "filepath" : "green_skp/bitmap-64bitMD5_7980646035555096146.png", |
| 458 | }, { |
| 459 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 460 | "checksumValue" : 17817086664365875131, |
| 461 | "comparisonResult" : "no-comparison", |
| 462 | "filepath" : "green_skp/bitmap-64bitMD5_17817086664365875131.png", |
| 463 | }, { |
| 464 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 465 | "checksumValue" : 10673669813016809363, |
| 466 | "comparisonResult" : "no-comparison", |
| 467 | "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363.png", |
| 468 | }], |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | } |
| 472 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 473 | self._assert_directory_contents(self._temp_dir, [ |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 474 | 'red_skp', 'green_skp', 'actuals.json']) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 475 | self._assert_directory_contents( |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 476 | os.path.join(self._temp_dir, 'red_skp'), |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 477 | ['bitmap-64bitMD5_5815827069051002745.png', |
| 478 | 'bitmap-64bitMD5_9323613075234140270.png', |
| 479 | 'bitmap-64bitMD5_16670399404877552232.png', |
| 480 | 'bitmap-64bitMD5_2507897274083364964.png', |
| 481 | 'bitmap-64bitMD5_7325267995523877959.png', |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 482 | 'bitmap-64bitMD5_2181381724594493116.png']) |
| 483 | self._assert_directory_contents( |
| 484 | os.path.join(self._temp_dir, 'green_skp'), |
| 485 | ['bitmap-64bitMD5_12587324416545178013.png', |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 486 | 'bitmap-64bitMD5_7624374914829746293.png', |
| 487 | 'bitmap-64bitMD5_5686489729535631913.png', |
| 488 | 'bitmap-64bitMD5_7980646035555096146.png', |
| 489 | 'bitmap-64bitMD5_17817086664365875131.png', |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 490 | 'bitmap-64bitMD5_10673669813016809363.png']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 491 | |
| 492 | def _run_render_pictures(self, args): |
| 493 | binary = self.find_path_to_program('render_pictures') |
| 494 | return self.run_command([binary, |
| 495 | '--clone', '1', |
| 496 | '--config', '8888', |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 497 | ] + args) |
| 498 | |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 499 | def _create_expectations(self, missing_some_images=False, |
| 500 | rel_path='expectations.json'): |
| 501 | """Creates expectations JSON file within self._expectations_dir . |
| 502 | |
| 503 | Args: |
| 504 | missing_some_images: (bool) whether to remove expectations for a subset |
| 505 | of the images |
| 506 | rel_path: (string) relative path within self._expectations_dir to write |
| 507 | the expectations into |
| 508 | |
| 509 | Returns: full path to the expectations file created. |
| 510 | """ |
| 511 | expectations_dict = { |
| 512 | "header" : EXPECTED_HEADER_CONTENTS, |
| 513 | "expected-results" : { |
| 514 | # red.skp: these should fail the comparison |
| 515 | "red.skp": { |
| 516 | "tiled-images": modified_list_of_dicts( |
| 517 | RED_TILES, {'checksumValue': 11111}), |
| 518 | "whole-image": modified_dict( |
| 519 | RED_WHOLEIMAGE, {'checksumValue': 22222}), |
| 520 | }, |
| 521 | # green.skp: these should pass the comparison |
| 522 | "green.skp": { |
| 523 | "tiled-images": GREEN_TILES, |
| 524 | "whole-image": GREEN_WHOLEIMAGE, |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | if missing_some_images: |
| 529 | del expectations_dict['expected-results']['red.skp']['whole-image'] |
| 530 | del expectations_dict['expected-results']['red.skp']['tiled-images'][-1] |
| 531 | path = os.path.join(self._expectations_dir, rel_path) |
| 532 | with open(path, 'w') as fh: |
| 533 | json.dump(expectations_dict, fh) |
| 534 | return path |
| 535 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 536 | def _generate_skps(self): |
| 537 | """Runs the skpmaker binary to generate files in self._input_skp_dir.""" |
| 538 | self._run_skpmaker( |
| 539 | output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255) |
| 540 | self._run_skpmaker( |
| 541 | output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255) |
| 542 | |
| 543 | def _run_skpmaker(self, output_path, red=0, green=0, blue=0, |
| 544 | width=640, height=400): |
| 545 | """Runs the skpmaker binary to generate SKP with known characteristics. |
| 546 | |
| 547 | Args: |
| 548 | output_path: Filepath to write the SKP into. |
| 549 | red: Value of red color channel in image, 0-255. |
| 550 | green: Value of green color channel in image, 0-255. |
| 551 | blue: Value of blue color channel in image, 0-255. |
| 552 | width: Width of canvas to create. |
| 553 | height: Height of canvas to create. |
| 554 | """ |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 555 | binary = self.find_path_to_program('skpmaker') |
| 556 | return self.run_command([binary, |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 557 | '--red', str(red), |
| 558 | '--green', str(green), |
| 559 | '--blue', str(blue), |
| 560 | '--width', str(width), |
| 561 | '--height', str(height), |
| 562 | '--writePath', str(output_path), |
| 563 | ]) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 564 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 565 | def _assert_directory_contents(self, dir_path, expected_filenames): |
| 566 | """Asserts that files found in a dir are identical to expected_filenames. |
| 567 | |
| 568 | Args: |
| 569 | dir_path: Path to a directory on local disk. |
| 570 | expected_filenames: Set containing the expected filenames within the dir. |
| 571 | |
| 572 | Raises: |
| 573 | AssertionError: contents of the directory are not identical to |
| 574 | expected_filenames. |
| 575 | """ |
| 576 | self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames)) |
| 577 | |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 578 | def _assert_json_contents(self, json_path, expected_dict): |
| 579 | """Asserts that contents of a JSON file are identical to expected_dict. |
| 580 | |
| 581 | Args: |
| 582 | json_path: Path to a JSON file. |
| 583 | expected_dict: Dictionary indicating the expected contents of the JSON |
| 584 | file. |
| 585 | |
| 586 | Raises: |
| 587 | AssertionError: contents of the JSON file are not identical to |
| 588 | expected_dict. |
| 589 | """ |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame^] | 590 | prettyprinted_expected_dict = json.dumps(expected_dict, sort_keys=True, |
| 591 | indent=2) |
| 592 | with open(json_path, 'r') as fh: |
| 593 | prettyprinted_json_dict = json.dumps(json.load(fh), sort_keys=True, |
| 594 | indent=2) |
| 595 | self.assertMultiLineEqual(prettyprinted_expected_dict, |
| 596 | prettyprinted_json_dict) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 597 | |
| 598 | |
| 599 | def main(): |
| 600 | base_unittest.main(RenderPicturesTest) |
| 601 | |
| 602 | |
| 603 | if __name__ == '__main__': |
| 604 | main() |