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", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 39 | "checksumValue" : 2853310525600416231, |
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", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 49 | "checksumValue" : 11143979097452425335, |
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", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 71 | "checksumValue" : 15939355025996362179, |
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", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 76 | "checksumValue" : 649771916797529222, |
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", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 81 | "checksumValue" : 8132820002266077288, |
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", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 86 | "checksumValue" : 2406160701181324581, |
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", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 108 | "checksumValue" : 11866144860997809880, |
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", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 113 | "checksumValue" : 3893392565127823822, |
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", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 118 | "checksumValue" : 2083084978343901738, |
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", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 123 | "checksumValue" : 89620927366502076, |
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, |
rmistry | 2529f2e | 2014-08-22 04:46:30 -0700 | [diff] [blame] | 200 | "image-base-gs-url" : None, |
epoger | b492c6f | 2014-08-14 07:32:49 -0700 | [diff] [blame] | 201 | "descriptions" : None, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 202 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 203 | "red.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 204 | "tiled-images": RED_TILES, |
| 205 | "whole-image": RED_WHOLEIMAGE, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 206 | }, |
| 207 | "green.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 208 | "tiled-images": GREEN_TILES, |
| 209 | "whole-image": GREEN_WHOLEIMAGE, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 210 | } |
| 211 | } |
commit-bot@chromium.org | 238771c | 2014-01-15 16:33:31 +0000 | [diff] [blame] | 212 | } |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 213 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 214 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 215 | write_path_dir, ['red_skp.png', 'green_skp.png']) |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 216 | |
epoger | 85b438d | 2014-08-21 23:21:32 -0700 | [diff] [blame] | 217 | def test_ignore_some_failures(self): |
| 218 | """test_tiled_whole_image, but ignoring some failed tests. |
| 219 | """ |
| 220 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 221 | write_path_dir = self.create_empty_dir( |
| 222 | path=os.path.join(self._output_dir, 'writePath')) |
| 223 | self._generate_skps() |
| 224 | expectations_path = self._create_expectations(ignore_some_failures=True) |
| 225 | self._run_render_pictures([ |
| 226 | '-r', self._input_skp_dir, |
| 227 | '--bbh', 'grid', '256', '256', |
| 228 | '--mode', 'tile', '256', '256', |
| 229 | '--readJsonSummaryPath', expectations_path, |
| 230 | '--writeJsonSummaryPath', output_json_path, |
| 231 | '--writePath', write_path_dir, |
| 232 | '--writeWholeImage']) |
| 233 | modified_red_tiles = copy.deepcopy(RED_TILES) |
| 234 | modified_red_tiles[5]['comparisonResult'] = 'failure-ignored' |
| 235 | expected_summary_dict = { |
| 236 | "header" : EXPECTED_HEADER_CONTENTS, |
rmistry | 2529f2e | 2014-08-22 04:46:30 -0700 | [diff] [blame] | 237 | "image-base-gs-url" : None, |
epoger | 85b438d | 2014-08-21 23:21:32 -0700 | [diff] [blame] | 238 | "descriptions" : None, |
| 239 | "actual-results" : { |
| 240 | "red.skp": { |
| 241 | "tiled-images": modified_red_tiles, |
| 242 | "whole-image": modified_dict( |
| 243 | RED_WHOLEIMAGE, {"comparisonResult" : "failure-ignored"}), |
| 244 | }, |
| 245 | "green.skp": { |
| 246 | "tiled-images": GREEN_TILES, |
| 247 | "whole-image": GREEN_WHOLEIMAGE, |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 252 | self._assert_directory_contents( |
| 253 | write_path_dir, ['red_skp.png', 'green_skp.png']) |
| 254 | |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 255 | def test_missing_tile_and_whole_image(self): |
| 256 | """test_tiled_whole_image, but missing expectations for some images. |
| 257 | """ |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 258 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 259 | write_path_dir = self.create_empty_dir( |
| 260 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 261 | self._generate_skps() |
| 262 | expectations_path = self._create_expectations(missing_some_images=True) |
| 263 | self._run_render_pictures([ |
| 264 | '-r', self._input_skp_dir, |
| 265 | '--bbh', 'grid', '256', '256', |
| 266 | '--mode', 'tile', '256', '256', |
| 267 | '--readJsonSummaryPath', expectations_path, |
| 268 | '--writeJsonSummaryPath', output_json_path, |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 269 | '--writePath', write_path_dir, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 270 | '--writeWholeImage']) |
| 271 | modified_red_tiles = copy.deepcopy(RED_TILES) |
| 272 | modified_red_tiles[5]['comparisonResult'] = 'no-comparison' |
| 273 | expected_summary_dict = { |
| 274 | "header" : EXPECTED_HEADER_CONTENTS, |
rmistry | 2529f2e | 2014-08-22 04:46:30 -0700 | [diff] [blame] | 275 | "image-base-gs-url" : None, |
epoger | b492c6f | 2014-08-14 07:32:49 -0700 | [diff] [blame] | 276 | "descriptions" : None, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 277 | "actual-results" : { |
| 278 | "red.skp": { |
| 279 | "tiled-images": modified_red_tiles, |
| 280 | "whole-image": modified_dict( |
| 281 | RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), |
| 282 | }, |
| 283 | "green.skp": { |
| 284 | "tiled-images": GREEN_TILES, |
| 285 | "whole-image": GREEN_WHOLEIMAGE, |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 290 | |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 291 | def _test_untiled(self, expectations_path=None, expected_summary_dict=None, |
| 292 | additional_args=None): |
| 293 | """Base for multiple tests without tiles. |
| 294 | |
| 295 | Args: |
| 296 | expectations_path: path we should pass using --readJsonSummaryPath, or |
| 297 | None if we should create the default expectations file |
| 298 | expected_summary_dict: dict we should compare against the output actual |
| 299 | results summary, or None if we should use a default comparison dict |
| 300 | additional_args: array of command-line args to add when we run |
| 301 | render_pictures |
| 302 | """ |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 303 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 304 | write_path_dir = self.create_empty_dir( |
| 305 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 306 | self._generate_skps() |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 307 | if expectations_path == None: |
| 308 | expectations_path = self._create_expectations() |
| 309 | args = [ |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 310 | '-r', self._input_skp_dir, |
| 311 | '--readJsonSummaryPath', expectations_path, |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 312 | '--writePath', write_path_dir, |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 313 | '--writeJsonSummaryPath', output_json_path, |
| 314 | ] |
| 315 | if additional_args: |
| 316 | args.extend(additional_args) |
| 317 | self._run_render_pictures(args) |
| 318 | if expected_summary_dict == None: |
| 319 | expected_summary_dict = { |
| 320 | "header" : EXPECTED_HEADER_CONTENTS, |
rmistry | 2529f2e | 2014-08-22 04:46:30 -0700 | [diff] [blame] | 321 | "image-base-gs-url" : None, |
epoger | b492c6f | 2014-08-14 07:32:49 -0700 | [diff] [blame] | 322 | "descriptions" : None, |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 323 | "actual-results" : { |
| 324 | "red.skp": { |
| 325 | "whole-image": RED_WHOLEIMAGE, |
| 326 | }, |
| 327 | "green.skp": { |
| 328 | "whole-image": GREEN_WHOLEIMAGE, |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 333 | self._assert_directory_contents( |
| 334 | write_path_dir, ['red_skp.png', 'green_skp.png']) |
| 335 | |
| 336 | def test_untiled(self): |
| 337 | """Basic test without tiles.""" |
| 338 | self._test_untiled() |
| 339 | |
| 340 | def test_untiled_empty_expectations_file(self): |
| 341 | """Same as test_untiled, but with an empty expectations file.""" |
| 342 | expectations_path = os.path.join(self._expectations_dir, 'empty') |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 343 | with open(expectations_path, 'w'): |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 344 | pass |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 345 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 346 | "header" : EXPECTED_HEADER_CONTENTS, |
rmistry | 2529f2e | 2014-08-22 04:46:30 -0700 | [diff] [blame] | 347 | "image-base-gs-url" : None, |
epoger | b492c6f | 2014-08-14 07:32:49 -0700 | [diff] [blame] | 348 | "descriptions" : None, |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 349 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 350 | "red.skp": { |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 351 | "whole-image": modified_dict( |
| 352 | RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 353 | }, |
| 354 | "green.skp": { |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 355 | "whole-image": modified_dict( |
| 356 | GREEN_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | } |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 360 | self._test_untiled(expectations_path=expectations_path, |
| 361 | expected_summary_dict=expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 362 | |
| 363 | def test_untiled_writeChecksumBasedFilenames(self): |
| 364 | """Same as test_untiled, but with --writeChecksumBasedFilenames.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 365 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 366 | write_path_dir = self.create_empty_dir( |
| 367 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 368 | self._generate_skps() |
epoger | b492c6f | 2014-08-14 07:32:49 -0700 | [diff] [blame] | 369 | self._run_render_pictures([ |
| 370 | '-r', self._input_skp_dir, |
| 371 | '--descriptions', 'builder=builderName', 'renderMode=renderModeName', |
| 372 | '--writeChecksumBasedFilenames', |
| 373 | '--writePath', write_path_dir, |
| 374 | '--writeJsonSummaryPath', output_json_path, |
| 375 | ]) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 376 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 377 | "header" : EXPECTED_HEADER_CONTENTS, |
rmistry | 2529f2e | 2014-08-22 04:46:30 -0700 | [diff] [blame] | 378 | "image-base-gs-url" : None, |
epoger | b492c6f | 2014-08-14 07:32:49 -0700 | [diff] [blame] | 379 | "descriptions" : { |
| 380 | "builder": "builderName", |
| 381 | "renderMode": "renderModeName", |
| 382 | }, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 383 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 384 | "red.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 385 | # Manually verified: 640x400 red rectangle with black border |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 386 | "whole-image": { |
| 387 | "checksumAlgorithm" : "bitmap-64bitMD5", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 388 | "checksumValue" : 2853310525600416231, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 389 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 390 | "filepath" : |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 391 | "red_skp/bitmap-64bitMD5_2853310525600416231.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 392 | }, |
| 393 | }, |
| 394 | "green.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 395 | # Manually verified: 640x400 green rectangle with black border |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 396 | "whole-image": { |
| 397 | "checksumAlgorithm" : "bitmap-64bitMD5", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 398 | "checksumValue" : 11143979097452425335, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 399 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 400 | "filepath" : |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 401 | "green_skp/bitmap-64bitMD5_11143979097452425335.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 402 | }, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | } |
| 406 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 407 | 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] | 408 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 409 | os.path.join(write_path_dir, 'red_skp'), |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 410 | ['bitmap-64bitMD5_2853310525600416231.png']) |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 411 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 412 | os.path.join(write_path_dir, 'green_skp'), |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 413 | ['bitmap-64bitMD5_11143979097452425335.png']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 414 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 415 | def test_untiled_validate(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 416 | """Same as test_untiled, but with --validate.""" |
commit-bot@chromium.org | abeb958 | 2014-05-19 15:25:10 +0000 | [diff] [blame] | 417 | self._test_untiled(additional_args=['--validate']) |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 418 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 419 | def test_untiled_without_writePath(self): |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 420 | """Same as test_untiled, but without --writePath.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 421 | 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] | 422 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 423 | expectations_path = self._create_expectations() |
| 424 | self._run_render_pictures([ |
| 425 | '-r', self._input_skp_dir, |
| 426 | '--readJsonSummaryPath', expectations_path, |
| 427 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 428 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 429 | "header" : EXPECTED_HEADER_CONTENTS, |
rmistry | 2529f2e | 2014-08-22 04:46:30 -0700 | [diff] [blame] | 430 | "image-base-gs-url" : None, |
epoger | b492c6f | 2014-08-14 07:32:49 -0700 | [diff] [blame] | 431 | "descriptions" : None, |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 432 | "actual-results" : { |
| 433 | "red.skp": { |
| 434 | "whole-image": RED_WHOLEIMAGE, |
| 435 | }, |
| 436 | "green.skp": { |
| 437 | "whole-image": GREEN_WHOLEIMAGE, |
| 438 | } |
| 439 | } |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 440 | } |
| 441 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 442 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 443 | def test_tiled(self): |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 444 | """Generate individual tiles.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 445 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 446 | write_path_dir = self.create_empty_dir( |
| 447 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 448 | self._generate_skps() |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 449 | expectations_path = self._create_expectations() |
| 450 | self._run_render_pictures([ |
| 451 | '-r', self._input_skp_dir, |
| 452 | '--bbh', 'grid', '256', '256', |
| 453 | '--mode', 'tile', '256', '256', |
| 454 | '--readJsonSummaryPath', expectations_path, |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 455 | '--writePath', write_path_dir, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 456 | '--writeJsonSummaryPath', output_json_path]) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 457 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 458 | "header" : EXPECTED_HEADER_CONTENTS, |
rmistry | 2529f2e | 2014-08-22 04:46:30 -0700 | [diff] [blame] | 459 | "image-base-gs-url" : None, |
epoger | b492c6f | 2014-08-14 07:32:49 -0700 | [diff] [blame] | 460 | "descriptions" : None, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 461 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 462 | "red.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 463 | "tiled-images": RED_TILES, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 464 | }, |
| 465 | "green.skp": { |
commit-bot@chromium.org | 4610a46 | 2014-04-29 19:39:22 +0000 | [diff] [blame] | 466 | "tiled-images": GREEN_TILES, |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 467 | } |
| 468 | } |
commit-bot@chromium.org | c3147c6 | 2014-01-15 20:35:54 +0000 | [diff] [blame] | 469 | } |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 470 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 471 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 472 | write_path_dir, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 473 | ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', |
| 474 | 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png', |
| 475 | 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png', |
| 476 | '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] | 477 | ]) |
| 478 | |
| 479 | def test_tiled_mismatches(self): |
| 480 | """Same as test_tiled, but only write out mismatching images.""" |
| 481 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 482 | mismatch_path_dir = self.create_empty_dir( |
| 483 | path=os.path.join(self._output_dir, 'mismatchPath')) |
| 484 | self._generate_skps() |
| 485 | expectations_path = self._create_expectations() |
| 486 | self._run_render_pictures([ |
| 487 | '-r', self._input_skp_dir, |
| 488 | '--bbh', 'grid', '256', '256', |
| 489 | '--mode', 'tile', '256', '256', |
| 490 | '--readJsonSummaryPath', expectations_path, |
| 491 | '--mismatchPath', mismatch_path_dir, |
| 492 | '--writeJsonSummaryPath', output_json_path]) |
| 493 | expected_summary_dict = { |
| 494 | "header" : EXPECTED_HEADER_CONTENTS, |
rmistry | 2529f2e | 2014-08-22 04:46:30 -0700 | [diff] [blame] | 495 | "image-base-gs-url" : None, |
epoger | b492c6f | 2014-08-14 07:32:49 -0700 | [diff] [blame] | 496 | "descriptions" : None, |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 497 | "actual-results" : { |
| 498 | "red.skp": { |
| 499 | "tiled-images": RED_TILES, |
| 500 | }, |
| 501 | "green.skp": { |
| 502 | "tiled-images": GREEN_TILES, |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | self._assert_json_contents(output_json_path, expected_summary_dict) |
| 507 | self._assert_directory_contents( |
| 508 | mismatch_path_dir, |
| 509 | ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png', |
| 510 | 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png', |
| 511 | ]) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 512 | |
| 513 | def test_tiled_writeChecksumBasedFilenames(self): |
| 514 | """Same as test_tiled, but with --writeChecksumBasedFilenames.""" |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 515 | output_json_path = os.path.join(self._output_dir, 'actuals.json') |
| 516 | write_path_dir = self.create_empty_dir( |
| 517 | path=os.path.join(self._output_dir, 'writePath')) |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 518 | self._generate_skps() |
| 519 | self._run_render_pictures(['-r', self._input_skp_dir, |
| 520 | '--bbh', 'grid', '256', '256', |
| 521 | '--mode', 'tile', '256', '256', |
| 522 | '--writeChecksumBasedFilenames', |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 523 | '--writePath', write_path_dir, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 524 | '--writeJsonSummaryPath', output_json_path]) |
| 525 | expected_summary_dict = { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 526 | "header" : EXPECTED_HEADER_CONTENTS, |
rmistry | 2529f2e | 2014-08-22 04:46:30 -0700 | [diff] [blame] | 527 | "image-base-gs-url" : None, |
epoger | b492c6f | 2014-08-14 07:32:49 -0700 | [diff] [blame] | 528 | "descriptions" : None, |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 529 | "actual-results" : { |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 530 | "red.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 531 | # Manually verified these 6 images, all 256x256 tiles, |
| 532 | # consistent with a tiled version of the 640x400 red rect |
| 533 | # with black borders. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 534 | "tiled-images": [{ |
| 535 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 536 | "checksumValue" : 5815827069051002745, |
| 537 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 538 | "filepath" : |
| 539 | "red_skp/bitmap-64bitMD5_5815827069051002745.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 540 | }, { |
| 541 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 542 | "checksumValue" : 9323613075234140270, |
| 543 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 544 | "filepath" : |
| 545 | "red_skp/bitmap-64bitMD5_9323613075234140270.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 546 | }, { |
| 547 | "checksumAlgorithm" : "bitmap-64bitMD5", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 548 | "checksumValue" : 15939355025996362179, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 549 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 550 | "filepath" : |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 551 | "red_skp/bitmap-64bitMD5_15939355025996362179.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 552 | }, { |
| 553 | "checksumAlgorithm" : "bitmap-64bitMD5", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 554 | "checksumValue" : 649771916797529222, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 555 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 556 | "filepath" : |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 557 | "red_skp/bitmap-64bitMD5_649771916797529222.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 558 | }, { |
| 559 | "checksumAlgorithm" : "bitmap-64bitMD5", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 560 | "checksumValue" : 8132820002266077288, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 561 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 562 | "filepath" : |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 563 | "red_skp/bitmap-64bitMD5_8132820002266077288.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 564 | }, { |
| 565 | "checksumAlgorithm" : "bitmap-64bitMD5", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 566 | "checksumValue" : 2406160701181324581, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 567 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 568 | "filepath" : |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 569 | "red_skp/bitmap-64bitMD5_2406160701181324581.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 570 | }], |
| 571 | }, |
| 572 | "green.skp": { |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 573 | # Manually verified these 6 images, all 256x256 tiles, |
| 574 | # consistent with a tiled version of the 640x400 green rect |
| 575 | # with black borders. |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 576 | "tiled-images": [{ |
| 577 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 578 | "checksumValue" : 12587324416545178013, |
| 579 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 580 | "filepath" : |
| 581 | "green_skp/bitmap-64bitMD5_12587324416545178013.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 582 | }, { |
| 583 | "checksumAlgorithm" : "bitmap-64bitMD5", |
| 584 | "checksumValue" : 7624374914829746293, |
| 585 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 586 | "filepath" : |
| 587 | "green_skp/bitmap-64bitMD5_7624374914829746293.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 588 | }, { |
| 589 | "checksumAlgorithm" : "bitmap-64bitMD5", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 590 | "checksumValue" : 11866144860997809880, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 591 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 592 | "filepath" : |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 593 | "green_skp/bitmap-64bitMD5_11866144860997809880.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 594 | }, { |
| 595 | "checksumAlgorithm" : "bitmap-64bitMD5", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 596 | "checksumValue" : 3893392565127823822, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 597 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 598 | "filepath" : |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 599 | "green_skp/bitmap-64bitMD5_3893392565127823822.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 600 | }, { |
| 601 | "checksumAlgorithm" : "bitmap-64bitMD5", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 602 | "checksumValue" : 2083084978343901738, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 603 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 604 | "filepath" : |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 605 | "green_skp/bitmap-64bitMD5_2083084978343901738.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 606 | }, { |
| 607 | "checksumAlgorithm" : "bitmap-64bitMD5", |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 608 | "checksumValue" : 89620927366502076, |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 609 | "comparisonResult" : "no-comparison", |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 610 | "filepath" : |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 611 | "green_skp/bitmap-64bitMD5_89620927366502076.png", |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 612 | }], |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | } |
| 616 | self._assert_json_contents(output_json_path, expected_summary_dict) |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 617 | 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] | 618 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 619 | os.path.join(write_path_dir, 'red_skp'), |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 620 | ['bitmap-64bitMD5_5815827069051002745.png', |
| 621 | 'bitmap-64bitMD5_9323613075234140270.png', |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 622 | 'bitmap-64bitMD5_15939355025996362179.png', |
| 623 | 'bitmap-64bitMD5_649771916797529222.png', |
| 624 | 'bitmap-64bitMD5_8132820002266077288.png', |
| 625 | 'bitmap-64bitMD5_2406160701181324581.png']) |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 626 | self._assert_directory_contents( |
commit-bot@chromium.org | 3f04517 | 2014-05-15 15:10:48 +0000 | [diff] [blame] | 627 | os.path.join(write_path_dir, 'green_skp'), |
commit-bot@chromium.org | 24c568c | 2014-04-10 15:39:02 +0000 | [diff] [blame] | 628 | ['bitmap-64bitMD5_12587324416545178013.png', |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 629 | 'bitmap-64bitMD5_7624374914829746293.png', |
stephana | 7260d72 | 2014-09-05 13:21:42 -0700 | [diff] [blame] | 630 | 'bitmap-64bitMD5_11866144860997809880.png', |
| 631 | 'bitmap-64bitMD5_3893392565127823822.png', |
| 632 | 'bitmap-64bitMD5_2083084978343901738.png', |
| 633 | 'bitmap-64bitMD5_89620927366502076.png']) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 634 | |
| 635 | def _run_render_pictures(self, args): |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 636 | binary = find_run_binary.find_path_to_program('render_pictures') |
| 637 | return find_run_binary.run_command( |
| 638 | [binary, '--config', '8888'] + args) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 639 | |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 640 | def _create_expectations(self, missing_some_images=False, |
epoger | 85b438d | 2014-08-21 23:21:32 -0700 | [diff] [blame] | 641 | ignore_some_failures=False, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 642 | rel_path='expectations.json'): |
| 643 | """Creates expectations JSON file within self._expectations_dir . |
| 644 | |
| 645 | Args: |
| 646 | missing_some_images: (bool) whether to remove expectations for a subset |
| 647 | of the images |
epoger | 85b438d | 2014-08-21 23:21:32 -0700 | [diff] [blame] | 648 | ignore_some_failures: (bool) whether to ignore some failing tests |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 649 | rel_path: (string) relative path within self._expectations_dir to write |
| 650 | the expectations into |
| 651 | |
| 652 | Returns: full path to the expectations file created. |
| 653 | """ |
| 654 | expectations_dict = { |
| 655 | "header" : EXPECTED_HEADER_CONTENTS, |
epoger | b492c6f | 2014-08-14 07:32:49 -0700 | [diff] [blame] | 656 | "descriptions" : None, |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 657 | "expected-results" : { |
| 658 | # red.skp: these should fail the comparison |
| 659 | "red.skp": { |
| 660 | "tiled-images": modified_list_of_dicts( |
| 661 | RED_TILES, {'checksumValue': 11111}), |
| 662 | "whole-image": modified_dict( |
| 663 | RED_WHOLEIMAGE, {'checksumValue': 22222}), |
| 664 | }, |
| 665 | # green.skp: these should pass the comparison |
| 666 | "green.skp": { |
| 667 | "tiled-images": GREEN_TILES, |
| 668 | "whole-image": GREEN_WHOLEIMAGE, |
| 669 | } |
| 670 | } |
| 671 | } |
| 672 | if missing_some_images: |
epoger | 85b438d | 2014-08-21 23:21:32 -0700 | [diff] [blame] | 673 | red_subdict = expectations_dict['expected-results']['red.skp'] |
| 674 | del red_subdict['whole-image'] |
| 675 | del red_subdict['tiled-images'][-1] |
| 676 | elif ignore_some_failures: |
| 677 | red_subdict = expectations_dict['expected-results']['red.skp'] |
| 678 | red_subdict['whole-image']['ignoreFailure'] = True |
| 679 | red_subdict['tiled-images'][-1]['ignoreFailure'] = True |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 680 | path = os.path.join(self._expectations_dir, rel_path) |
| 681 | with open(path, 'w') as fh: |
| 682 | json.dump(expectations_dict, fh) |
| 683 | return path |
| 684 | |
commit-bot@chromium.org | f11943f | 2014-03-12 20:09:46 +0000 | [diff] [blame] | 685 | def _generate_skps(self): |
| 686 | """Runs the skpmaker binary to generate files in self._input_skp_dir.""" |
| 687 | self._run_skpmaker( |
| 688 | output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255) |
| 689 | self._run_skpmaker( |
| 690 | output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255) |
| 691 | |
| 692 | def _run_skpmaker(self, output_path, red=0, green=0, blue=0, |
| 693 | width=640, height=400): |
| 694 | """Runs the skpmaker binary to generate SKP with known characteristics. |
| 695 | |
| 696 | Args: |
| 697 | output_path: Filepath to write the SKP into. |
| 698 | red: Value of red color channel in image, 0-255. |
| 699 | green: Value of green color channel in image, 0-255. |
| 700 | blue: Value of blue color channel in image, 0-255. |
| 701 | width: Width of canvas to create. |
| 702 | height: Height of canvas to create. |
| 703 | """ |
epoger | 66ed8dc | 2014-07-17 12:54:16 -0700 | [diff] [blame] | 704 | binary = find_run_binary.find_path_to_program('skpmaker') |
| 705 | return find_run_binary.run_command([ |
| 706 | binary, |
| 707 | '--red', str(red), |
| 708 | '--green', str(green), |
| 709 | '--blue', str(blue), |
| 710 | '--width', str(width), |
| 711 | '--height', str(height), |
| 712 | '--writePath', str(output_path), |
| 713 | ]) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 714 | |
commit-bot@chromium.org | f5e315c | 2014-03-19 17:26:07 +0000 | [diff] [blame] | 715 | def _assert_directory_contents(self, dir_path, expected_filenames): |
| 716 | """Asserts that files found in a dir are identical to expected_filenames. |
| 717 | |
| 718 | Args: |
| 719 | dir_path: Path to a directory on local disk. |
| 720 | expected_filenames: Set containing the expected filenames within the dir. |
| 721 | |
| 722 | Raises: |
| 723 | AssertionError: contents of the directory are not identical to |
| 724 | expected_filenames. |
| 725 | """ |
| 726 | self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames)) |
| 727 | |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 728 | def _assert_json_contents(self, json_path, expected_dict): |
| 729 | """Asserts that contents of a JSON file are identical to expected_dict. |
| 730 | |
| 731 | Args: |
| 732 | json_path: Path to a JSON file. |
| 733 | expected_dict: Dictionary indicating the expected contents of the JSON |
| 734 | file. |
| 735 | |
| 736 | Raises: |
| 737 | AssertionError: contents of the JSON file are not identical to |
| 738 | expected_dict. |
| 739 | """ |
commit-bot@chromium.org | 205ce48 | 2014-05-12 15:37:20 +0000 | [diff] [blame] | 740 | prettyprinted_expected_dict = json.dumps(expected_dict, sort_keys=True, |
| 741 | indent=2) |
| 742 | with open(json_path, 'r') as fh: |
| 743 | prettyprinted_json_dict = json.dumps(json.load(fh), sort_keys=True, |
| 744 | indent=2) |
| 745 | self.assertMultiLineEqual(prettyprinted_expected_dict, |
| 746 | prettyprinted_json_dict) |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame] | 747 | |
| 748 | |
| 749 | def main(): |
| 750 | base_unittest.main(RenderPicturesTest) |
| 751 | |
| 752 | |
| 753 | if __name__ == '__main__': |
| 754 | main() |