Skip to content

Commit 53700f9

Browse files
committed
Convert python jerry-debugger support python3 on win32 and OSX
Convert run-debugger-test.sh to run-debugger-test.py After this change, run-debugger-test.py could running on Win32 and OSX JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
1 parent 9c77b98 commit 53700f9

File tree

7 files changed

+131
-71
lines changed

7 files changed

+131
-71
lines changed

.github/workflows/gh-actions.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ jobs:
8585
- run: python $env:RUNNER -q --unittests --build-debug
8686
- run: python $env:RUNNER -q --buildoption-test --build-debug
8787

88+
Win_x86-64_Debugger:
89+
runs-on: windows-latest
90+
steps:
91+
- uses: actions/checkout@v2
92+
- run: python $env:RUNNER -q --jerry-debugger --run-check-timeout=60
93+
- run: python $env:RUNNER -q --jerry-debugger --build-debug --run-check-timeout=60
94+
8895
OSX_x86-64_Build_Correctness_Unit_Tests:
8996
runs-on: macos-13
9097
steps:
@@ -94,6 +101,7 @@ jobs:
94101
python-version: '>=3.6'
95102
- run: $RUNNER -q --jerry-tests
96103
- run: $RUNNER -q --unittests
104+
- run: $RUNNER -q --jerry-debugger --run-check-timeout=60
97105

98106
OSX_x86-64_Build_Correctness_Unit_Tests_Debug:
99107
runs-on: macos-13
@@ -104,6 +112,7 @@ jobs:
104112
python-version: '>=3.6'
105113
- run: $RUNNER -q --jerry-tests --build-debug
106114
- run: $RUNNER -q --unittests --build-debug
115+
- run: $RUNNER -q --jerry-debugger --build-debug --run-check-timeout=60
107116

108117
Linux_x86-64_Build_Option_Tests:
109118
runs-on: ubuntu-latest

jerry-debugger/jerry_client.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from cmd import Cmd
1818
from pprint import pprint
19+
import codecs
1920
import math
2021
import socket
2122
import sys
@@ -25,6 +26,7 @@
2526

2627
from jerry_client_websocket import WebSocket
2728
from jerry_client_rawpacket import RawPacket
29+
from jerry_client_serial import Serial
2830
from jerry_client_tcp import Socket
2931

3032
def write(string):
@@ -261,8 +263,19 @@ def src_check_args(args):
261263
print(f"Error: Non-negative integer number expected: {val_errno}")
262264
return -1
263265

264-
# pylint: disable=too-many-branches,too-many-locals,too-many-statements,import-outside-toplevel
266+
# This is for not lost data on 'win32' with python 'print'.
267+
# When use python subprocess call another script on win32, output with
268+
# 'utf-8' encoding, that's the same like linux platform; but when
269+
# call the python script in 'cmd.exe' shell, we have to output in 'native' encoding.
270+
def setup_stdio():
271+
# For tty using native encoding, otherwise (pipe) use 'utf-8'
272+
encoding = sys.stdout.encoding if sys.stdout.isatty() else 'utf-8'
273+
# Always override it to avoid encode error
274+
sys.stdout = codecs.getwriter(encoding)(sys.stdout.buffer, 'xmlcharrefreplace')
275+
sys.stderr = codecs.getwriter(encoding)(sys.stderr.buffer, 'xmlcharrefreplace')
276+
265277
def main():
278+
setup_stdio()
266279
args = jerry_client_main.arguments_parse()
267280

268281
channel = None
@@ -278,7 +291,6 @@ def main():
278291

279292
protocol = Socket(address)
280293
elif args.protocol == "serial":
281-
from jerry_client_serial import Serial
282294
protocol = Serial(args.serial_config)
283295
else:
284296
print("Unsupported transmission protocol")
@@ -326,6 +338,8 @@ def main():
326338
break
327339
if res_type == result.PROMPT:
328340
prompt.cmdloop()
341+
sys.stdout.flush()
342+
sys.stderr.flush()
329343
elif res_type == result.TEXT:
330344
write(result.get_text())
331345
continue

jerry-debugger/jerry_client_serial.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
# limitations under the License.
1414

1515
import select
16-
import serial
16+
try:
17+
import serial
18+
except ImportError:
19+
# OSX do not have serial
20+
pass
1721

1822
class Serial:
1923
""" Create a new socket using the given address family, socket type and protocol number. """

tools/run-tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def run_jerry_debugger_tests():
332332
if test_file.endswith(".cmd"):
333333
test_case, _ = os.path.splitext(test_file)
334334
test_case_path = os.path.join(settings.DEBUGGER_TESTS_DIR, test_case)
335-
test_cmd = [
335+
test_cmd = util.get_python_cmd_prefix() + [
336336
settings.DEBUGGER_TEST_RUNNER_SCRIPT,
337337
get_binary_path(build_dir_path),
338338
channel,

tools/runners/run-debugger-test.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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()))

tools/runners/run-debugger-test.sh

Lines changed: 0 additions & 66 deletions
This file was deleted.

tools/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
BUILD_SCRIPT = path.join(TOOLS_DIR, 'build.py')
2525
CPPCHECK_SCRIPT = path.join(TOOLS_DIR, 'check-cppcheck.sh')
2626
DEBUGGER_CLIENT_SCRIPT = path.join(PROJECT_DIR, 'jerry-debugger/jerry_client.py')
27-
DEBUGGER_TEST_RUNNER_SCRIPT = path.join(TOOLS_DIR, 'runners/run-debugger-test.sh')
27+
DEBUGGER_TEST_RUNNER_SCRIPT = path.join(TOOLS_DIR, 'runners/run-debugger-test.py')
2828
DOXYGEN_SCRIPT = path.join(TOOLS_DIR, 'check-doxygen.sh')
2929
LICENSE_SCRIPT = path.join(TOOLS_DIR, 'check-license.py')
3030
STRINGS_SCRIPT = path.join(TOOLS_DIR, 'check-strings.sh')

0 commit comments

Comments
 (0)