| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The PDFium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import optparse | |
| 7 import os | |
| 8 import re | |
| 9 import subprocess | |
| 10 import sys | 6 import sys |
| 11 | 7 import test_runner |
| 12 import common | |
| 13 import pngdiffer | |
| 14 import suppressor | |
| 15 | |
| 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, | |
| 23 fixup_path, pdfium_test_path, image_differ, | |
| 24 drmem_wrapper): | |
| 25 input_root, _ = os.path.splitext(input_filename) | |
| 26 input_path = os.path.join(source_dir, input_root + '.in') | |
| 27 pdf_path = os.path.join(working_dir, input_root + '.pdf') | |
| 28 | |
| 29 # Remove any existing generated images from previous runs. | |
| 30 actual_images = image_differ.GetActualFiles( | |
| 31 input_filename, source_dir, working_dir) | |
| 32 for image in actual_images: | |
| 33 if os.path.exists(image): | |
| 34 os.remove(image) | |
| 35 | |
| 36 try: | |
| 37 sys.stdout.flush() | |
| 38 subprocess.check_call( | |
| 39 [sys.executable, fixup_path, '--output-dir=' + working_dir, input_path]) | |
| 40 # add Dr. Memory wrapper if exist | |
| 41 cmd_to_run = common.DrMemoryWrapper(drmem_wrapper, input_root) | |
| 42 cmd_to_run.extend([pdfium_test_path, '--png', pdf_path]) | |
| 43 # run test | |
| 44 subprocess.check_call(cmd_to_run) | |
| 45 except subprocess.CalledProcessError as e: | |
| 46 print "FAILURE: " + input_filename + "; " + str(e) | |
| 47 return False | |
| 48 if image_differ.HasDifferences(input_filename, source_dir, working_dir): | |
| 49 print "FAILURE: " + input_filename | |
| 50 return False | |
| 51 return True | |
| 52 | |
| 53 | 8 |
| 54 def main(): | 9 def main(): |
| 55 parser = optparse.OptionParser() | 10 runner = test_runner.TestRunner('pixel') |
| 56 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), | 11 return runner.Run() |
| 57 help='relative path from the base source directory') | |
| 58 parser.add_option('-j', default=1, | |
| 59 dest='num_workers', type='int', | |
| 60 help='run NUM_WORKERS jobs in parallel (currently ignored)') | |
| 61 parser.add_option('--wrapper', default='', dest="wrapper", | |
| 62 help='Dr. Memory wrapper for running test under Dr. Memory') | |
| 63 options, args = parser.parse_args() | |
| 64 finder = common.DirectoryFinder(options.build_dir) | |
| 65 fixup_path = finder.ScriptPath('fixup_pdf_template.py') | |
| 66 source_dir = finder.TestingDir(os.path.join('resources', 'pixel')) | |
| 67 pdfium_test_path = finder.ExecutablePath('pdfium_test') | |
| 68 if not os.path.exists(pdfium_test_path): | |
| 69 print "FAILURE: Can't find test executable '%s'" % pdfium_test_path | |
| 70 print "Use --build-dir to specify its location." | |
| 71 return 1 | |
| 72 working_dir = finder.WorkingDir(os.path.join('testing', 'pixel')) | |
| 73 if not os.path.exists(working_dir): | |
| 74 os.makedirs(working_dir) | |
| 75 | |
| 76 feature_string = subprocess.check_output([pdfium_test_path, '--show-config']) | |
| 77 test_suppressor = suppressor.Suppressor(finder, feature_string) | |
| 78 image_differ = pngdiffer.PNGDiffer(finder) | |
| 79 | |
| 80 input_files = [] | |
| 81 if len(args): | |
| 82 for file_name in args: | |
| 83 input_files.append(file_name.replace(".pdf", ".in")) | |
| 84 else: | |
| 85 input_files = os.listdir(source_dir) | |
| 86 | |
| 87 failures = [] | |
| 88 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') | |
| 89 for input_filename in input_files: | |
| 90 if input_file_re.match(input_filename): | |
| 91 input_path = os.path.join(source_dir, input_filename) | |
| 92 if os.path.isfile(input_path): | |
| 93 if test_suppressor.IsResultSuppressed(input_filename): | |
| 94 continue | |
| 95 if not generate_and_test(input_filename, source_dir, working_dir, | |
| 96 fixup_path, pdfium_test_path, image_differ, | |
| 97 options.wrapper): | |
| 98 failures.append(input_path) | |
| 99 | |
| 100 if failures: | |
| 101 failures.sort() | |
| 102 print '\n\nSummary of Failures:' | |
| 103 for failure in failures: | |
| 104 print failure | |
| 105 return 1 | |
| 106 return 0 | |
| 107 | |
| 108 | 12 |
| 109 if __name__ == '__main__': | 13 if __name__ == '__main__': |
| 110 sys.exit(main()) | 14 sys.exit(main()) |
| OLD | NEW |