Skip to content

Commit 2b3faf6

Browse files
ossy-szegedrerobika
authored andcommitted
Make all test262 tests pass on Windows (#3157)
Changes: - Implemented jerry_port_get_local_time_zone_adjustment on Windows - Implemented jerry_port_get_current_time on Windows - Run test262 tests on Windows in PST/PDT timezone JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác [email protected]
1 parent 9ab4872 commit 2b3faf6

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

jerry-port/default/default-date.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,32 @@
1616
#ifdef HAVE_TM_GMTOFF
1717
#include <time.h>
1818
#endif /* HAVE_TM_GMTOFF */
19+
20+
#ifdef _WINDOWS
21+
#include <windows.h>
22+
#include <winbase.h>
23+
#include <winnt.h>
24+
#include <time.h>
25+
#endif /* _WINDOWS */
26+
1927
#ifdef __GNUC__
2028
#include <sys/time.h>
2129
#endif /* __GNUC__ */
2230

2331
#include "jerryscript-port.h"
2432
#include "jerryscript-port-default.h"
2533

34+
#ifdef _WINDOWS
35+
/* https://support.microsoft.com/en-us/help/167296/how-to-convert-a-unix-time-t-to-a-win32-filetime-or-systemtime */
36+
void UnixTimeToFileTime (LONGLONG t, LPFILETIME pft)
37+
{
38+
LONGLONG ll = t * 10000000 + 116444736000000000;
39+
pft->dwLowDateTime = (DWORD) ll;
40+
pft->dwHighDateTime = ll >> 32;
41+
} /* UnixTimeToFileTime */
42+
#endif /* _WINDOWS */
43+
44+
2645
/**
2746
* Default implementation of jerry_port_get_local_time_zone_adjustment. Uses the 'tm_gmtoff' field
2847
* of 'struct tm' (a GNU extension) filled by 'localtime_r' if available on the
@@ -47,6 +66,25 @@ double jerry_port_get_local_time_zone_adjustment (double unix_ms, /**< ms since
4766
#else /* !HAVE_TM_GMTOFF */
4867
(void) unix_ms;
4968
(void) is_utc;
69+
#ifdef _WINDOWS
70+
FILETIME fileTime, localFileTime;
71+
SYSTEMTIME systemTime, localSystemTime;
72+
ULARGE_INTEGER time, localTime;
73+
74+
_tzset ();
75+
UnixTimeToFileTime ((LONGLONG) (unix_ms / 1000), &fileTime);
76+
77+
if (FileTimeToSystemTime (&fileTime, &systemTime)
78+
&& SystemTimeToTzSpecificLocalTime (0, &systemTime, &localSystemTime)
79+
&& SystemTimeToFileTime (&localSystemTime, &localFileTime))
80+
{
81+
time.LowPart = fileTime.dwLowDateTime;
82+
time.HighPart = fileTime.dwHighDateTime;
83+
localTime.LowPart = localFileTime.dwLowDateTime;
84+
localTime.HighPart = localFileTime.dwHighDateTime;
85+
return ((LONGLONG) localTime.QuadPart - (LONGLONG) time.QuadPart) / 10000;
86+
}
87+
#endif /* _WINDOWS */
5088
return 0.0;
5189
#endif /* HAVE_TM_GMTOFF */
5290
} /* jerry_port_get_local_time_zone_adjustment */
@@ -70,5 +108,11 @@ double jerry_port_get_current_time (void)
70108
}
71109
#endif /* __GNUC__ */
72110

111+
#ifdef _WINDOWS
112+
time_t ltime;
113+
time (&ltime);
114+
return ltime * 1000;
115+
#endif /* _WINDOWS */
116+
73117
return 0.0;
74118
} /* jerry_port_get_current_time */

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,29 @@
1515
# limitations under the License.
1616

1717
from __future__ import print_function
18-
import sys
1918
import os
20-
import subprocess
2119
import shutil
20+
import signal
21+
import subprocess
22+
import sys
23+
2224

2325
def get_platform_cmd_prefix():
2426
if sys.platform == 'win32':
2527
return ['cmd', '/S', '/C']
2628
return ['python2'] # The official test262.py isn't python3 compatible, but has python shebang.
2729

2830

31+
def set_timezone(timezone):
32+
assert sys.platform == 'win32', "set_timezone is Windows only function"
33+
subprocess.call(get_platform_cmd_prefix() + ['tzutil', '/s', timezone])
34+
35+
36+
def set_timezone_and_exit(timezone):
37+
set_timezone(timezone)
38+
sys.exit(1)
39+
40+
2941
def run_test262_tests(runtime, engine, path_to_test262):
3042
if not os.path.isdir(os.path.join(path_to_test262, '.git')):
3143
return_code = subprocess.call(['git', 'clone', 'https://github.com/tc39/test262.git',
@@ -42,6 +54,11 @@ def run_test262_tests(runtime, engine, path_to_test262):
4254
if os.path.isdir(path_to_remove):
4355
shutil.rmtree(path_to_remove)
4456

57+
if sys.platform == 'win32':
58+
original_timezone = subprocess.check_output(get_platform_cmd_prefix() + ['tzutil', '/g'])
59+
set_timezone('Pacific Standard Time')
60+
signal.signal(signal.SIGINT, lambda signal, frame: set_timezone_and_exit(original_timezone))
61+
4562
proc = subprocess.Popen(get_platform_cmd_prefix() +
4663
[os.path.join(path_to_test262, 'tools/packaging/test262.py'),
4764
'--command', (runtime + ' ' + engine).strip(),
@@ -73,6 +90,10 @@ def run_test262_tests(runtime, engine, path_to_test262):
7390
return_code = 1
7491

7592
proc.wait()
93+
94+
if sys.platform == 'win32':
95+
set_timezone(original_timezone)
96+
7697
return return_code
7798

7899

0 commit comments

Comments
 (0)