OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 """ | 3 """ |
4 Copyright 2014 Google Inc. | 4 Copyright 2014 Google Inc. |
5 | 5 |
6 Use of this source code is governed by a BSD-style license that can be | 6 Use of this source code is governed by a BSD-style license that can be |
7 found in the LICENSE file. | 7 found in the LICENSE file. |
8 | 8 |
9 Test the render_pictures binary. | 9 Test the render_pictures binary. |
10 """ | 10 """ |
11 | 11 |
12 # System-level imports | 12 # System-level imports |
13 import copy | 13 import copy |
14 import json | 14 import json |
15 import os | 15 import os |
16 import shutil | 16 import shutil |
17 import tempfile | 17 import tempfile |
18 | 18 |
| 19 # Must fix up PYTHONPATH before importing from within Skia |
| 20 import fix_pythonpath # pylint: disable=W0611 |
| 21 |
19 # Imports from within Skia | 22 # Imports from within Skia |
20 import base_unittest | 23 import base_unittest |
| 24 import find_run_binary |
21 | 25 |
22 # Maximum length of text diffs to show when tests fail | 26 # Maximum length of text diffs to show when tests fail |
23 MAX_DIFF_LENGTH = 30000 | 27 MAX_DIFF_LENGTH = 30000 |
24 | 28 |
25 EXPECTED_HEADER_CONTENTS = { | 29 EXPECTED_HEADER_CONTENTS = { |
26 "type" : "ChecksummedImages", | 30 "type" : "ChecksummedImages", |
27 "revision" : 1, | 31 "revision" : 1, |
28 } | 32 } |
29 | 33 |
30 # Manually verified: 640x400 red rectangle with black border | 34 # Manually verified: 640x400 red rectangle with black border |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 self._assert_directory_contents( | 289 self._assert_directory_contents( |
286 write_path_dir, ['red_skp.png', 'green_skp.png']) | 290 write_path_dir, ['red_skp.png', 'green_skp.png']) |
287 | 291 |
288 def test_untiled(self): | 292 def test_untiled(self): |
289 """Basic test without tiles.""" | 293 """Basic test without tiles.""" |
290 self._test_untiled() | 294 self._test_untiled() |
291 | 295 |
292 def test_untiled_empty_expectations_file(self): | 296 def test_untiled_empty_expectations_file(self): |
293 """Same as test_untiled, but with an empty expectations file.""" | 297 """Same as test_untiled, but with an empty expectations file.""" |
294 expectations_path = os.path.join(self._expectations_dir, 'empty') | 298 expectations_path = os.path.join(self._expectations_dir, 'empty') |
295 with open(expectations_path, 'w') as fh: | 299 with open(expectations_path, 'w'): |
296 pass | 300 pass |
297 expected_summary_dict = { | 301 expected_summary_dict = { |
298 "header" : EXPECTED_HEADER_CONTENTS, | 302 "header" : EXPECTED_HEADER_CONTENTS, |
299 "actual-results" : { | 303 "actual-results" : { |
300 "red.skp": { | 304 "red.skp": { |
301 "whole-image": modified_dict( | 305 "whole-image": modified_dict( |
302 RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), | 306 RED_WHOLEIMAGE, {"comparisonResult" : "no-comparison"}), |
303 }, | 307 }, |
304 "green.skp": { | 308 "green.skp": { |
305 "whole-image": modified_dict( | 309 "whole-image": modified_dict( |
(...skipping 16 matching lines...) Expand all Loading... |
322 '--writeJsonSummaryPath', output_json_path]) | 326 '--writeJsonSummaryPath', output_json_path]) |
323 expected_summary_dict = { | 327 expected_summary_dict = { |
324 "header" : EXPECTED_HEADER_CONTENTS, | 328 "header" : EXPECTED_HEADER_CONTENTS, |
325 "actual-results" : { | 329 "actual-results" : { |
326 "red.skp": { | 330 "red.skp": { |
327 # Manually verified: 640x400 red rectangle with black border | 331 # Manually verified: 640x400 red rectangle with black border |
328 "whole-image": { | 332 "whole-image": { |
329 "checksumAlgorithm" : "bitmap-64bitMD5", | 333 "checksumAlgorithm" : "bitmap-64bitMD5", |
330 "checksumValue" : 11092453015575919668, | 334 "checksumValue" : 11092453015575919668, |
331 "comparisonResult" : "no-comparison", | 335 "comparisonResult" : "no-comparison", |
332 "filepath" : "red_skp/bitmap-64bitMD5_11092453015575919668.p
ng", | 336 "filepath" : |
| 337 "red_skp/bitmap-64bitMD5_11092453015575919668.png", |
333 }, | 338 }, |
334 }, | 339 }, |
335 "green.skp": { | 340 "green.skp": { |
336 # Manually verified: 640x400 green rectangle with black border | 341 # Manually verified: 640x400 green rectangle with black border |
337 "whole-image": { | 342 "whole-image": { |
338 "checksumAlgorithm" : "bitmap-64bitMD5", | 343 "checksumAlgorithm" : "bitmap-64bitMD5", |
339 "checksumValue" : 8891695120562235492, | 344 "checksumValue" : 8891695120562235492, |
340 "comparisonResult" : "no-comparison", | 345 "comparisonResult" : "no-comparison", |
341 "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492.
png", | 346 "filepath" : |
| 347 "green_skp/bitmap-64bitMD5_8891695120562235492.png", |
342 }, | 348 }, |
343 } | 349 } |
344 } | 350 } |
345 } | 351 } |
346 self._assert_json_contents(output_json_path, expected_summary_dict) | 352 self._assert_json_contents(output_json_path, expected_summary_dict) |
347 self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp']) | 353 self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp']) |
348 self._assert_directory_contents( | 354 self._assert_directory_contents( |
349 os.path.join(write_path_dir, 'red_skp'), | 355 os.path.join(write_path_dir, 'red_skp'), |
350 ['bitmap-64bitMD5_11092453015575919668.png']) | 356 ['bitmap-64bitMD5_11092453015575919668.png']) |
351 self._assert_directory_contents( | 357 self._assert_directory_contents( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 "header" : EXPECTED_HEADER_CONTENTS, | 466 "header" : EXPECTED_HEADER_CONTENTS, |
461 "actual-results" : { | 467 "actual-results" : { |
462 "red.skp": { | 468 "red.skp": { |
463 # Manually verified these 6 images, all 256x256 tiles, | 469 # Manually verified these 6 images, all 256x256 tiles, |
464 # consistent with a tiled version of the 640x400 red rect | 470 # consistent with a tiled version of the 640x400 red rect |
465 # with black borders. | 471 # with black borders. |
466 "tiled-images": [{ | 472 "tiled-images": [{ |
467 "checksumAlgorithm" : "bitmap-64bitMD5", | 473 "checksumAlgorithm" : "bitmap-64bitMD5", |
468 "checksumValue" : 5815827069051002745, | 474 "checksumValue" : 5815827069051002745, |
469 "comparisonResult" : "no-comparison", | 475 "comparisonResult" : "no-comparison", |
470 "filepath" : "red_skp/bitmap-64bitMD5_5815827069051002745.pn
g", | 476 "filepath" : |
| 477 "red_skp/bitmap-64bitMD5_5815827069051002745.png", |
471 }, { | 478 }, { |
472 "checksumAlgorithm" : "bitmap-64bitMD5", | 479 "checksumAlgorithm" : "bitmap-64bitMD5", |
473 "checksumValue" : 9323613075234140270, | 480 "checksumValue" : 9323613075234140270, |
474 "comparisonResult" : "no-comparison", | 481 "comparisonResult" : "no-comparison", |
475 "filepath" : "red_skp/bitmap-64bitMD5_9323613075234140270.pn
g", | 482 "filepath" : |
| 483 "red_skp/bitmap-64bitMD5_9323613075234140270.png", |
476 }, { | 484 }, { |
477 "checksumAlgorithm" : "bitmap-64bitMD5", | 485 "checksumAlgorithm" : "bitmap-64bitMD5", |
478 "checksumValue" : 16670399404877552232, | 486 "checksumValue" : 16670399404877552232, |
479 "comparisonResult" : "no-comparison", | 487 "comparisonResult" : "no-comparison", |
480 "filepath" : "red_skp/bitmap-64bitMD5_16670399404877552232.p
ng", | 488 "filepath" : |
| 489 "red_skp/bitmap-64bitMD5_16670399404877552232.png", |
481 }, { | 490 }, { |
482 "checksumAlgorithm" : "bitmap-64bitMD5", | 491 "checksumAlgorithm" : "bitmap-64bitMD5", |
483 "checksumValue" : 2507897274083364964, | 492 "checksumValue" : 2507897274083364964, |
484 "comparisonResult" : "no-comparison", | 493 "comparisonResult" : "no-comparison", |
485 "filepath" : "red_skp/bitmap-64bitMD5_2507897274083364964.pn
g", | 494 "filepath" : |
| 495 "red_skp/bitmap-64bitMD5_2507897274083364964.png", |
486 }, { | 496 }, { |
487 "checksumAlgorithm" : "bitmap-64bitMD5", | 497 "checksumAlgorithm" : "bitmap-64bitMD5", |
488 "checksumValue" : 7325267995523877959, | 498 "checksumValue" : 7325267995523877959, |
489 "comparisonResult" : "no-comparison", | 499 "comparisonResult" : "no-comparison", |
490 "filepath" : "red_skp/bitmap-64bitMD5_7325267995523877959.pn
g", | 500 "filepath" : |
| 501 "red_skp/bitmap-64bitMD5_7325267995523877959.png", |
491 }, { | 502 }, { |
492 "checksumAlgorithm" : "bitmap-64bitMD5", | 503 "checksumAlgorithm" : "bitmap-64bitMD5", |
493 "checksumValue" : 2181381724594493116, | 504 "checksumValue" : 2181381724594493116, |
494 "comparisonResult" : "no-comparison", | 505 "comparisonResult" : "no-comparison", |
495 "filepath" : "red_skp/bitmap-64bitMD5_2181381724594493116.pn
g", | 506 "filepath" : |
| 507 "red_skp/bitmap-64bitMD5_2181381724594493116.png", |
496 }], | 508 }], |
497 }, | 509 }, |
498 "green.skp": { | 510 "green.skp": { |
499 # Manually verified these 6 images, all 256x256 tiles, | 511 # Manually verified these 6 images, all 256x256 tiles, |
500 # consistent with a tiled version of the 640x400 green rect | 512 # consistent with a tiled version of the 640x400 green rect |
501 # with black borders. | 513 # with black borders. |
502 "tiled-images": [{ | 514 "tiled-images": [{ |
503 "checksumAlgorithm" : "bitmap-64bitMD5", | 515 "checksumAlgorithm" : "bitmap-64bitMD5", |
504 "checksumValue" : 12587324416545178013, | 516 "checksumValue" : 12587324416545178013, |
505 "comparisonResult" : "no-comparison", | 517 "comparisonResult" : "no-comparison", |
506 "filepath" : "green_skp/bitmap-64bitMD5_12587324416545178013
.png", | 518 "filepath" : |
| 519 "green_skp/bitmap-64bitMD5_12587324416545178013.png", |
507 }, { | 520 }, { |
508 "checksumAlgorithm" : "bitmap-64bitMD5", | 521 "checksumAlgorithm" : "bitmap-64bitMD5", |
509 "checksumValue" : 7624374914829746293, | 522 "checksumValue" : 7624374914829746293, |
510 "comparisonResult" : "no-comparison", | 523 "comparisonResult" : "no-comparison", |
511 "filepath" : "green_skp/bitmap-64bitMD5_7624374914829746293.
png", | 524 "filepath" : |
| 525 "green_skp/bitmap-64bitMD5_7624374914829746293.png", |
512 }, { | 526 }, { |
513 "checksumAlgorithm" : "bitmap-64bitMD5", | 527 "checksumAlgorithm" : "bitmap-64bitMD5", |
514 "checksumValue" : 5686489729535631913, | 528 "checksumValue" : 5686489729535631913, |
515 "comparisonResult" : "no-comparison", | 529 "comparisonResult" : "no-comparison", |
516 "filepath" : "green_skp/bitmap-64bitMD5_5686489729535631913.
png", | 530 "filepath" : |
| 531 "green_skp/bitmap-64bitMD5_5686489729535631913.png", |
517 }, { | 532 }, { |
518 "checksumAlgorithm" : "bitmap-64bitMD5", | 533 "checksumAlgorithm" : "bitmap-64bitMD5", |
519 "checksumValue" : 7980646035555096146, | 534 "checksumValue" : 7980646035555096146, |
520 "comparisonResult" : "no-comparison", | 535 "comparisonResult" : "no-comparison", |
521 "filepath" : "green_skp/bitmap-64bitMD5_7980646035555096146.
png", | 536 "filepath" : |
| 537 "green_skp/bitmap-64bitMD5_7980646035555096146.png", |
522 }, { | 538 }, { |
523 "checksumAlgorithm" : "bitmap-64bitMD5", | 539 "checksumAlgorithm" : "bitmap-64bitMD5", |
524 "checksumValue" : 17817086664365875131, | 540 "checksumValue" : 17817086664365875131, |
525 "comparisonResult" : "no-comparison", | 541 "comparisonResult" : "no-comparison", |
526 "filepath" : "green_skp/bitmap-64bitMD5_17817086664365875131
.png", | 542 "filepath" : |
| 543 "green_skp/bitmap-64bitMD5_17817086664365875131.png", |
527 }, { | 544 }, { |
528 "checksumAlgorithm" : "bitmap-64bitMD5", | 545 "checksumAlgorithm" : "bitmap-64bitMD5", |
529 "checksumValue" : 10673669813016809363, | 546 "checksumValue" : 10673669813016809363, |
530 "comparisonResult" : "no-comparison", | 547 "comparisonResult" : "no-comparison", |
531 "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363
.png", | 548 "filepath" : |
| 549 "green_skp/bitmap-64bitMD5_10673669813016809363.png", |
532 }], | 550 }], |
533 } | 551 } |
534 } | 552 } |
535 } | 553 } |
536 self._assert_json_contents(output_json_path, expected_summary_dict) | 554 self._assert_json_contents(output_json_path, expected_summary_dict) |
537 self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp']) | 555 self._assert_directory_contents(write_path_dir, ['red_skp', 'green_skp']) |
538 self._assert_directory_contents( | 556 self._assert_directory_contents( |
539 os.path.join(write_path_dir, 'red_skp'), | 557 os.path.join(write_path_dir, 'red_skp'), |
540 ['bitmap-64bitMD5_5815827069051002745.png', | 558 ['bitmap-64bitMD5_5815827069051002745.png', |
541 'bitmap-64bitMD5_9323613075234140270.png', | 559 'bitmap-64bitMD5_9323613075234140270.png', |
542 'bitmap-64bitMD5_16670399404877552232.png', | 560 'bitmap-64bitMD5_16670399404877552232.png', |
543 'bitmap-64bitMD5_2507897274083364964.png', | 561 'bitmap-64bitMD5_2507897274083364964.png', |
544 'bitmap-64bitMD5_7325267995523877959.png', | 562 'bitmap-64bitMD5_7325267995523877959.png', |
545 'bitmap-64bitMD5_2181381724594493116.png']) | 563 'bitmap-64bitMD5_2181381724594493116.png']) |
546 self._assert_directory_contents( | 564 self._assert_directory_contents( |
547 os.path.join(write_path_dir, 'green_skp'), | 565 os.path.join(write_path_dir, 'green_skp'), |
548 ['bitmap-64bitMD5_12587324416545178013.png', | 566 ['bitmap-64bitMD5_12587324416545178013.png', |
549 'bitmap-64bitMD5_7624374914829746293.png', | 567 'bitmap-64bitMD5_7624374914829746293.png', |
550 'bitmap-64bitMD5_5686489729535631913.png', | 568 'bitmap-64bitMD5_5686489729535631913.png', |
551 'bitmap-64bitMD5_7980646035555096146.png', | 569 'bitmap-64bitMD5_7980646035555096146.png', |
552 'bitmap-64bitMD5_17817086664365875131.png', | 570 'bitmap-64bitMD5_17817086664365875131.png', |
553 'bitmap-64bitMD5_10673669813016809363.png']) | 571 'bitmap-64bitMD5_10673669813016809363.png']) |
554 | 572 |
555 def _run_render_pictures(self, args): | 573 def _run_render_pictures(self, args): |
556 binary = self.find_path_to_program('render_pictures') | 574 binary = find_run_binary.find_path_to_program('render_pictures') |
557 return self.run_command([binary, | 575 return find_run_binary.run_command( |
558 '--config', '8888', | 576 [binary, '--config', '8888'] + args) |
559 ] + args) | |
560 | 577 |
561 def _create_expectations(self, missing_some_images=False, | 578 def _create_expectations(self, missing_some_images=False, |
562 rel_path='expectations.json'): | 579 rel_path='expectations.json'): |
563 """Creates expectations JSON file within self._expectations_dir . | 580 """Creates expectations JSON file within self._expectations_dir . |
564 | 581 |
565 Args: | 582 Args: |
566 missing_some_images: (bool) whether to remove expectations for a subset | 583 missing_some_images: (bool) whether to remove expectations for a subset |
567 of the images | 584 of the images |
568 rel_path: (string) relative path within self._expectations_dir to write | 585 rel_path: (string) relative path within self._expectations_dir to write |
569 the expectations into | 586 the expectations into |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 """Runs the skpmaker binary to generate SKP with known characteristics. | 624 """Runs the skpmaker binary to generate SKP with known characteristics. |
608 | 625 |
609 Args: | 626 Args: |
610 output_path: Filepath to write the SKP into. | 627 output_path: Filepath to write the SKP into. |
611 red: Value of red color channel in image, 0-255. | 628 red: Value of red color channel in image, 0-255. |
612 green: Value of green color channel in image, 0-255. | 629 green: Value of green color channel in image, 0-255. |
613 blue: Value of blue color channel in image, 0-255. | 630 blue: Value of blue color channel in image, 0-255. |
614 width: Width of canvas to create. | 631 width: Width of canvas to create. |
615 height: Height of canvas to create. | 632 height: Height of canvas to create. |
616 """ | 633 """ |
617 binary = self.find_path_to_program('skpmaker') | 634 binary = find_run_binary.find_path_to_program('skpmaker') |
618 return self.run_command([binary, | 635 return find_run_binary.run_command([ |
619 '--red', str(red), | 636 binary, |
620 '--green', str(green), | 637 '--red', str(red), |
621 '--blue', str(blue), | 638 '--green', str(green), |
622 '--width', str(width), | 639 '--blue', str(blue), |
623 '--height', str(height), | 640 '--width', str(width), |
624 '--writePath', str(output_path), | 641 '--height', str(height), |
625 ]) | 642 '--writePath', str(output_path), |
| 643 ]) |
626 | 644 |
627 def _assert_directory_contents(self, dir_path, expected_filenames): | 645 def _assert_directory_contents(self, dir_path, expected_filenames): |
628 """Asserts that files found in a dir are identical to expected_filenames. | 646 """Asserts that files found in a dir are identical to expected_filenames. |
629 | 647 |
630 Args: | 648 Args: |
631 dir_path: Path to a directory on local disk. | 649 dir_path: Path to a directory on local disk. |
632 expected_filenames: Set containing the expected filenames within the dir. | 650 expected_filenames: Set containing the expected filenames within the dir. |
633 | 651 |
634 Raises: | 652 Raises: |
635 AssertionError: contents of the directory are not identical to | 653 AssertionError: contents of the directory are not identical to |
(...skipping 21 matching lines...) Expand all Loading... |
657 self.assertMultiLineEqual(prettyprinted_expected_dict, | 675 self.assertMultiLineEqual(prettyprinted_expected_dict, |
658 prettyprinted_json_dict) | 676 prettyprinted_json_dict) |
659 | 677 |
660 | 678 |
661 def main(): | 679 def main(): |
662 base_unittest.main(RenderPicturesTest) | 680 base_unittest.main(RenderPicturesTest) |
663 | 681 |
664 | 682 |
665 if __name__ == '__main__': | 683 if __name__ == '__main__': |
666 main() | 684 main() |
OLD | NEW |