Skip to content

Commit e401d3d

Browse files
committed
Revise tools scripts to be python3 compatible
We introduce setup_stdio function to setup stdout/stderr properly. For python <-> python pipe, we always use 'utf8'/'ignore' encoding for not lost characters. For tty <-> python, we using native encoding with xmlcharrefreplace to encode, to preserve maximal information. For python <-> native program, we use naive encoding with 'ignore' to not cause error Fixes #4854 JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
1 parent 55acdf2 commit e401d3d

File tree

6 files changed

+19
-0
lines changed

6 files changed

+19
-0
lines changed

tools/run-tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ def run_buildoption_test(options):
498498
Check = collections.namedtuple('Check', ['enabled', 'runner', 'arg'])
499499

500500
def main(options):
501+
util.setup_stdio()
501502
checks = [
502503
Check(options.check_signed_off, run_check, [settings.SIGNED_OFF_SCRIPT]
503504
+ {'tolerant': ['--tolerant'], 'gh-actions': ['--gh-actions']}.get(options.check_signed_off, [])),

tools/runners/run-test-suite-test262.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def update_exclude_list(args):
174174

175175

176176
def main(args):
177+
util.setup_stdio()
177178
return_code = prepare_test262_test_suite(args)
178179
if return_code:
179180
return return_code

tools/runners/run-test-suite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def execute_test_command(test_cmd):
8686

8787

8888
def main(args):
89+
util.setup_stdio()
8990
tests = get_tests(args.test_dir, args.test_list, args.skip_list)
9091
total = len(tests)
9192
if total == 0:

tools/runners/run-unittests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def get_unittests(path):
5050

5151

5252
def main(args):
53+
util.setup_stdio()
5354
unittests = get_unittests(args.path)
5455
total = len(unittests)
5556
if total == 0:

tools/runners/test262-harness.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
import threading
5959
import multiprocessing
6060

61+
import util
62+
6163
#######################################################################
6264
# based on _monkeyYaml.py
6365
#######################################################################
@@ -917,6 +919,7 @@ def list_includes(self, tests):
917919

918920

919921
def main():
922+
util.setup_stdio()
920923
code = 0
921924
parser = build_options()
922925
(options, args) = parser.parse_args()

tools/runners/util.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616

1717
from __future__ import print_function
18+
import codecs
1819
import signal
1920
import subprocess
2021
import sys
@@ -45,6 +46,17 @@ def set_sighdl_to_reset_timezone(timezone):
4546
signal.signal(signal.SIGINT, lambda signal, frame: set_timezone_and_exit(timezone))
4647

4748

49+
def setup_stdio():
50+
(out_stream, err_stream) = (sys.stdout, sys.stderr)
51+
if sys.version_info.major >= 3:
52+
(out_stream, err_stream) = (sys.stdout.buffer, sys.stderr.buffer)
53+
# For tty using native encoding, otherwise (pipe) use 'utf-8'
54+
encoding = sys.stdout.encoding if sys.stdout.isatty() else 'utf-8'
55+
# Always override it to anvoid encode error
56+
sys.stdout = codecs.getwriter(encoding)(out_stream, 'xmlcharrefreplace')
57+
sys.stderr = codecs.getwriter(encoding)(err_stream, 'xmlcharrefreplace')
58+
59+
4860
def print_test_summary(summary_string, total, passed, failed):
4961
print("\n[summary] %s\n" % summary_string)
5062
print("TOTAL: %d" % total)

0 commit comments

Comments
 (0)