OLD | NEW |
1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions | 4 # modification, are permitted provided that the following conditions |
5 # are met: | 5 # are met: |
6 # 1. Redistributions of source code must retain the above copyright | 6 # 1. 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 # 2. Redistributions in binary form must reproduce the above copyright | 8 # 2. Redistributions in binary form must reproduce the above copyright |
9 # notice, this list of conditions and the following disclaimer in the | 9 # notice, this list of conditions and the following disclaimer in the |
10 # documentation and/or other materials provided with the distribution. | 10 # documentation and/or other materials provided with the distribution. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 | 90 |
91 class BindingsTests(object): | 91 class BindingsTests(object): |
92 def __init__(self, reset_results, test_python, verbose, executive): | 92 def __init__(self, reset_results, test_python, verbose, executive): |
93 self.reset_results = reset_results | 93 self.reset_results = reset_results |
94 self.test_python = test_python | 94 self.test_python = test_python |
95 self.verbose = verbose | 95 self.verbose = verbose |
96 self.executive = executive | 96 self.executive = executive |
97 _, self.interface_dependencies_filename = provider.newtempfile() | 97 _, self.interface_dependencies_filename = provider.newtempfile() |
98 _, self.derived_sources_list_filename = provider.newtempfile() | 98 _, self.derived_sources_list_filename = provider.newtempfile() |
| 99 # Generate output into the reference directory if resetting results, or |
| 100 # a temp directory if not. |
99 if reset_results: | 101 if reset_results: |
100 self.event_names_filename = os.path.join(reference_directory, 'Event
Interfaces.in') | 102 self.output_directory = reference_directory |
101 else: | 103 else: |
102 _, self.event_names_filename = provider.newtempfile() | 104 self.output_directory = provider.newtempdir() |
| 105 self.event_names_filename = os.path.join(self.output_directory, 'EventIn
terfaces.in') |
103 | 106 |
104 def run_command(self, cmd): | 107 def run_command(self, cmd): |
105 output = self.executive.run_command(cmd) | 108 output = self.executive.run_command(cmd) |
106 if output: | 109 if output: |
107 print output | 110 print output |
108 | 111 |
109 def generate_from_idl_pl(self, idl_file, output_directory): | 112 def generate_from_idl_pl(self, idl_file): |
110 cmd = ['perl', '-w', | 113 cmd = ['perl', '-w', |
111 '-Ibindings/scripts', | 114 '-Ibindings/scripts', |
112 '-Ibuild/scripts', | 115 '-Ibuild/scripts', |
113 '-Icore/scripts', | 116 '-Icore/scripts', |
114 '-I../../JSON/out/lib/perl5', | 117 '-I../../JSON/out/lib/perl5', |
115 'bindings/scripts/generate_bindings.pl', | 118 'bindings/scripts/generate_bindings.pl', |
116 # idl include directories (path relative to generate-bindings.pl) | 119 # idl include directories (path relative to generate-bindings.pl) |
117 '--include', '.', | 120 '--include', '.', |
118 '--outputDir', output_directory, | 121 '--outputDir', self.output_directory, |
119 '--interfaceDependenciesFile', self.interface_dependencies_filena
me, | 122 '--interfaceDependenciesFile', self.interface_dependencies_filena
me, |
120 '--idlAttributesFile', 'bindings/IDLExtendedAttributes.txt', | 123 '--idlAttributesFile', 'bindings/IDLExtendedAttributes.txt', |
121 idl_file] | 124 idl_file] |
122 try: | 125 try: |
123 self.run_command(cmd) | 126 self.run_command(cmd) |
124 except ScriptError, e: | 127 except ScriptError, e: |
125 print 'ERROR: generate_bindings.pl: ' + os.path.basename(idl_file) | 128 print 'ERROR: generate_bindings.pl: ' + os.path.basename(idl_file) |
126 print e.output | 129 print e.output |
127 return e.exit_code | 130 return e.exit_code |
128 return 0 | 131 return 0 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 if self.reset_results and self.verbose: | 186 if self.reset_results and self.verbose: |
184 print 'Reset results: EventInterfaces.in' | 187 print 'Reset results: EventInterfaces.in' |
185 try: | 188 try: |
186 self.run_command(cmd) | 189 self.run_command(cmd) |
187 except ScriptError, e: | 190 except ScriptError, e: |
188 print 'ERROR: compute_dependencies.py' | 191 print 'ERROR: compute_dependencies.py' |
189 print e.output | 192 print e.output |
190 return e.exit_code | 193 return e.exit_code |
191 return 0 | 194 return 0 |
192 | 195 |
193 def identical_file(self, reference_filename, work_filename): | 196 def identical_file(self, reference_filename, output_filename): |
194 reference_basename = os.path.basename(reference_filename) | 197 reference_basename = os.path.basename(reference_filename) |
195 cmd = ['diff', | 198 cmd = ['diff', |
196 '-u', | 199 '-u', |
197 '-N', | 200 '-N', |
198 reference_filename, | 201 reference_filename, |
199 work_filename] | 202 output_filename] |
200 try: | 203 try: |
201 self.run_command(cmd) | 204 self.run_command(cmd) |
202 except ScriptError, e: | 205 except ScriptError, e: |
203 # run_command throws an exception on diff (b/c non-zero exit code) | 206 # run_command throws an exception on diff (b/c non-zero exit code) |
204 print 'FAIL: %s' % reference_basename | 207 print 'FAIL: %s' % reference_basename |
205 print e.output | 208 print e.output |
206 return False | 209 return False |
207 | 210 |
208 if self.verbose: | 211 if self.verbose: |
209 print 'PASS: %s' % reference_basename | 212 print 'PASS: %s' % reference_basename |
210 return True | 213 return True |
211 | 214 |
212 def identical_output_directory(self, work_directory): | 215 def identical_output_files(self, output_directory): |
213 file_pairs = [(os.path.join(reference_directory, output_file), | 216 file_pairs = [(os.path.join(reference_directory, output_file), |
214 os.path.join(work_directory, output_file)) | 217 os.path.join(output_directory, output_file)) |
215 for output_file in os.listdir(work_directory) | 218 for output_file in os.listdir(output_directory) |
216 # FIXME: add option to compiler to not generate tables | 219 # FIXME: add option to compiler to not generate tables |
217 if output_file != 'parsetab.py'] | 220 if output_file != 'parsetab.py'] |
218 return all([self.identical_file(reference_filename, work_filename) | 221 return all([self.identical_file(reference_filename, output_filename) |
219 for (reference_filename, work_filename) in file_pairs]) | 222 for (reference_filename, output_filename) in file_pairs]) |
| 223 |
| 224 def no_excess_files(self): |
| 225 generated_files = set(os.listdir(self.output_directory)) |
| 226 excess_files = [output_file |
| 227 for output_file in os.listdir(reference_directory) |
| 228 if output_file not in generated_files] |
| 229 if excess_files: |
| 230 print ('Excess reference files! ' |
| 231 '(probably cruft from renaming or deleting):\n' + |
| 232 '\n'.join(excess_files)) |
| 233 return False |
| 234 return True |
220 | 235 |
221 def run_tests(self): | 236 def run_tests(self): |
222 def generate_and_check_output_pl(idl_filename, directory): | 237 def generate_and_check_output_pl(idl_filename, directory): |
223 # Generate output into the reference directory if resetting | |
224 # results, or a temp directory if not. | |
225 if self.reset_results: | |
226 work_directory = reference_directory | |
227 else: | |
228 work_directory = provider.newtempdir() | |
229 idl_path = os.path.join(directory, idl_filename) | 238 idl_path = os.path.join(directory, idl_filename) |
230 if self.generate_from_idl_pl(idl_path, work_directory): | 239 if self.generate_from_idl_pl(idl_path): |
231 return False | 240 return False |
232 if self.reset_results: | 241 if self.reset_results: |
233 if self.verbose: | 242 if self.verbose: |
234 print 'Reset results: %s' % input_file | 243 print 'Reset results: %s' % input_file |
235 return True | 244 return True |
236 return self.identical_output_directory(work_directory) | 245 return self.identical_output_files(self.output_directory) |
237 | 246 |
238 def generate_and_check_output_py(idl_filename): | 247 def generate_and_check_output_py(idl_filename): |
239 if idl_filename in SKIP_PYTHON: | 248 if idl_filename in SKIP_PYTHON: |
240 if self.verbose: | 249 if self.verbose: |
241 print 'SKIP: %s' % idl_filename | 250 print 'SKIP: %s' % idl_filename |
242 return True | 251 return True |
243 work_directory = provider.newtempdir() | 252 output_directory_py = provider.newtempdir() |
244 idl_path = os.path.join(input_directory, idl_filename) | 253 idl_path = os.path.join(input_directory, idl_filename) |
245 if self.generate_from_idl_py(idl_path, work_directory): | 254 if self.generate_from_idl_py(idl_path, output_directory_py): |
246 return False | 255 return False |
247 # Detect changes | 256 # Detect changes |
248 return self.identical_output_directory(work_directory) | 257 return self.identical_output_files(output_directory_py) |
249 | 258 |
250 if self.reset_results: | 259 if self.reset_results: |
251 passed = True | 260 passed = True |
252 else: | 261 else: |
253 passed = self.identical_file(reference_event_names_filename, | 262 passed = self.identical_file(reference_event_names_filename, |
254 self.event_names_filename) | 263 self.event_names_filename) |
255 for directory in [input_directory, support_input_directory]: | 264 for directory in [input_directory, support_input_directory]: |
256 passed &= all([generate_and_check_output_pl(input_file, directory) | 265 passed &= all([generate_and_check_output_pl(input_file, directory) |
257 for input_file in os.listdir(directory) | 266 for input_file in os.listdir(directory) |
258 if input_file.endswith('.idl')]) | 267 if input_file.endswith('.idl')]) |
| 268 passed &= self.no_excess_files() |
259 if self.test_python: | 269 if self.test_python: |
260 if self.verbose: | 270 if self.verbose: |
261 print | 271 print |
262 print 'Python:' | 272 print 'Python:' |
263 passed &= all([generate_and_check_output_py(input_file) | 273 passed &= all([generate_and_check_output_py(input_file) |
264 for input_file in os.listdir(input_directory) | 274 for input_file in os.listdir(input_directory) |
265 if input_file.endswith('.idl')]) | 275 if input_file.endswith('.idl')]) |
266 return passed | 276 return passed |
267 | 277 |
268 def main(self): | 278 def main(self): |
269 current_scm = detect_scm_system(os.curdir) | 279 current_scm = detect_scm_system(os.curdir) |
270 os.chdir(os.path.join(current_scm.checkout_root, 'Source')) | 280 os.chdir(os.path.join(current_scm.checkout_root, 'Source')) |
271 | 281 |
272 if self.generate_interface_dependencies(): | 282 if self.generate_interface_dependencies(): |
273 print 'Failed to generate interface dependencies file.' | 283 print 'Failed to generate interface dependencies file.' |
274 return -1 | 284 return -1 |
275 | 285 |
276 all_tests_passed = self.run_tests() | 286 all_tests_passed = self.run_tests() |
277 if all_tests_passed: | 287 if all_tests_passed: |
278 if self.verbose: | 288 if self.verbose: |
279 print | 289 print |
280 print PASS_MESSAGE | 290 print PASS_MESSAGE |
281 return 0 | 291 return 0 |
282 print | 292 print |
283 print FAIL_MESSAGE | 293 print FAIL_MESSAGE |
284 return -1 | 294 return -1 |
OLD | NEW |