| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 self.files.append(path) | 45 self.files.append(path) |
| 46 return path | 46 return path |
| 47 | 47 |
| 48 | 48 |
| 49 class BindingsTests: | 49 class BindingsTests: |
| 50 | 50 |
| 51 def __init__(self, reset_results, executive): | 51 def __init__(self, reset_results, executive): |
| 52 self.reset_results = reset_results | 52 self.reset_results = reset_results |
| 53 self.executive = executive | 53 self.executive = executive |
| 54 | 54 |
| 55 def generate_from_idl(self, idl_file, output_directory, supplemental_depende
ncy_file): | 55 def generate_from_idl(self, idl_file, output_directory, interface_dependenci
es_file): |
| 56 cmd = ['perl', '-w', | 56 cmd = ['perl', '-w', |
| 57 '-Ibindings/scripts', | 57 '-Ibindings/scripts', |
| 58 '-Icore/scripts', | 58 '-Icore/scripts', |
| 59 '-I../../JSON/out/lib/perl5', | 59 '-I../../JSON/out/lib/perl5', |
| 60 'bindings/scripts/generate-bindings.pl', | 60 'bindings/scripts/generate-bindings.pl', |
| 61 # idl include directories (path relative to generate-bindings.pl) | 61 # idl include directories (path relative to generate-bindings.pl) |
| 62 '--include', '.', | 62 '--include', '.', |
| 63 '--outputDir', output_directory, | 63 '--outputDir', output_directory, |
| 64 '--supplementalDependencyFile', supplemental_dependency_file, | 64 '--interfaceDependenciesFile', interface_dependencies_file, |
| 65 '--idlAttributesFile', 'bindings/scripts/IDLAttributes.txt', | 65 '--idlAttributesFile', 'bindings/scripts/IDLAttributes.txt', |
| 66 idl_file] | 66 idl_file] |
| 67 | 67 |
| 68 exit_code = 0 | 68 exit_code = 0 |
| 69 try: | 69 try: |
| 70 output = self.executive.run_command(cmd) | 70 output = self.executive.run_command(cmd) |
| 71 if output: | 71 if output: |
| 72 print output | 72 print output |
| 73 except ScriptError, e: | 73 except ScriptError, e: |
| 74 print e.output | 74 print e.output |
| 75 exit_code = e.exit_code | 75 exit_code = e.exit_code |
| 76 return exit_code | 76 return exit_code |
| 77 | 77 |
| 78 def generate_supplemental_dependency(self, input_directory, supplemental_dep
endency_file, window_constructors_file, workerglobalscope_constructors_file, sha
redworkerglobalscope_constructors_file, dedicatedworkerglobalscope_constructors_
file, event_names_file): | 78 def generate_interface_dependencies(self, input_directory, interface_depende
ncies_file, window_constructors_file, workerglobalscope_constructors_file, share
dworkerglobalscope_constructors_file, dedicatedworkerglobalscope_constructors_fi
le, event_names_file): |
| 79 idl_files_list = tempfile.mkstemp() | 79 idl_files_list = tempfile.mkstemp() |
| 80 for input_file in os.listdir(input_directory): | 80 for input_file in os.listdir(input_directory): |
| 81 (name, extension) = os.path.splitext(input_file) | 81 (name, extension) = os.path.splitext(input_file) |
| 82 if extension != '.idl': | 82 if extension != '.idl': |
| 83 continue | 83 continue |
| 84 os.write(idl_files_list[0], os.path.join(input_directory, input_file
) + "\n") | 84 os.write(idl_files_list[0], os.path.join(input_directory, input_file
) + "\n") |
| 85 os.close(idl_files_list[0]) | 85 os.close(idl_files_list[0]) |
| 86 | 86 |
| 87 cmd = ['python', | 87 cmd = ['python', |
| 88 'bindings/scripts/preprocess_idls.py', | 88 'bindings/scripts/compute_dependencies.py', |
| 89 '--idl-files-list', idl_files_list[1], | 89 '--idl-files-list', idl_files_list[1], |
| 90 '--supplemental-dependency-file', supplemental_dependency_file, | 90 '--interface-dependencies-file', interface_dependencies_file, |
| 91 '--window-constructors-file', window_constructors_file, | 91 '--window-constructors-file', window_constructors_file, |
| 92 '--workerglobalscope-constructors-file', workerglobalscope_constr
uctors_file, | 92 '--workerglobalscope-constructors-file', workerglobalscope_constr
uctors_file, |
| 93 '--sharedworkerglobalscope-constructors-file', sharedworkerglobal
scope_constructors_file, | 93 '--sharedworkerglobalscope-constructors-file', sharedworkerglobal
scope_constructors_file, |
| 94 '--dedicatedworkerglobalscope-constructors-file', dedicatedworker
globalscope_constructors_file, | 94 '--dedicatedworkerglobalscope-constructors-file', dedicatedworker
globalscope_constructors_file, |
| 95 '--event-names-file', event_names_file, | 95 '--event-names-file', event_names_file, |
| 96 '--write-file-only-if-changed', '0'] | 96 '--write-file-only-if-changed', '0'] |
| 97 | 97 |
| 98 if self.reset_results: | 98 if self.reset_results: |
| 99 print "Reset results: EventNames.in" | 99 print "Reset results: EventNames.in" |
| 100 | 100 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 return changes_found | 134 return changes_found |
| 135 | 135 |
| 136 | 136 |
| 137 def detect_changes(self, work_directory, reference_directory): | 137 def detect_changes(self, work_directory, reference_directory): |
| 138 changes_found = False | 138 changes_found = False |
| 139 for output_file in os.listdir(work_directory): | 139 for output_file in os.listdir(work_directory): |
| 140 if self.detect_changes_in_file(os.path.join(reference_directory, out
put_file), os.path.join(work_directory, output_file)): | 140 if self.detect_changes_in_file(os.path.join(reference_directory, out
put_file), os.path.join(work_directory, output_file)): |
| 141 changes_found = True | 141 changes_found = True |
| 142 return changes_found | 142 return changes_found |
| 143 | 143 |
| 144 def run_tests(self, input_directory, reference_directory, supplemental_depen
dency_file, event_names_file): | 144 def run_tests(self, input_directory, reference_directory, interface_dependen
cies_file, event_names_file): |
| 145 work_directory = reference_directory | 145 work_directory = reference_directory |
| 146 | 146 |
| 147 passed = True | 147 passed = True |
| 148 | 148 |
| 149 if not self.reset_results and self.detect_changes_in_file(event_names_fi
le, os.path.join(reference_directory, 'EventNames.in')): | 149 if not self.reset_results and self.detect_changes_in_file(event_names_fi
le, os.path.join(reference_directory, 'EventNames.in')): |
| 150 passed = False | 150 passed = False |
| 151 | 151 |
| 152 for input_file in os.listdir(input_directory): | 152 for input_file in os.listdir(input_directory): |
| 153 (name, extension) = os.path.splitext(input_file) | 153 (name, extension) = os.path.splitext(input_file) |
| 154 if extension != '.idl': | 154 if extension != '.idl': |
| 155 continue | 155 continue |
| 156 # Generate output into the work directory (either the given one or a | 156 # Generate output into the work directory (either the given one or a |
| 157 # temp one if not reset_results is performed) | 157 # temp one if not reset_results is performed) |
| 158 if not self.reset_results: | 158 if not self.reset_results: |
| 159 work_directory = tempfile.mkdtemp() | 159 work_directory = tempfile.mkdtemp() |
| 160 | 160 |
| 161 if self.generate_from_idl(os.path.join(input_directory, input_file), | 161 if self.generate_from_idl(os.path.join(input_directory, input_file), |
| 162 work_directory, | 162 work_directory, |
| 163 supplemental_dependency_file): | 163 interface_dependencies_file): |
| 164 passed = False | 164 passed = False |
| 165 | 165 |
| 166 if self.reset_results: | 166 if self.reset_results: |
| 167 print "Reset results: %s" % (input_file) | 167 print "Reset results: %s" % (input_file) |
| 168 continue | 168 continue |
| 169 | 169 |
| 170 # Detect changes | 170 # Detect changes |
| 171 if self.detect_changes(work_directory, reference_directory): | 171 if self.detect_changes(work_directory, reference_directory): |
| 172 passed = False | 172 passed = False |
| 173 shutil.rmtree(work_directory) | 173 shutil.rmtree(work_directory) |
| 174 | 174 |
| 175 return passed | 175 return passed |
| 176 | 176 |
| 177 def main(self): | 177 def main(self): |
| 178 current_scm = detect_scm_system(os.curdir) | 178 current_scm = detect_scm_system(os.curdir) |
| 179 os.chdir(os.path.join(current_scm.checkout_root, 'Source')) | 179 os.chdir(os.path.join(current_scm.checkout_root, 'Source')) |
| 180 | 180 |
| 181 all_tests_passed = True | 181 all_tests_passed = True |
| 182 | 182 |
| 183 provider = ScopedTempFileProvider() | 183 provider = ScopedTempFileProvider() |
| 184 | 184 |
| 185 input_directory = os.path.join('bindings', 'tests', 'idls') | 185 input_directory = os.path.join('bindings', 'tests', 'idls') |
| 186 reference_directory = os.path.join('bindings', 'tests', 'results') | 186 reference_directory = os.path.join('bindings', 'tests', 'results') |
| 187 | 187 |
| 188 supplemental_dependency_file = provider.newtempfile() | 188 interface_dependencies_file = provider.newtempfile() |
| 189 window_constructors_file = provider.newtempfile() | 189 window_constructors_file = provider.newtempfile() |
| 190 workerglobalscope_constructors_file = provider.newtempfile() | 190 workerglobalscope_constructors_file = provider.newtempfile() |
| 191 sharedworkerglobalscope_constructors_file = provider.newtempfile() | 191 sharedworkerglobalscope_constructors_file = provider.newtempfile() |
| 192 dedicatedworkerglobalscope_constructors_file = provider.newtempfile() | 192 dedicatedworkerglobalscope_constructors_file = provider.newtempfile() |
| 193 | 193 |
| 194 if self.reset_results: | 194 if self.reset_results: |
| 195 event_names_file = os.path.join(reference_directory, 'EventNames.in'
) | 195 event_names_file = os.path.join(reference_directory, 'EventNames.in'
) |
| 196 else: | 196 else: |
| 197 event_names_file = provider.newtempfile() | 197 event_names_file = provider.newtempfile() |
| 198 | 198 |
| 199 if self.generate_supplemental_dependency(input_directory, supplemental_d
ependency_file, window_constructors_file, workerglobalscope_constructors_file, s
haredworkerglobalscope_constructors_file, dedicatedworkerglobalscope_constructor
s_file, event_names_file): | 199 if self.generate_interface_dependencies(input_directory, interface_depen
dencies_file, window_constructors_file, workerglobalscope_constructors_file, sha
redworkerglobalscope_constructors_file, dedicatedworkerglobalscope_constructors_
file, event_names_file): |
| 200 print 'Failed to generate a supplemental dependency file.' | 200 print 'Failed to generate interface dependencies file.' |
| 201 return -1 | 201 return -1 |
| 202 | 202 |
| 203 if not self.run_tests(input_directory, reference_directory, supplemental
_dependency_file, event_names_file): | 203 if not self.run_tests(input_directory, reference_directory, interface_de
pendencies_file, event_names_file): |
| 204 all_tests_passed = False | 204 all_tests_passed = False |
| 205 | 205 |
| 206 print '' | 206 print '' |
| 207 if all_tests_passed: | 207 if all_tests_passed: |
| 208 print 'All tests PASS!' | 208 print 'All tests PASS!' |
| 209 return 0 | 209 return 0 |
| 210 else: | 210 else: |
| 211 print 'Some tests FAIL! (To update the reference files, execute "run
-bindings-tests --reset-results")' | 211 print 'Some tests FAIL! (To update the reference files, execute "run
-bindings-tests --reset-results")' |
| 212 return -1 | 212 return -1 |
| OLD | NEW |