aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/tests/render_pictures_test.py
blob: 6daadd8b08b46aaa95ca17af396c94f83d1ceb8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
#!/usr/bin/python

"""
Copyright 2014 Google Inc.

Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.

Test the render_pictures binary.
"""

# System-level imports
import copy
import json
import os
import shutil
import tempfile

# Must fix up PYTHONPATH before importing from within Skia
import fix_pythonpath  # pylint: disable=W0611

# Imports from within Skia
import base_unittest
import find_run_binary

# Maximum length of text diffs to show when tests fail
MAX_DIFF_LENGTH = 30000

EXPECTED_HEADER_CONTENTS = {
    "type" : "ChecksummedImages",
    "revision" : 1,
}

# Manually verified: 640x400 red rectangle with black border
# Standard expectations will be set up in such a way that this image fails
# the comparison.
RED_WHOLEIMAGE = {
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 11092453015575919668,
    "comparisonResult" : "failed",
    "filepath" : "red_skp.png",
}

# Manually verified: 640x400 green rectangle with black border
# Standard expectations will be set up in such a way that this image passes
# the comparison.
GREEN_WHOLEIMAGE = {
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 8891695120562235492,
    "comparisonResult" : "succeeded",
    "filepath" : "green_skp.png",
}

# Manually verified these 6 images, all 256x256 tiles,
# consistent with a tiled version of the 640x400 red rect
# with black borders.
# Standard expectations will be set up in such a way that these images fail
# the comparison.
RED_TILES = [{
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 5815827069051002745,
    "comparisonResult" : "failed",
    "filepath" : "red_skp-tile0.png",
},{
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 9323613075234140270,
    "comparisonResult" : "failed",
    "filepath" : "red_skp-tile1.png",
}, {
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 16670399404877552232,
    "comparisonResult" : "failed",
    "filepath" : "red_skp-tile2.png",
}, {
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 2507897274083364964,
    "comparisonResult" : "failed",
    "filepath" : "red_skp-tile3.png",
}, {
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 7325267995523877959,
    "comparisonResult" : "failed",
    "filepath" : "red_skp-tile4.png",
}, {
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 2181381724594493116,
    "comparisonResult" : "failed",
    "filepath" : "red_skp-tile5.png",
}]

# Manually verified these 6 images, all 256x256 tiles,
# consistent with a tiled version of the 640x400 green rect
# with black borders.
# Standard expectations will be set up in such a way that these images pass
# the comparison.
GREEN_TILES = [{
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 12587324416545178013,
    "comparisonResult" : "succeeded",
    "filepath" : "green_skp-tile0.png",
}, {
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 7624374914829746293,
    "comparisonResult" : "succeeded",
    "filepath" : "green_skp-tile1.png",
}, {
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 5686489729535631913,
    "comparisonResult" : "succeeded",
    "filepath" : "green_skp-tile2.png",
}, {
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 7980646035555096146,
    "comparisonResult" : "succeeded",
    "filepath" : "green_skp-tile3.png",
}, {
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 17817086664365875131,
    "comparisonResult" : "succeeded",
    "filepath" : "green_skp-tile4.png",
}, {
    "checksumAlgorithm" : "bitmap-64bitMD5",
    "checksumValue" : 10673669813016809363,
    "comparisonResult" : "succeeded",
    "filepath" : "green_skp-tile5.png",
}]


def modified_dict(input_dict, modification_dict):
  """Returns a dict, with some modifications applied to it.

  Args:
    input_dict: a dictionary (which will be copied, not modified in place)
    modification_dict: a set of key/value pairs to overwrite in the dict
  """
  output_dict = input_dict.copy()
  output_dict.update(modification_dict)
  return output_dict


def modified_list_of_dicts(input_list, modification_dict):
  """Returns a list of dicts, with some modifications applied to each dict.

  Args:
    input_list: a list of dictionaries; these dicts will be copied, not
        modified in place
    modification_dict: a set of key/value pairs to overwrite in each dict
        within input_list
  """
  output_list = []
  for input_dict in input_list:
    output_dict = modified_dict(input_dict, modification_dict)
    output_list.append(output_dict)
  return output_list


