Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1026)

Side by Side Diff: testing/tools/run_corpus_tests.py

Issue 1031203003: Create per-platform pdfium test suppression files. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « testing/SUPPRESSIONS_win ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 test_one_file(input_filename, source_dir, working_dir, 24 def test_one_file(input_filename, source_dir, working_dir,
19 pdfium_test_path, pdfium_diff_path): 25 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_filename) 27 input_path = os.path.join(source_dir, input_filename)
22 pdf_path = os.path.join(working_dir, input_filename) 28 pdf_path = os.path.join(working_dir, input_filename)
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 10 matching lines...) Expand all
38 print "Checking " + actual_path 44 print "Checking " + actual_path
39 sys.stdout.flush() 45 sys.stdout.flush()
40 subprocess.check_call([pdfium_diff_path, expected_path, actual_path]) 46 subprocess.check_call([pdfium_diff_path, expected_path, actual_path])
41 i += 1 47 i += 1
42 except subprocess.CalledProcessError as e: 48 except subprocess.CalledProcessError as e:
43 print "FAILURE: " + input_filename + "; " + str(e) 49 print "FAILURE: " + input_filename + "; " + str(e)
44 return False 50 return False
45 return True 51 return True
46 52
47 def main(): 53 def main():
54 os_name = 'linux'
Lei Zhang 2015/03/25 20:39:20 Can we explicitly check for startswith('linux'), s
Tom Sepez 2015/03/25 20:49:35 Done.
55 if sys.platform.startswith('win'):
56 os_name = 'win'
57 elif sys.platform.startswith('darwin'):
58 os_name = 'mac'
59
48 parser = optparse.OptionParser() 60 parser = optparse.OptionParser()
49 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), 61 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'),
50 help='relative path from the base source directory') 62 help='relative path from the base source directory')
51 options, args = parser.parse_args() 63 options, args = parser.parse_args()
52 64
53 # Expect |my_dir| to be .../pdfium/testing/tools. 65 # Expect |my_dir| to be .../pdfium/testing/tools.
54 my_dir = os.path.dirname(os.path.realpath(__file__)) 66 my_dir = os.path.dirname(os.path.realpath(__file__))
55 testing_dir = os.path.dirname(my_dir) 67 testing_dir = os.path.dirname(my_dir)
56 pdfium_dir = os.path.dirname(testing_dir) 68 pdfium_dir = os.path.dirname(testing_dir)
57 if (os.path.basename(my_dir) != 'tools' or 69 if (os.path.basename(my_dir) != 'tools' or
(...skipping 11 matching lines...) Expand all
69 one_up_dir = os.path.dirname(base_dir) 81 one_up_dir = os.path.dirname(base_dir)
70 two_up_dir = os.path.dirname(one_up_dir) 82 two_up_dir = os.path.dirname(one_up_dir)
71 if (os.path.basename(two_up_dir) == 'src' and 83 if (os.path.basename(two_up_dir) == 'src' and
72 os.path.basename(one_up_dir) == 'third_party'): 84 os.path.basename(one_up_dir) == 'third_party'):
73 base_dir = two_up_dir 85 base_dir = two_up_dir
74 build_dir = os.path.join(base_dir, options.build_dir) 86 build_dir = os.path.join(base_dir, options.build_dir)
75 87
76 # Compiled binaries are found under the build path. 88 # Compiled binaries are found under the build path.
77 pdfium_test_path = os.path.join(build_dir, 'pdfium_test') 89 pdfium_test_path = os.path.join(build_dir, 'pdfium_test')
78 pdfium_diff_path = os.path.join(build_dir, 'pdfium_diff') 90 pdfium_diff_path = os.path.join(build_dir, 'pdfium_diff')
79 if sys.platform.startswith('win'): 91 if os_name == 'win':
80 pdfium_test_path = pdfium_test_path + '.exe' 92 pdfium_test_path = pdfium_test_path + '.exe'
81 pdfium_diff_path = pdfium_diff_path + '.exe' 93 pdfium_diff_path = pdfium_diff_path + '.exe'
82 # TODO(tsepez): Mac may require special handling here. 94 # TODO(tsepez): Mac may require special handling here.
83 95
84 # Place generated files under the build directory, not source directory. 96 # Place generated files under the build directory, not source directory.
85 working_dir = os.path.join(build_dir, 'gen', 'pdfium', 'testing', 'corpus') 97 working_dir = os.path.join(build_dir, 'gen', 'pdfium', 'testing', 'corpus')
86 if not os.path.exists(working_dir): 98 if not os.path.exists(working_dir):
87 os.makedirs(working_dir) 99 os.makedirs(working_dir)
88 100
89 with open(os.path.join(testing_dir, 'SUPPRESSIONS')) as f: 101 suppression_list = extract_suppressions(
90 suppression_list = [y for y in [ 102 os.path.join(testing_dir, 'SUPPRESSIONS'))
91 x.split('#')[0].strip() for x in f.readlines()] if y] 103
104 platform_suppression_filename = 'SUPPRESSIONS_%s' % os_name
105 platform_suppression_list = extract_suppressions(
106 os.path.join(testing_dir, platform_suppression_filename))
92 107
93 # test files are under .../pdfium/testing/corpus. 108 # test files are under .../pdfium/testing/corpus.
94 failures = [] 109 failures = []
95 walk_from_dir = os.path.join(testing_dir, 'corpus'); 110 walk_from_dir = os.path.join(testing_dir, 'corpus');
96 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]pdf$') 111 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]pdf$')
97 for source_dir, _, filename_list in os.walk(walk_from_dir): 112 for source_dir, _, filename_list in os.walk(walk_from_dir):
98 for input_filename in filename_list: 113 for input_filename in filename_list:
99 if input_file_re.match(input_filename): 114 if input_file_re.match(input_filename):
100 input_path = os.path.join(source_dir, input_filename) 115 input_path = os.path.join(source_dir, input_filename)
101 if os.path.isfile(input_path): 116 if os.path.isfile(input_path):
102 if input_filename in suppression_list: 117 if input_filename in suppression_list:
103 print "Not running %s, found in SUPPRESSIONS file" % input_filename 118 print "Not running %s, found in SUPPRESSIONS file" % input_filename
104 continue 119 continue
120 if input_filename in platform_suppression_list:
121 print ("Not running %s, found in %s file" %
122 (input_filename, platform_suppression_filename))
123 continue
124
105 if not test_one_file(input_filename, source_dir, working_dir, 125 if not test_one_file(input_filename, source_dir, working_dir,
106 pdfium_test_path, pdfium_diff_path): 126 pdfium_test_path, pdfium_diff_path):
107 failures.append(input_path) 127 failures.append(input_path)
108 128
109 if failures: 129 if failures:
110 print '\n\nSummary of Failures:' 130 print '\n\nSummary of Failures:'
111 for failure in failures: 131 for failure in failures:
112 print failure 132 print failure
113 return 1 133 return 1
114 134
115 return 0 135 return 0
116 136
117 137
118 if __name__ == '__main__': 138 if __name__ == '__main__':
119 sys.exit(main()) 139 sys.exit(main())
OLDNEW
« no previous file with comments | « testing/SUPPRESSIONS_win ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698