Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2015 The PDFium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | import optparse |
| 7 | import os |
| 8 | import re |
| 9 | import subprocess |
| 10 | import sys |
| 11 | |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 12 | import common |
| 13 | import pngdiffer |
| 14 | import suppressor |
| 15 | |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 16 | # Nomenclature: |
| 17 | # x_root - "x" |
| 18 | # x_filename - "x.ext" |
| 19 | # x_path - "path/to/a/b/c/x.ext" |
| 20 | # c_dir - "path/to/a/b/c" |
| 21 | |
| 22 | def generate_and_test(input_filename, source_dir, working_dir, |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 23 | fixup_path, pdfium_test_path, image_differ): |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 24 | input_root, _ = os.path.splitext(input_filename) |
| 25 | input_path = os.path.join(source_dir, input_root + '.in') |
| 26 | pdf_path = os.path.join(working_dir, input_root + '.pdf') |
Lei Zhang | 77aaf96 | 2015-09-09 13:05:42 -0700 | [diff] [blame^] | 27 | |
| 28 | # Remove any existing generated images from previous runs. |
| 29 | actual_images = image_differ.GetActualFiles( |
| 30 | input_filename, source_dir, working_dir) |
| 31 | for image in actual_images: |
| 32 | if os.path.exists(image): |
| 33 | os.remove(image) |
| 34 | |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 35 | try: |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 36 | sys.stdout.flush() |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 37 | subprocess.check_call( |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 38 | [sys.executable, fixup_path, '--output-dir=' + working_dir, input_path]) |
Tom Sepez | df16baf | 2015-02-24 12:47:58 -0800 | [diff] [blame] | 39 | subprocess.check_call([pdfium_test_path, '--png', pdf_path]) |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 40 | except subprocess.CalledProcessError as e: |
| 41 | print "FAILURE: " + input_filename + "; " + str(e) |
Tom Sepez | a8fd0e8 | 2015-03-17 13:30:11 -0700 | [diff] [blame] | 42 | return False |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 43 | if image_differ.HasDifferences(input_filename, source_dir, working_dir): |
| 44 | print "FAILURE: " + input_filename |
| 45 | return False |
Tom Sepez | a8fd0e8 | 2015-03-17 13:30:11 -0700 | [diff] [blame] | 46 | return True |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 47 | |
Lei Zhang | 77aaf96 | 2015-09-09 13:05:42 -0700 | [diff] [blame^] | 48 | |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 49 | def main(): |
| 50 | parser = optparse.OptionParser() |
| 51 | parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), |
| 52 | help='relative path from the base source directory') |
| 53 | options, args = parser.parse_args() |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 54 | finder = common.DirectoryFinder(options.build_dir) |
| 55 | fixup_path = finder.ScriptPath('fixup_pdf_template.py') |
| 56 | source_dir = finder.TestingDir(os.path.join('resources', 'pixel')) |
| 57 | pdfium_test_path = finder.ExecutablePath('pdfium_test') |
Bruce Dawson | 56ba429 | 2015-06-01 14:53:02 -0700 | [diff] [blame] | 58 | if not os.path.exists(pdfium_test_path): |
| 59 | print "FAILURE: Can't find test executable '%s'" % pdfium_test_path |
| 60 | print "Use --build-dir to specify its location." |
| 61 | return 1 |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 62 | working_dir = finder.WorkingDir(os.path.join('testing', 'pixel')) |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 63 | if not os.path.exists(working_dir): |
| 64 | os.makedirs(working_dir) |
| 65 | |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 66 | test_suppressor = suppressor.Suppressor(finder) |
| 67 | image_differ = pngdiffer.PNGDiffer(finder) |
| 68 | |
| 69 | failures = [] |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 70 | input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') |
| 71 | for input_filename in os.listdir(source_dir): |
| 72 | if input_file_re.match(input_filename): |
| 73 | input_path = os.path.join(source_dir, input_filename) |
| 74 | if os.path.isfile(input_path): |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 75 | if test_suppressor.IsSuppressed(input_filename): |
| 76 | continue |
Tom Sepez | a8fd0e8 | 2015-03-17 13:30:11 -0700 | [diff] [blame] | 77 | if not generate_and_test(input_filename, source_dir, working_dir, |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 78 | fixup_path, pdfium_test_path, image_differ): |
| 79 | failures.append(input_path) |
Tom Sepez | a8fd0e8 | 2015-03-17 13:30:11 -0700 | [diff] [blame] | 80 | |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 81 | if failures: |
Lei Zhang | d44f107 | 2015-07-16 18:46:57 -0700 | [diff] [blame] | 82 | failures.sort() |
Tom Sepez | 30762ce | 2015-04-09 13:37:02 -0700 | [diff] [blame] | 83 | print '\n\nSummary of Failures:' |
| 84 | for failure in failures: |
| 85 | print failure |
| 86 | return 1 |
| 87 | return 0 |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 88 | |
Lei Zhang | 77aaf96 | 2015-09-09 13:05:42 -0700 | [diff] [blame^] | 89 | |
Tom Sepez | b7cb36a | 2015-02-13 16:54:48 -0800 | [diff] [blame] | 90 | if __name__ == '__main__': |
| 91 | sys.exit(main()) |