Yonggang Luo d2d30df420
Revise tools scripts to be python3 compatible on win32 (#4856)
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

update_exclude_list with binary mode so that on win32 would not generate \r\n

run-test-suite.py: Handling skiplist properly on win32

Fixes #4854

Fixes test262-harness.py complain cannot use a string pattern on a bytes-like object with running test262 with python3

For reading/writing to file, we use 'utf8' /'ignore' encoding for not lost characters.
For decoding from process stdout, using native encoding with decoding error ignored for not lost data.
Execute commands also ignore errors
Fixes #4853

Fixes running test262-esnext failed with installed python3.9 on win32 with space in path
Fixes #4852

support both / \ in --test262-test-list arg

On win32.
python tools/run-tests.py  --test262-es2015=update --test262-test-list=built-ins/decodeURI/
python tools/run-tests.py  --test262-es2015=update --test262-test-list=built-ins\decodeURI\
should be both valid,
currently only --test262-test-list=built-ins\decodeURI\ are valid.

Support snapshot-tests-skiplist.txt on win32 by use os.path.normpath

Guard run-tests.py with timer.

All run-tests.py are finished in 30 minutes in normal situation.
May change the timeout by command line option

Move Windows CI to github actions
Define TERM colors for win32 properly

flush stderr.write stdout.write

On CI, the stderr are redirect to stdout, and if we don't flush stderr and stdout,
The output from stderr/stdout would out of sync.

`Testing new Date(-8640000000000000) and fixes date for win32`
So that the CI can passed

if sys.version_info.major >= 3: remove, as we do not support python2 anymore

Fixes compiling warnings/errors for mingw/gcc

JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com
2024-12-17 10:41:12 +01:00

98 lines
3.4 KiB
Python
Executable File

# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import codecs
import signal
import subprocess
import sys
if sys.platform == 'win32':
TERM_NORMAL = ''
TERM_RED = ''
TERM_GREEN = ''
TERM_YELLOW = ''
TERM_BLUE = ''
else:
TERM_NORMAL = '\033[0m'
TERM_RED = '\033[1;31m'
TERM_GREEN = '\033[1;32m'
TERM_YELLOW = '\033[1;33m'
TERM_BLUE = '\033[1;34m'
def set_timezone(timezone):
assert sys.platform == 'win32', "set_timezone is Windows only function"
subprocess.call(['cmd', '/S', '/C', 'tzutil', '/s', timezone])
def set_timezone_and_exit(timezone):
assert sys.platform == 'win32', "set_timezone_and_exit is Windows only function"
set_timezone(timezone)
sys.exit(1)
def get_timezone():
assert sys.platform == 'win32', "get_timezone is Windows only function"
return subprocess.check_output(['cmd', '/S', '/C', 'tzutil', '/g'], universal_newlines=True)
def set_sighdl_to_reset_timezone(timezone):
assert sys.platform == 'win32', "install_signal_handler_to_restore_timezone is Windows only function"
signal.signal(signal.SIGINT, lambda signal, frame: set_timezone_and_exit(timezone))
# This is for not lost data on 'win32' with python 'print'.
# When use python subprocess call another script on win32, output with
# 'utf-8' encoding, that's the same like linux platform; but when
# call the python script in 'cmd.exe' shell, we have to output in 'native' encoding.
def setup_stdio():
# For tty using native encoding, otherwise (pipe) use 'utf-8'
encoding = sys.stdout.encoding if sys.stdout.isatty() else 'utf-8'
# Always override it to avoid encode error
sys.stdout = codecs.getwriter(encoding)(sys.stdout.buffer, 'xmlcharrefreplace')
sys.stderr = codecs.getwriter(encoding)(sys.stderr.buffer, 'xmlcharrefreplace')
def print_test_summary(summary_string, total, passed, failed):
print(f"\n[summary] {summary_string}\n")
print(f"TOTAL: {total}")
print(f"{TERM_GREEN}PASS: {passed}{TERM_NORMAL}")
print(f"{TERM_RED}FAIL: {failed}{TERM_NORMAL}\n")
success_color = TERM_GREEN if passed == total else TERM_RED
print(f"{success_color}Success: {passed*100/total}{TERM_NORMAL}")
def print_test_result(tested, total, is_passed, passed_string, test_path, is_snapshot_generation=None):
if is_snapshot_generation is None:
snapshot_string = ''
elif is_snapshot_generation:
snapshot_string = ' (generate snapshot)'
else:
snapshot_string = ' (execute snapshot)'
color = TERM_GREEN if is_passed else TERM_RED
print(f"[{tested:>4}/{total:>4}] {color}{passed_string}: {test_path}{snapshot_string}{TERM_NORMAL}")
def get_platform_cmd_prefix():
if sys.platform == 'win32':
return ['cmd', '/S', '/C']
return []
def get_python_cmd_prefix():
# python script doesn't have execute permission on github actions windows runner
return [sys.executable or 'python']