blob: b09ea49e788e19f699a10373305d6787ea6b2e9a [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
13
14# Nomenclature:
15# x_root - "x"
16# x_filename - "x.ext"
17# x_path - "path/to/a/b/c/x.ext"
18# c_dir - "path/to/a/b/c"
19
20def generate_and_test(input_filename, source_dir, working_dir,
Qin Zhaofba46da2015-11-23 16:50:49 -050021 fixup_path, pdfium_test_path, text_diff_path,
22 drmem_wrapper):
Dan Sinclairdccfe572015-11-03 11:30:00 -050023 input_root, _ = os.path.splitext(input_filename)
24 input_path = os.path.join(source_dir, input_root + '.in')
25 pdf_path = os.path.join(working_dir, input_root + '.pdf')
26 txt_path = os.path.join(working_dir, input_root + '.txt')
27 expected_path = os.path.join(source_dir, input_root + '_expected.txt')
28 try:
29 sys.stdout.flush()
30 subprocess.check_call(
31 [sys.executable, fixup_path, '--output-dir=' + working_dir, input_path])
32 with open(txt_path, 'w') as outfile:
Qin Zhaofba46da2015-11-23 16:50:49 -050033 # add Dr. Memory wrapper if exist
34 cmd_to_run = common.DrMemoryWrapper(drmem_wrapper, input_root)
35 cmd_to_run.extend([pdfium_test_path, pdf_path])
36 # run test
37 subprocess.check_call(cmd_to_run, stdout=outfile)
Dan Sinclairdccfe572015-11-03 11:30:00 -050038 subprocess.check_call(
39 [sys.executable, text_diff_path, expected_path, txt_path])
40 except subprocess.CalledProcessError as e:
41 print "FAILURE: " + input_filename + "; " + str(e)
42 return False
43 return True
Tom Sepezb7cb36a2015-02-13 16:54:48 -080044
45def main():
Dan Sinclairdccfe572015-11-03 11:30:00 -050046 parser = optparse.OptionParser()
47 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'),
48 help='relative path from the base source directory')
Qin Zhaofba46da2015-11-23 16:50:49 -050049 parser.add_option('--wrapper', default='', dest="wrapper",
50 help='Dr. Memory wrapper for running test under Dr. Memory')
Dan Sinclairdccfe572015-11-03 11:30:00 -050051 options, args = parser.parse_args()
52
53 finder = common.DirectoryFinder(options.build_dir)
54 fixup_path = finder.ScriptPath('fixup_pdf_template.py')
55 text_diff_path = finder.ScriptPath('text_diff.py')
56 source_dir = finder.TestingDir(os.path.join('resources', 'javascript'))
57 pdfium_test_path = finder.ExecutablePath('pdfium_test')
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
62 working_dir = finder.WorkingDir(os.path.join('testing', 'javascript'))
63 if not os.path.exists(working_dir):
64 os.makedirs(working_dir)
65
Tom Sepez5c1efd42016-01-19 15:05:36 -080066 feature_string = subprocess.check_output([pdfium_test_path, '--show-config'])
67 if "V8" not in feature_string.strip().split(","):
68 print "V8 not enabled, skipping."
69 return 0
70
Dan Sinclairdccfe572015-11-03 11:30:00 -050071 input_files = []
72 if len(args):
73 for file_name in args:
74 input_files.append(file_name.replace(".pdf", ".in"))
75 else:
76 input_files = os.listdir(source_dir)
77
78 failures = []
79 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$')
80 for input_filename in input_files:
81 if input_file_re.match(input_filename):
82 input_path = os.path.join(source_dir, input_filename)
83 if os.path.isfile(input_path):
84 if not generate_and_test(input_filename, source_dir, working_dir,
Qin Zhaofba46da2015-11-23 16:50:49 -050085 fixup_path, pdfium_test_path, text_diff_path,
86 options.wrapper):
Dan Sinclairdccfe572015-11-03 11:30:00 -050087 failures.append(input_path)
88
89 if failures:
90 failures.sort()
91 print '\n\nSummary of Failures:'
92 for failure in failures:
93 print failure
94 return 1
95 return 0
96
Tom Sepezb7cb36a2015-02-13 16:54:48 -080097
98if __name__ == '__main__':
99 sys.exit(main())