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 extract_suppressions(filename): |
| 19 with open(filename) as f: |
| 20 suppressions = [y for y in [ |
| 21 x.split('#')[0].strip() for x in f.readlines()] if y] |
| 22 return suppressions |
| 23 |
18 def generate_and_test(input_filename, source_dir, working_dir, | 24 def generate_and_test(input_filename, source_dir, working_dir, |
19 fixup_path, pdfium_test_path, pdfium_diff_path): | 25 fixup_path, pdfium_test_path, pdfium_diff_path): |
20 input_root, _ = os.path.splitext(input_filename) | 26 input_root, _ = os.path.splitext(input_filename) |
21 input_path = os.path.join(source_dir, input_root + '.in') | 27 input_path = os.path.join(source_dir, input_root + '.in') |
22 pdf_path = os.path.join(working_dir, input_root + '.pdf') | 28 pdf_path = os.path.join(working_dir, input_root + '.pdf') |
23 actual_path_template = os.path.join(working_dir, input_root + '.pdf.%d.png') | 29 actual_path_template = os.path.join(working_dir, input_root + '.pdf.%d.png') |
24 expected_path_template = os.path.join(source_dir, | 30 expected_path_template = os.path.join(source_dir, |
25 input_root + '_expected.pdf.%d.png') | 31 input_root + '_expected.pdf.%d.png') |
26 try: | 32 try: |
27 sys.stdout.flush() | 33 sys.stdout.flush() |
(...skipping 11 matching lines...) Expand all Loading... |
39 print "Checking " + actual_path | 45 print "Checking " + actual_path |
40 sys.stdout.flush() | 46 sys.stdout.flush() |
41 subprocess.check_call([pdfium_diff_path, expected_path, actual_path]) | 47 subprocess.check_call([pdfium_diff_path, expected_path, actual_path]) |
42 i += 1 | 48 i += 1 |
43 except subprocess.CalledProcessError as e: | 49 except subprocess.CalledProcessError as e: |
44 print "FAILURE: " + input_filename + "; " + str(e) | 50 print "FAILURE: " + input_filename + "; " + str(e) |
45 return False | 51 return False |
46 return True | 52 return True |
47 | 53 |
48 def main(): | 54 def main(): |
| 55 if sys.platform.startswith('linux'): |
| 56 os_name = 'linux' |
| 57 elif sys.platform.startswith('win'): |
| 58 os_name = 'win' |
| 59 elif sys.platform.startswith('darwin'): |
| 60 os_name = 'mac' |
| 61 else: |
| 62 print 'Confused, can not determine OS, aborting.' |
| 63 return 1 |
| 64 |
49 parser = optparse.OptionParser() | 65 parser = optparse.OptionParser() |
50 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), | 66 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), |
51 help='relative path from the base source directory') | 67 help='relative path from the base source directory') |
52 options, args = parser.parse_args() | 68 options, args = parser.parse_args() |
53 | 69 |
54 # Expect |my_dir| to be .../pdfium/testing/tools. | 70 # Expect |my_dir| to be .../pdfium/testing/tools. |
55 my_dir = os.path.dirname(os.path.realpath(__file__)) | 71 my_dir = os.path.dirname(os.path.realpath(__file__)) |
56 testing_dir = os.path.dirname(my_dir) | 72 testing_dir = os.path.dirname(my_dir) |
57 pdfium_dir = os.path.dirname(testing_dir) | 73 pdfium_dir = os.path.dirname(testing_dir) |
58 if (os.path.basename(my_dir) != 'tools' or | 74 if (os.path.basename(my_dir) != 'tools' or |
(...skipping 28 matching lines...) Expand all Loading... |
87 pdfium_test_path = pdfium_test_path + '.exe' | 103 pdfium_test_path = pdfium_test_path + '.exe' |
88 pdfium_diff_path = pdfium_diff_path + '.exe' | 104 pdfium_diff_path = pdfium_diff_path + '.exe' |
89 # TODO(tsepez): Mac may require special handling here. | 105 # TODO(tsepez): Mac may require special handling here. |
90 | 106 |
91 # Place generated files under the build directory, not source directory. | 107 # Place generated files under the build directory, not source directory. |
92 gen_dir = os.path.join(build_dir, 'gen', 'pdfium') | 108 gen_dir = os.path.join(build_dir, 'gen', 'pdfium') |
93 working_dir = os.path.join(gen_dir, 'testing', 'pixel') | 109 working_dir = os.path.join(gen_dir, 'testing', 'pixel') |
94 if not os.path.exists(working_dir): | 110 if not os.path.exists(working_dir): |
95 os.makedirs(working_dir) | 111 os.makedirs(working_dir) |
96 | 112 |
| 113 suppression_list = extract_suppressions( |
| 114 os.path.join(testing_dir, 'SUPPRESSIONS')) |
| 115 |
| 116 platform_suppression_filename = 'SUPPRESSIONS_%s' % os_name |
| 117 platform_suppression_list = extract_suppressions( |
| 118 os.path.join(testing_dir, platform_suppression_filename)) |
| 119 |
97 failures = [] | 120 failures = [] |
98 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') | 121 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') |
99 for input_filename in os.listdir(source_dir): | 122 for input_filename in os.listdir(source_dir): |
100 if input_file_re.match(input_filename): | 123 if input_file_re.match(input_filename): |
101 input_path = os.path.join(source_dir, input_filename) | 124 input_path = os.path.join(source_dir, input_filename) |
102 if os.path.isfile(input_path): | 125 if os.path.isfile(input_path): |
| 126 if input_filename in suppression_list: |
| 127 print "Not running %s, found in SUPPRESSIONS file" % input_filename |
| 128 continue |
| 129 if input_filename in platform_suppression_list: |
| 130 print ("Not running %s, found in %s file" % |
| 131 (input_filename, platform_suppression_filename)) |
| 132 continue |
103 if not generate_and_test(input_filename, source_dir, working_dir, | 133 if not generate_and_test(input_filename, source_dir, working_dir, |
104 fixup_path, pdfium_test_path, pdfium_diff_path)
: | 134 fixup_path, pdfium_test_path, pdfium_diff_path)
: |
105 failures.append(input_path) | 135 failures.append(input_path) |
106 | 136 |
107 if failures: | 137 if failures: |
108 print '\n\nSummary of Failures:' | 138 print '\n\nSummary of Failures:' |
109 for failure in failures: | 139 for failure in failures: |
110 print failure | 140 print failure |
111 return 1 | 141 return 1 |
112 return 0 | 142 return 0 |
113 | 143 |
114 if __name__ == '__main__': | 144 if __name__ == '__main__': |
115 sys.exit(main()) | 145 sys.exit(main()) |
OLD | NEW |