From 2b3faf683d5f78e696ad97999b761b53f3fed0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csaba=20Osztrogon=C3=A1c?= Date: Thu, 26 Sep 2019 14:31:22 +0200 Subject: [PATCH] Make all test262 tests pass on Windows (#3157) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 oszi@inf.u-szeged.hu --- jerry-port/default/default-date.c | 44 +++++++++++++++++++++++++ tools/runners/run-test-suite-test262.py | 25 ++++++++++++-- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/jerry-port/default/default-date.c b/jerry-port/default/default-date.c index 702134371..f988cc8c9 100644 --- a/jerry-port/default/default-date.c +++ b/jerry-port/default/default-date.c @@ -16,6 +16,14 @@ #ifdef HAVE_TM_GMTOFF #include #endif /* HAVE_TM_GMTOFF */ + +#ifdef _WINDOWS +#include +#include +#include +#include +#endif /* _WINDOWS */ + #ifdef __GNUC__ #include #endif /* __GNUC__ */ @@ -23,6 +31,17 @@ #include "jerryscript-port.h" #include "jerryscript-port-default.h" +#ifdef _WINDOWS +/* https://support.microsoft.com/en-us/help/167296/how-to-convert-a-unix-time-t-to-a-win32-filetime-or-systemtime */ +void UnixTimeToFileTime (LONGLONG t, LPFILETIME pft) +{ + LONGLONG ll = t * 10000000 + 116444736000000000; + pft->dwLowDateTime = (DWORD) ll; + pft->dwHighDateTime = ll >> 32; +} /* UnixTimeToFileTime */ +#endif /* _WINDOWS */ + + /** * Default implementation of jerry_port_get_local_time_zone_adjustment. Uses the 'tm_gmtoff' field * 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 #else /* !HAVE_TM_GMTOFF */ (void) unix_ms; (void) is_utc; +#ifdef _WINDOWS + FILETIME fileTime, localFileTime; + SYSTEMTIME systemTime, localSystemTime; + ULARGE_INTEGER time, localTime; + + _tzset (); + UnixTimeToFileTime ((LONGLONG) (unix_ms / 1000), &fileTime); + + if (FileTimeToSystemTime (&fileTime, &systemTime) + && SystemTimeToTzSpecificLocalTime (0, &systemTime, &localSystemTime) + && SystemTimeToFileTime (&localSystemTime, &localFileTime)) + { + time.LowPart = fileTime.dwLowDateTime; + time.HighPart = fileTime.dwHighDateTime; + localTime.LowPart = localFileTime.dwLowDateTime; + localTime.HighPart = localFileTime.dwHighDateTime; + return ((LONGLONG) localTime.QuadPart - (LONGLONG) time.QuadPart) / 10000; + } +#endif /* _WINDOWS */ return 0.0; #endif /* HAVE_TM_GMTOFF */ } /* jerry_port_get_local_time_zone_adjustment */ @@ -70,5 +108,11 @@ double jerry_port_get_current_time (void) } #endif /* __GNUC__ */ +#ifdef _WINDOWS + time_t ltime; + time (<ime); + return ltime * 1000; +#endif /* _WINDOWS */ + return 0.0; } /* jerry_port_get_current_time */ diff --git a/tools/runners/run-test-suite-test262.py b/tools/runners/run-test-suite-test262.py index 6884ef680..059562df2 100755 --- a/tools/runners/run-test-suite-test262.py +++ b/tools/runners/run-test-suite-test262.py @@ -15,10 +15,12 @@ # limitations under the License. from __future__ import print_function -import sys import os -import subprocess import shutil +import signal +import subprocess +import sys + def get_platform_cmd_prefix(): if sys.platform == 'win32': @@ -26,6 +28,16 @@ def get_platform_cmd_prefix(): return ['python2'] # The official test262.py isn't python3 compatible, but has python shebang. +def set_timezone(timezone): + assert sys.platform == 'win32', "set_timezone is Windows only function" + subprocess.call(get_platform_cmd_prefix() + ['tzutil', '/s', timezone]) + + +def set_timezone_and_exit(timezone): + set_timezone(timezone) + sys.exit(1) + + def run_test262_tests(runtime, engine, path_to_test262): if not os.path.isdir(os.path.join(path_to_test262, '.git')): 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): if os.path.isdir(path_to_remove): shutil.rmtree(path_to_remove) + if sys.platform == 'win32': + original_timezone = subprocess.check_output(get_platform_cmd_prefix() + ['tzutil', '/g']) + set_timezone('Pacific Standard Time') + signal.signal(signal.SIGINT, lambda signal, frame: set_timezone_and_exit(original_timezone)) + proc = subprocess.Popen(get_platform_cmd_prefix() + [os.path.join(path_to_test262, 'tools/packaging/test262.py'), '--command', (runtime + ' ' + engine).strip(), @@ -73,6 +90,10 @@ def run_test262_tests(runtime, engine, path_to_test262): return_code = 1 proc.wait() + + if sys.platform == 'win32': + set_timezone(original_timezone) + return return_code