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
This commit is contained in:
@@ -22,12 +22,6 @@ import sys
|
||||
|
||||
import util
|
||||
|
||||
def get_platform_cmd_prefix():
|
||||
if sys.platform == 'win32':
|
||||
return ['cmd', '/S', '/C']
|
||||
return ['python3']
|
||||
|
||||
|
||||
def get_arguments():
|
||||
execution_runtime = os.environ.get('RUNTIME', '')
|
||||
parser = argparse.ArgumentParser()
|
||||
@@ -91,7 +85,7 @@ def update_exclude_list(args):
|
||||
# Tests pass in strict-mode but fail in non-strict-mode (or vice versa) should be considered as failures
|
||||
passing_tests = passing_tests - failing_tests
|
||||
|
||||
with open(args.excludelist_path, 'r+', encoding='utf8') as exclude_file:
|
||||
with open(args.excludelist_path, 'r+', encoding='utf8', errors='ignore') as exclude_file:
|
||||
lines = exclude_file.readlines()
|
||||
exclude_file.seek(0)
|
||||
exclude_file.truncate()
|
||||
@@ -135,6 +129,7 @@ def update_exclude_list(args):
|
||||
|
||||
|
||||
def main(args):
|
||||
util.setup_stdio()
|
||||
return_code = prepare_test262_test_suite(args)
|
||||
if return_code:
|
||||
return return_code
|
||||
@@ -149,12 +144,11 @@ def main(args):
|
||||
command += ' --test262-object'
|
||||
|
||||
kwargs = {}
|
||||
if sys.version_info.major >= 3:
|
||||
kwargs['errors'] = 'ignore'
|
||||
kwargs['errors'] = 'ignore'
|
||||
|
||||
test262_harness_path = os.path.join(args.test262_harness_dir, 'test262-harness.py')
|
||||
|
||||
test262_command = get_platform_cmd_prefix() + \
|
||||
test262_command = util.get_python_cmd_prefix() + \
|
||||
[test262_harness_path,
|
||||
'--command', command,
|
||||
'--tests', args.test_dir,
|
||||
|
||||
@@ -61,13 +61,13 @@ def get_tests(test_dir, test_list, skip_list):
|
||||
dirname = os.path.dirname(test_list)
|
||||
with open(test_list, "r", encoding='utf8') as test_list_fd:
|
||||
for test in test_list_fd:
|
||||
tests.append(os.path.normpath(os.path.join(dirname, test.rstrip())))
|
||||
tests.append(os.path.join(dirname, test.rstrip()))
|
||||
|
||||
tests.sort()
|
||||
|
||||
def filter_tests(test):
|
||||
for skipped in skip_list:
|
||||
if skipped in test:
|
||||
if os.path.normpath(skipped) in os.path.normpath(test):
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -76,8 +76,8 @@ def get_tests(test_dir, test_list, skip_list):
|
||||
|
||||
def execute_test_command(test_cmd):
|
||||
kwargs = {}
|
||||
if sys.version_info.major >= 3:
|
||||
kwargs['encoding'] = 'unicode_escape'
|
||||
kwargs['encoding'] = 'unicode_escape'
|
||||
kwargs['errors'] = 'ignore'
|
||||
with subprocess.Popen(test_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||
universal_newlines=True, **kwargs) as process:
|
||||
stdout, _ = process.communicate()
|
||||
@@ -85,6 +85,7 @@ def execute_test_command(test_cmd):
|
||||
|
||||
|
||||
def main(args):
|
||||
util.setup_stdio()
|
||||
tests = get_tests(args.test_dir, args.test_list, args.skip_list)
|
||||
total = len(tests)
|
||||
if total == 0:
|
||||
|
||||
@@ -49,6 +49,7 @@ def get_unittests(path):
|
||||
|
||||
|
||||
def main(args):
|
||||
util.setup_stdio()
|
||||
unittests = get_unittests(args.path)
|
||||
total = len(unittests)
|
||||
if total == 0:
|
||||
|
||||
@@ -46,6 +46,7 @@ from collections import Counter
|
||||
import signal
|
||||
import multiprocessing
|
||||
|
||||
import util
|
||||
|
||||
# The timeout of each test case
|
||||
TEST262_CASE_TIMEOUT = 180
|
||||
@@ -130,10 +131,10 @@ class TempFile:
|
||||
text=self.text)
|
||||
|
||||
def write(self, string):
|
||||
os.write(self.file_desc, string.encode('utf8'))
|
||||
os.write(self.file_desc, string.encode('utf8', 'ignore'))
|
||||
|
||||
def read(self):
|
||||
with open(self.name, "r", newline='', encoding='utf8') as file_desc:
|
||||
with open(self.name, "r", newline='', encoding='utf8', errors='ignore') as file_desc:
|
||||
return file_desc.read()
|
||||
|
||||
def close(self):
|
||||
@@ -227,7 +228,7 @@ class TestCase:
|
||||
self.validate()
|
||||
|
||||
def parse_test_record(self):
|
||||
with open(self.full_path, "r", newline='', encoding='utf8') as file_desc:
|
||||
with open(self.full_path, "r", newline='', encoding='utf8', errors='ignore') as file_desc:
|
||||
full_test = file_desc.read()
|
||||
|
||||
match = TEST_RE.search(full_test)
|
||||
@@ -488,7 +489,7 @@ class TestSuite:
|
||||
if not tests:
|
||||
return True
|
||||
for test in tests:
|
||||
if test in rel_path:
|
||||
if os.path.normpath(test) in os.path.normpath(rel_path):
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -496,7 +497,7 @@ class TestSuite:
|
||||
if not name in self.include_cache:
|
||||
static = path.join(self.lib_root, name)
|
||||
if path.exists(static):
|
||||
with open(static, encoding='utf8') as file_desc:
|
||||
with open(static, encoding='utf8', errors='ignore') as file_desc:
|
||||
contents = file_desc.read()
|
||||
contents = re.sub(r'\r\n', '\n', contents)
|
||||
self.include_cache[name] = contents + "\n"
|
||||
@@ -585,7 +586,7 @@ class TestSuite:
|
||||
report_error("No tests to run")
|
||||
progress = ProgressIndicator(len(cases))
|
||||
if logname:
|
||||
self.logf = open(logname, "w", encoding='utf8') # pylint: disable=consider-using-with
|
||||
self.logf = open(logname, "w", encoding='utf8', errors='ignore') # pylint: disable=consider-using-with
|
||||
|
||||
if job_count == 1:
|
||||
for case in cases:
|
||||
@@ -647,6 +648,7 @@ class TestSuite:
|
||||
|
||||
|
||||
def main():
|
||||
util.setup_stdio()
|
||||
code = 0
|
||||
parser = build_options()
|
||||
options = parser.parse_args()
|
||||
|
||||
+26
-4
@@ -12,13 +12,23 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import codecs
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
TERM_NORMAL = '\033[0m'
|
||||
TERM_RED = '\033[1;31m'
|
||||
TERM_GREEN = '\033[1;32m'
|
||||
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):
|
||||
@@ -42,6 +52,18 @@ def set_sighdl_to_reset_timezone(timezone):
|
||||
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}")
|
||||
@@ -72,4 +94,4 @@ def get_platform_cmd_prefix():
|
||||
|
||||
def get_python_cmd_prefix():
|
||||
# python script doesn't have execute permission on github actions windows runner
|
||||
return get_platform_cmd_prefix() + [sys.executable or 'python']
|
||||
return [sys.executable or 'python']
|
||||
|
||||
Reference in New Issue
Block a user