|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Copyright JS Foundation and other contributors, http://js.foundation |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +from __future__ import print_function |
| 18 | +import sys |
| 19 | +import os |
| 20 | +import subprocess |
| 21 | +import shutil |
| 22 | + |
| 23 | +def get_platform_cmd_prefix(): |
| 24 | + if sys.platform == 'win32': |
| 25 | + return ['cmd', '/S', '/C'] |
| 26 | + return ['python2'] # The official test262.py isn't python3 compatible, but has python shebang. |
| 27 | + |
| 28 | + |
| 29 | +def run_test262_tests(runtime, engine, path_to_test262): |
| 30 | + if not os.path.isdir(os.path.join(path_to_test262, '.git')): |
| 31 | + return_code = subprocess.call(['git', 'clone', 'https://github.com/tc39/test262.git', |
| 32 | + '-b', 'es5-tests', path_to_test262]) |
| 33 | + if return_code: |
| 34 | + print('Cloning test262 repository failed.') |
| 35 | + return return_code |
| 36 | + |
| 37 | + path_to_remove = os.path.join(path_to_test262, 'test', 'suite', 'bestPractice') |
| 38 | + if os.path.isdir(path_to_remove): |
| 39 | + shutil.rmtree(path_to_remove) |
| 40 | + |
| 41 | + path_to_remove = os.path.join(path_to_test262, 'test', 'suite', 'intl402') |
| 42 | + if os.path.isdir(path_to_remove): |
| 43 | + shutil.rmtree(path_to_remove) |
| 44 | + |
| 45 | + proc = subprocess.Popen(get_platform_cmd_prefix() + |
| 46 | + [os.path.join(path_to_test262, 'tools/packaging/test262.py'), |
| 47 | + '--command', (runtime + ' ' + engine).strip(), |
| 48 | + '--tests', path_to_test262, |
| 49 | + '--summary'], |
| 50 | + stdout=subprocess.PIPE) |
| 51 | + |
| 52 | + return_code = 0 |
| 53 | + with open(os.path.join(os.path.dirname(engine), 'test262.report'), 'w') as output_file: |
| 54 | + counter = 0 |
| 55 | + summary_found = False |
| 56 | + while True: |
| 57 | + counter += 1 |
| 58 | + output = proc.stdout.readline() |
| 59 | + if not output: |
| 60 | + break |
| 61 | + output_file.write(output) |
| 62 | + if (counter % 100) == 0: |
| 63 | + print("\rExecuted approx %d tests..." % counter, end='') |
| 64 | + |
| 65 | + if output.startswith('=== Summary ==='): |
| 66 | + summary_found = True |
| 67 | + print('') |
| 68 | + |
| 69 | + if summary_found: |
| 70 | + print(output, end='') |
| 71 | + if ('Failed tests' in output) or ('Expected to fail but passed' in output): |
| 72 | + return_code = 1 |
| 73 | + |
| 74 | + proc.wait() |
| 75 | + return return_code |
| 76 | + |
| 77 | + |
| 78 | +def main(): |
| 79 | + if len(sys.argv) != 3: |
| 80 | + print ("This script performs test262 compliance testing of the specified engine.") |
| 81 | + print ("") |
| 82 | + print ("Usage:") |
| 83 | + print (" 1st parameter: JavaScript engine to be tested.") |
| 84 | + print (" 2nd parameter: path to the directory with official test262 testsuite.") |
| 85 | + print ("") |
| 86 | + print ("Example:") |
| 87 | + print (" ./run-test-suite-test262.py <engine> <test262_dir>") |
| 88 | + sys.exit(1) |
| 89 | + |
| 90 | + runtime = os.environ.get('RUNTIME', '') |
| 91 | + engine = sys.argv[1] |
| 92 | + path_to_test262 = sys.argv[2] |
| 93 | + |
| 94 | + sys.exit(run_test262_tests(runtime, engine, path_to_test262)) |
| 95 | + |
| 96 | +if __name__ == "__main__": |
| 97 | + main() |
0 commit comments