class RenderPicturesTest(base_unittest.TestCase):

  def setUp(self):
    self.maxDiff = MAX_DIFF_LENGTH
    self._expectations_dir = tempfile.mkdtemp()
    self._input_skp_dir = tempfile.mkdtemp()
    # All output of render_pictures binary will go into this directory.
    self._output_dir = tempfile.mkdtemp()

  def tearDown(self):
    shutil.rmtree(self._expectations_dir)
    shutil.rmtree(self._input_skp_dir)
    shutil.rmtree(self._output_dir)

  def test_tiled_whole_image(self):
    """Run render_pictures with tiles and --writeWholeImage flag.

    TODO(epoger): This test generates undesired results!  The JSON summary
    includes both whole-image and tiled-images (as it should), but only
    whole-images are written out to disk.  See http://skbug.com/2463
    Once I fix that, I should add a similar test that exercises mismatchPath.

    TODO(epoger): I noticed that when this is run without --writePath being
    specified, this test writes red_skp.png and green_skp.png to the current
    directory.  We should fix that... if --writePath is not specified, this
    probably shouldn't write out red_skp.png and green_skp.png at all!
    See http://skbug.com/2464
    """
    output_json_path = os.path.join(self._output_dir, 'actuals.json')
    write_path_dir = self.create_empty_dir(
        path=os.path.join(self._output_dir, 'writePath'))
    self._generate_skps()
    expectations_path = self._create_expectations()
    self._run_render_pictures([
        '-r', self._input_skp_dir,
        '--bbh', 'grid', '256', '256',
        '--mode', 'tile', '256', '256',
        '--readJsonSummaryPath', expectations_path,
        '--writeJsonSummaryPath', output_json_path,
        '--writePath', write_path_dir,
        '--writeWholeImage'])
    expected_summary_dict = {
        "header" : EXPECTED_HEADER_CONTENTS,
        "image-base-gs-url" : None,
        "descriptions" : None,
        "actual-results" : {
            "red.skp": {
                "tiled-images": RED_TILES,
                "whole-image": RED_WHOLEIMAGE,
            },
            "green.skp": {
                "tiled-images": GREEN_TILES,
                "whole-image": GREEN_WHOLEIMAGE,
            }
        }
    }
    self._assert_json_contents(output_json_path, expected_summary_dict)
    self._assert_directory_contents(
        write_path_dir, ['red_skp.png', 'green_skp.png'])

  def test_ignore_some_failures(self):
    """test_tiled_whole_image, but ignoring some failed tests.
    """
    output_json_path = os.path.join(self._output_dir, 'actuals.json')
    write_path_dir = self.create_empty_dir(
        path=os.path.join(self._output_dir, 'writePath'))
    self._generate_skps()
    expectations_path = self._create_expectations(ignore_some_failures=True)
    self._run_render_pictures([
        '-r', self._input_skp_dir,
        '--bbh', 'grid', '256', '256',
        '--mode', 'tile', '256', '256',
        '--readJsonSummaryPath', expectations_path,
        '--writeJsonSummaryPath', output_json_path,
        '--writePath', write_path_dir,
        '--writeWholeImage'])
    modified_red_tiles = copy.deepcopy(RED_TILES)
    modified_red_tiles[5]['comparisonResult'] = 'failure-ignored'
    expected_summary_dict = {
        "header" : EXPECTED_HEADER_CONTENTS,
        "image-base-gs-url" : None,
        "descriptions" : None,
        "actual-results" : {
            "red.skp": {
                "tiled-images": modified_red_tiles,
                "whole-image": modified_dict(
                    RED_WHOLEIMAGE, {"comparisonResult" : "failure-ignored"}),
            },
            "green.skp": {
                "tiled-images": GREEN_TILES,
                "whole-image": GREEN_WHOLEIMAGE,
            }
        }
    }
    self._assert_json_contents(output_json_path, expected_summary_dict)
    self._assert_directory_contents(
        write_path_dir, ['red_skp.png', 'green_skp.png'])

  def test_missing_tile_and_whole_image(self):
    """test_tiled_whole_image, but missing expectations for some images.
    """
    output_json_path = os.path.join(self._output_dir, 'actuals.json')
    write_path_dir = self.create_empty_dir(
        path=os.path.join(self._output_dir, 'writePath'))
    self._generate_skps()
    expectations_path = self._create_expectations(missing_some_images=True)
    self._run_render_pictures([
        '-r', self._input_skp_dir,
        '--bbh', 'grid', '256', '256',
        '--mode', 'tile', '256', '256',
        '--readJsonSummaryPath', expectations_path,
        '--writeJsonSummaryPath', output_json_path,
        '--writePath', write_path_dir,
        '--writeWholeImage'])
    modified_red_tiles = copy.deepcopy(RED_TILES)
    modified_red_tiles[5]['comparisonResult'] = 'no-comparison'
    expected_summary_dict = {
        "header" : EXPECTED_HEADER_CONTENTS,
        "image-base-gs-url" : None,
        "descriptions" : None,
        "actual-results" : {
            "red.skp": {
                "tiled-images": modified_red_tiles,
                "whole-image": modified_dict(
                    RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}),
            },
            "green.skp": {
                "tiled-images": GREEN_TILES,
                "whole-image": GREEN_WHOLEIMAGE,
            }
        }
    }
    self._assert_json_contents(output_json_path, expected_summary_dict)

  def _test_untiled(self, expectations_path=None, expected_summary_dict=None,
                    additional_args=None):
    """Base for multiple tests without tiles.

    Args:
      expectations_path: path we should pass using --readJsonSummaryPath, or
          None if we should create the default expectations file
      expected_summary_dict: dict we should compare against the output actual
          results summary, or None if we should use a default comparison dict
      additional_args: array of command-line args to add when we run
          render_pictures
    """
    output_json_path = os.path.join(self._output_dir, 'actuals.json')
    write_path_dir = self.create_empty_dir(
        path=os.path.join(self._output_dir, 'writePath'))
    self._generate_skps()
    if expectations_path == None:
      expectations_path = self._create_expectations()
    args = [
        '-r', self._input_skp_dir,
        '--readJsonSummaryPath', expectations_path,
        '--writePath', write_path_dir,
        '--writeJsonSummaryPath', output_json_path,
    ]
    if additional_args:
      args.extend(additional_args)
    self._run_render_pictures(args)
    if expected_summary_dict == None:
      expected_summary_dict = {
          "header" : EXPECTED_HEADER_CONTENTS,
          "image-base-gs-url" : None,
          "descriptions" : None,
          "actual-results" : {
              "red.skp": {
                  "whole-image": RED_WHOLEIMAGE,
              },
              "green.skp": {
                  "whole-image": GREEN_WHOLEIMAGE,
              }
          }
      }
    self._assert_json_contents(output_json_path, expected_summary_dict)
    self._assert_directory_contents(
        write_path_dir, ['red_skp.png', 'green_skp.png'])

  def test_untiled(self):
    """Basic test without tiles."""
    self._test_untiled()

  def test_untiled_empty_expectations_file(self):
    """Same as test_untiled, but with an empty expectations file."""
    expectations_path = os.path.join(self._expectations_dir, 'empty')
    with open(expectations_path, 'w'):
      pass
    expected_summary_dict = {
        "header" : EXPECTED_HEADER_CONTENTS,
        "image-base-gs-url" : None,
        "descriptions" : None,
        "actual-results" : {
            "red.skp": {
                "whole-image": modified_dict(
                    RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}),
            },
            "green.skp": {
                "whole-image": modified_dict(
                    GREEN_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}),
            }
        }
    }
    self._test_untiled(expectations_path=expectations_path,
                       expected_summary_dict=expected_summary_dict)

  def test_untiled_writeChecksumBasedFilenames(self):
    """Same as test_untiled, but with --writeChecksumBasedFilenames."""
    output_json_path = os.path.join(self._output_dir, 'actuals.json')
    write_path_dir = self.create_empty_dir(
        path=os.path.join(self._output_dir, 'writePath'))
    self._generate_skps()
    self._run_render_pictures([
        '-r', self._input_skp_dir,
        '--descriptions', 'builder=builderName', 'renderMode=renderModeName',
        '--writeChecksumBasedFilenames',
        '--writePath', write_path_dir,
        '--writeJsonSummaryPath', output_json_path,
    ])
    expected_summary_dict = {
        "header" : EXPECTED_HEADER_CONTENTS,
        "image-base-gs-url" : None,
        "descriptions" : {
            "builder": "builderName",
            "renderMode": "renderModeName",
        },
        "actual-results" : {
            "red.skp": {
                # Manually verified: 640x400 red rectangle with black border
                "whole-image": {
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 11092453015575919668,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "red_skp/bitmap-64bitMD5_11092453015575919668.png",
                },
            },
            "green.skp": {
                # Manually verified: 640x400 green rectangle with black border
                "whole-image": {
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 8891695120562235492,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "green_skp/bitmap-64bitMD5_8891695120562235492.png",
                },
            }
        }
    }
    self._assert_json_contents(output_json_path, expected_summary_dict)
    self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp'])
    self._assert_directory_contents(
        os.path.join(write_path_dir, 'red_skp'),
        ['bitmap-64bitMD5_11092453015575919668.png'])
    self._assert_directory_contents(
        os.path.join(write_path_dir, 'green_skp'),
        ['bitmap-64bitMD5_8891695120562235492.png'])

  def test_untiled_validate(self):
    """Same as test_untiled, but with --validate."""
    self._test_untiled(additional_args=['--validate'])

  def test_untiled_without_writePath(self):
    """Same as test_untiled, but without --writePath."""
    output_json_path = os.path.join(self._output_dir, 'actuals.json')
    self._generate_skps()
    expectations_path = self._create_expectations()
    self._run_render_pictures([
        '-r', self._input_skp_dir,
        '--readJsonSummaryPath', expectations_path,
        '--writeJsonSummaryPath', output_json_path])
    expected_summary_dict = {
        "header" : EXPECTED_HEADER_CONTENTS,
        "image-base-gs-url" : None,
        "descriptions" : None,
        "actual-results" : {
            "red.skp": {
                "whole-image": RED_WHOLEIMAGE,
            },
            "green.skp": {
                "whole-image": GREEN_WHOLEIMAGE,
            }
        }
    }
    self._assert_json_contents(output_json_path, expected_summary_dict)

  def test_tiled(self):
    """Generate individual tiles."""
    output_json_path = os.path.join(self._output_dir, 'actuals.json')
    write_path_dir = self.create_empty_dir(
        path=os.path.join(self._output_dir, 'writePath'))
    self._generate_skps()
    expectations_path = self._create_expectations()
    self._run_render_pictures([
        '-r', self._input_skp_dir,
        '--bbh', 'grid', '256', '256',
        '--mode', 'tile', '256', '256',
        '--readJsonSummaryPath', expectations_path,
        '--writePath', write_path_dir,
        '--writeJsonSummaryPath', output_json_path])
    expected_summary_dict = {
        "header" : EXPECTED_HEADER_CONTENTS,
        "image-base-gs-url" : None,
        "descriptions" : None,
        "actual-results" : {
            "red.skp": {
                "tiled-images": RED_TILES,
            },
            "green.skp": {
                "tiled-images": GREEN_TILES,
            }
        }
    }
    self._assert_json_contents(output_json_path, expected_summary_dict)
    self._assert_directory_contents(
        write_path_dir,
        ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png',
         'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png',
         'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png',
         'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png',
        ])

  def test_tiled_mismatches(self):
    """Same as test_tiled, but only write out mismatching images."""
    output_json_path = os.path.join(self._output_dir, 'actuals.json')
    mismatch_path_dir = self.create_empty_dir(
        path=os.path.join(self._output_dir, 'mismatchPath'))
    self._generate_skps()
    expectations_path = self._create_expectations()
    self._run_render_pictures([
        '-r', self._input_skp_dir,
        '--bbh', 'grid', '256', '256',
        '--mode', 'tile', '256', '256',
        '--readJsonSummaryPath', expectations_path,
        '--mismatchPath', mismatch_path_dir,
        '--writeJsonSummaryPath', output_json_path])
    expected_summary_dict = {
        "header" : EXPECTED_HEADER_CONTENTS,
        "image-base-gs-url" : None,
        "descriptions" : None,
        "actual-results" : {
            "red.skp": {
                "tiled-images": RED_TILES,
            },
            "green.skp": {
                "tiled-images": GREEN_TILES,
            }
        }
    }
    self._assert_json_contents(output_json_path, expected_summary_dict)
    self._assert_directory_contents(
        mismatch_path_dir,
        ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png',
         'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png',
        ])

  def test_tiled_writeChecksumBasedFilenames(self):
    """Same as test_tiled, but with --writeChecksumBasedFilenames."""
    output_json_path = os.path.join(self._output_dir, 'actuals.json')
    write_path_dir = self.create_empty_dir(
        path=os.path.join(self._output_dir, 'writePath'))
    self._generate_skps()
    self._run_render_pictures(['-r', self._input_skp_dir,
                               '--bbh', 'grid', '256', '256',
                               '--mode', 'tile', '256', '256',
                               '--writeChecksumBasedFilenames',
                               '--writePath', write_path_dir,
                               '--writeJsonSummaryPath', output_json_path])
    expected_summary_dict = {
        "header" : EXPECTED_HEADER_CONTENTS,
        "image-base-gs-url" : None,
        "descriptions" : None,
        "actual-results" : {
            "red.skp": {
                # Manually verified these 6 images, all 256x256 tiles,
                # consistent with a tiled version of the 640x400 red rect
                # with black borders.
                "tiled-images": [{
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 5815827069051002745,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "red_skp/bitmap-64bitMD5_5815827069051002745.png",
                }, {
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 9323613075234140270,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "red_skp/bitmap-64bitMD5_9323613075234140270.png",
                }, {
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 16670399404877552232,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "red_skp/bitmap-64bitMD5_16670399404877552232.png",
                }, {
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 2507897274083364964,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "red_skp/bitmap-64bitMD5_2507897274083364964.png",
                }, {
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 7325267995523877959,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "red_skp/bitmap-64bitMD5_7325267995523877959.png",
                }, {
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 2181381724594493116,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "red_skp/bitmap-64bitMD5_2181381724594493116.png",
                }],
            },
            "green.skp": {
                # Manually verified these 6 images, all 256x256 tiles,
                # consistent with a tiled version of the 640x400 green rect
                # with black borders.
                "tiled-images": [{
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 12587324416545178013,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "green_skp/bitmap-64bitMD5_12587324416545178013.png",
                }, {
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 7624374914829746293,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "green_skp/bitmap-64bitMD5_7624374914829746293.png",
                }, {
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 5686489729535631913,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "green_skp/bitmap-64bitMD5_5686489729535631913.png",
                }, {
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 7980646035555096146,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "green_skp/bitmap-64bitMD5_7980646035555096146.png",
                }, {
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 17817086664365875131,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "green_skp/bitmap-64bitMD5_17817086664365875131.png",
                }, {
                    "checksumAlgorithm" : "bitmap-64bitMD5",
                    "checksumValue" : 10673669813016809363,
                    "comparisonResult" : "no-comparison",
                    "filepath" :
                        "green_skp/bitmap-64bitMD5_10673669813016809363.png",
                }],
            }
        }
    }
    self._assert_json_contents(output_json_path, expected_summary_dict)
    self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp'])
    self._assert_directory_contents(
        os.path.join(write_path_dir, 'red_skp'),
        ['bitmap-64bitMD5_5815827069051002745.png',
         'bitmap-64bitMD5_9323613075234140270.png',
         'bitmap-64bitMD5_16670399404877552232.png',
         'bitmap-64bitMD5_2507897274083364964.png',
         'bitmap-64bitMD5_7325267995523877959.png',
         'bitmap-64bitMD5_2181381724594493116.png'])
    self._assert_directory_contents(
        os.path.join(write_path_dir, 'green_skp'),
        ['bitmap-64bitMD5_12587324416545178013.png',
         'bitmap-64bitMD5_7624374914829746293.png',
         'bitmap-64bitMD5_5686489729535631913.png',
         'bitmap-64bitMD5_7980646035555096146.png',
         'bitmap-64bitMD5_17817086664365875131.png',
         'bitmap-64bitMD5_10673669813016809363.png'])

  def _run_render_pictures(self, args):
    binary = find_run_binary.find_path_to_program('render_pictures')
    return find_run_binary.run_command(
        [binary, '--config', '8888'] + args)

  def _create_expectations(self, missing_some_images=False,
                           ignore_some_failures=False,
                           rel_path='expectations.json'):
    """Creates expectations JSON file within self._expectations_dir .

    Args:
      missing_some_images: (bool) whether to remove expectations for a subset
          of the images
      ignore_some_failures: (bool) whether to ignore some failing tests
      rel_path: (string) relative path within self._expectations_dir to write
          the expectations into

    Returns: full path to the expectations file created.
    """
    expectations_dict = {
        "header" : EXPECTED_HEADER_CONTENTS,
        "descriptions" : None,
        "expected-results" : {
            # red.skp: these should fail the comparison
            "red.skp": {
                "tiled-images": modified_list_of_dicts(
                    RED_TILES, {'checksumValue': 11111}),
                "whole-image": modified_dict(
                    RED_WHOLEIMAGE, {'checksumValue': 22222}),
            },
            # green.skp: these should pass the comparison
            "green.skp": {
                "tiled-images": GREEN_TILES,
                "whole-image": GREEN_WHOLEIMAGE,
            }
        }
    }
    if missing_some_images:
      red_subdict = expectations_dict['expected-results']['red.skp']
      del red_subdict['whole-image']
      del red_subdict['tiled-images'][-1]
    elif ignore_some_failures:
      red_subdict = expectations_dict['expected-results']['red.skp']
      red_subdict['whole-image']['ignoreFailure'] = True
      red_subdict['tiled-images'][-1]['ignoreFailure'] = True
    path = os.path.join(self._expectations_dir, rel_path)
    with open(path, 'w') as fh:
      json.dump(expectations_dict, fh)
    return path

  def _generate_skps(self):
    """Runs the skpmaker binary to generate files in self._input_skp_dir."""
    self._run_skpmaker(
        output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255)
    self._run_skpmaker(
        output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255)

  def _run_skpmaker(self, output_path, red=0, green=0, blue=0,
                    width=640, height=400):
    """Runs the skpmaker binary to generate SKP with known characteristics.

    Args:
      output_path: Filepath to write the SKP into.
      red: Value of red color channel in image, 0-255.
      green: Value of green color channel in image, 0-255.
      blue: Value of blue color channel in image, 0-255.
      width: Width of canvas to create.
      height: Height of canvas to create.
    """
    binary = find_run_binary.find_path_to_program('skpmaker')
    return find_run_binary.run_command([
        binary,
        '--red', str(red),
        '--green', str(green),
        '--blue', str(blue),
        '--width', str(width),
        '--height', str(height),
        '--writePath', str(output_path),
    ])

  def _assert_directory_contents(self, dir_path, expected_filenames):
    """Asserts that files found in a dir are identical to expected_filenames.

    Args:
      dir_path: Path to a directory on local disk.
      expected_filenames: Set containing the expected filenames within the dir.

    Raises:
      AssertionError: contents of the directory are not identical to
                      expected_filenames.
    """
    self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames))

  def _assert_json_contents(self, json_path, expected_dict):
    """Asserts that contents of a JSON file are identical to expected_dict.

    Args:
      json_path: Path to a JSON file.
      expected_dict: Dictionary indicating the expected contents of the JSON
                     file.

    Raises:
      AssertionError: contents of the JSON file are not identical to
                      expected_dict.
    """
    prettyprinted_expected_dict = json.dumps(expected_dict, sort_keys=True,
                                             indent=2)
    with open(json_path, 'r') as fh:
      prettyprinted_json_dict = json.dumps(json.load(fh), sort_keys=True,
                                           indent=2)
    self.assertMultiLineEqual(prettyprinted_expected_dict,
                              prettyprinted_json_dict)


def main():
  base_unittest.main(RenderPicturesTest)


if __name__ == '__main__':
  main()