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