From d2d30df420da79442f8d53585822e7d5ff220d5d Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Tue, 17 Dec 2024 17:41:12 +0800 Subject: [PATCH] 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 --- .github/workflows/gh-actions.yml | 48 ++++++++++++++++ CMakeLists.txt | 13 +++-- README.md | 1 - appveyor.yml | 27 --------- jerry-core/CMakeLists.txt | 14 ++--- jerry-core/ecma/base/ecma-helpers-string.c | 3 +- jerry-core/include/jerryscript-compiler.h | 15 ++++- jerry-port/common/jerry-port-fs.c | 4 +- jerry-port/win/jerry-port-win-date.c | 37 ++++++------ jerry-port/win/jerry-port-win-fs.c | 2 +- tests/jerry/date-getters.js | 8 +++ tools/run-tests.py | 66 +++++++++++++--------- tools/runners/run-test-suite-test262.py | 14 ++--- tools/runners/run-test-suite.py | 9 +-- tools/runners/run-unittests.py | 1 + tools/runners/test262-harness.py | 14 +++-- tools/runners/util.py | 30 ++++++++-- 17 files changed, 188 insertions(+), 118 deletions(-) delete mode 100644 appveyor.yml diff --git a/.github/workflows/gh-actions.yml b/.github/workflows/gh-actions.yml index d8db661351..8216728149 100644 --- a/.github/workflows/gh-actions.yml +++ b/.github/workflows/gh-actions.yml @@ -56,6 +56,54 @@ jobs: - run: $RUNNER -q --jerry-tests --buildoptions=--compile-flag=-m32,--cpointer-32bit=on - run: $RUNNER -q --jerry-tests --buildoptions=--compile-flag=-m32,--cpointer-32bit=on --build-debug + Win_x86-64_Conformance_Tests_ESNext: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - run: python $env:RUNNER --test262 update + + Win_x86-64_Conformance_Tests_ESNext_Debug: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - run: python $env:RUNNER --test262 update --build-debug + + Win_x86-64_Tests-MINGW: + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + steps: + - uses: actions/checkout@v4 + - uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: true + install: >- + mingw-w64-x86_64-python + mingw-w64-x86_64-cmake + mingw-w64-x86_64-make + mingw-w64-x86_64-toolchain + - run: python $RUNNER -q --jerry-tests + - run: python $RUNNER -q --unittests --build-config='' + # FIXME: enable it with upgrade valgrind - run: python $RUNNER -q --buildoption-test + + Win_x86-64_Tests: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - run: python $env:RUNNER -q --jerry-tests + - run: python $env:RUNNER -q --unittests + - run: python $env:RUNNER -q --buildoption-test + + Win_x86-64_Tests_Debug: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - run: python $env:RUNNER -q --jerry-tests --build-debug + - run: python $env:RUNNER -q --unittests --build-debug + - run: python $env:RUNNER -q --buildoption-test --build-debug + OSX_x86-64_Build_Correctness_Unit_Tests: runs-on: macos-13 steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ba1628e63..314d5adaa8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,11 +28,16 @@ set(PLATFORM "${CMAKE_SYSTEM_NAME}") string(TOUPPER "${PLATFORM}" PLATFORM) # Determining compiler +if(MSVC) + set(USING_MSVC 1) +endif() + if(CMAKE_C_COMPILER_ID MATCHES "GNU") set(USING_GCC 1) endif() -if(CMAKE_C_COMPILER_ID MATCHES "Clang") +# Clang may support for MSVC +if(NOT USING_MSVC AND CMAKE_C_COMPILER_ID MATCHES "Clang") set(USING_CLANG 1) endif() @@ -40,10 +45,6 @@ if(CMAKE_C_COMPILER_ID MATCHES "TI") set(USING_TI 1) endif() -if(CMAKE_C_COMPILER_ID MATCHES "MSVC") - set(USING_MSVC 1) -endif() - # Determining build type if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "MinSizeRel") @@ -68,7 +69,7 @@ set(ENABLE_STRIP ON CACHE BOOL "Enable stripping all symbols from set(ENABLE_COMPILE_COMMANDS ON CACHE BOOL "Enable generating compile_commands.json?") if(USING_MSVC) -set(ENABLE_STATIC_CRT OFF CACHE BOOL "Enable MSVC static CRT?") + set(ENABLE_STATIC_CRT OFF CACHE BOOL "Enable MSVC static CRT?") endif() # Option overrides diff --git a/README.md b/README.md index eac8ef0c45..ebe84d3f96 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ # JerryScript: JavaScript engine for the Internet of Things [![License](https://img.shields.io/badge/licence-Apache%202.0-brightgreen.svg?style=flat)](LICENSE) [![GitHub Actions Status](https://github.com/jerryscript-project/jerryscript/workflows/JerryScript%20CI/badge.svg)](https://github.com/jerryscript-project/jerryscript/actions) -[![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) [![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) [![IRC Channel](https://img.shields.io/badge/chat-on%20freenode-brightgreen.svg)](https://kiwiirc.com/client/irc.freenode.net/#jerryscript) diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index cc215ac00d..0000000000 --- a/appveyor.yml +++ /dev/null @@ -1,27 +0,0 @@ -version: "{build}" -branches: - except: - - coverity_scan - - gh_pages -skip_tags: true - -# Build matrix setup. -image: - - Visual Studio 2017 -configuration: - - Debug - - Release -platform: - - x64 - - Win32 - -# Steps of a job. -init: - - cmake -version -before_build: - - if "%PLATFORM%"=="Win32" cmake -G"Visual Studio 15 2017" -Bbuild -H. -DJERRY_DEBUGGER=ON - - if "%PLATFORM%"=="x64" cmake -G"Visual Studio 15 2017 Win64" -Bbuild -H. -DJERRY_DEBUGGER=ON -build: - project: build\Jerry.sln - parallel: false # FIXME: This should not be needed but right now it is: msbuild generates all amalgamated files twice, at the same time in parallel builds, leading to I/O errors. - verbosity: minimal diff --git a/jerry-core/CMakeLists.txt b/jerry-core/CMakeLists.txt index a2c3a6921c..c5e0bde7d9 100644 --- a/jerry-core/CMakeLists.txt +++ b/jerry-core/CMakeLists.txt @@ -123,6 +123,13 @@ set(INCLUDE_CORE_PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/parser/regexp" "${CMAKE_CURRENT_SOURCE_DIR}/vm") +# Third-party +# Valgrind +set(INCLUDE_THIRD_PARTY_VALGRIND "${CMAKE_SOURCE_DIR}/third-party/valgrind") +if(JERRY_VALGRIND) + set(INCLUDE_CORE_PRIVATE ${INCLUDE_CORE_PRIVATE} ${INCLUDE_THIRD_PARTY_VALGRIND}) +endif() + set(INCLUDE_CORE_PUBLIC ${INCLUDE_CORE_PUBLIC} PARENT_SCOPE) # for jerry-port set(INCLUDE_CORE_PRIVATE ${INCLUDE_CORE_PRIVATE} PARENT_SCOPE) # for tests/unit-core @@ -533,10 +540,6 @@ if(ENABLE_AMALGAM) set(INCLUDE_CORE_PRIVATE PARENT_SCOPE) endif() -# Third-party -# Valgrind -set(INCLUDE_THIRD_PARTY_VALGRIND "${CMAKE_SOURCE_DIR}/third-party/valgrind") - # build mode specific compile/link flags set(DEFINES_JERRY ${DEFINES_JERRY} $<$>:JERRY_NDEBUG>) @@ -641,9 +644,6 @@ jerry_add_define01(JERRY_SYSTEM_ALLOCATOR) # Valgrind jerry_add_define01(JERRY_VALGRIND) -if(JERRY_VALGRIND) - set(INCLUDE_CORE_PRIVATE ${INCLUDE_CORE_PRIVATE} ${INCLUDE_THIRD_PARTY_VALGRIND}) -endif() # Enable VM execution stop callback jerry_add_define01(JERRY_VM_HALT) diff --git a/jerry-core/ecma/base/ecma-helpers-string.c b/jerry-core/ecma/base/ecma-helpers-string.c index 294bbaa87c..2f88abab7a 100644 --- a/jerry-core/ecma/base/ecma-helpers-string.c +++ b/jerry-core/ecma/base/ecma-helpers-string.c @@ -1599,7 +1599,8 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /**< ecma-st const ecma_string_t *string2_p) /**< ecma-string */ { const lit_utf8_byte_t *utf8_string1_p, *utf8_string2_p; - lit_utf8_size_t string1_size_and_length[2], string2_size_and_length[2]; + lit_utf8_size_t string1_size_and_length[2] = { 0 }; + lit_utf8_size_t string2_size_and_length[2] = { 0 }; utf8_string1_p = ecma_compare_get_string_chars (string1_p, string1_size_and_length); utf8_string2_p = ecma_compare_get_string_chars (string2_p, string2_size_and_length); diff --git a/jerry-core/include/jerryscript-compiler.h b/jerry-core/include/jerryscript-compiler.h index 4732f010f7..7de32248ca 100644 --- a/jerry-core/include/jerryscript-compiler.h +++ b/jerry-core/include/jerryscript-compiler.h @@ -30,6 +30,16 @@ JERRY_C_API_BEGIN * @{ */ +/* + * Compiler-specific macros relevant for Win32. + */ +#ifdef _WIN32 +/** + * Both MINGW/MSVC do not support for declare a function a weak symbol. + */ +#define JERRY_ATTR_WEAK +#endif /* _WIN32 */ + #ifdef __GNUC__ /* @@ -45,9 +55,10 @@ JERRY_C_API_BEGIN #define JERRY_ATTR_NORETURN __attribute__ ((noreturn)) #define JERRY_ATTR_PURE __attribute__ ((pure)) #define JERRY_ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) -#define JERRY_ATTR_WEAK __attribute__ ((weak)) -#define JERRY_WEAK_SYMBOL_SUPPORT +#ifndef JERRY_ATTR_WEAK +#define JERRY_ATTR_WEAK __attribute__ ((weak)) +#endif /* !JERRY_ATTR_WEAK*/ #ifndef JERRY_LIKELY #define JERRY_LIKELY(x) __builtin_expect (!!(x), 1) diff --git a/jerry-port/common/jerry-port-fs.c b/jerry-port/common/jerry-port-fs.c index b249213822..d32264c47c 100644 --- a/jerry-port/common/jerry-port-fs.c +++ b/jerry-port/common/jerry-port-fs.c @@ -97,7 +97,7 @@ jerry_port_source_free (uint8_t *buffer_p) * These functions provide generic implementation for paths and are only enabled when the compiler support weak symbols, * and we are not building for a platform that has platform specific versions. */ -#if defined(JERRY_WEAK_SYMBOL_SUPPORT) && !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32)) +#if !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32)) jerry_char_t *JERRY_ATTR_WEAK jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size) @@ -134,4 +134,4 @@ jerry_port_path_base (const jerry_char_t *path_p) return (jerry_size_t) (basename_p - path_p); } /* jerry_port_path_base */ -#endif /* defined(JERRY_WEAK_SYMBOL_SUPPORT) && !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32)) */ +#endif /* !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32)) */ diff --git a/jerry-port/win/jerry-port-win-date.c b/jerry-port/win/jerry-port-win-date.c index 634b505c46..b00b484a54 100644 --- a/jerry-port/win/jerry-port-win-date.c +++ b/jerry-port/win/jerry-port-win-date.c @@ -23,8 +23,8 @@ #include #include -#define UNIX_EPOCH_IN_TICKS 116444736000000000ull /* difference between 1970 and 1601 */ -#define TICKS_PER_MS 10000ull /* 1 tick is 100 nanoseconds */ +#define UNIX_EPOCH_IN_TICKS 116444736000000000LL /* difference between 1970 and 1601 */ +#define TICKS_PER_MS 10000LL /* 1 tick is 100 nanoseconds */ /* * If you take the limit of SYSTEMTIME (last millisecond in 30827) then you end up with @@ -44,15 +44,9 @@ * https://support.microsoft.com/en-us/help/167296/how-to-convert-a-unix-time-t-to-a-win32-filetime-or-systemtime */ static void -unix_time_to_filetime (double t, LPFILETIME ft_p) +unix_time_to_filetime (LONGLONG t, LPFILETIME ft_p) { - LONGLONG ll = (LONGLONG) t * TICKS_PER_MS + UNIX_EPOCH_IN_TICKS; - - /* FILETIME values before the epoch are invalid. */ - if (ll < 0) - { - ll = 0; - } + LONGLONG ll = t * TICKS_PER_MS + UNIX_EPOCH_IN_TICKS; ft_p->dwLowDateTime = (DWORD) ll; ft_p->dwHighDateTime = (DWORD) (ll >> 32); @@ -63,13 +57,15 @@ unix_time_to_filetime (double t, LPFILETIME ft_p) * * @return unix time */ -static double +static LONGLONG filetime_to_unix_time (LPFILETIME ft_p) { ULARGE_INTEGER date; + LONGLONG ll; date.HighPart = ft_p->dwHighDateTime; date.LowPart = ft_p->dwLowDateTime; - return (double) (((LONGLONG) date.QuadPart - UNIX_EPOCH_IN_TICKS) / TICKS_PER_MS); + ll = (LONGLONG) date.QuadPart - UNIX_EPOCH_IN_TICKS; + return ll / TICKS_PER_MS; } /* filetime_to_unix_time */ int32_t @@ -79,6 +75,7 @@ jerry_port_local_tza (double unix_ms) FILETIME local; SYSTEMTIME utc_sys; SYSTEMTIME local_sys; + LONGLONG t = (LONGLONG) (unix_ms); /* * If the time is earlier than the date 1601-01-02, then always using date 1601-01-02 to @@ -87,23 +84,23 @@ jerry_port_local_tza (double unix_ms) * after converting between local time and utc time, the time may be earlier than 1601-01-01 * in UTC time, that exceeds the FILETIME representation range. */ - if (unix_ms < (double) UNIX_EPOCH_DATE_1601_01_02) + if (t < UNIX_EPOCH_DATE_1601_01_02) { - unix_ms = (double) UNIX_EPOCH_DATE_1601_01_02; + t = UNIX_EPOCH_DATE_1601_01_02; } /* Like above, do not use the last supported day */ - if (unix_ms > (double) UNIX_EPOCH_DATE_30827_12_29) + if (t > UNIX_EPOCH_DATE_30827_12_29) { - unix_ms = (double) UNIX_EPOCH_DATE_30827_12_29; + t = UNIX_EPOCH_DATE_30827_12_29; } - unix_time_to_filetime (unix_ms, &utc); + unix_time_to_filetime (t, &utc); if (FileTimeToSystemTime (&utc, &utc_sys) && SystemTimeToTzSpecificLocalTime (NULL, &utc_sys, &local_sys) && SystemTimeToFileTime (&local_sys, &local)) { - double unix_local = filetime_to_unix_time (&local); - return (int32_t) (unix_local - unix_ms); + LONGLONG unix_local = filetime_to_unix_time (&local); + return (int32_t) (unix_local - t); } return 0; @@ -114,7 +111,7 @@ jerry_port_current_time (void) { FILETIME ft; GetSystemTimeAsFileTime (&ft); - return filetime_to_unix_time (&ft); + return (double) filetime_to_unix_time (&ft); } /* jerry_port_current_time */ #endif /* defined(_WIN32) */ diff --git a/jerry-port/win/jerry-port-win-fs.c b/jerry-port/win/jerry-port-win-fs.c index b55f0cd44d..a761d32cb6 100644 --- a/jerry-port/win/jerry-port-win-fs.c +++ b/jerry-port/win/jerry-port-win-fs.c @@ -25,7 +25,7 @@ jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size) { (void) path_size; - return (jerry_char_t *) _fullpath (NULL, path_p, _MAX_PATH); + return (jerry_char_t *) _fullpath (NULL, (const char *) path_p, _MAX_PATH); } /* jerry_port_path_normalize */ void diff --git a/tests/jerry/date-getters.js b/tests/jerry/date-getters.js index 77cd9042b1..0a2061fd38 100644 --- a/tests/jerry/date-getters.js +++ b/tests/jerry/date-getters.js @@ -110,8 +110,16 @@ assert (new Date(-1, -1, -1, -1, -1, -1, -1, -1).getMilliseconds() === 999); assert (isNaN(new Date(20000000, 0).getFullYear())); assert (new Date(0, 0).getFullYear() === 1900); assert (new Date(1.2, 0).getFullYear() === 1901); + +/* 7. test case */ +/* 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). + A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds. */ assert((new Date(8640000000000000).getFullYear()) == 275760); assert(isNaN(new Date(8640000000000001).getFullYear())); +assert((new Date(-8640000000000000).getFullYear()) == -271821); +assert(isNaN(new Date(-8640000000000001).getFullYear())); + +/* 8. test case */ assert((new Date(-271821, 3, 21).getFullYear()) == -271821); assert(isNaN(new Date(1970, 0, -100000000).getFullYear())); assert(new Date(1970, 0, -100000000 + 1).getFullYear() == -271821); diff --git a/tools/run-tests.py b/tools/run-tests.py index 64bc1ed827..8423487b42 100755 --- a/tools/run-tests.py +++ b/tools/run-tests.py @@ -23,11 +23,8 @@ import sys import settings -if sys.version_info.major >= 3: - from runners import util -else: - sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/runners') - import util +from runners import util +from runners.util import TERM_NORMAL, TERM_YELLOW, TERM_BLUE, TERM_RED OUTPUT_DIR = os.path.join(settings.PROJECT_DIR, 'build', 'tests') @@ -168,8 +165,12 @@ def get_arguments(): help='Run license check') parser.add_argument('--check-strings', action='store_true', help='Run "magic string source code generator should be executed" check') + parser.add_argument('--build-config', type=str, default=None, + help='Build config, when not specified, auto detect it') parser.add_argument('--build-debug', action='store_true', help='Build debug version jerryscript') + parser.add_argument('--run-check-timeout', type=int, default=30 * 60, + help='Specify run_check timeout, default to 30 minutes, unit: second') parser.add_argument('--jerry-debugger', action='store_true', help='Run jerry-debugger tests') parser.add_argument('--jerry-tests', action='store_true', @@ -197,11 +198,6 @@ def get_arguments(): BINARY_CACHE = {} -TERM_NORMAL = '\033[0m' -TERM_YELLOW = '\033[1;33m' -TERM_BLUE = '\033[1;34m' -TERM_RED = '\033[1;31m' - def report_command(cmd_type, cmd, env=None): sys.stderr.write(f'{TERM_BLUE}{cmd_type}{TERM_NORMAL}\n') if env is not None: @@ -210,12 +206,14 @@ def report_command(cmd_type, cmd, env=None): sys.stderr.write(f"{TERM_BLUE}" + f" \\{TERM_NORMAL}\n\t{TERM_BLUE}".join(cmd) + f"{TERM_NORMAL}\n") + sys.stderr.flush() def report_skip(job): sys.stderr.write(f'{TERM_YELLOW}Skipping: {job.name}') if job.skip: sys.stderr.write(f' ({job.skip})') sys.stderr.write(f'{TERM_NORMAL}\n') + sys.stderr.flush() def create_binary(job, options): build_args = job.build_args[:] @@ -246,6 +244,7 @@ def create_binary(job, options): if binary_key in BINARY_CACHE: ret, build_dir_path = BINARY_CACHE[binary_key] sys.stderr.write(f'(skipping: already built at {build_dir_path} with returncode {ret})\n') + sys.stderr.flush() return ret, build_dir_path try: @@ -283,6 +282,7 @@ def iterate_test_runner_jobs(jobs, options): if build_dir_path in tested_paths: sys.stderr.write(f'(skipping: already tested with {build_dir_path})\n') + sys.stderr.flush() continue tested_paths.add(build_dir_path) @@ -291,6 +291,7 @@ def iterate_test_runner_jobs(jobs, options): if bin_hash in tested_hashes: sys.stderr.write(f'(skipping: already tested with equivalent {tested_hashes[bin_hash]})\n') + sys.stderr.flush() continue tested_hashes[bin_hash] = build_dir_path @@ -299,7 +300,7 @@ def iterate_test_runner_jobs(jobs, options): yield job, ret_build, test_cmd -def run_check(runnable, env=None): +def run_check(options, runnable, env=None): report_command('Test command:', runnable, env=env) if env is not None: @@ -308,7 +309,11 @@ def run_check(runnable, env=None): env = full_env with subprocess.Popen(runnable, env=env) as proc: - proc.wait() + try: + proc.wait(timeout=options.run_check_timeout) + except subprocess.TimeoutExpired: + proc.kill() + return -1 return proc.returncode def run_jerry_debugger_tests(options): @@ -335,7 +340,7 @@ def run_jerry_debugger_tests(options): if job.test_args: test_cmd.extend(job.test_args) - ret_test |= run_check(test_cmd) + ret_test |= run_check(options, test_cmd) return ret_build | ret_test @@ -367,7 +372,7 @@ def run_jerry_tests(options): if job.test_args: test_cmd.extend(job.test_args) - ret_test |= run_check(test_cmd, env=dict(TZ='UTC')) + ret_test |= run_check(options, test_cmd, env=dict(TZ='UTC')) return ret_build | ret_test @@ -397,7 +402,7 @@ def run_test262_test_suite(options): test_cmd.append('--test262-test-list') test_cmd.append(options.test262_test_list) - ret_test |= run_check(test_cmd, env=dict(TZ='America/Los_Angeles')) + ret_test |= run_check(options, test_cmd, env=dict(TZ='America/Los_Angeles')) return ret_build | ret_test @@ -412,16 +417,19 @@ def run_unittests(options): print(f"\n{TERM_RED}Build failed{TERM_NORMAL}\n") break - if sys.platform == 'win32': - if options.build_debug: - build_config = "Debug" + build_config = options.build_config + if build_config is None: + if sys.platform == 'win32': + if options.build_debug: + build_config = "Debug" + else: + build_config = "MinSizeRel" else: - build_config = "MinSizeRel" - else: - build_config = "" + build_config = "" ret_test |= run_check( + options, util.get_python_cmd_prefix() + [settings.UNITTEST_RUNNER_SCRIPT] + [os.path.join(build_dir_path, 'tests', build_config)] + @@ -446,6 +454,7 @@ def run_buildoption_test(options): Check = collections.namedtuple('Check', ['enabled', 'runner', 'arg']) def main(options): + util.setup_stdio() checks = [ Check(options.check_signed_off, run_check, [settings.SIGNED_OFF_SCRIPT] + {'tolerant': ['--tolerant'], 'gh-actions': ['--gh-actions']}.get(options.check_signed_off, [])), @@ -455,16 +464,19 @@ def main(options): Check(options.check_format, run_check, [settings.FORMAT_SCRIPT]), Check(options.check_license, run_check, [settings.LICENSE_SCRIPT]), Check(options.check_strings, run_check, [settings.STRINGS_SCRIPT]), - Check(options.jerry_debugger, run_jerry_debugger_tests, options), - Check(options.jerry_tests, run_jerry_tests, options), - Check(options.test262, run_test262_test_suite, options), - Check(options.unittests, run_unittests, options), - Check(options.buildoption_test, run_buildoption_test, options), + Check(options.jerry_debugger, run_jerry_debugger_tests, None), + Check(options.jerry_tests, run_jerry_tests, None), + Check(options.test262, run_test262_test_suite, None), + Check(options.unittests, run_unittests, None), + Check(options.buildoption_test, run_buildoption_test, None), ] for check in checks: if check.enabled or options.all: - ret = check.runner(check.arg) + if check.arg is None: + ret = check.runner(options) + else: + ret = check.runner(options, check.arg) if ret: sys.exit(ret) diff --git a/tools/runners/run-test-suite-test262.py b/tools/runners/run-test-suite-test262.py index a03c678627..08e665ef2a 100755 --- a/tools/runners/run-test-suite-test262.py +++ b/tools/runners/run-test-suite-test262.py @@ -22,12 +22,6 @@ 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, diff --git a/tools/runners/run-test-suite.py b/tools/runners/run-test-suite.py index afd4477f77..fb3c341dda 100755 --- a/tools/runners/run-test-suite.py +++ b/tools/runners/run-test-suite.py @@ -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 filter_tests(test): 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: diff --git a/tools/runners/run-unittests.py b/tools/runners/run-unittests.py index d54f643692..ef07d41f14 100755 --- a/tools/runners/run-unittests.py +++ b/tools/runners/run-unittests.py @@ -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: diff --git a/tools/runners/test262-harness.py b/tools/runners/test262-harness.py index d4389db752..a368d0bd5d 100755 --- a/tools/runners/test262-harness.py +++ b/tools/runners/test262-harness.py @@ -46,6 +46,7 @@ import signal import multiprocessing +import util # The timeout of each test case TEST262_CASE_TIMEOUT = 180 @@ -130,10 +131,10 @@ def open_file(self): 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 @@ def __init__(self, suite, name, full_path, strict_mode, command_template, module 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 @@ def should_run(rel_path, tests): 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 @@ def get_include(self, name): 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 @@ def run(self, command_template, tests, print_summary, full_summary, logname, job 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 @@ def list_includes(self, tests): def main(): + util.setup_stdio() code = 0 parser = build_options() options = parser.parse_args() diff --git a/tools/runners/util.py b/tools/runners/util.py index 90e920491b..f4225da62a 100755 --- a/tools/runners/util.py +++ b/tools/runners/util.py @@ -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']