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 # Nomenclature: | 12 # Nomenclature: |
13 # x_root - "x" | 13 # x_root - "x" |
14 # x_filename - "x.ext" | 14 # x_filename - "x.ext" |
15 # x_path - "path/to/a/b/c/x.ext" | 15 # x_path - "path/to/a/b/c/x.ext" |
16 # c_dir - "path/to/a/b/c" | 16 # c_dir - "path/to/a/b/c" |
17 | 17 |
18 def test_one_file(input_filename, source_dir, working_dir, | 18 def test_one_file(input_filename, source_dir, working_dir, |
19 pdfium_test_path, pdfium_diff_path): | 19 pdfium_test_path, pdfium_diff_path): |
20 input_root, _ = os.path.splitext(input_filename) | 20 input_root, _ = os.path.splitext(input_filename) |
21 input_path = os.path.join(source_dir, input_filename) | 21 input_path = os.path.join(source_dir, input_filename) |
22 pdf_path = os.path.join(working_dir, input_filename) | 22 pdf_path = os.path.join(working_dir, input_filename) |
23 actual_path_template = os.path.join(working_dir, input_root + '.pdf.%d.png') | 23 actual_path_template = os.path.join(working_dir, input_root + '.pdf.%d.png') |
24 expected_path_template = os.path.join(source_dir, | 24 expected_path_template = os.path.join(source_dir, |
25 input_root + '_expected.pdf.%d.png') | 25 input_root + '_expected.pdf.%d.png') |
26 try: | 26 try: |
27 sys.stdout.flush() | |
27 subprocess.check_call(['cp', input_path, pdf_path]) | 28 subprocess.check_call(['cp', input_path, pdf_path]) |
28 subprocess.check_call([pdfium_test_path, '--png', pdf_path]) | 29 subprocess.check_call([pdfium_test_path, '--png', pdf_path]) |
29 i = 0; | 30 i = 0; |
30 while True: | 31 while True: |
31 expected_path = expected_path_template % i; | 32 expected_path = expected_path_template % i; |
32 actual_path = actual_path_template % i; | 33 actual_path = actual_path_template % i; |
33 if not os.path.exists(expected_path): | 34 if not os.path.exists(expected_path): |
34 if i == 0: | 35 if i == 0: |
35 print "WARNING: no expected results files found for " + input_filename | 36 print "WARNING: no expected results files found for " + input_filename |
36 break | 37 break |
37 print "Checking " + actual_path | 38 print "Checking " + actual_path |
39 sys.stdout.flush() | |
38 subprocess.check_call([pdfium_diff_path, expected_path, actual_path]) | 40 subprocess.check_call([pdfium_diff_path, expected_path, actual_path]) |
39 i += 1 | 41 i += 1 |
40 except subprocess.CalledProcessError as e: | 42 except subprocess.CalledProcessError as e: |
41 print "FAILURE: " + input_filename + "; " + str(e) | 43 print "FAILURE: " + input_filename + "; " + str(e) |
42 return False | 44 return False |
43 return True | 45 return True |
44 | 46 |
45 def main(): | 47 def main(): |
46 parser = optparse.OptionParser() | 48 parser = optparse.OptionParser() |
47 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), | 49 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), |
48 help='relative path from the base source directory') | 50 help='relative path from the base source directory') |
49 options, args = parser.parse_args() | 51 options, args = parser.parse_args() |
50 | 52 |
51 # Expect |my_dir| to be .../pdfium/testing/tools. | 53 # Expect |my_dir| to be .../pdfium/testing/tools. |
52 my_dir = os.path.dirname(os.path.realpath(__file__)) | 54 my_dir = os.path.dirname(os.path.realpath(__file__)) |
53 testing_dir = os.path.dirname(my_dir) | 55 testing_dir = os.path.dirname(my_dir) |
54 pdfium_dir = os.path.dirname(testing_dir) | 56 pdfium_dir = os.path.dirname(testing_dir) |
55 if (os.path.basename(my_dir) != 'tools' or | 57 if (os.path.basename(my_dir) != 'tools' or |
56 os.path.basename(testing_dir) != 'testing'): | 58 os.path.basename(testing_dir) != 'testing'): |
57 print 'Confused, can not find pdfium root directory, aborting.' | 59 print 'Confused, can not find pdfium root directory, aborting.' |
58 return 1 | 60 return 2 |
59 | 61 |
60 # Find path to build directory. This depends on whether this is a | 62 # Find path to build directory. This depends on whether this is a |
61 # standalone build vs. a build as part of a chromium checkout. For | 63 # standalone build vs. a build as part of a chromium checkout. For |
62 # standalone, we expect a path like .../pdfium/out/Debug, but for | 64 # standalone, we expect a path like .../pdfium/out/Debug, but for |
63 # chromium, we expect a path like .../src/out/Debug two levels | 65 # chromium, we expect a path like .../src/out/Debug two levels |
64 # higher (to skip over the third_party/pdfium path component under | 66 # higher (to skip over the third_party/pdfium path component under |
65 # which chromium sticks pdfium). | 67 # which chromium sticks pdfium). |
66 base_dir = pdfium_dir | 68 base_dir = pdfium_dir |
67 one_up_dir = os.path.dirname(base_dir) | 69 one_up_dir = os.path.dirname(base_dir) |
68 two_up_dir = os.path.dirname(one_up_dir) | 70 two_up_dir = os.path.dirname(one_up_dir) |
69 if (os.path.basename(two_up_dir) == 'src' and | 71 if (os.path.basename(two_up_dir) == 'src' and |
70 os.path.basename(one_up_dir) == 'third_party'): | 72 os.path.basename(one_up_dir) == 'third_party'): |
71 base_dir = two_up_dir | 73 base_dir = two_up_dir |
72 build_dir = os.path.join(base_dir, options.build_dir) | 74 build_dir = os.path.join(base_dir, options.build_dir) |
73 | 75 |
74 # Compiled binaries are found under the build path. | 76 # Compiled binaries are found under the build path. |
75 pdfium_test_path = os.path.join(build_dir, 'pdfium_test') | 77 pdfium_test_path = os.path.join(build_dir, 'pdfium_test') |
76 pdfium_diff_path = os.path.join(build_dir, 'pdfium_diff') | 78 pdfium_diff_path = os.path.join(build_dir, 'pdfium_diff') |
77 if sys.platform.startswith('win'): | 79 if sys.platform.startswith('win'): |
78 pdfium_test_path = pdfium_test_path + '.exe' | 80 pdfium_test_path = pdfium_test_path + '.exe' |
79 pdfium_diff_path = pdfium_diff_path + '.exe' | 81 pdfium_diff_path = pdfium_diff_path + '.exe' |
80 # TODO(tsepez): Mac may require special handling here. | 82 # TODO(tsepez): Mac may require special handling here. |
81 | 83 |
82 # Place generated files under the build directory, not source directory. | 84 # Place generated files under the build directory, not source directory. |
83 working_dir = os.path.join(build_dir, 'gen', 'pdfium', 'testing', 'corpus') | 85 working_dir = os.path.join(build_dir, 'gen', 'pdfium', 'testing', 'corpus') |
84 if not os.path.exists(working_dir): | 86 if not os.path.exists(working_dir): |
85 os.makedirs(working_dir) | 87 os.makedirs(working_dir) |
86 | 88 |
87 # test files are under .../pdfium/testing/corpus. | 89 # test files are under .../pdfium/testing/corpus. |
88 os_exit_code = 0 | 90 failures = [] |
89 walk_from_dir = os.path.join(testing_dir, 'corpus'); | 91 walk_from_dir = os.path.join(testing_dir, 'corpus'); |
90 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]pdf$') | 92 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]pdf$') |
91 for source_dir, _, filename_list in os.walk(walk_from_dir): | 93 for source_dir, _, filename_list in os.walk(walk_from_dir): |
92 for input_filename in filename_list: | 94 for input_filename in filename_list: |
93 if input_file_re.match(input_filename): | 95 if input_file_re.match(input_filename): |
94 input_path = os.path.join(source_dir, input_filename) | 96 input_path = os.path.join(source_dir, input_filename) |
95 if os.path.isfile(input_path): | 97 if os.path.isfile(input_path): |
96 if not test_one_file(input_filename, source_dir, working_dir, | 98 if not test_one_file(input_filename, source_dir, working_dir, |
97 pdfium_test_path, pdfium_diff_path): | 99 pdfium_test_path, pdfium_diff_path): |
98 os_exit_code = 1 | 100 failures.append(input_path) |
99 | 101 |
100 return os_exit_code | 102 if failures: |
103 print '\n\nSummary of Failures:' | |
Lei Zhang
2015/03/20 21:22:33
Maybe print out an easily recognized header and fo
| |
104 for failure in failures: | |
105 print failure | |
106 return 2 | |
107 | |
108 return 0 | |
101 | 109 |
102 | 110 |
103 if __name__ == '__main__': | 111 if __name__ == '__main__': |
104 sys.exit(main()) | 112 sys.exit(main()) |
OLD | NEW |