blob: 8d838402f955635f7204967dc0b0a8da800d03db [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
Dan Sinclairdccfe572015-11-03 11:30:00 -05006import optparse
7import os
8import re
9import subprocess
Tom Sepezb7cb36a2015-02-13 16:54:48 -080010import sys
11
Dan Sinclairdccfe572015-11-03 11:30:00 -050012import common
13import pngdiffer
14import 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
22def generate_and_test(input_filename, source_dir, working_dir,
Qin Zhaofba46da2015-11-23 16:50:49 -050023 fixup_path, pdfium_test_path, image_differ,
24 drmem_wrapper):
Dan Sinclairdccfe572015-11-03 11:30:00 -050025 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])
Qin Zhaofba46da2015-11-23 16:50:49 -050040 # 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)
Dan Sinclairdccfe572015-11-03 11:30:00 -050045 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
Lei Zhang77aaf962015-09-09 13:05:42 -070053
Tom Sepezb7cb36a2015-02-13 16:54:48 -080054def main():
Dan Sinclairdccfe572015-11-03 11:30:00 -050055 parser = optparse.OptionParser()
56 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'),
57 help='relative path from the base source directory')
Qin Zhaofba46da2015-11-23 16:50:49 -050058 parser.add_option('--wrapper', default='', dest="wrapper",
59 help='Dr. Memory wrapper for running test under Dr. Memory')
Dan Sinclairdccfe572015-11-03 11:30:00 -050060 options, args = parser.parse_args()
61 finder = common.DirectoryFinder(options.build_dir)
62 fixup_path = finder.ScriptPath('fixup_pdf_template.py')
63 source_dir = finder.TestingDir(os.path.join('resources', 'pixel'))
64 pdfium_test_path = finder.ExecutablePath('pdfium_test')
65 if not os.path.exists(pdfium_test_path):
66 print "FAILURE: Can't find test executable '%s'" % pdfium_test_path
67 print "Use --build-dir to specify its location."
68 return 1
69 working_dir = finder.WorkingDir(os.path.join('testing', 'pixel'))
70 if not os.path.exists(working_dir):
71 os.makedirs(working_dir)
72
73 test_suppressor = suppressor.Suppressor(finder)
74 image_differ = pngdiffer.PNGDiffer(finder)
75
76 input_files = []
77 if len(args):
78 for file_name in args:
79 input_files.append(file_name.replace(".pdf", ".in"))
80 else:
81 input_files = os.listdir(source_dir)
82
83 failures = []
84 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$')
85 for input_filename in input_files:
86 if input_file_re.match(input_filename):
87 input_path = os.path.join(source_dir, input_filename)
88 if os.path.isfile(input_path):
89 if test_suppressor.IsSuppressed(input_filename):
90 continue
91 if not generate_and_test(input_filename, source_dir, working_dir,
Qin Zhaofba46da2015-11-23 16:50:49 -050092 fixup_path, pdfium_test_path, image_differ,
93 options.wrapper):
Dan Sinclairdccfe572015-11-03 11:30:00 -050094 failures.append(input_path)
95
96 if failures:
97 failures.sort()
98 print '\n\nSummary of Failures:'
99 for failure in failures:
100 print failure
101 return 1
102 return 0
103
Lei Zhang77aaf962015-09-09 13:05:42 -0700104
Tom Sepezb7cb36a2015-02-13 16:54:48 -0800105if __name__ == '__main__':
106 sys.exit(main())