Skip to content

Commit 4fd4566

Browse files
committed
Revise tools scripts to be python3 compatible on win32
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 jerryscript-project#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 jerryscript-project#4853 Fixes running test262-esnext failed with installed python3.9 on win32 with space in path Fixes jerryscript-project#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 increase the timeout future. wait JERRY_CHECK_TIMEOUT ``` Move Windows CI to github actions Convert run-debugger-test.sh to run-debugger-test.py After this change, run-debugger-test.py could running on Win32 and OSX 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 JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
1 parent d2e0d71 commit 4fd4566

15 files changed

+231
-158
lines changed

.github/workflows/gh-actions.yml

+30
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,34 @@ jobs:
5656
- run: $RUNNER -q --jerry-tests --buildoptions=--compile-flag=-m32,--cpointer-32bit=on
5757
- run: $RUNNER -q --jerry-tests --buildoptions=--compile-flag=-m32,--cpointer-32bit=on --build-debug
5858

59+
Win_x86-64_Conformance_Tests_ESNext:
60+
runs-on: windows-latest
61+
steps:
62+
- uses: actions/checkout@v2
63+
- run: python $env:RUNNER --test262 update
64+
65+
Win_x86-64_Conformance_Tests_ESNext_Debug:
66+
runs-on: windows-latest
67+
steps:
68+
- uses: actions/checkout@v2
69+
- run: python $env:RUNNER --test262 update --build-debug
70+
71+
Win_x86-64_Tests:
72+
runs-on: windows-latest
73+
steps:
74+
- uses: actions/checkout@v2
75+
- run: python $env:RUNNER -q --jerry-tests
76+
- run: python $env:RUNNER -q --unittests
77+
- run: python $env:RUNNER -q --buildoption-test
78+
79+
Win_x86-64_Tests_Debug:
80+
runs-on: windows-latest
81+
steps:
82+
- uses: actions/checkout@v2
83+
- run: python $env:RUNNER -q --jerry-tests --build-debug
84+
- run: python $env:RUNNER -q --unittests --build-debug
85+
- run: python $env:RUNNER -q --buildoption-test --build-debug
86+
5987
OSX_x86-64_Build_Correctness_Unit_Tests:
6088
runs-on: macos-13
6189
steps:
@@ -65,6 +93,7 @@ jobs:
6593
python-version: '>=3.6'
6694
- run: $RUNNER -q --jerry-tests
6795
- run: $RUNNER -q --unittests
96+
- run: $RUNNER -q --jerry-debugger
6897

6998
OSX_x86-64_Build_Correctness_Unit_Tests_Debug:
7099
runs-on: macos-13
@@ -75,6 +104,7 @@ jobs:
75104
python-version: '>=3.6'
76105
- run: $RUNNER -q --jerry-tests --build-debug
77106
- run: $RUNNER -q --unittests --build-debug
107+
- run: $RUNNER -q --jerry-debugger --build-debug
78108

