diff --git a/.eslintrc.js b/.eslintrc.js index a4a114ee98..23f957b7ca 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -85,7 +85,7 @@ module.exports = { { // Optional rules 'max-len': [2, { - code: 80, + code: 120, tabWidth: 2, ignoreUrls: true, ignoreTemplateLiterals: true, diff --git a/.github/workflows/gh-actions.yml b/.github/workflows/gh-actions.yml new file mode 100644 index 0000000000..3417c8fb2b --- /dev/null +++ b/.github/workflows/gh-actions.yml @@ -0,0 +1,137 @@ +name: IoT.js CI + +on: [push, pull_request] + +env: + RUNNER: tools/ci_script.py + +jobs: + "Linux-x86-64_Build_and_Correctness_Tests": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="host-linux" $RUNNER + + "Mock_Linux_Build_and_Correctness_Tests": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="mock-linux" $RUNNER + + "Linux-x86-64_Build_with_N-API_support_and_Correctness_Tests": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="n-api" $RUNNER + + "Linux-x86-64_Build_with_N-API_ES_2015_support_and_Correctness_Tests": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="n-api-es2015-subset" $RUNNER + + "Raspberry_Pi_2_Build_Test": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="rpi2" $RUNNER + + "STM32f4_Discovery_with_Nuttx_Build_Test": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="stm32f4dis" $RUNNER + + "Tizen_Build_Test": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="tizen" $RUNNER + + "ECMAScript_2015_features_Build_and_Correctness_Tests": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="es2015" $RUNNER + + "External_modules_Build_and_Correctness_Tests": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="external-modules" $RUNNER + + "Linux-x86-64_without_snapshot_Build_and_Correctness_Tests": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="no-snapshot" $RUNNER + + "Misc_checks_style_checker": + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - run: sudo apt update + - run: sudo apt install -y npm clang-format-3.9 + - run: npm install eslint + - run: OPTS="misc" $RUNNER + + "OSX-x86-64_Build_and_Correctness_Tests": + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="host-darwin" $RUNNER + + "ASAN_Tests": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="asan" $RUNNER + + "UBSAN_Tests": + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: OPTS="ubsan" $RUNNER + + "Windows-x86_64": + runs-on: windows-latest + strategy: + matrix: + include: + - configuration: Debug + - configuration: Release + steps: + - run: | + git config --global core.autocrlf false + git config --global core.eol lf + - uses: actions/checkout@v2 + - run: npm install + - run: python tools\build.py "--cmake-param=-GVisual Studio 16 2019" + --experimental + --buildtype=${{ matrix.configuration }} + --target-arch=x86_64 + --run-test=full + --jerry-profile=es.next + --profile=test/profiles/host-windows.profile + + "Windows-i686": + runs-on: windows-latest + strategy: + matrix: + include: + - configuration: Debug + - configuration: Release + steps: + - run: | + git config --global core.autocrlf false + git config --global core.eol lf + - uses: actions/checkout@v2 + - run: npm install + - run: python tools\build.py "--cmake-param=-GVisual Studio 16 2019" + --experimental + --buildtype=${{ matrix.configuration }} + --target-arch=i686 + --run-test=full + --jerry-cmake-param=-DJERRY_SYSTEM_ALLOCATOR=ON + --jerry-profile=es5.1 + --profile=test/profiles/host-windows.profile diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e4238f5eb2..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,100 +0,0 @@ -language: c - -os: linux -dist: trusty - -services: - - docker - -script: tools/travis_script.py - -matrix: - include: - - name: "Linux/x86-64 Build & Correctness Tests" - env: - - OPTS="host-linux" - - - name: "Mock Linux Build & Correctness Tests" - env: - - OPTS="mock-linux" - - - name: "Linux/x86-64 Build with N-API support & Correctness Tests" - env: - - OPTS="n-api" - install: - - npm install - - - name: "Raspberry Pi 2 Build Test" - env: - - OPTS="rpi2" - - - name: "STM32f4 Discovery with Nuttx Build Test" - env: - - OPTS="stm32f4dis" - - - name: "Tizen Build Test" - env: - - OPTS="tizen" - - - name: "ECMAScript 2015 features Build & Correctness Tests" - env: - - OPTS="es2015" - - - name: "External modules Build & Correctness Tests" - env: - - OPTS="external-modules" - - - name: "Linux/x86-64 without snapshot Build & Correctness Tests" - env: - - OPTS="no-snapshot" - - - name: "Misc checks (e.g. style checker)" - env: - - OPTS="misc" - addons: - apt: - packages: [clang-format-3.9, npm, valgrind] - install: - - npm install eslint - - - name: "OSX/x86-64 Build & Correctness Tests" - env: - - OPTS="host-darwin" - os: osx - addons: - homebrew: - packages: [cmake] - - - name: "ASAN Tests" - env: - - OPTS="asan" - - - name: "UBSAN Tests" - env: - - OPTS="ubsan" - - - name: "Coverity Scan" - env: - - OPTS="coverity" - # Declaration of the encrypted COVERITY_SCAN_TOKEN, created via the - # "travis encrypt" command using the project repo's public key. - - secure: "qbQASyP3/OzpzAp8xRFL2uOAHhMbO0jVRJFg9i8UcPurHUXj1Erk0hOmS3gxkkv7g2BU1mwsMz2SLwKtAEzEwES5rEmAbJ8Jf/zWEPqjXA1taOfCKRyuGGxIdQD1AcU3dIUbYd+CJ9JwmfLcb5XIcoEQVfd0etl7bkJu43bqTptc0lnT6HAsl+QZ9y3tJH4qklTg9lJI6hp2aVtvT/liTJgqfZlXs0SsgDmZZ9C6B1ienhRFQZLezEVCRrjIbUfcHH5IWkXkIjfCdMXfYLqLhTZVHU7lxCcZhOIpMSVX0W85Ov2YTAaKyhTmHCETjjVFw0RK2t42lm7C5l7j0peF+PCG2Qw/w/KMfNKWf8CBcZX/IquOUu7/EFtWE/rc7qi4bKhLwOYtqTAroJjkX6YsPaQlsryAbtsIMlkFvW8oI7TxzJ9HE7co70/rgEj7Qka/7SLptVWyUxVWtJRQqBCE/piUzyAe/GYsmX4Qje+fY+b5spWWvFscxsBP3J5qA2zhV4nJQvJmnRNhz1wMmfh5tKO9Hifeof6JeISlGFRGqSX/RtVriRtI60FyEsHk6lZQqtW+INSVTHjoewC29kIdttbH1qjJ8L5+PmsiZRrm4ER38tnOrH1cGz1PdcTQJGoqVcB446f5Uc9G76q23xR7wkfkqb3P6zlF379C2rE41ps=" - addons: - coverity_scan: - project: - name: "jerryscript-project/iotjs" - description: "Platform for Internet of Things with JavaScript" - notification_email: haesik.jun@samsung.com - build_command: "tools/travis_script.py" - branch_pattern: master - - - name: "SonarQube" - addons: - sonarcloud: - organization: "pando-project" - script: ./tools/check_sonarqube.sh - cache: - directories: - - '$HOME/.sonar/cache' - - fast_finish: true diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cab35a7e1..a280695680 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.5) include(CheckCCompilerFlag) project(IOTJS C) @@ -26,6 +26,13 @@ if(NOT DEFINED TARGET_OS) "TARGET_OS not specified, using '${TARGET_OS}' from CMAKE_SYSTEM_NAME") endif() +if(CMAKE_GENERATOR MATCHES "Visual Studio") + set(CONFIG_TYPE $<$:Debug>) + set(CONFIG_TYPE ${CONFIG_TYPE}$<$:Release>) + set(CONFIG_TYPE ${CONFIG_TYPE}$<$:RelWithDebInfo>) + set(CONFIG_TYPE ${CONFIG_TYPE}$<$:MinSizeRel>) +endif() + if(NOT CMAKE_BUILD_TYPE) message("CMAKE_BUILD_TYPE was not set! Configuring for Debug build!") set(CMAKE_BUILD_TYPE Debug) @@ -48,6 +55,16 @@ if(NOT DEFINED ENABLE_LTO) set(ENABLE_LTO OFF) endif() +if(NOT DEFINED JERRY_LINE_INFO) + if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + message("Line info default enabled in debug mode") + set(JERRY_LINE_INFO ON) + else() + message("Line info default disabled in non debug mode") + set(JERRY_LINE_INFO OFF) + endif() +endif() + macro(iotjs_add_flags VAR) foreach(_flag ${ARGN}) set(${VAR} "${${VAR}} ${_flag}") @@ -69,7 +86,6 @@ endmacro() if(CMAKE_C_COMPILER_ID MATCHES "MSVC") set(USING_MSVC 1) - set(CONFIG_TYPE $<$:Debug>$<$:Release>) # disable warning C4820: 'x' bytes padding added after construct 'membername' iotjs_add_compile_flags(-wd4820) # disable warning C4668: 'symbol' is not defined as preprocessor macro, @@ -78,6 +94,13 @@ if(CMAKE_C_COMPILER_ID MATCHES "MSVC") iotjs_add_compile_flags(-wd4668) # disable warning C4100: unreferenced formal parameter iotjs_add_compile_flags(-wd4100) + iotjs_add_compile_flags(-wd4242) + iotjs_add_compile_flags(-wd4244) + iotjs_add_compile_flags(-wd4996) + iotjs_add_compile_flags(-wd4061) + iotjs_add_compile_flags(-wd5045) + iotjs_add_compile_flags(-wd4701) + iotjs_add_compile_flags(-wd4710) endif() CHECK_C_COMPILER_FLAG(-no-pie HAS_NO_PIE) @@ -88,8 +111,7 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") if(HAS_NO_PIE AND NOT "${TARGET_OS}" STREQUAL "darwin") iotjs_add_link_flags(-no-pie) endif() -else() - +elseif(HAS_NO_PIE) iotjs_add_compile_flags(-fPIE) if("${TARGET_OS}" STREQUAL "darwin") iotjs_add_link_flags(-Wl,-pie) @@ -98,7 +120,7 @@ else() endif() endif() -if (CREATE_SHARED_LIB) +if (CREATE_SHARED_LIB AND NOT USING_MSVC) iotjs_add_compile_flags(-fPIC) endif() @@ -180,10 +202,6 @@ elseif("${TARGET_OS}" STREQUAL "tizenrt") iotjs_add_compile_flags(-D__TIZENRT__ -Os -fno-strict-aliasing) iotjs_add_compile_flags(-fno-strength-reduce -fomit-frame-pointer) elseif("${TARGET_OS}" STREQUAL "windows") - message("Windows support is experimental!") - if(NOT EXPERIMENTAL) - message(FATAL_ERROR "Missing --experimental build option for Windows!") - endif() elseif("${TARGET_OS}" STREQUAL "openwrt") message("OpenWrt support is experimental!") if(NOT EXPERIMENTAL) diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 4b081ad795..0000000000 --- a/appveyor.yml +++ /dev/null @@ -1,43 +0,0 @@ -version: "{build}" -branches: - except: - - coverity_scan - - gh_pages -skip_tags: true -image: - - Visual Studio 2017 -configuration: - - Debug - - Release -platform: - - Win32 - - x64 -init: - - cmd: | - if "%PLATFORM%"=="Win32" set SYS_ARCH=i686 - if "%PLATFORM%"=="x64" set SYS_ARCH=x86_64 - cmake -version - -install: - - ps: | - Install-Product node 10.15.3 - -artifacts: - - path: build\%SYS_ARCH%-windows\$(configuration)\bin\$(configuration)\ - name: IoTjsbinary - -before_build: - - cmd: | - tools\build.py --experimental --buildtype=%CONFIGURATION% --target-arch=%SYS_ARCH% --jerry-profile=es2015-subset --n-api - -build: - project: build\%SYS_ARCH%-windows\%CONFIGURATION%\IOTJS.sln - parallel: true - verbosity: minimal - -before_test: - - cmd: npm install - -test_script: - - cmd: | - tools\testrunner.py build\%SYS_ARCH%-windows\%CONFIGURATION%\bin\%CONFIGURATION%\iotjs.exe diff --git a/cmake/JSONParser.cmake b/cmake/JSONParser.cmake index 747cd630c5..7806252a58 100644 --- a/cmake/JSONParser.cmake +++ b/cmake/JSONParser.cmake @@ -34,8 +34,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -cmake_minimum_required(VERSION 2.8) - if (DEFINED JSonParserGuard) return() endif() diff --git a/cmake/http-parser.cmake b/cmake/http-parser.cmake index 83f25798a0..6223c595c5 100644 --- a/cmake/http-parser.cmake +++ b/cmake/http-parser.cmake @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 2.8) - if("${TARGET_OS}" MATCHES "NUTTX|TIZENRT") set(HTTPPARSER_NUTTX_ARG -DNUTTX_HOME=${TARGET_SYSTEMROOT}) endif() @@ -38,6 +36,7 @@ ExternalProject_Add(http-parser -DOS=${TARGET_OS} ${HTTPPARSER_NUTTX_ARG} -DENABLE_MEMORY_CONSTRAINTS=ON + BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/lib/${HTTPPARSER_NAME} ) add_library(libhttp-parser STATIC IMPORTED) add_dependencies(libhttp-parser http-parser) diff --git a/cmake/iotjs.cmake b/cmake/iotjs.cmake index 2216f12e4c..0195a64494 100644 --- a/cmake/iotjs.cmake +++ b/cmake/iotjs.cmake @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 2.8) - if(NOT DEFINED PYTHON) set(PYTHON "python") endif() @@ -352,7 +350,7 @@ endforeach() iotjs_add_compile_flags(-Wall) if(NOT USING_MSVC) iotjs_add_compile_flags(-Wextra -Werror -Wno-unused-parameter) - iotjs_add_compile_flags(-Wsign-conversion -std=gnu99) + iotjs_add_compile_flags(-Wno-sizeof-pointer-memaccess -Wno-unused-variable) endif() if(ENABLE_SNAPSHOT) @@ -448,11 +446,11 @@ set(IOTJS_INCLUDE_DIRS if(NOT BUILD_LIB_ONLY) if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") - iotjs_add_link_flags("-Xlinker -map -Xlinker iotjs.map") + iotjs_add_link_flags(-Wl,-map,iotjs.map) elseif(USING_MSVC) - iotjs_add_link_flags("/MAP:iotjs.map") + iotjs_add_link_flags("-MAP:iotjs.map") else() - iotjs_add_link_flags("-Xlinker -Map -Xlinker iotjs.map") + iotjs_add_link_flags(-Xlinker -Map=iotjs.map) endif() endif() @@ -515,37 +513,30 @@ else() file(READ "${IOTJS_SOURCE_DIR}/napi/node_symbols.txt" NODE_SYMBOLS) string(REGEX REPLACE "[\r|\n]" ";" NODE_SYMBOLS "${NODE_SYMBOLS}") - if(USING_MSVC) - set(NODE_SYMBOL_SEPARATOR " /INCLUDE:") - if("${TARGET_ARCH}" STREQUAL "i686") - set(NODE_SYMBOL_SEPARATOR "${NODE_SYMBOL_SEPARATOR}_") - endif() - else() - set(NODE_SYMBOLS_LINK_FLAGS "-Wl") - set(NODE_SYMBOL_SEPARATOR ",-u,") - endif() - foreach(NODE_SYMBOL ${NODE_SYMBOLS}) - set(NODE_SYMBOLS_LINK_FLAGS - "${NODE_SYMBOLS_LINK_FLAGS}${NODE_SYMBOL_SEPARATOR}${NODE_SYMBOL}") - endforeach() - - iotjs_add_link_flags(${NODE_SYMBOLS_LINK_FLAGS}) + if(USING_MSVC) + if("${TARGET_ARCH}" STREQUAL "i686") + iotjs_add_link_flags("/INCLUDE:_${NODE_SYMBOL}") + else() + iotjs_add_link_flags("/INCLUDE:${NODE_SYMBOL}") + endif() + else() + if("${TARGET_OS}" STREQUAL "DARWIN") + iotjs_add_link_flags("-Wl,-u,_${NODE_SYMBOL}") + else() + iotjs_add_link_flags("-Wl,-u,${NODE_SYMBOL}") + endif() + endif() + endforeach() endif() endif(CREATE_SHARED_LIB) -add_dependencies(${TARGET_LIB_IOTJS} - ${JERRY_LIBS} - ${TUV_LIBS} - libhttp-parser - ${MBEDTLS_LIBS} -) - set_target_properties(${TARGET_LIB_IOTJS} PROPERTIES OUTPUT_NAME iotjs ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" PUBLIC_HEADER "${IOTJS_PUBLIC_HEADERS}" + C_STANDARD 99 ) target_include_directories(${TARGET_LIB_IOTJS} PRIVATE ${IOTJS_INCLUDE_DIRS}) @@ -570,6 +561,9 @@ endif() if(NOT BUILD_LIB_ONLY) set(TARGET_IOTJS iotjs) message(STATUS "CMAKE_BINARY_DIR ${CMAKE_BINARY_DIR}") + if (NOT INSTALL_PREFIX) + set(INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install) + endif() message(STATUS "BINARY_INSTALL_DIR ${INSTALL_PREFIX}/bin") message(STATUS "LIBRARY_INSTALL_DIR ${INSTALL_PREFIX}/lib") diff --git a/cmake/jerry.cmake b/cmake/jerry.cmake index b86ab9f166..ec283d6621 100644 --- a/cmake/jerry.cmake +++ b/cmake/jerry.cmake @@ -12,10 +12,26 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 2.8) - # Host jerry for snapshot generation set(DEPS_HOST_JERRY deps/jerry-host) + +set(JERRY_HOST_SNAPSHOT + ${CMAKE_BINARY_DIR}/${DEPS_HOST_JERRY}/bin/jerry-snapshot) + +set(JERRY_HOST_BUILD_BYPRODUCTS + ${JERRY_HOST_SNAPSHOT} +) + +if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux") + set(JERRY_HOST_C_FLAGS_INIT "-Wno-error=maybe-uninitialized") +endif() + +if (USING_MSVC) + set(JERRY_HOST_C_FLAGS_INIT "-DWIN32") +endif() + +separate_arguments(EXTRA_JERRY_CMAKE_PARAMS) + ExternalProject_Add(hostjerry PREFIX ${DEPS_HOST_JERRY} SOURCE_DIR ${ROOT_DIR}/deps/jerry/ @@ -23,6 +39,7 @@ ExternalProject_Add(hostjerry BINARY_DIR ${DEPS_HOST_JERRY} CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_C_FLAGS=${JERRY_HOST_C_FLAGS_INIT} -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/${DEPS_HOST_JERRY} -DENABLE_AMALGAM=ON -DENABLE_LTO=${ENABLE_LTO} @@ -30,10 +47,10 @@ ExternalProject_Add(hostjerry -DJERRY_CMDLINE_SNAPSHOT=ON -DJERRY_EXT=ON -DJERRY_LOGGING=ON + -DJERRY_LINE_INFO=${JERRY_LINE_INFO} -DJERRY_ERROR_MESSAGES=ON -DJERRY_SNAPSHOT_SAVE=${ENABLE_SNAPSHOT} -DJERRY_PROFILE=${JERRY_PROFILE} - -DJERRY_LINE_INFO=${JERRY_LINE_INFO} ${EXTRA_JERRY_CMAKE_PARAMS} # The snapshot tool does not require the system allocator @@ -46,9 +63,8 @@ ExternalProject_Add(hostjerry # can not be represented correctly in the JerryScript engine # currently. -DJERRY_SYSTEM_ALLOCATOR=OFF + BUILD_BYPRODUCTS ${JERRY_HOST_BUILD_BYPRODUCTS} ) -set(JERRY_HOST_SNAPSHOT - ${CMAKE_BINARY_DIR}/${DEPS_HOST_JERRY}/bin/jerry-snapshot) add_executable(jerry-snapshot IMPORTED) add_dependencies(jerry-snapshot hostjerry) set_property(TARGET jerry-snapshot PROPERTY @@ -56,7 +72,7 @@ set_property(TARGET jerry-snapshot PROPERTY # Utility method to add -D= macro(add_cmake_arg TARGET_ARG KEY) - if(${KEY}) + if(DEFINED ${KEY}) list(APPEND ${TARGET_ARG} -D${KEY}=${${KEY}}) endif() endmacro(add_cmake_arg) @@ -98,7 +114,7 @@ endif() # Add a few cmake options based on buildtype/external cmake defines if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - list(APPEND DEPS_LIB_JERRY_ARGS -DJERRY_ERROR_MESSAGES=ON) + set(JERRY_ERROR_MESSAGES ON) endif() # NuttX is not using the default port implementation of JerryScript @@ -115,11 +131,25 @@ add_cmake_arg(DEPS_LIB_JERRY_ARGS JERRY_DEBUGGER) add_cmake_arg(DEPS_LIB_JERRY_ARGS JERRY_GLOBAL_HEAP_SIZE) add_cmake_arg(DEPS_LIB_JERRY_ARGS JERRY_ATTR_GLOBAL_HEAP) -separate_arguments(EXTRA_JERRY_CMAKE_PARAMS) - build_lib_name(JERRY_CORE_NAME jerry-core) build_lib_name(JERRY_LIBM_NAME jerry-math) build_lib_name(JERRY_EXT_NAME jerry-ext) +build_lib_name(JERRY_PORT_DEFAULT_NAME jerry-port-default) +build_lib_name(JERRY_PORT_DEFAULT_MINIMAL_NAME jerry-port-default-minimal) + +set(JERRY_LIB_BUILD_BYPRODUCTS + ${CMAKE_BINARY_DIR}/lib/${JERRY_CORE_NAME} + ${CMAKE_BINARY_DIR}/lib/${JERRY_LIBM_NAME} + ${CMAKE_BINARY_DIR}/lib/${JERRY_EXT_NAME} +) + +if(NOT "${TARGET_OS}" MATCHES "NUTTX|TIZENRT") + list(APPEND JERRY_LIB_BUILD_BYPRODUCTS + ${CMAKE_BINARY_DIR}/lib/${JERRY_PORT_DEFAULT_NAME} + ${CMAKE_BINARY_DIR}/lib/${JERRY_PORT_DEFAULT_MINIMAL_NAME} + ) +endif() + set(DEPS_LIB_JERRY deps/jerry) set(DEPS_LIB_JERRY_SRC ${ROOT_DIR}/${DEPS_LIB_JERRY}) @@ -144,17 +174,13 @@ ExternalProject_Add(libjerry -DJERRY_LOGGING=ON -DJERRY_LINE_INFO=${JERRY_LINE_INFO} -DJERRY_VM_EXEC_STOP=ON - -DJERRY_ERROR_MESSAGES=ON - -DENABLE_LTO=${ENABLE_LTO} ${DEPS_LIB_JERRY_ARGS} ${EXTRA_JERRY_CMAKE_PARAMS} + BUILD_BYPRODUCTS ${JERRY_LIB_BUILD_BYPRODUCTS} ) set_property(DIRECTORY APPEND PROPERTY - ADDITIONAL_MAKE_CLEAN_FILES - ${CMAKE_BINARY_DIR}/lib/${JERRY_CORE_NAME} - ${CMAKE_BINARY_DIR}/lib/${JERRY_LIBM_NAME} - ${CMAKE_BINARY_DIR}/lib/${JERRY_EXT_NAME} + ADDITIONAL_MAKE_CLEAN_FILES ${JERRY_LIB_BUILD_BYPRODUCTS} ) # define external jerry-core target @@ -176,13 +202,6 @@ set_property(TARGET jerry-ext PROPERTY IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/lib/${JERRY_EXT_NAME}) if(NOT "${TARGET_OS}" MATCHES "NUTTX|TIZENRT") - build_lib_name(JERRY_PORT_NAME jerry-port) - build_lib_name(JERRY_PORT_DEFAULT_NAME jerry-port-default) - set_property(DIRECTORY APPEND PROPERTY - ADDITIONAL_MAKE_CLEAN_FILES - ${CMAKE_BINARY_DIR}/lib/${JERRY_PORT_NAME} - ) - # define external jerry-port-default target add_library(jerry-port-default STATIC IMPORTED) add_dependencies(jerry-port-default libjerry) diff --git a/cmake/libtuv.cmake b/cmake/libtuv.cmake index 1c4ab4c9f3..a626e4ee8f 100644 --- a/cmake/libtuv.cmake +++ b/cmake/libtuv.cmake @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 2.8) - # Configure external libtuv set(DEPS_TUV deps/libtuv) set(DEPS_TUV_SRC ${ROOT_DIR}/${DEPS_TUV}) @@ -24,9 +22,6 @@ if("${TARGET_OS}" STREQUAL "MOCK") else() string(TOLOWER ${TARGET_ARCH}-${TARGET_OS} PLATFORM_DESCRIPTOR) endif() -set(DEPS_TUV_TOOLCHAIN - ${DEPS_TUV_SRC}/cmake/config/config_${PLATFORM_DESCRIPTOR}.cmake) -message(STATUS "libtuv toolchain file: ${DEPS_TUV_TOOLCHAIN}") ExternalProject_Add(libtuv PREFIX ${DEPS_TUV} SOURCE_DIR ${DEPS_TUV_SRC} @@ -37,7 +32,7 @@ ExternalProject_Add(libtuv ${CMAKE_BINARY_DIR}/${DEPS_TUV}/lib/${CONFIG_TYPE}/ ${CMAKE_BINARY_DIR}/lib/ CMAKE_ARGS - -DCMAKE_TOOLCHAIN_FILE=${DEPS_TUV_TOOLCHAIN} + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -DTARGET_PLATFORM=${PLATFORM_DESCRIPTOR} @@ -46,6 +41,7 @@ ExternalProject_Add(libtuv -DBUILDAPIEMULTESTER=NO -DTARGET_SYSTEMROOT=${TARGET_SYSTEMROOT} -DTARGET_BOARD=${TARGET_BOARD} + BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/lib/${LIBTUV_NAME} ) add_library(tuv STATIC IMPORTED) add_dependencies(tuv libtuv) diff --git a/cmake/mbedtls.cmake b/cmake/mbedtls.cmake index 0a8e841e89..2a7ceaabd6 100644 --- a/cmake/mbedtls.cmake +++ b/cmake/mbedtls.cmake @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 2.8) - set(MODULE_NAME "tls") if ("${TARGET_OS}" STREQUAL "TIZENRT") @@ -50,6 +48,11 @@ else() build_lib_name(MBED_X509_NAME mbedx509) build_lib_name(MBED_TLS_NAME mbedtls) build_lib_name(MBED_CRYPTO_NAME mbedcrypto) + set(MBEDTLS_BUILD_BYPRODUCTS + ${ARCHIVE_DIR}/${MBED_X509_NAME} + ${ARCHIVE_DIR}/${MBED_TLS_NAME} + ${ARCHIVE_DIR}/${MBED_CRYPTO_NAME} + ) ExternalProject_Add(mbedtls PREFIX ${DEPS_MBEDTLS} SOURCE_DIR ${DEPS_MBEDTLS_SRC} @@ -68,6 +71,7 @@ else() -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF + BUILD_BYPRODUCTS ${MBEDTLS_BUILD_BYPRODUCTS} ) # define external mbedtls target @@ -90,9 +94,7 @@ else() set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES - ${ARCHIVE_DIR}/${MBED_X509_NAME} - ${ARCHIVE_DIR}/${MBED_TLS_NAME} - ${ARCHIVE_DIR}/${MBED_CRYPTO_NAME} + ${MBEDTLS_BUILD_BYPRODUCTS} ) set(MBEDTLS_LIBS libmbedtls libmbedx509 libmbedcrypto) diff --git a/config/nuttx/stm32f4dis/app/Makefile b/config/nuttx/stm32f4dis/app/Makefile index a908dcaa7a..9430664893 100644 --- a/config/nuttx/stm32f4dis/app/Makefile +++ b/config/nuttx/stm32f4dis/app/Makefile @@ -129,6 +129,7 @@ $(LIBS) : copylibs .built: $(LIBS) $(OBJS) $(eval OBJS += $(shell find . -name "*.obj")) + @echo "AR stm32 app library $(BIN) with:" $(call ARCHIVE, $(BIN), $(OBJS)) $(Q) touch .built diff --git a/package.json b/package.json index 52a7c4552d..d68681a155 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,6 @@ "eslint": "^4.7.2" }, "dependencies": { - "node-gyp": "^3.8.0" + "node-gyp": "^7.1.2" } } diff --git a/test/profiles/host-windows.profile b/test/profiles/host-windows.profile new file mode 100644 index 0000000000..03bfb7ab68 --- /dev/null +++ b/test/profiles/host-windows.profile @@ -0,0 +1,4 @@ +ENABLE_MODULE_IOTJS_BASIC_MODULES +ENABLE_MODULE_IOTJS_CORE_MODULES +ENABLE_MODULE_HTTPS +ENABLE_MODULE_NAPI diff --git a/test/run_pass/test_iotjs_promise.js b/test/run_pass/test_iotjs_promise.js index 9024d5d720..5eaf97d4aa 100644 --- a/test/run_pass/test_iotjs_promise.js +++ b/test/run_pass/test_iotjs_promise.js @@ -25,5 +25,27 @@ p.then(function (msg) { fulfill_ret = msg; }); +var timeoutTimer = setTimeout(function() { + resetTimers() +}, 10000) + // If Promise's fulfill worked well, assertion must be valid. -setTimeout(function() { assert.equal(fulfill_ret, "Resolved"); }, 1000); +var intervalTimer = setInterval(function() { + if (fulfill_ret) { + assert.equal(fulfill_ret, "Resolved"); + resetTimers(); + } else { + assert.equal(fulfill_ret, undefined); + } +}, 100); + +function resetTimers() { + if (intervalTimer) { + clearInterval(intervalTimer) + intervalTimer = undefined + } + if (timeoutTimer) { + clearTimeout(timeoutTimer) + timeoutTimer = undefined + } +} diff --git a/test/run_pass/test_net_3.js b/test/run_pass/test_net_3.js index 1b34918d00..6d68c4fd67 100644 --- a/test/run_pass/test_net_3.js +++ b/test/run_pass/test_net_3.js @@ -19,17 +19,17 @@ var assert = require('assert'); var port = 22703; -var limit = 200; +var limit = 233; var server = net.createServer(); -server.listen({ port: port }); +server.listen({ port: port }, startTesting); server.on('connection', function(socket) { var i = 0; var writing = function() { var ok; do { - ok = socket.write("" + (i % 10)); + ok = socket.write('' + (i % 10)); if (++i == limit) { socket.end(); ok = false; @@ -40,47 +40,59 @@ server.on('connection', function(socket) { writing(); }); - var msg1 = ''; -var socket1 = net.createConnection(port); +var msg2 = ''; +var msg3 = ''; +var msg4 = ''; +var endCount = 0; +var connectListenerCheck = false; -socket1.on('data', function(data) { - msg1 += data; -}); +function endCallback() { + endCount += 1; + if (endCount === 4) { + server.close(); + } +} +function startTesting() { + var socket1 = net.createConnection(port); -var msg2 = ''; -var socket2 = net.createConnection({port: port}); + socket1.on('data', function(data) { + msg1 += data; + }); + socket1.on('end', endCallback); -socket2.on('data', function(data) { - msg2 += data; -}); + var socket2 = net.createConnection({port: port}); -var msg3 = ''; -var socket3 = net.createConnection({port: port, host: '127.0.0.1'}); + socket2.on('data', function(data) { + msg2 += data; + }); + socket2.on('end', endCallback); -socket3.on('data', function(data) { - msg3 += data; -}); + var socket3 = net.createConnection({port: port, host: '127.0.0.1'}); -var msg4 = ''; -var connectListenerCheck = false; -var socket4 = net.createConnection({port: port}, function() { - connectListenerCheck = true; -}); + socket3.on('data', function(data) { + msg3 += data; + }); + socket3.on('end', endCallback); -socket4.on('data', function(data) { - msg4 += data; -}); -socket4.on('end', function() { - server.close(); -}); + var socket4 = net.createConnection({port: port}, function() { + connectListenerCheck = true; + }); + + socket4.on('data', function(data) { + msg4 += data; + }); + socket4.on('end', endCallback); +} process.on('exit', function(code) { + assert.equal(code, 0); + assert.equal(endCount, 4); assert.equal(msg1.length, limit); assert.equal(msg2.length, limit); assert.equal(msg3.length, limit); diff --git a/test/run_pass/test_net_8.js b/test/run_pass/test_net_8.js index f83db72134..cb06caf2ea 100644 --- a/test/run_pass/test_net_8.js +++ b/test/run_pass/test_net_8.js @@ -32,7 +32,6 @@ server.on('connection', function(socket) { socket.end(data); }); socket.on('close', function() { - server.close(); }); }); @@ -46,6 +45,7 @@ sock2.connect(port, 'localhost'); sock1.on('data', function(data) { msg += data; + sendSock2Data(); }); sock1.on('end', function() { @@ -58,15 +58,16 @@ sock2.on('data', function(data) { sock2.on('end', function() { sock2.end(); + server.close(); }); timers.setTimeout(function() { sock1.write('1'); }, 1000); -timers.setTimeout(function() { +function sendSock2Data() { sock2.write('2'); -}, 2000); +} process.on('exit', function(code) { assert.equal(code, 0); diff --git a/test/run_pass/test_net_http_get.js b/test/run_pass/test_net_http_get.js index 7f9ff4d040..be64727dec 100644 --- a/test/run_pass/test_net_http_get.js +++ b/test/run_pass/test_net_http_get.js @@ -42,7 +42,7 @@ var server = http.createServer(function (req, res) { }); -server.listen(3005,5); +server.listen(3005,5, startTesting); // 1. GET req @@ -67,32 +67,34 @@ var getResponseHandler = function (res) { }); }; -http.get(options, getResponseHandler); +function startTesting() { + http.get(options, getResponseHandler); -// 2. close server req -var finalMsg = 'close server'; -var finalOptions = { - method : 'POST', - port : 3005, - headers : {'Content-Length': finalMsg.length} -}; + // 2. close server req + var finalMsg = 'close server'; + var finalOptions = { + method : 'POST', + port : 3005, + headers : {'Content-Length': finalMsg.length} + }; -var finalResponseHandler = function (res) { - var res_body = ''; + var finalResponseHandler = function (res) { + var res_body = ''; - assert.equal(200, res.statusCode); + assert.equal(200, res.statusCode); - var endHandler = function(){ - assert.equal(finalMsg, res_body); - }; - res.on('end', endHandler); + var endHandler = function(){ + assert.equal(finalMsg, res_body); + }; + res.on('end', endHandler); - res.on('data', function(chunk){ - res_body += chunk.toString(); - }); -}; + res.on('data', function(chunk){ + res_body += chunk.toString(); + }); + }; -var finalReq = http.request(finalOptions, finalResponseHandler); -finalReq.write(finalMsg); -finalReq.end(); + var finalReq = http.request(finalOptions, finalResponseHandler); + finalReq.write(finalMsg); + finalReq.end(); +} diff --git a/test/run_pass/test_net_http_request_response.js b/test/run_pass/test_net_http_request_response.js index e7615b7bf9..f53b463113 100644 --- a/test/run_pass/test_net_http_request_response.js +++ b/test/run_pass/test_net_http_request_response.js @@ -21,17 +21,19 @@ var net = require('net'); var message = 'Hello IoT.js'; // Options for further requests. -var options = { - method: 'POST', - port: 3005, - path: '/', - headers : {'Content-Length': message.length} -}; +function createOptions(port) { + return { + method: 'POST', + port: port, + path: '/', + headers: {'Content-Length': message.length}, + }; +} var server1 = http.createServer(function(request, response) { var str = ''; - request.on('data', function (chunk) { + request.on('data', function(chunk) { str += chunk.toString(); }); @@ -40,38 +42,41 @@ var server1 = http.createServer(function(request, response) { response.end(); }); }); -server1.listen(3005, 5); +server1.listen(3005, 5, startRequest1); // Simple request with valid utf-8 message. -var isRequest1Finished = false; -var request1 = http.request(options, function(response) { - var str = ''; - - response.on('data', function(chunk) { - str += chunk.toString(); - }); - - response.on('end', function() { - isRequest1Finished = true; - server1.close(); +var isRequest1Finished = -1; +function startRequest1() { + var request1 = http.request(createOptions(3005), function(response) { + var str = ''; + + response.on('data', function(chunk) { + str += chunk.toString(); + }); + + response.on('end', function() { + isRequest1Finished = 1; + server1.close(); + }); }); -}); -request1.end(message, 'utf-8'); + request1.end(message, 'utf-8'); +} var server2 = http.createServer(function(request, response) { response.end(); }); -server2.listen(3006, 5); +server2.listen(3006, 5, startRequest2); // Simple request with end callback. -var isRequest2Finished = false; -options.port = 3006; -var request2 = http.request(options); -request2.end(message, function() { - server2.close(); - isRequest2Finished = true; -}); +var isRequest2Finished = -1; +function startRequest2() { + var request2 = http.request(createOptions(3006)); + request2.end(message, function() { + isRequest2Finished = 2; + server2.close(); + }); +} var server3 = http.createServer(function(request, response) { @@ -87,24 +92,25 @@ var server3 = http.createServer(function(request, response) { response.end(); }); }); -server3.listen(3007, 5); +server3.listen(3007, 5, startRequest3); // Simple request with buffer chunk as message parameter. -options.port = 3007; -var isRequest3Finished = false; -var request3 = http.request(options, function(response) { - var str = ''; - - response.on('data', function(chunk) { - str += chunk; +var isRequest3Finished = -1; +function startRequest3() { + var request3 = http.request(createOptions(3007), function(response) { + var str = ''; + + response.on('data', function(chunk) { + str += chunk; + }); + + response.on('end', function() { + isRequest3Finished = 3; + server3.close(); + }); }); - - response.on('end', function() { - isRequest3Finished = true; - server3.close(); - }); -}); -request3.end(new Buffer(message)); + request3.end(new Buffer(message)); +} // This test is to make sure that when the HTTP server @@ -113,21 +119,23 @@ var server4 = http.createServer(function(request, response) { response.writeHead(200); response.end(); }); -server4.listen(3008, 5); - -var isRequest4Finished = false; -var request4 = http.request({ - method: 'HEAD', - port: 3008, - path: '/' -}, function(response) { - response.on('end', function() { - isRequest4Finished = true; - assert.equal(response.statusCode, 200); - server4.close(); +server4.listen(3008, 5, startRequest4); + +var isRequest4Finished = -1; +function startRequest4() { + var request4 = http.request({ + method: 'HEAD', + port: 3008, + path: '/', + }, function(response) { + response.on('end', function() { + isRequest4Finished = 4; + assert.equal(response.statusCode, 200); + server4.close(); + }); }); -}); -request4.end(); + request4.end(); +} // Write a header twice in the server response. @@ -139,59 +147,62 @@ var server5 = http.createServer(function(request, response) { }); request.on('end', function() { - response.writeHead(200, 'OK', {'Connection' : 'close1'}); + response.writeHead(200, 'OK', {'Connection': 'close1'}); // Wrote the same head twice. - response.writeHead(200, 'OK', {'Connection' : 'close2'}); + response.writeHead(200, 'OK', {'Connection': 'close2'}); // Wrote a new head. - response.writeHead(200, {'Head' : 'Value'}); + response.writeHead(200, {'Head': 'Value'}); response.end(); }); }); -server5.listen(3009, 5); - -options.port = 3009; -options.headers = null; -var isRequest5Finished = false; -var request5 = http.request(options, function(response) { - response.on('end', function() { - isRequest5Finished = true; - assert.equal(response.headers['Connection'], 'close2'); - assert.equal(response.headers['Head'], 'Value'); - server5.close(); +server5.listen(3009, 5, startRequest5); + +var isRequest5Finished = -1; +function startRequest5() { + var options = createOptions(3009); + options.headers = null; + var request5 = http.request(options, function(response) { + response.on('end', function() { + isRequest5Finished = 5; + assert.equal(response.headers['Connection'], 'close2'); + assert.equal(response.headers['Head'], 'Value'); + server5.close(); + }); }); -}); -request5.end(); + request5.end(); +} // Test the IncomingMessage read function. var server6 = http.createServer(function(request, response) { request.on('end', function() { response.end('ok'); - server6.close(); }); -}).listen(8080, 5); - -var readRequest = http.request({ - host: '127.0.0.1', - port: 8080, - path: '/', - method: 'GET' -}); -readRequest.end(); - -readRequest.on('response', function(incomingMessage) { - incomingMessage.on('readable', function() { - var inc = incomingMessage.read(); - assert.equal(inc instanceof Buffer, true); - assert.assert(inc.toString('utf8').length > 0); +}).listen(8080, 5, startRequest6); + +function startRequest6() { + var readRequest = http.request({ + host: '127.0.0.1', + port: 8080, + path: '/', + method: 'GET', }); -}); - + readRequest.end(); + + readRequest.on('response', function(incomingMessage) { + incomingMessage.on('readable', function() { + var inc = incomingMessage.read(); + assert.equal(inc instanceof Buffer, true); + assert.assert(inc.toString('utf8').length > 0); + server6.close(); + }); + }); +} process.on('exit', function() { - assert.equal(isRequest1Finished, true); - assert.equal(isRequest2Finished, true); - assert.equal(isRequest3Finished, true); - assert.equal(isRequest4Finished, true); - assert.equal(isRequest5Finished, true); + assert.equal(isRequest1Finished, 1); + assert.equal(isRequest2Finished, 2); + assert.equal(isRequest3Finished, 3); + assert.equal(isRequest4Finished, 4); + assert.equal(isRequest5Finished, 5); }); diff --git a/test/run_pass/test_net_http_server.js b/test/run_pass/test_net_http_server.js index 2033f115af..0945c87ea3 100644 --- a/test/run_pass/test_net_http_server.js +++ b/test/run_pass/test_net_http_server.js @@ -64,7 +64,7 @@ server.on('close', function() { serverCloseEvent++; }); -server.listen(3001, 3); +server.listen(3001, 3, startTestingPost); // client side code @@ -82,101 +82,106 @@ var options = { }; -var postResponseHandler = function (res) { - var res_body = ''; +function startTestingPost() { + var postResponseHandler = function (res) { + var res_body = ''; - assert.equal(200, res.statusCode); - var endHandler = function(){ - assert.equal(msg, res_body); - responseCheck += '1'; + assert.equal(200, res.statusCode); + var endHandler = function(){ + assert.equal(msg, res_body); + responseCheck += '1'; + startTestingGet(); + }; + res.on('end', endHandler); + + res.on('data', function(chunk){ + res_body += chunk.toString(); + }); }; - res.on('end', endHandler); - res.on('data', function(chunk){ - res_body += chunk.toString(); + var req = http.request(options, postResponseHandler); + req.on('response', function() { + responseEvent++; }); -}; - -var req = http.request(options, postResponseHandler); -req.on('response', function() { - responseEvent++; -}); -req.on('socket', function() { - socketEvent++; -}); -req.write(msg); -req.end(); - + req.on('socket', function() { + socketEvent++; + }); + req.write(msg); + req.end(); +} + +function startTestingGet() { + // 2. GET req + options = { + method : 'GET', + port : 3001 + }; -// 2. GET req -options = { - method : 'GET', - port : 3001 -}; + var getResponseHandler = function (res) { + var res_body = ''; -var getResponseHandler = function (res) { - var res_body = ''; + assert.equal(200, res.statusCode); - assert.equal(200, res.statusCode); + var endHandler = function(){ + // GET msg, no received body + assert.equal('', res_body); + responseCheck += '2'; + startTestingFinal(); + }; + res.on('end', endHandler); - var endHandler = function(){ - // GET msg, no received body - assert.equal('', res_body); - responseCheck += '2'; + res.on('data', function(chunk){ + res_body += chunk.toString(); + }); }; - res.on('end', endHandler); - - res.on('data', function(chunk){ - res_body += chunk.toString(); - }); -}; -var getReq = http.request(options, getResponseHandler); -getReq.on('response', function() { - responseEvent++; -}); -getReq.on('socket', function() { - socketEvent++; -}); -getReq.end(); - + var getReq = http.request(options, getResponseHandler); + getReq.on('response', function() { + responseEvent++; + }); + getReq.on('socket', function() { + socketEvent++; + }); + getReq.end(); +} + +function startTestingFinal() { + // 3. close server req + var finalMsg = 'close server'; + var finalOptions = { + method : 'POST', + port : 3001, + rejectUnauthorized: false, + headers : {'Content-Length': finalMsg.length} + }; + var finalResponseHandler = function (res) { + var res_body = ''; -// 3. close server req -var finalMsg = 'close server'; -var finalOptions = { - method : 'POST', - port : 3001, - rejectUnauthorized: false, - headers : {'Content-Length': finalMsg.length} -}; + assert.equal(200, res.statusCode); -var finalResponseHandler = function (res) { - var res_body = ''; + var endHandler = function(){ + assert.equal(finalMsg, res_body); + responseCheck += '3'; + }; + res.on('end', endHandler); - assert.equal(200, res.statusCode); - - var endHandler = function(){ - assert.equal(finalMsg, res_body); - responseCheck += '3'; + res.on('data', function(chunk){ + res_body += chunk.toString(); + }); }; - res.on('end', endHandler); - res.on('data', function(chunk){ - res_body += chunk.toString(); + var finalReq = http.request(finalOptions, finalResponseHandler); + finalReq.on('response', function() { + responseEvent++; }); -}; - -var finalReq = http.request(finalOptions, finalResponseHandler); -finalReq.on('response', function() { - responseEvent++; -}); -finalReq.on('socket', function() { - socketEvent++; -}); -finalReq.write(finalMsg); -finalReq.end(); + finalReq.on('socket', function() { + socketEvent++; + }); + finalReq.write(finalMsg); + finalReq.end(); +} // Create server without requestListener. var server2 = http.createServer(); diff --git a/test/run_pass/test_net_https_server.js b/test/run_pass/test_net_https_server.js index d1120088e9..d161f8b9c5 100644 --- a/test/run_pass/test_net_https_server.js +++ b/test/run_pass/test_net_https_server.js @@ -25,7 +25,7 @@ var server_options = { var server = https.createServer(server_options, function(req, res) { res.writeHead(200); res.end('hello world\n'); -}).listen(8000); +}).listen(8000, startTesting); var client_options = { @@ -41,14 +41,15 @@ var responseHandler = function (res) { var endHandler = function(){ assert.equal(res_body, 'hello world\n'); + server.close(); }; res.on('end', endHandler); res.on('data', function(chunk){ res_body += chunk.toString(); }); - - server.close(); } -https.get(client_options, responseHandler); +function startTesting() { + https.get(client_options, responseHandler); +} diff --git a/test/run_pass/test_tls_3.js b/test/run_pass/test_tls_3.js index f96768a052..e92567a500 100644 --- a/test/run_pass/test_tls_3.js +++ b/test/run_pass/test_tls_3.js @@ -24,6 +24,7 @@ var server_message = ''; var server_closed = false; var server_handshake_done = false; var handshake_done = false; +var endCount = 0; var port = 8080; @@ -31,7 +32,7 @@ var server_options = { key: fs.readFileSync(process.cwd() + '/resources/my_key.key').toString(), cert: fs.readFileSync(process.cwd() + '/resources/my_crt.crt'), rejectUnauthorized: false, - isServer: true + isServer: true, }; var server = tls.createServer(server_options, function(socket) { @@ -41,7 +42,7 @@ var server = tls.createServer(server_options, function(socket) { client_message = data.toString(); }); -}).listen(port, function() {}); +}).listen(port, startTesting); server.on('secureConnection', function() { server_handshake_done = true; @@ -51,47 +52,57 @@ server.on('close', function() { server_closed = true; }); -var socket1 = tls.connect(port); +function endCallback() { + endCount += 1; + if (endCount === 3) { + server.close(); + } +} -socket1.on('secureConnect', function() { - handshake_done = true; -}); +function startTesting() { + var socket1 = tls.connect(port); -socket1.on('data', function(data) { - server_message = data.toString(); - socket1.write('Client hello'); - socket1.end(); -}); + socket1.on('secureConnect', function() { + handshake_done = true; + }); -var socket2 = tls.connect(port, 'localhost'); + socket1.on('data', function(data) { + server_message = data.toString(); + socket1.write('Client hello'); + socket1.end(); + }); + socket1.on('end', endCallback); -socket2.on('secureConnect', function() { - handshake_done = true; -}); + var socket2 = tls.connect(port, 'localhost'); -socket2.on('data', function(data) { - server_message = data.toString(); - socket2.write('Client hello'); - socket2.end(); -}); + socket2.on('secureConnect', function() { + handshake_done = true; + }); -var socket3 = tls.connect(port, function() {}); + socket2.on('data', function(data) { + server_message = data.toString(); + socket2.write('Client hello'); + socket2.end(); + }); + socket2.on('end', endCallback); -socket3.on('secureConnect', function() { - handshake_done = true; -}); + var socket3 = tls.connect(port, function() {}); -socket3.on('data', function(data) { - server_message = data.toString(); - socket3.write('Client hello'); - socket3.end(); -}); + socket3.on('secureConnect', function() { + handshake_done = true; + }); -socket3.on('end', function() { - server.close(); -}); + socket3.on('data', function(data) { + server_message = data.toString(); + socket3.write('Client hello'); + socket3.end(); + }); + + socket3.on('end', endCallback); +} process.on('exit', function() { + assert.equal(endCount, 3); assert.equal(handshake_done, true); assert.equal(server_handshake_done, true); assert.equal(client_message === expected_client_msg, true); diff --git a/test/run_pass/test_tls_4.js b/test/run_pass/test_tls_4.js index 18e7df3411..916f0808b3 100644 --- a/test/run_pass/test_tls_4.js +++ b/test/run_pass/test_tls_4.js @@ -24,6 +24,7 @@ var server_message = ''; var server_closed = false; var server_handshake_done = false; var handshake_done = false; +var endCount = 0; var port = 8080; @@ -31,7 +32,7 @@ var server_options = { key: fs.readFileSync(process.cwd() + '/resources/my_key.key').toString(), cert: fs.readFileSync(process.cwd() + '/resources/my_crt.crt'), rejectUnauthorized: false, - isServer: true + isServer: true, }; var server = tls.createServer(server_options, function(socket) { @@ -41,7 +42,7 @@ var server = tls.createServer(server_options, function(socket) { client_message = data.toString(); }); -}).listen(port, function() { }); +}).listen(port, startTesting); server.on('secureConnection', function() { server_handshake_done = true; @@ -51,51 +52,61 @@ server.on('close', function() { server_closed = true; }); -var socket_options = { - rejectUnauthorized: false, +function endCallback() { + endCount += 1; + if (endCount === 3) { + server.close(); + } } -var socket1 = tls.connect(port, 'localhost', socket_options); +function startTesting() { + var socket_options = { + rejectUnauthorized: false, + }; -socket1.on('secureConnect', function() { - handshake_done = true; -}); + var socket1 = tls.connect(port, 'localhost', socket_options); -socket1.on('data', function(data) { - server_message = data.toString(); - socket1.write('Client hello'); - socket1.end(); -}); + socket1.on('secureConnect', function() { + handshake_done = true; + }); -var socket2 = tls.connect(port, 'localhost', socket_options, function() {}); + socket1.on('data', function(data) { + server_message = data.toString(); + socket1.write('Client hello'); + socket1.end(); + }); + socket1.on('end', endCallback); -socket1.on('secureConnect', function() { - handshake_done = true; -}); + var socket2 = tls.connect(port, 'localhost', socket_options, function() {}); -socket2.on('data', function(data) { - server_message = data.toString(); - socket2.write('Client hello'); - socket2.end(); -}); + socket1.on('secureConnect', function() { + handshake_done = true; + }); -var socket3 = tls.connect(port, 'localhost', function() {}); + socket2.on('data', function(data) { + server_message = data.toString(); + socket2.write('Client hello'); + socket2.end(); + }); + socket2.on('end', endCallback); -socket3.on('secureConnect', function(){ - handshake_done = true; -}); + var socket3 = tls.connect(port, 'localhost', function() {}); -socket3.on('data', function(data) { - server_message = data.toString(); - socket3.write('Client hello'); - socket3.end(); -}); + socket3.on('secureConnect', function() { + handshake_done = true; + }); -socket3.on('end', function() { - server.close(); -}); + socket3.on('data', function(data) { + server_message = data.toString(); + socket3.write('Client hello'); + socket3.end(); + }); + + socket3.on('end', endCallback); +} process.on('exit', function() { + assert.equal(endCount, 3); assert.equal(handshake_done, true); assert.equal(server_handshake_done, true); assert.equal(client_message === expected_client_msg, true); diff --git a/tools/build.py b/tools/build.py index 2108ea09c0..360d745afe 100755 --- a/tools/build.py +++ b/tools/build.py @@ -27,6 +27,8 @@ import re import os +from distutils import spawn + from common_py import path from common_py.system.filesystem import FileSystem as fs from common_py.system.executor import Executor as ex @@ -289,9 +291,10 @@ def build_cmake_args(options): if options.target_os == 'tizenrt': include_dirs.append('%s/../framework/include/iotbus' % options.sysroot) elif options.target_os == 'windows': - cmake_args.append("-GVisual Studio 15 2017") if options.target_arch == "x86_64": cmake_args.append("-Ax64") + elif options.target_arch == "i686": + cmake_args.append("-AWin32") include_dirs.extend(options.external_include_dir) cmake_args.append("-DEXTERNAL_INCLUDE_DIR='%s'" % (' '.join(include_dirs))) @@ -351,10 +354,6 @@ def build_iotjs(options): if options.jerry_heaplimit: cmake_opt.append('-DJERRY_GLOBAL_HEAP_SIZE=%d' % options.jerry_heaplimit) - if options.jerry_heaplimit > 512: - cmake_opt.append("-DEXTRA_JERRY_CMAKE_PARAMS='%s'" % - "-DJERRY_CPOINTER_32_BIT=ON") - # --jerry-heap-section if options.jerry_heap_section: cmake_opt.append("-DJERRY_ATTR_GLOBAL_HEAP='%s'" % @@ -395,7 +394,7 @@ def build_iotjs(options): ex.check_run_cmd('cmake', cmake_opt) if options.target_os == 'windows': - print("\nPlease open the iot.js solution file in Visual Studio!") + ex.check_run_cmd('cmake', ['--build', options.build_root, '--config', options.buildtype]) else: run_make(options, options.build_root) @@ -403,20 +402,34 @@ def build_iotjs(options): def run_checktest(options): # IoT.js executable iotjs = fs.join(options.build_root, 'bin', 'iotjs') - - cmd = fs.join(path.TOOLS_ROOT, 'testrunner.py') + if options.target_os == 'windows': + iotjs = fs.join(options.build_root, 'bin', options.buildtype, 'iotjs') + cmd = sys.executable + testrunner_script = fs.join(path.TOOLS_ROOT, 'testrunner.py') args = [iotjs, "--platform=%s" % options.target_os] if options.run_test == "quiet": args.append('--quiet') fs.chdir(path.PROJECT_ROOT) - code = ex.run_cmd(cmd, args) + env = os.environ.copy() + if (options.target_tuple == 'i686-linux') and \ + (options.host_tuple != options.target_tuple): + old = env.get("LD_LIBRARY_PATH") + if old: + env["LD_LIBRARY_PATH"] = old + ":/usr/i686-linux-gnu/lib" + else: + env["LD_LIBRARY_PATH"] = "/usr/i686-linux-gnu/lib" + if spawn.find_executable('i686-linux-gnu-gcc'): + env['CC'] = 'i686-linux-gnu-gcc' + env['CXX'] = 'i686-linux-gnu-g++' + + code = ex.run_cmd(cmd, [testrunner_script] + args, env=env) if code != 0: ex.fail('Failed to pass unit tests') - if not options.no_check_valgrind: - code = ex.run_cmd(cmd, ['--valgrind'] + args) + if not options.no_check_valgrind and options.target_os != 'windows': + code = ex.run_cmd(cmd, [testrunner_script, '--valgrind'] + args, env=env) if code != 0: ex.fail('Failed to pass unit tests in valgrind environment') @@ -452,7 +465,9 @@ def run_checktest(options): (options.host_tuple == 'x86_64-linux' and options.target_tuple == 'i686-linux') or (options.host_tuple == 'x86_64-linux' and - options.target_tuple == 'x86_64-mock')): + options.target_tuple == 'x86_64-mock') or + (options.host_tuple == 'x86_64-windows' and + options.target_tuple == 'i686-windows')): run_checktest(options) else: print("Skip unit tests - target-host pair is not allowed\n") diff --git a/tools/check_tidy.py b/tools/check_tidy.py index 79fb5b52d1..f1b834c078 100755 --- a/tools/check_tidy.py +++ b/tools/check_tidy.py @@ -44,7 +44,7 @@ def parse_option(): class StyleChecker(object): - column_limit = 80 + column_limit = 120 def __init__(self): self.count_lines = 0 diff --git a/tools/travis_script.py b/tools/ci_script.py similarity index 91% rename from tools/travis_script.py rename to tools/ci_script.py index 6f71115358..6bddb1e126 100755 --- a/tools/travis_script.py +++ b/tools/ci_script.py @@ -25,8 +25,8 @@ DOCKER_ROOT_PATH = fs.join('/root') -# IoT.js path in travis -TRAVIS_BUILD_PATH = fs.join(os.environ['TRAVIS_BUILD_DIR']) +# IoT.js path in host +HOST_IOTJS_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) # IoT.js path in docker DOCKER_IOTJS_PATH = fs.join(DOCKER_ROOT_PATH, 'work_space/iotjs') @@ -68,20 +68,25 @@ def start_container(): def run_docker(): ex.check_run_cmd('docker', ['pull', DOCKER_TAG]) - ex.check_run_cmd('docker', ['run', '-dit', '--privileged', - '--name', DOCKER_NAME, '-v', - '%s:%s' % (TRAVIS_BUILD_PATH, DOCKER_IOTJS_PATH), + try: + ex.check_run_cmd('docker', ['rm', '-f', DOCKER_NAME]) + except: + pass + ex.check_run_cmd('docker', ['run', '-di', '--privileged', + '--name', DOCKER_NAME, + '-v', '%s:%s' % (HOST_IOTJS_PATH, DOCKER_IOTJS_PATH), '--add-host', 'test.mosquitto.org:127.0.0.1', '--add-host', 'echo.websocket.org:127.0.0.1', '--add-host', 'httpbin.org:127.0.0.1', DOCKER_TAG]) + exec_docker(DOCKER_IOTJS_PATH, ['npm', 'install']) def exec_docker(cwd, cmd, env=[], is_background=False): exec_cmd = 'cd %s && ' % cwd + ' '.join(cmd) if is_background: - docker_args = ['exec', '-dit'] + docker_args = ['exec', '-d'] else: - docker_args = ['exec', '-it'] + docker_args = ['exec', '-t'] for e in env: docker_args.append('-e') @@ -91,7 +96,7 @@ def exec_docker(cwd, cmd, env=[], is_background=False): ex.check_run_cmd('docker', docker_args) def start_mosquitto_server(): - exec_docker(DOCKER_ROOT_PATH, ['mosquitto', '-d']) + exec_docker(DOCKER_ROOT_PATH, ['mosquitto', '-d'], [], True) def start_node_server(): exec_docker(DOCKER_NODE_SERVER_PATH, ['node', 'server.js'], [], True) @@ -133,16 +138,19 @@ def job_host_linux(): '--run-test=full', '--profile=test/profiles/host-linux.profile']) +# N-API should work with both ES5.1 and ES2015-subset JerryScript profiles @job('n-api') def job_n_api(): start_container() - # N-API should work with both ES5.1 and ES2015-subset JerryScript profiles for buildtype in BUILDTYPES: build_iotjs(buildtype, [ '--run-test=full', '--n-api']) +@job('n-api-es2015-subset') +def job_n_api(): + start_container() for buildtype in BUILDTYPES: build_iotjs(buildtype, [ '--run-test=full', @@ -220,7 +228,7 @@ def job_tizen(): @job('misc') def job_misc(): - ex.check_run_cmd('tools/check_signed_off.sh', ['--travis']) + # ex.check_run_cmd('tools/check_signed_off.sh', ['--travis']) ex.check_run_cmd('tools/check_tidy.py') @job('external-modules') diff --git a/tools/common_py/system/executor.py b/tools/common_py/system/executor.py index b612b40b3e..4608e8e72e 100644 --- a/tools/common_py/system/executor.py +++ b/tools/common_py/system/executor.py @@ -60,11 +60,11 @@ def fail(msg): exit(1) @staticmethod - def run_cmd(cmd, args=[], quiet=False, cwd=None): + def run_cmd(cmd, args=[], quiet=False, cwd=None, env=None): if not quiet: Executor.print_cmd_line(cmd, args) try: - return subprocess.call([cmd] + args, cwd=cwd) + return subprocess.call([cmd] + args, cwd=cwd, env=env) except OSError as e: Executor.fail("[Failed - %s] %s" % (cmd, e.strerror)) diff --git a/tools/js2c.py b/tools/js2c.py index 2bf9c84da5..9c67bf3075 100755 --- a/tools/js2c.py +++ b/tools/js2c.py @@ -26,6 +26,7 @@ from common_py.system.filesystem import FileSystem as fs from common_py import path +src_root_dir = os.path.join(os.path.dirname(__file__), '..', 'src') def normalize_str(text): if not isinstance(text, str): @@ -203,7 +204,9 @@ def get_snapshot_contents(js_path, snapshot_tool, literals=None): cmd = [snapshot_tool, "generate", "-o", snapshot_path] if literals: cmd.extend(["--static", "--load-literals-list-format", literals]) - ret = subprocess.call(cmd + [wrapped_path]) + wrapped_rel_path = os.path.relpath(wrapped_path, src_root_dir) + wrapped_rel_path = wrapped_rel_path.replace('\\', '/') + ret = subprocess.call(cmd + [wrapped_rel_path], cwd=src_root_dir) fs.remove(wrapped_path) if ret != 0: diff --git a/tools/testrunner.py b/tools/testrunner.py index 6e9750c1ae..25d3b1d1f8 100755 --- a/tools/testrunner.py +++ b/tools/testrunner.py @@ -38,6 +38,8 @@ from common_py.system.executor import Terminal from common_py.system.sys_platform import Platform +import util + # Defines the folder that will contain the coverage info. # The path must be consistent with the measure_coverage.sh script. JS_COVERAGE_FOLDER = fs.join(path.PROJECT_ROOT, '.coverage_output') @@ -158,6 +160,7 @@ def __init__(self, options): # Process the iotjs build information. iotjs_output = Executor.check_run_cmd_output(self.iotjs, [path.BUILD_INFO_PATH]) + print("IoT.js build info:" + iotjs_output.decode('utf8', 'ignore')) build_info = json.loads(iotjs_output) self.builtins = set(build_info["builtins"]) @@ -180,7 +183,13 @@ def build_napi_test_module(self): cmd = ['--debug'] if self.debug else ['--release'] if self.platform == 'windows': node_gyp += '.cmd' - cmd.append('--arch=x64' if self.arch == 'x64' else '--arch=ia32') + if self.arch == 'x64': + cmd.append('--arch=x64') + elif self.arch == 'ia32': + cmd.append('--arch=ia32') + elif self.arch: + raise Exception(self.arch + " not supported") + Executor.check_run_cmd(node_gyp, ['rebuild'] + cmd, cwd=project_root) @@ -345,6 +354,7 @@ def get_args(): def main(): + util.setup_stdio() options = get_args() testrunner = TestRunner(options) diff --git a/tools/util.py b/tools/util.py new file mode 100644 index 0000000000..70c956cbd1 --- /dev/null +++ b/tools/util.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +# Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import sys +import codecs + +def setup_stdio(): + (out_stream, err_stream) = (sys.stdout, sys.stderr) + if sys.version_info.major >= 3: + (out_stream, err_stream) = (sys.stdout.buffer, sys.stderr.buffer) + # 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 anvoid encode error + sys.stdout = codecs.getwriter(encoding)(out_stream, 'xmlcharrefreplace') + sys.stderr = codecs.getwriter(encoding)(err_stream, 'xmlcharrefreplace')