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

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: Fix typo in error msg. 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 if sys.platform.startswith('linux'):
55 os_name = 'linux'
56 elif sys.platform.startswith('win'):
57 os_name = 'win'
58 elif sys.platform.startswith('darwin'):
59 os_name = 'mac'
60 else:
61 print 'Confused, can not determine OS, aborting.'
62 return 1
63
48 parser = optparse.OptionParser() 64 parser = optparse.OptionParser()
49 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'), 65 parser.add_option('--build-dir', default=os.path.join('out', 'Debug'),
50 help='relative path from the base source directory') 66 help='relative path from the base source directory')
51 options, args = parser.parse_args() 67 options, args = parser.parse_args()
52 68
53 # Expect |my_dir| to be .../pdfium/testing/tools. 69 # Expect |my_dir| to be .../pdfium/testing/tools.
54 my_dir = os.path.dirname(os.path.realpath(__file__)) 70 my_dir = os.path.dirname(os.path.realpath(__file__))
55 testing_dir = os.path.dirname(my_dir) 71 testing_dir = os.path.dirname(my_dir)
56 pdfium_dir = os.path.dirname(testing_dir) 72 pdfium_dir = os.path.dirname(testing_dir)
57 if (os.path.basename(my_dir) != 'tools' or 73 if (os.path.basename(my_dir) != 'tools' or
(...skipping 11 matching lines...) Expand all
69 one_up_dir = os.path.dirname(base_dir) 85 one_up_dir = os.path.dirname(base_dir)
70 two_up_dir = os.path.dirname(one_up_dir) 86 two_up_dir = os.path.dirname(one_up_dir)
71 if (os.path.basename(two_up_dir) == 'src' and 87 if (os.path.basename(two_up_dir) == 'src' and
72 os.path.basename(one_up_dir) == 'third_party'): 88 os.path.basename(one_up_dir) == 'third_party'):
73 base_dir = two_up_dir 89 base_dir = two_up_dir
74 build_dir = os.path.join(base_dir, options.build_dir) 90 build_dir = os.path.join(base_dir, options.build_dir)
75 91
76 # Compiled binaries are found under the build path. 92 # Compiled binaries are found under the build path.
77 pdfium_test_path = os.path.join(build_dir, 'pdfium_test') 93 pdfium_test_path = os.path.join(build_dir, 'pdfium_test')
78 pdfium_diff_path = os.path.join(build_dir, 'pdfium_diff') 94 pdfium_diff_path = os.path.join(build_dir, 'pdfium_diff')
79 if sys.platform.startswith('win'): 95 if os_name == 'win':
80 pdfium_test_path = pdfium_test_path + '.exe' 96 pdfium_test_path = pdfium_test_path + '.exe'
81 pdfium_diff_path = pdfium_diff_path + '.exe' 97 pdfium_diff_path = pdfium_diff_path + '.exe'
82 # TODO(tsepez): Mac may require special handling here. 98 # TODO(tsepez): Mac may require special handling here.
83 99
84 # Place generated files under the build directory, not source directory. 100 # Place generated files under the build directory, not source directory.
85 working_dir = os.path.join(build_dir, 'gen', 'pdfium', 'testing', 'corpus') 101 working_dir = os.path.join(build_dir, 'gen', 'pdfium', 'testing', 'corpus')
86 if not os.path.exists(working_dir): 102 if not os.path.exists(working_dir):
87 os.makedirs(working_dir) 103 os.makedirs(working_dir)
88 104
89 with open(os.path.join(testing_dir, 'SUPPRESSIONS')) as f: 105 suppression_list = extract_suppressions(
90 suppression_list = [y for y in [ 106 os.path.join(testing_dir, 'SUPPRESSIONS'))
91 x.split('#')[0].strip() for x in f.readlines()] if y] 107
108 platform_suppression_filename = 'SUPPRESSIONS_%s' % os_name
109 platform_suppression_list = extract_suppressions(
110 os.path.join(testing_dir, platform_suppression_filename))
92 111
93 # test files are under .../pdfium/testing/corpus. 112 # test files are under .../pdfium/testing/corpus.
94 failures = [] 113 failures = []
95 walk_from_dir = os.path.join(testing_dir, 'corpus'); 114 walk_from_dir = os.path.join(testing_dir, 'corpus');
96 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]pdf$') 115 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]pdf$')
97 for source_dir, _, filename_list in os.walk(walk_from_dir): 116 for source_dir, _, filename_list in os.walk(walk_from_dir):
98 for input_filename in filename_list: 117 for input_filename in filename_list:
99 if input_file_re.match(input_filename): 118 if input_file_re.match(input_filename):
100 input_path = os.path.join(source_dir, input_filename) 119 input_path = os.path.join(source_dir, input_filename)
101 if os.path.isfile(input_path): 120 if os.path.isfile(input_path):
102 if input_filename in suppression_list: 121 if input_filename in suppression_list:
103 print "Not running %s, found in SUPPRESSIONS file" % input_filename 122 print "Not running %s, found in SUPPRESSIONS file" % input_filename
104 continue 123 continue
124 if input_filename in platform_suppression_list:
125 print ("Not running %s, found in %s file" %
126 (input_filename, platform_suppression_filename))
127 continue
128
105 if not test_one_file(input_filename, source_dir, working_dir, 129 if not test_one_file(input_filename, source_dir, working_dir,
106 pdfium_test_path, pdfium_diff_path): 130 pdfium_test_path, pdfium_diff_path):
107 failures.append(input_path) 131 failures.append(input_path)
108 132
109 if failures: 133 if failures:
110 print '\n\nSummary of Failures:' 134 print '\n\nSummary of Failures:'
111 for failure in failures: 135 for failure in failures:
112 print failure 136 print failure
113 return 1 137 return 1
114 138
115 return 0 139 return 0
116 140
117 141
118 if __name__ == '__main__': 142 if __name__ == '__main__':
119 sys.exit(main()) 143 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