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

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

Issue 1010973002: Merge to XFA: Pull our new test case repository via deps. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
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 | « DEPS ('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 generate_and_test(input_filename, source_dir, working_dir, 18 def test_one_file(input_filename, source_dir, working_dir,
19 fixup_path, 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_root + '.in') 21 input_path = os.path.join(source_dir, input_filename)
22 pdf_path = os.path.join(working_dir, input_root + '.pdf') 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 subprocess.check_call( 27 subprocess.check_call(['cp', input_path, pdf_path])
28 [fixup_path, '--output-dir=' + working_dir, input_path])
29 subprocess.check_call([pdfium_test_path, '--png', pdf_path]) 28 subprocess.check_call([pdfium_test_path, '--png', pdf_path])
30 i = 0; 29 i = 0;
31 while True: 30 while True:
32 expected_path = expected_path_template % i; 31 expected_path = expected_path_template % i;
33 actual_path = actual_path_template % i; 32 actual_path = actual_path_template % i;
34 if not os.path.exists(expected_path): 33 if not os.path.exists(expected_path):
35 if i == 0: 34 if i == 0:
36 print "WARNING: no expected results files found for " + input_filename 35 print "WARNING: no expected results files found for " + input_filename
37 break 36 break
38 print "Checking " + actual_path 37 print "Checking " + actual_path
(...skipping 10 matching lines...) Expand all
49 48
50 # Expect |my_dir| to be .../pdfium/testing/tools. 49 # Expect |my_dir| to be .../pdfium/testing/tools.
51 my_dir = os.path.dirname(os.path.realpath(__file__)) 50 my_dir = os.path.dirname(os.path.realpath(__file__))
52 testing_dir = os.path.dirname(my_dir) 51 testing_dir = os.path.dirname(my_dir)
53 pdfium_dir = os.path.dirname(testing_dir) 52 pdfium_dir = os.path.dirname(testing_dir)
54 if (os.path.basename(my_dir) != 'tools' or 53 if (os.path.basename(my_dir) != 'tools' or
55 os.path.basename(testing_dir) != 'testing'): 54 os.path.basename(testing_dir) != 'testing'):
56 print 'Confused, can not find pdfium root directory, aborting.' 55 print 'Confused, can not find pdfium root directory, aborting.'
57 return 1 56 return 1
58 57
59 # Other scripts are found in the same directory as this one.
60 fixup_path = os.path.join(my_dir, 'fixup_pdf_template.py')
61
62 # test files are in .../pdfium/testing/resources/pixel.
63 source_dir = os.path.join(testing_dir, 'resources', 'pixel')
64
65 # Find path to build directory. This depends on whether this is a 58 # Find path to build directory. This depends on whether this is a
66 # standalone build vs. a build as part of a chromium checkout. For 59 # standalone build vs. a build as part of a chromium checkout. For
67 # standalone, we expect a path like .../pdfium/out/Debug, but for 60 # standalone, we expect a path like .../pdfium/out/Debug, but for
68 # chromium, we expect a path like .../src/out/Debug two levels 61 # chromium, we expect a path like .../src/out/Debug two levels
69 # higher (to skip over the third_party/pdfium path component under 62 # higher (to skip over the third_party/pdfium path component under
70 # which chromium sticks pdfium). 63 # which chromium sticks pdfium).
71 base_dir = pdfium_dir 64 base_dir = pdfium_dir
72 one_up_dir = os.path.dirname(base_dir) 65 one_up_dir = os.path.dirname(base_dir)
73 two_up_dir = os.path.dirname(one_up_dir) 66 two_up_dir = os.path.dirname(one_up_dir)
74 if (os.path.basename(two_up_dir) == 'src' and 67 if (os.path.basename(two_up_dir) == 'src' and
75 os.path.basename(one_up_dir) == 'third_party'): 68 os.path.basename(one_up_dir) == 'third_party'):
76 base_dir = two_up_dir 69 base_dir = two_up_dir
77 build_dir = os.path.join(base_dir, options.build_dir) 70 build_dir = os.path.join(base_dir, options.build_dir)
78 71
79 # Compiled binaries are found under the build path. 72 # Compiled binaries are found under the build path.
80 pdfium_test_path = os.path.join(build_dir, 'pdfium_test') 73 pdfium_test_path = os.path.join(build_dir, 'pdfium_test')
81 pdfium_diff_path = os.path.join(build_dir, 'pdfium_diff') 74 pdfium_diff_path = os.path.join(build_dir, 'pdfium_diff')
82 if sys.platform.startswith('win'): 75 if sys.platform.startswith('win'):
83 pdfium_test_path = pdfium_test_path + '.exe' 76 pdfium_test_path = pdfium_test_path + '.exe'
84 pdfium_diff_path = pdfium_diff_path + '.exe' 77 pdfium_diff_path = pdfium_diff_path + '.exe'
85 # TODO(tsepez): Mac may require special handling here. 78 # TODO(tsepez): Mac may require special handling here.
86 79
87 # Place generated files under the build directory, not source directory. 80 # Place generated files under the build directory, not source directory.
88 gen_dir = os.path.join(build_dir, 'gen', 'pdfium') 81 working_dir = os.path.join(build_dir, 'gen', 'pdfium', 'testing', 'corpus')
89 working_dir = os.path.join(gen_dir, 'testing', 'pixel')
90 if not os.path.exists(working_dir): 82 if not os.path.exists(working_dir):
91 os.makedirs(working_dir) 83 os.makedirs(working_dir)
92 84
93 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]in$') 85 # test files are under .../pdfium/testing/corpus.
94 for input_filename in os.listdir(source_dir): 86 walk_from_dir = os.path.join(testing_dir, 'corpus');
95 if input_file_re.match(input_filename): 87 input_file_re = re.compile('^[a-zA-Z0-9_.]+[.]pdf$')
96 input_path = os.path.join(source_dir, input_filename) 88 for source_dir, _, filename_list in os.walk(walk_from_dir):
97 if os.path.isfile(input_path): 89 for input_filename in filename_list:
98 generate_and_test(input_filename, source_dir, working_dir, 90 if input_file_re.match(input_filename):
99 fixup_path, pdfium_test_path, pdfium_diff_path) 91 input_path = os.path.join(source_dir, input_filename)
92 if os.path.isfile(input_path):
93 test_one_file(input_filename, source_dir, working_dir,
94 pdfium_test_path, pdfium_diff_path)
100 return 0 95 return 0
101 96
102 97
103 if __name__ == '__main__': 98 if __name__ == '__main__':
104 sys.exit(main()) 99 sys.exit(main())
OLDNEW
« no previous file with comments | « DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698