|
| 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 | +import os |
| 18 | +import subprocess |
| 19 | +import sys |
| 20 | +import time |
| 21 | + |
| 22 | +import util |
| 23 | +TempFile = __import__("test262-harness").TempFile # pylint: disable=invalid-name |
| 24 | + |
| 25 | +class DebuggerArgs: |
| 26 | + def __init__(self): |
| 27 | + self.jerry = sys.argv[1] |
| 28 | + self.channel = sys.argv[2] |
| 29 | + self.debugger_client = sys.argv[3] |
| 30 | + self.test_case = sys.argv[4] |
| 31 | + |
| 32 | + |
| 33 | +def check_output(command_args, stdin=None, encoding=None): |
| 34 | + try: |
| 35 | + out = subprocess.check_output(command_args, stdin=stdin, shell=False, stderr=subprocess.STDOUT) |
| 36 | + except subprocess.CalledProcessError as check_error: |
| 37 | + out = check_error.output |
| 38 | + return out.decode(encoding or 'utf-8', 'ignore') |
| 39 | + |
| 40 | + |
| 41 | +def execute_debug_client(out_tmp, cmd_file_name, debug_client_args): |
| 42 | + print(f'input debug cmd: {cmd_file_name}') |
| 43 | + with open(cmd_file_name, 'rb') as cmd_file: |
| 44 | + out = check_output(debug_client_args, cmd_file) |
| 45 | + out_tmp.write(out) |
| 46 | + |
| 47 | + |
| 48 | +def main(args): |
| 49 | + util.setup_stdio() |
| 50 | + jerry_debug_server_cmd = [args.jerry] |
| 51 | + client_args = [] |
| 52 | + if 'client_source' in args.test_case: |
| 53 | + jerry_debug_server_cmd += ['--start-debug-server', '--debug-channel', |
| 54 | + args.channel, '--debugger-wait-source'] |
| 55 | + client_args += ['--client-source'] |
| 56 | + if 'client_source_multiple' in args.test_case: |
| 57 | + client_args += [args.test_case + '_2.js', args.test_case + '_1.js'] |
| 58 | + else: |
| 59 | + client_args += [args.test_case + '.js'] |
| 60 | + else: |
| 61 | + jerry_debug_server_cmd += [args.test_case + '.js', '--start-debug-server', '--debug-channel', args.channel] |
| 62 | + print(f'run debug server: {jerry_debug_server_cmd}') |
| 63 | + with subprocess.Popen(jerry_debug_server_cmd, stdin=subprocess.PIPE, |
| 64 | + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as proc: |
| 65 | + time.sleep(1) |
| 66 | + |
| 67 | + out_tmp = TempFile(prefix=os.path.basename(args.test_case), suffix='out') |
| 68 | + git_failed = False |
| 69 | + try: |
| 70 | + debug_client_args = util.get_python_cmd_prefix() |
| 71 | + debug_client_args += [args.debugger_client, '--channel', args.channel, '--non-interactive'] |
| 72 | + debug_client_args += client_args |
| 73 | + print(f"run debug client: {' '.join(debug_client_args)}") |
| 74 | + execute_debug_client(out_tmp, args.test_case + '.cmd', debug_client_args) |
| 75 | + if 'restart' in args.test_case: |
| 76 | + continue_case = args.test_case.replace('restart', 'continue') |
| 77 | + execute_debug_client(out_tmp, continue_case + '.cmd', debug_client_args) |
| 78 | + out_tmp.close() |
| 79 | + git_diff_cmd = ['git', '--no-pager', 'diff', '--ignore-space-at-eol', |
| 80 | + '--no-index', args.test_case + '.expected', out_tmp.name] |
| 81 | + git_out = check_output(git_diff_cmd) |
| 82 | + if '@@' in git_out: |
| 83 | + git_failed = True |
| 84 | + finally: |
| 85 | + proc.wait() |
| 86 | + if git_failed: |
| 87 | + print(f"jerry out:\n{proc.stdout.read().decode('utf-8')}\nEOF") |
| 88 | + print(f"git diff cmd: {' '.join(git_diff_cmd)}") |
| 89 | + print(f'git diff result:\n{git_out}\nEOF') |
| 90 | + print(f'{util.TERM_RED}FAIL: {args.test_case}{util.TERM_NORMAL}') |
| 91 | + sys.exit(1) |
| 92 | + else: |
| 93 | + out_tmp.dispose() |
| 94 | + print(f'{util.TERM_GREEN}PASS: {args.test_case}{util.TERM_NORMAL}') |
| 95 | + sys.exit(0) |
| 96 | + |
| 97 | + |
| 98 | +if __name__ == "__main__": |
| 99 | + sys.exit(main(DebuggerArgs())) |
0 commit comments