79109
Linux_x86-64_Build_Option_Tests:
80110
runs-on: ubuntu-latest

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# JerryScript: JavaScript engine for the Internet of Things
33
[![License](https://img.shields.io/badge/licence-Apache%202.0-brightgreen.svg?style=flat)](LICENSE)
44
[![GitHub Actions Status](https://github.com/jerryscript-project/jerryscript/workflows/JerryScript%20CI/badge.svg)](https://github.com/jerryscript-project/jerryscript/actions)
5-
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/ct8reap35u2vooa5/branch/master?svg=true)](https://ci.appveyor.com/project/jerryscript-project/jerryscript/branch/master)
65
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fjerryscript-project%2Fjerryscript.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fjerryscript-project%2Fjerryscript?ref=badge_shield)
76
[![IRC Channel](https://img.shields.io/badge/chat-on%20freenode-brightgreen.svg)](https://kiwiirc.com/client/irc.freenode.net/#jerryscript)
87

appveyor.yml

-27
This file was deleted.

jerry-debugger/jerry_client.py

+2
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ def main():
326326
break
327327
if res_type == result.PROMPT:
328328
prompt.cmdloop()
329+
sys.stdout.flush()
330+
sys.stderr.flush()
329331
elif res_type == result.TEXT:
330332
write(result.get_text())
331333
continue

jerry-port/win/jerry-port-win-date.c

+17-20
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include <winbase.h>
2424
#include <winnt.h>
2525

26-
#define UNIX_EPOCH_IN_TICKS 116444736000000000ull /* difference between 1970 and 1601 */
27-
#define TICKS_PER_MS 10000ull /* 1 tick is 100 nanoseconds */
26+
#define UNIX_EPOCH_IN_TICKS 116444736000000000LL /* difference between 1970 and 1601 */
27+
#define TICKS_PER_MS 10000LL /* 1 tick is 100 nanoseconds */
2828

2929
/*
3030
* If you take the limit of SYSTEMTIME (last millisecond in 30827) then you end up with
@@ -44,15 +44,9 @@
4444
* https://support.microsoft.com/en-us/help/167296/how-to-convert-a-unix-time-t-to-a-win32-filetime-or-systemtime
4545
*/
4646
static void
47-
unix_time_to_filetime (double t, LPFILETIME ft_p)
47+
unix_time_to_filetime (LONGLONG t, LPFILETIME ft_p)
4848
{
49-
LONGLONG ll = (LONGLONG) t * TICKS_PER_MS + UNIX_EPOCH_IN_TICKS;
50-
51-
/* FILETIME values before the epoch are invalid. */
52-
if (ll < 0)
53-
{
54-
ll = 0;
55-
}
49+
LONGLONG ll = t * TICKS_PER_MS + UNIX_EPOCH_IN_TICKS;
5650

5751
ft_p->dwLowDateTime = (DWORD) ll;
5852
ft_p->dwHighDateTime = (DWORD) (ll >> 32);
@@ -63,13 +57,15 @@ unix_time_to_filetime (double t, LPFILETIME ft_p)
6357
*
6458
* @return unix time
6559
*/
66-
static double
60+
static LONGLONG
6761
filetime_to_unix_time (LPFILETIME ft_p)
6862
{
6963
ULARGE_INTEGER date;
64+
LONGLONG ll;
7065
date.HighPart = ft_p->dwHighDateTime;
7166
date.LowPart = ft_p->dwLowDateTime;
72-
return (double) (((LONGLONG) date.QuadPart - UNIX_EPOCH_IN_TICKS) / TICKS_PER_MS);
67+
ll = date.QuadPart - UNIX_EPOCH_IN_TICKS;
68+
return ll / TICKS_PER_MS;
7369
} /* filetime_to_unix_time */
7470

7571
/**
@@ -85,6 +81,7 @@ jerry_port_local_tza (double unix_ms)
8581
FILETIME local;
8682
SYSTEMTIME utc_sys;
8783
SYSTEMTIME local_sys;
84+
LONGLONG t = (LONGLONG) (unix_ms);
8885

8986
/*
9087
* If the time is earlier than the date 1601-01-02, then always using date 1601-01-02 to
@@ -93,23 +90,23 @@ jerry_port_local_tza (double unix_ms)
9390
* after converting between local time and utc time, the time may be earlier than 1601-01-01
9491
* in UTC time, that exceeds the FILETIME representation range.
9592
*/
96-
if (unix_ms < (double) UNIX_EPOCH_DATE_1601_01_02)
93+
if (t < UNIX_EPOCH_DATE_1601_01_02)
9794
{
98-
unix_ms = (double) UNIX_EPOCH_DATE_1601_01_02;
95+
t = UNIX_EPOCH_DATE_1601_01_02;
9996
}
10097

10198
/* Like above, do not use the last supported day */
102-
if (unix_ms > (double) UNIX_EPOCH_DATE_30827_12_29)
99+
if (t > UNIX_EPOCH_DATE_30827_12_29)
103100
{
104-
unix_ms = (double) UNIX_EPOCH_DATE_30827_12_29;
101+
t = UNIX_EPOCH_DATE_30827_12_29;
105102
}
106-
unix_time_to_filetime (unix_ms, &utc);
103+
unix_time_to_filetime (t, &utc);
107104

108105
if (FileTimeToSystemTime (&utc, &utc_sys) && SystemTimeToTzSpecificLocalTime (NULL, &utc_sys, &local_sys)
109106
&& SystemTimeToFileTime (&local_sys, &local))
110107
{
111-
double unix_local = filetime_to_unix_time (&local);
112-
return (int32_t) (unix_local - unix_ms);
108+
LONGLONG unix_local = filetime_to_unix_time (&local);
109+
return (int32_t) (unix_local - t);
113110
}
114111

115112
return 0;
@@ -125,7 +122,7 @@ jerry_port_current_time (void)
125122
{
126123
FILETIME ft;
127124
GetSystemTimeAsFileTime (&ft);
128-
return filetime_to_unix_time (&ft);
125+
return (double) filetime_to_unix_time (&ft);
129126
} /* jerry_port_current_time */
130127

131128
#endif /* defined(_WIN32) */

tests/jerry/date-getters.js

+8
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,16 @@ assert (new Date(-1, -1, -1, -1, -1, -1, -1, -1).getMilliseconds() === 999);
110110
assert (isNaN(new Date(20000000, 0).getFullYear()));
111111
assert (new Date(0, 0).getFullYear() === 1900);
112112
assert (new Date(1.2, 0).getFullYear() === 1901);
113+
114+
/* 7. test case */
115+
/* A Number can exactly represent all integers from -9,007,199,254,740,992 to 9,007,199,254,740,992 (21.1.2.8 and 21.1.2.6).
116+
A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds. */
113117
assert((new Date(8640000000000000).getFullYear()) == 275760);
114118
assert(isNaN(new Date(8640000000000001).getFullYear()));
119+
assert((new Date(-8640000000000000).getFullYear()) == -271821);
120+
assert(isNaN(new Date(-8640000000000001).getFullYear()));
121+
122+
/* 8. test case */
115123
assert((new Date(-271821, 3, 21).getFullYear()) == -271821);
116124
assert(isNaN(new Date(1970, 0, -100000000).getFullYear()));
117125
assert(new Date(1970, 0, -100000000 + 1).getFullYear() == -271821);

tools/run-tests.py

+24-19
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
OUTPUT_DIR = os.path.join(settings.PROJECT_DIR, 'build', 'tests')
3333

34+
# All run_check proc must finished in 30 minutes, may increase in future
35+
JERRY_CHECK_TIMEOUT = 30 * 60
36+
3437
Options = collections.namedtuple('Options', ['name', 'build_args', 'test_args', 'skip'])
3538
Options.__new__.__defaults__ = ([], [], False)
3639

@@ -197,25 +200,22 @@ def get_arguments():
197200

198201
BINARY_CACHE = {}
199202

200-
TERM_NORMAL = '\033[0m'
201-
TERM_YELLOW = '\033[1;33m'
202-
TERM_BLUE = '\033[1;34m'
203-
TERM_RED = '\033[1;31m'
204-
205203
def report_command(cmd_type, cmd, env=None):
206-
sys.stderr.write(f'{TERM_BLUE}{cmd_type}{TERM_NORMAL}\n')
204+
sys.stderr.write(f'{util.TERM_BLUE}{cmd_type}{util.TERM_NORMAL}\n')
207205
if env is not None:
208-
sys.stderr.write(''.join(f'{TERM_BLUE}{var}={val!r} \\{TERM_NORMAL}\n'
206+
sys.stderr.write(''.join(f'{util.TERM_BLUE}{var}={val!r} \\{util.TERM_NORMAL}\n'
209207
for var, val in sorted(env.items())))
210-
sys.stderr.write(f"{TERM_BLUE}" +
211-
f" \\{TERM_NORMAL}\n\t{TERM_BLUE}".join(cmd) +
212-
f"{TERM_NORMAL}\n")
208+
sys.stderr.write(f"{util.TERM_BLUE}" +
209+
f" \\{util.TERM_NORMAL}\n\t{util.TERM_BLUE}".join(cmd) +
210+
f"{util.TERM_NORMAL}\n")
211+
sys.stderr.flush()
213212

214213
def report_skip(job):
215-
sys.stderr.write(f'{TERM_YELLOW}Skipping: {job.name}')
214+
sys.stderr.write(f'{util.TERM_YELLOW}Skipping: {job.name}')
216215
if job.skip:
217216
sys.stderr.write(f' ({job.skip})')
218-
sys.stderr.write(f'{TERM_NORMAL}\n')
217+
sys.stderr.write(f'{util.TERM_NORMAL}\n')
218+
sys.stderr.flush()
219219

220220
def create_binary(job, options):
221221
build_args = job.build_args[:]
@@ -246,13 +246,15 @@ def create_binary(job, options):
246246
if binary_key in BINARY_CACHE:
247247
ret, build_dir_path = BINARY_CACHE[binary_key]
248248
sys.stderr.write(f'(skipping: already built at {build_dir_path} with returncode {ret})\n')
249+
sys.stderr.flush()
249250
return ret, build_dir_path
250251

251252
try:
252253
subprocess.check_output(build_cmd)
253254
ret = 0
254255
except subprocess.CalledProcessError as err:
255-
print(err.output.decode("utf8"))
256+
# For python <-> native program, we use default encoding with error='ignore' to not lost data
257+
print(err.output.decode(errors="ignore"))
256258
ret = err.returncode
257259

258260
BINARY_CACHE[binary_key] = (ret, build_dir_path)
@@ -283,6 +285,7 @@ def iterate_test_runner_jobs(jobs, options):
283285

284286
if build_dir_path in tested_paths:
285287
sys.stderr.write(f'(skipping: already tested with {build_dir_path})\n')
288+
sys.stderr.flush()
286289
continue
287290
tested_paths.add(build_dir_path)
288291

@@ -291,6 +294,7 @@ def iterate_test_runner_jobs(jobs, options):
291294

292295
if bin_hash in tested_hashes:
293296
sys.stderr.write(f'(skipping: already tested with equivalent {tested_hashes[bin_hash]})\n')
297+
sys.stderr.flush()
294298
continue
295299
tested_hashes[bin_hash] = build_dir_path
296300

@@ -308,23 +312,23 @@ def run_check(runnable, env=None):
308312
env = full_env
309313

310314
with subprocess.Popen(runnable, env=env) as proc:
311-
proc.wait()
315+
proc.wait(timeout=JERRY_CHECK_TIMEOUT)
312316
return proc.returncode
313317

314318
def run_jerry_debugger_tests(options):
315319
ret_build = ret_test = 0
316320
for job in DEBUGGER_TEST_OPTIONS:
317321
ret_build, build_dir_path = create_binary(job, options)
318322
if ret_build:
319-
print(f"\n{TERM_RED}Build failed{TERM_NORMAL}\n")
323+
print(f"\n{util.TERM_RED}Build failed{util.TERM_NORMAL}\n")
320324
break
321325

322326
for channel in ["websocket", "rawpacket"]:
323327
for test_file in os.listdir(settings.DEBUGGER_TESTS_DIR):
324328
if test_file.endswith(".cmd"):
325329
test_case, _ = os.path.splitext(test_file)
326330
test_case_path = os.path.join(settings.DEBUGGER_TESTS_DIR, test_case)
327-
test_cmd = [
331+
test_cmd = util.get_python_cmd_prefix() + [
328332
settings.DEBUGGER_TEST_RUNNER_SCRIPT,
329333
get_binary_path(build_dir_path),
330334
channel,
@@ -379,7 +383,7 @@ def run_test262_test_suite(options):
379383
for job in jobs:
380384
ret_build, build_dir_path = create_binary(job, options)
381385
if ret_build:
382-
print(f"\n{TERM_RED}Build failed{TERM_NORMAL}\n")
386+
print(f"\n{util.TERM_RED}Build failed{util.TERM_NORMAL}\n")
383387
break
384388

385389
test_cmd = util.get_python_cmd_prefix() + [
@@ -409,7 +413,7 @@ def run_unittests(options):
409413
continue
410414
ret_build, build_dir_path = create_binary(job, options)
411415
if ret_build:
412-
print(f"\n{TERM_RED}Build failed{TERM_NORMAL}\n")
416+
print(f"\n{util.TERM_RED}Build failed{util.TERM_NORMAL}\n")
413417
break
414418

415419
if sys.platform == 'win32':
@@ -438,14 +442,15 @@ def run_buildoption_test(options):
438442

439443
ret, _ = create_binary(job, options)
440444
if ret:
441-
print(f"\n{TERM_RED}Build failed{TERM_NORMAL}\n")
445+
print(f"\n{util.TERM_RED}Build failed{util.TERM_NORMAL}\n")
442446
break
443447

444448
return ret
445449

446450
Check = collections.namedtuple('Check', ['enabled', 'runner', 'arg'])
447451

448452
def main(options):
453+
util.setup_stdio()
449454
checks = [
450455
Check(options.check_signed_off, run_check, [settings.SIGNED_OFF_SCRIPT]
451456
+ {'tolerant': ['--tolerant'], 'gh-actions': ['--gh-actions']}.get(options.check_signed_off, [])),

0 commit comments

Comments
 (0)