blob: 168846265bd9c699e7e8ce6c5459e3a94d6e66a6 [file] [log] [blame]
Tom Sepezb7cb36a2015-02-13 16:54:48 -08001#!/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
6import optparse
7import os
8import re
9import subprocess
10import sys
11
Tom Sepez30762ce2015-04-09 13:37:02 -070012import common
13import pngdiffer
14import suppressor
15
Tom Sepezb7cb36a2015-02-13 16:54:48 -080016# 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
22def generate_and_test(input_filename, source_dir, working_dir,
Tom Sepez30762ce2015-04-09 13:37:02 -070023 fixup_path, pdfium_test_path, image_differ):
Tom Sepezb7cb36a2015-02-13 16:54:48 -080024 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')
Tom Sepezb7cb36a2015-02-13 16:54:48 -080027 try:
Tom Sepez30762ce2015-04-09 13:37:02 -070028 sys.stdout.flush()
Tom Sepezb7cb36a2015-02-13 16:54:48 -080029 subprocess.check_call(
Tom Sepez30762ce2015-04-09 13:37:02 -070030 [sys.executable, fixup_path, '--output-dir=' + working_dir, input_path])
Tom Sepezdf16baf2015-02-24 12:47:58 -080031 subprocess.check_call([pdfium_test_path, '--png', pdf_path])
Tom Sepezb7cb36a2015-02-13 16:54:48 -080032 except subprocess.CalledProcessError as e:
33 print "FAILURE: " + input_filename + "; " + str(e)
Tom Sepeza8fd0e82015-03-17 13:30:11 -070034 return False
Tom Sepez30762ce2015-04-09 13:37:02 -070035 if image_differ.HasDifferences(input_filename, source_dir, working_dir):
36 print "FAILURE: " + input_filename
37 return False
Tom Sepeza8fd0e82015-03-17 13:30:11 -070038 return True
Tom Sepezb7cb36a2015-02-13 16:54:48 -080039
40def main():
41 parser = optparse.OptionParser()
42 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'),
43 help='relative path from the base source directory')
44 options, args = parser.parse_args()
Tom Sepez30762ce2015-04-09 13:37:02 -070045 finder = common.DirectoryFinder(options.build_dir)
46 fixup_path = finder.ScriptPath('fixup_pdf_template.py')
47 source_dir = finder.TestingDir(os.path.join('resources', 'pixel'))
48 pdfium_test_path = finder.ExecutablePath('pdfium_test')
Bruce Dawson56ba4292015-06-01 14:53:02 -070049 if not os.path.exists(pdfium_test_path):
50 print "FAILURE: Can't find test executable '%s'" % pdfium_test_path
51 print "Use --build-dir to specify its location."
52 return 1
Tom Sepez30762ce2015-04-09 13:37:02 -070053 working_dir = finder.WorkingDir(os.path.join('testing', 'pixel'))
Tom Sepezb7cb36a2015-02-13 16:54:48 -080054 if not os.path.exists(working_dir):
55 os.makedirs(working_dir)
56
Tom Sepez30762ce2015-04-09 13:37:02 -070057 test_suppressor = suppressor.Suppressor(finder)
58 image_differ = pngdiffer.PNGDiffer(finder)
59
60 failures = []
Tom Sepezb7cb36a2015-02-13 16:54:48 -080061 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$')
62 for input_filename in os.listdir(source_dir):
63 if input_file_re.match(input_filename):
64 input_path = os.path.join(source_dir, input_filename)
65 if os.path.isfile(input_path):
Tom Sepez30762ce2015-04-09 13:37:02 -070066 if test_suppressor.IsSuppressed(input_filename):
67 continue
Tom Sepeza8fd0e82015-03-17 13:30:11 -070068 if not generate_and_test(input_filename, source_dir, working_dir,
Tom Sepez30762ce2015-04-09 13:37:02 -070069 fixup_path, pdfium_test_path, image_differ):
70 failures.append(input_path)
Tom Sepeza8fd0e82015-03-17 13:30:11 -070071
Tom Sepez30762ce2015-04-09 13:37:02 -070072 if failures:
73 print '\n\nSummary of Failures:'
74 for failure in failures:
75 print failure
76 return 1
77 return 0
Tom Sepezb7cb36a2015-02-13 16:54:48 -080078
79if __name__ == '__main__':
80 sys.exit(main())