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 | 6 import optparse |
7 import os | 7 import os |
8 import re | 8 import re |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
11 | 11 |
12 import common | 12 import common |
13 | 13 |
14 # Nomenclature: | 14 # Nomenclature: |
15 # x_root - "x" | 15 # x_root - "x" |
16 # x_filename - "x.ext" | 16 # x_filename - "x.ext" |
17 # x_path - "path/to/a/b/c/x.ext" | 17 # x_path - "path/to/a/b/c/x.ext" |
18 # c_dir - "path/to/a/b/c" | 18 # c_dir - "path/to/a/b/c" |
19 | 19 |
20 def generate_and_test(input_filename, source_dir, working_dir, | 20 def generate_and_test(input_filename, source_dir, working_dir, |
21 fixup_path, pdfium_test_path, text_diff_path): | 21 fixup_path, pdfium_test_path, text_diff_path, |
| 22 drmem_wrapper): |
22 input_root, _ = os.path.splitext(input_filename) | 23 input_root, _ = os.path.splitext(input_filename) |
23 input_path = os.path.join(source_dir, input_root + '.in') | 24 input_path = os.path.join(source_dir, input_root + '.in') |
24 pdf_path = os.path.join(working_dir, input_root + '.pdf') | 25 pdf_path = os.path.join(working_dir, input_root + '.pdf') |
25 txt_path = os.path.join(working_dir, input_root + '.txt') | 26 txt_path = os.path.join(working_dir, input_root + '.txt') |
26 expected_path = os.path.join(source_dir, input_root + '_expected.txt') | 27 expected_path = os.path.join(source_dir, input_root + '_expected.txt') |
27 try: | 28 try: |
28 sys.stdout.flush() | 29 sys.stdout.flush() |
29 subprocess.check_call( | 30 subprocess.check_call( |
30 [sys.executable, fixup_path, '--output-dir=' + working_dir, input_path]) | 31 [sys.executable, fixup_path, '--output-dir=' + working_dir, input_path]) |
31 with open(txt_path, 'w') as outfile: | 32 with open(txt_path, 'w') as outfile: |
32 subprocess.check_call([pdfium_test_path, pdf_path], stdout=outfile) | 33 # add Dr. Memory wrapper if exist |
| 34 if drmem_wrapper: |
| 35 cmd_to_run = common.DrMemoryWrapper(drmem_wrapper, input_root) |
| 36 else: |
| 37 cmd_to_run = [] |
| 38 cmd_to_run.extend([pdfium_test_path, pdf_path]) |
| 39 # run test |
| 40 subprocess.check_call(cmd_to_run, stdout=outfile) |
33 subprocess.check_call( | 41 subprocess.check_call( |
34 [sys.executable, text_diff_path, expected_path, txt_path]) | 42 [sys.executable, text_diff_path, expected_path, txt_path]) |
35 except subprocess.CalledProcessError as e: | 43 except subprocess.CalledProcessError as e: |
36 print "FAILURE: " + input_filename + "; " + str(e) | 44 print "FAILURE: " + input_filename + "; " + str(e) |
37 return False | 45 return False |
38 return True | 46 return True |
39 | 47 |
40 def main(): | 48 def main(): |
41 parser = optparse.OptionParser() | 49 parser = optparse.OptionParser() |
42 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), | 50 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), |
43 help='relative path from the base source directory') | 51 help='relative path from the base source directory') |
| 52 parser.add_option('--wrapper', default='', dest="wrapper", |
| 53 help='Dr. Memory wrapper for running test under Dr. Memory') |
44 options, args = parser.parse_args() | 54 options, args = parser.parse_args() |
45 | 55 |
46 finder = common.DirectoryFinder(options.build_dir) | 56 finder = common.DirectoryFinder(options.build_dir) |
47 fixup_path = finder.ScriptPath('fixup_pdf_template.py') | 57 fixup_path = finder.ScriptPath('fixup_pdf_template.py') |
48 text_diff_path = finder.ScriptPath('text_diff.py') | 58 text_diff_path = finder.ScriptPath('text_diff.py') |
49 source_dir = finder.TestingDir(os.path.join('resources', 'javascript')) | 59 source_dir = finder.TestingDir(os.path.join('resources', 'javascript')) |
50 pdfium_test_path = finder.ExecutablePath('pdfium_test') | 60 pdfium_test_path = finder.ExecutablePath('pdfium_test') |
51 if not os.path.exists(pdfium_test_path): | 61 if not os.path.exists(pdfium_test_path): |
52 print "FAILURE: Can't find test executable '%s'" % pdfium_test_path | 62 print "FAILURE: Can't find test executable '%s'" % pdfium_test_path |
53 print "Use --build-dir to specify its location." | 63 print "Use --build-dir to specify its location." |
54 return 1 | 64 return 1 |
55 working_dir = finder.WorkingDir(os.path.join('testing', 'javascript')) | 65 working_dir = finder.WorkingDir(os.path.join('testing', 'javascript')) |
56 if not os.path.exists(working_dir): | 66 if not os.path.exists(working_dir): |
57 os.makedirs(working_dir) | 67 os.makedirs(working_dir) |
58 | 68 |
59 input_files = [] | 69 input_files = [] |
60 if len(args): | 70 if len(args): |
61 for file_name in args: | 71 for file_name in args: |
62 input_files.append(file_name.replace(".pdf", ".in")) | 72 input_files.append(file_name.replace(".pdf", ".in")) |
63 else: | 73 else: |
64 input_files = os.listdir(source_dir) | 74 input_files = os.listdir(source_dir) |
65 | 75 |
66 failures = [] | 76 failures = [] |
67 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') | 77 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') |
68 for input_filename in input_files: | 78 for input_filename in input_files: |
69 if input_file_re.match(input_filename): | 79 if input_file_re.match(input_filename): |
70 input_path = os.path.join(source_dir, input_filename) | 80 input_path = os.path.join(source_dir, input_filename) |
71 if os.path.isfile(input_path): | 81 if os.path.isfile(input_path): |
72 if not generate_and_test(input_filename, source_dir, working_dir, | 82 if not generate_and_test(input_filename, source_dir, working_dir, |
73 fixup_path, pdfium_test_path, text_diff_path): | 83 fixup_path, pdfium_test_path, text_diff_path, |
| 84 options.wrapper): |
74 failures.append(input_path) | 85 failures.append(input_path) |
75 | 86 |
76 if failures: | 87 if failures: |
77 failures.sort() | 88 failures.sort() |
78 print '\n\nSummary of Failures:' | 89 print '\n\nSummary of Failures:' |
79 for failure in failures: | 90 for failure in failures: |
80 print failure | 91 print failure |
81 return 1 | 92 return 1 |
82 return 0 | 93 return 0 |
83 | 94 |
84 | 95 |
85 if __name__ == '__main__': | 96 if __name__ == '__main__': |
86 sys.exit(main()) | 97 sys.exit(main()) |
OLD | NEW |