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

Side by Side Diff: tools/lexer_generator/test/run_lexing_tests.py

Issue 192643003: Experimental parser: fix UTF8TO16 handling. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/lexer/lexer-shell.cc ('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 # Copyright 2013 the V8 project authors. All rights reserved. 1 # Copyright 2013 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without 2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are 3 # modification, are permitted provided that the following conditions are
4 # met: 4 # met:
5 # 5 #
6 # * Redistributions of source code must retain the above copyright 6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer. 7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above 8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following 9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided 10 # disclaimer in the documentation and/or other materials provided
11 # with the distribution. 11 # with the distribution.
12 # * Neither the name of Google Inc. nor the names of its 12 # * Neither the name of Google Inc. nor the names of its
13 # contributors may be used to endorse or promote products derived 13 # contributors may be used to endorse or promote products derived
14 # from this software without specific prior written permission. 14 # from this software without specific prior written permission.
15 # 15 #
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 import argparse
28 import subprocess 29 import subprocess
29 import sys 30 import sys
31 import time
32 import logging
30 33
31 def wait_processes(processes): 34 class ProcessRunner:
32 for p in processes: 35
33 if p[1].wait(): 36 def __init__(self, files, args):
34 print p[0], 'failed' 37 self.files = files
35 else: 38 self.process_map = {}
36 print p[0], 'ok' 39 self.complete_processes = {}
40 self.left_path = args.left_path
41 self.right_path = args.right_path
42 self.max_process_count = args.parallel_process_count
43 self.args = ['--break-after-illegal']
44 if args.use_harmony:
45 self.args.append('--use-harmony')
46 self.args.append('--%s' % args.encoding)
47 if self.right_path:
48 self.args.append('--print-tokens')
49
50 def build_process_map(self):
51 process_map = self.process_map
52 for i, f in enumerate(self.files):
53 process_map[2 * i] = {
54 'file': f, 'path' : self.left_path, 'type' : 'left' }
55 if self.right_path:
56 process_map[2 * i + 1] = {
57 'file': f, 'path' : self.right, 'type' : 'right' }
58
59 def wait_processes(self, running_processes):
60 complete_ids = []
61 while True:
62 for i in running_processes:
63 data = self.process_map[i]
64 response = data['process'].poll()
65 if response == None:
66 continue
67 self.complete_processes[i] = data
68 complete_ids.append(i)
69 if complete_ids:
70 break
71 time.sleep(0.001)
72 for i in complete_ids:
73 running_processes.remove(i)
74 del self.process_map[i]
75
76 def process_complete_processes(self):
77 complete_processes = self.complete_processes
78 complete_ids = []
79 for i, data in complete_processes.iteritems():
80 p = data['process']
81 if not self.right_path:
82 if p.returncode:
83 print "%s failed" % data['file']
84 else:
85 print "%s succeeded" % data['file']
86 complete_ids.append(i)
87 else:
88 # TODO(dcarney): perform compare
89 pass
90 # clear processed data
91 for i in complete_ids:
92 del complete_processes[i]
93
94 def run(self):
95 assert not self.process_map
96 self.build_process_map()
97 process_map = self.process_map
98 complete_processes = self.complete_processes
99 running_processes = set()
100 with open('/dev/null', 'w') as dev_null:
101 while True:
102 for id, data in process_map.iteritems():
103 if id in running_processes:
104 continue
105 if len(running_processes) == self.max_process_count:
106 break
107 out = sys.PIPE if self.right_path else dev_null
108 args = [data['path'], data['file']] + self.args
109 logging.info("running [%s]" % ' '.join(args))
110 data['process'] = subprocess.Popen(args,
111 stdout=out,
112 stderr=dev_null,
113 bufsize=16*1024)
114 running_processes.add(id)
115 if not running_processes:
116 break
117 self.wait_processes(running_processes)
118 self.process_complete_processes()
119 assert not running_processes
120 assert not self.process_map
121 assert not self.complete_processes
37 122
38 if __name__ == '__main__': 123 if __name__ == '__main__':
39 if len(sys.argv) < 4:
40 error_message = ('Usage:' + sys.argv[0] +
41 'LEXER_SHELL_PATH FILE_LIST_FILE PARALLEL_PROCESS_COUNT ' +
42 '[OTHER_ARGS]')
43 print >> sys.stderr, error_message
44 sys.exit(1)
45 lexer_shell = sys.argv[1]
46 file_file = sys.argv[2]
47 process_count = int(sys.argv[3])
48 with open(file_file, 'r') as f:
49 test_files = [filename for filename in f.read().split('\n') if filename]
50 124
51 with open('/dev/null', 'w') as dev_null: 125 parser = argparse.ArgumentParser()
52 processes = [] 126 parser.add_argument('-l', '--left-path')
53 for i, f in enumerate(test_files): 127 parser.add_argument('-r', '--right-path', default='')
54 lexer_shell_args = [lexer_shell, f, '--break-after-illegal'] + sys.argv[4: ] 128 parser.add_argument('-i', '--input-files-path', default='')
55 processes.append((f, subprocess.Popen(lexer_shell_args, stdout=dev_null))) 129 parser.add_argument('-f', '--single-file', default='')
56 if i % process_count == process_count - 1: 130 parser.add_argument('-p', '--parallel-process-count', default=1, type=int)
57 wait_processes(processes) 131 parser.add_argument('-e', '--encoding',
58 processes = [] 132 choices=['latin1', 'utf8', 'utf8to16', 'utf16'], default='utf8')
133 parser.add_argument('--use-harmony', action='store_true')
134 parser.add_argument('-v', '--verbose', action='store_true')
135 args = parser.parse_args()
59 136
60 wait_processes(processes) 137 if args.verbose:
138 logging.basicConfig(level=logging.INFO)
139
140 files = []
141 if args.input_files_path:
142 with open(args.input_files_path, 'r') as f:
143 files = [filename for filename in f.read().split('\n') if filename]
144 if args.single_file:
145 files.append(args.single_file)
146 assert files
147
148 process_runner = ProcessRunner(files, args)
149 process_runner.run()
OLDNEW
« no previous file with comments | « src/lexer/lexer-shell.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698