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

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

Issue 1057983003: Refactor PDFium python test utilities. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Line wrap. Created 5 years, 8 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
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
24 def generate_and_test(input_filename, source_dir, working_dir, 18 def generate_and_test(input_filename, source_dir, working_dir,
25 fixup_path, pdfium_test_path, pdfium_diff_path): 19 fixup_path, pdfium_test_path, image_differ):
26 input_root, _ = os.path.splitext(input_filename) 20 input_root, _ = os.path.splitext(input_filename)
27 input_path = os.path.join(source_dir, input_root + '.in') 21 input_path = os.path.join(source_dir, input_root + '.in')
28 pdf_path = os.path.join(working_dir, input_root + '.pdf') 22 pdf_path = os.path.join(working_dir, input_root + '.pdf')
29 actual_path_template = os.path.join(working_dir, input_root + '.pdf.%d.png')
30 expected_path_template = os.path.join(source_dir,
31 input_root + '_expected.pdf.%d.png')
32 try: 23 try:
33 sys.stdout.flush() 24 sys.stdout.flush()
34 subprocess.check_call( 25 subprocess.check_call(
35 [sys.executable, fixup_path, '--output-dir=' + working_dir, input_path]) 26 [sys.executable, fixup_path, '--output-dir=' + working_dir, input_path])
36 subprocess.check_call([pdfium_test_path, '--png', pdf_path]) 27 subprocess.check_call([pdfium_test_path, '--png', pdf_path])
37 i = 0;
38 while True:
39 expected_path = expected_path_template % i;
40 actual_path = actual_path_template % i;
41 if not os.path.exists(expected_path):
42 if i == 0:
43 print "WARNING: no expected results files found for " + input_filename
44 break
45 print "Checking " + actual_path
46 sys.stdout.flush()
47 subprocess.check_call([pdfium_diff_path, expected_path, actual_path])
48 i += 1
49 except subprocess.CalledProcessError as e: 28 except subprocess.CalledProcessError as e:
50 print "FAILURE: " + input_filename + "; " + str(e) 29 print "FAILURE: " + input_filename + "; " + str(e)
51 return False 30 return False
31 if image_differ.HasDifferences(input_filename, source_dir, working_dir):
32 print "FAILURE: " + input_filename
33 return False
52 return True 34 return True
53 35
54 def main(): 36 def main():
55 if sys.platform.startswith('linux'): 37 if sys.platform.startswith('linux'):
56 os_name = 'linux' 38 os_name = 'linux'
57 elif sys.platform.startswith('win'): 39 elif sys.platform.startswith('win'):
58 os_name = 'win' 40 os_name = 'win'
59 elif sys.platform.startswith('darwin'): 41 elif sys.platform.startswith('darwin'):
60 os_name = 'mac' 42 os_name = 'mac'
61 else: 43 else:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 pdfium_test_path = pdfium_test_path + '.exe' 85 pdfium_test_path = pdfium_test_path + '.exe'
104 pdfium_diff_path = pdfium_diff_path + '.exe' 86 pdfium_diff_path = pdfium_diff_path + '.exe'
105 # TODO(tsepez): Mac may require special handling here. 87 # TODO(tsepez): Mac may require special handling here.
106 88
107 # Place generated files under the build directory, not source directory. 89 # Place generated files under the build directory, not source directory.
108 gen_dir = os.path.join(build_dir, 'gen', 'pdfium') 90 gen_dir = os.path.join(build_dir, 'gen', 'pdfium')
109 working_dir = os.path.join(gen_dir, 'testing', 'pixel') 91 working_dir = os.path.join(gen_dir, 'testing', 'pixel')
110 if not os.path.exists(working_dir): 92 if not os.path.exists(working_dir):
111 os.makedirs(working_dir) 93 os.makedirs(working_dir)
112 94
113 suppression_list = extract_suppressions( 95 from suppressor import Suppressor
114 os.path.join(testing_dir, 'SUPPRESSIONS')) 96 test_suppressor = Suppressor(os_name, testing_dir)
115 97
116 platform_suppression_filename = 'SUPPRESSIONS_%s' % os_name 98 from pngdiffer import PNGDiffer
117 platform_suppression_list = extract_suppressions( 99 image_differ = PNGDiffer(os_name, pdfium_diff_path)
118 os.path.join(testing_dir, platform_suppression_filename))
119
120 failures = [] 100 failures = []
121 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') 101 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$')
122 for input_filename in os.listdir(source_dir): 102 for input_filename in os.listdir(source_dir):
123 if input_file_re.match(input_filename): 103 if input_file_re.match(input_filename):
124 input_path = os.path.join(source_dir, input_filename) 104 input_path = os.path.join(source_dir, input_filename)
125 if os.path.isfile(input_path): 105 if os.path.isfile(input_path):
126 if input_filename in suppression_list: 106 if test_suppressor.IsSuppressed(input_filename):
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 107 continue
133 if not generate_and_test(input_filename, source_dir, working_dir, 108 if not generate_and_test(input_filename, source_dir, working_dir,
134 fixup_path, pdfium_test_path, pdfium_diff_path) : 109 fixup_path, pdfium_test_path, image_differ):
135 failures.append(input_path) 110 failures.append(input_path)
136 111
137 if failures: 112 if failures:
138 print '\n\nSummary of Failures:' 113 print '\n\nSummary of Failures:'
139 for failure in failures: 114 for failure in failures:
140 print failure 115 print failure
141 return 1 116 return 1
142 return 0 117 return 0
143 118
144 if __name__ == '__main__': 119 if __name__ == '__main__':
145 sys.exit(main()) 120 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698