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

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

Issue 1026903002: Flush stdout before launching sub-processes. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: No need to change return os status code 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 | « no previous file | testing/tools/run_javascript_tests.py » ('j') | 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 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'),
(...skipping 30 matching lines...) Expand all
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:'
104 for failure in failures:
105 print failure
106 return 1
107
108 return 0
101 109
102 110
103 if __name__ == '__main__': 111 if __name__ == '__main__':
104 sys.exit(main()) 112 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | testing/tools/run_javascript_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698