From af6cda1be165181b3689c242ed7a896ca286dcff Mon Sep 17 00:00:00 2001 From: Petrov Igor Date: Fri, 9 Dec 2022 15:02:02 +0300 Subject: [PATCH] [MM] Separate gc and common parts of js tests Signed-off-by: Petrov Igor --- tests/CMakeLists.txt | 3 +- tests/runtime/common/CMakeLists.txt | 39 +----------- tests/runtime/common/gc/CMakeLists.txt | 59 +++++++++++++++++++ tests/runtime/common/gc/common.js | 28 +++++++++ tests/runtime/common/{ => gc}/concurrent.js | 8 +-- tests/runtime/common/{ => gc}/pinObject.js | 14 +---- tests/runtime/common/{ => gc}/scheduleGc.js | 14 +---- .../runtime/common/{ => gc}/spaceTypeTest.js | 8 +-- tests/runtime/common/{ => gc}/startGc.js | 14 +---- 9 files changed, 95 insertions(+), 92 deletions(-) create mode 100644 tests/runtime/common/gc/CMakeLists.txt create mode 100644 tests/runtime/common/gc/common.js rename tests/runtime/common/{ => gc}/concurrent.js (86%) rename tests/runtime/common/{ => gc}/pinObject.js (79%) rename tests/runtime/common/{ => gc}/scheduleGc.js (74%) rename tests/runtime/common/{ => gc}/spaceTypeTest.js (89%) rename tests/runtime/common/{ => gc}/startGc.js (88%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 765883ee5..4c42631d2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -264,6 +264,7 @@ endif() function(compile_file_ecma) set(prefix ARG) set(singleValues FILE OUTPUT_FILE WORKING_DIR) + set(multiValues OPTIONS) cmake_parse_arguments(${prefix} "" "${singleValues}" "${multiValues}" ${ARGN}) get_filename_component(FILE_NAME_WE "${ARG_FILE}" NAME_WE) @@ -273,7 +274,7 @@ function(compile_file_ecma) if (${FILE_TYPE} MATCHES "js") add_custom_command(OUTPUT "${ARG_OUTPUT_FILE}" COMMENT "Run es2panda for ${ARG_FILE}" - COMMAND ${es2panda_bin} --opt-level 0 --output ${ARG_OUTPUT_FILE} "${ARG_FILE}" + COMMAND ${es2panda_bin} ${ARG_OPTIONS} --opt-level 0 --output ${ARG_OUTPUT_FILE} "${ARG_FILE}" DEPENDS ${es2panda_target} "${ARG_FILE}" WORKING_DIRECTORY "${ARG_WORKING_DIR}") else() diff --git a/tests/runtime/common/CMakeLists.txt b/tests/runtime/common/CMakeLists.txt index cd7f53c1e..fd56f9394 100644 --- a/tests/runtime/common/CMakeLists.txt +++ b/tests/runtime/common/CMakeLists.txt @@ -15,44 +15,7 @@ add_custom_target(ecmascript_common_tests) add_dependencies(tests ecmascript_common_tests) -function(panda_add_ecma_test) - set(prefix ARG) - set(singleValues FILE) - set(multiValues OPTIONS) - cmake_parse_arguments(${prefix} "" "${singleValues}" "${multiValues}" ${ARGN}) - - get_filename_component(TEST_NAME "${ARG_FILE}" NAME_WE) - get_filename_component(TEST_FILE "${ARG_FILE}" REALPATH) - set(TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}") - set(BINARY_FILE "${TEST_DIR}/test.abc") - - file(MAKE_DIRECTORY "${TEST_DIR}") - compile_file_ecma(FILE ${TEST_FILE} OUTPUT_FILE ${BINARY_FILE} WORKING_DIR ${TEST_DIR}) - - set(OPTIONS "--load-runtimes=ecmascript" "${ARG_OPTIONS}") - - add_custom_target(${TEST_NAME} - COMMAND ${PANDA_RUN_PREFIX} $ - ${OPTIONS} - ${BINARY_FILE} - _GLOBAL::func_main_0 - DEPENDS ${TEST_FILE} - WORKING_DIRECTORY ${TEST_DIR} - COMMENT "Running ${TEST_NAME} test" - DEPENDS ${BINARY_FILE}) - - add_dependencies(${TEST_NAME} es2panda ark) - add_dependencies(ecmascript_common_tests ${TEST_NAME}) -endfunction() - -# Use --gc-trigger-type=debug-never to control GC in the test. -# In the test we don't need the runtime triggers GC during allocation. -panda_add_ecma_test(FILE startGc.js OPTIONS "--gc-trigger-type=debug-never") -panda_add_ecma_test(FILE scheduleGc.js OPTIONS "--gc-trigger-type=debug-never" "--gc-use-nth-alloc-trigger=true") -panda_add_ecma_test(FILE spaceTypeTest.js OPTIONS "--gc-type=g1-gc" "--run-gc-in-place=true") -panda_add_ecma_test(FILE concurrent.js OPTIONS "--gc-type=g1-gc" "--gc-trigger-type=debug-never") -panda_add_ecma_test(FILE pinObject.js OPTIONS "--gc-type=g1-gc" "--gc-trigger-type=debug-never") - +add_subdirectory(gc) add_subdirectory(helloworld) add_subdirectory(newobjdynrange) add_subdirectory(bitwiseop) diff --git a/tests/runtime/common/gc/CMakeLists.txt b/tests/runtime/common/gc/CMakeLists.txt new file mode 100644 index 000000000..6fb88582b --- /dev/null +++ b/tests/runtime/common/gc/CMakeLists.txt @@ -0,0 +1,59 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# 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. + +add_custom_target(gc_ecma_common_tests) +add_dependencies(ecmascript_common_tests gc_ecma_common_tests) + +set(COMMON_GC_MODULE_JS ${CMAKE_CURRENT_SOURCE_DIR}/common.js) +set(COMMON_GC_MODULE_BIN ${CMAKE_CURRENT_BINARY_DIR}/common.abc) +add_custom_target(gc_common_module + COMMENT "running javascript common gc module compilation" + COMMAND ${PANDA_RUN_PREFIX} $ --module ${COMMON_GC_MODULE_JS} --output ${COMMON_GC_MODULE_BIN} +) +add_dependencies(gc_common_module es2panda ark_asm ark) + +function(panda_add_ecma_gc_test) + set(prefix ARG) + set(singleValues FILE) + set(multiValues OPTIONS) + cmake_parse_arguments(${prefix} "" "${singleValues}" "${multiValues}" ${ARGN}) + + get_filename_component(TEST_NAME "${ARG_FILE}" NAME_WE) + get_filename_component(TEST_FILE "${ARG_FILE}" REALPATH) + set(BINARY_FILE "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.abc") + + compile_file_ecma(FILE ${TEST_FILE} OPTIONS "--module" OUTPUT_FILE ${BINARY_FILE} WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR}) + + set(OPTIONS "--load-runtimes=ecmascript" "--compiler-enable-jit=false" "${ARG_OPTIONS}") + + add_custom_target(${TEST_NAME} + COMMAND ${PANDA_RUN_PREFIX} $ + ${OPTIONS} + ${BINARY_FILE} + _GLOBAL::func_main_0 + DEPENDS ${TEST_FILE} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Running ${TEST_NAME} test" + DEPENDS ${BINARY_FILE}) + + add_dependencies(${TEST_NAME} gc_common_module) + add_dependencies(gc_ecma_common_tests ${TEST_NAME}) +endfunction() + +# Use --gc-trigger-type=debug-never to control GC in the test. +# In the test we don't need the runtime triggers GC during allocation. +panda_add_ecma_gc_test(FILE startGc.js OPTIONS "--gc-trigger-type=debug-never") +panda_add_ecma_gc_test(FILE scheduleGc.js OPTIONS "--gc-trigger-type=debug-never" "--gc-use-nth-alloc-trigger=true") +panda_add_ecma_gc_test(FILE spaceTypeTest.js OPTIONS "--gc-type=g1-gc" "--run-gc-in-place=true") +panda_add_ecma_gc_test(FILE concurrent.js OPTIONS "--gc-type=g1-gc" "--gc-trigger-type=debug-never") +panda_add_ecma_gc_test(FILE pinObject.js OPTIONS "--gc-type=g1-gc" "--gc-trigger-type=debug-never") diff --git a/tests/runtime/common/gc/common.js b/tests/runtime/common/gc/common.js new file mode 100644 index 000000000..2d3fdc5dc --- /dev/null +++ b/tests/runtime/common/gc/common.js @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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. + */ + +export function assert(value, message) { + if (value) { + return; + } + print("Assertion failed: " + message); + throw Error(); +} + +export function newWeakRefInYoung() { + // use a separate function because temporary object 'Object' + // are kept in vreg and GC treat it as a root. + return new WeakRef(new Object()); +} diff --git a/tests/runtime/common/concurrent.js b/tests/runtime/common/gc/concurrent.js similarity index 86% rename from tests/runtime/common/concurrent.js rename to tests/runtime/common/gc/concurrent.js index b6273ac31..64c164634 100644 --- a/tests/runtime/common/concurrent.js +++ b/tests/runtime/common/gc/concurrent.js @@ -13,13 +13,7 @@ * limitations under the License. */ -function assert(value, message) { - if (value) { - return; - } - print("Assertion failed: " + message); - throw Error(); -} +import { assert } from 'common.abc'; function alloc() { for (let i = 0; i < 100; ++i) { diff --git a/tests/runtime/common/pinObject.js b/tests/runtime/common/gc/pinObject.js similarity index 79% rename from tests/runtime/common/pinObject.js rename to tests/runtime/common/gc/pinObject.js index 680ee4f19..0d9b42232 100644 --- a/tests/runtime/common/pinObject.js +++ b/tests/runtime/common/gc/pinObject.js @@ -13,19 +13,7 @@ * limitations under the License. */ -function assert(value, message) { - if (value) { - return; - } - print("Assertion failed: " + message); - throw Error(); -} - -function newWeakRefInYoung() { - // use a separate function because temporary object 'Object' - // are kept in vreg and GC treat it as a root. - return new WeakRef(new Object()); -} +import { assert, newWeakRefInYoung } from 'common.abc'; let ref = newWeakRefInYoung(); { diff --git a/tests/runtime/common/scheduleGc.js b/tests/runtime/common/gc/scheduleGc.js similarity index 74% rename from tests/runtime/common/scheduleGc.js rename to tests/runtime/common/gc/scheduleGc.js index bc2b56bd7..8ea3b6498 100644 --- a/tests/runtime/common/scheduleGc.js +++ b/tests/runtime/common/gc/scheduleGc.js @@ -13,19 +13,7 @@ * limitations under the License. */ -function assert(value, message) { - if (value) { - return; - } - print("Assertion failed: " + message); - throw Error(); -} - -function newWeakRefInYoung() { - // use a separate function because temporary object 'Object' - // are kept in vreg and GC treat it as a root. - return new WeakRef(new Object()); -} +import { assert, newWeakRefInYoung } from 'common.abc'; let ref = newWeakRefInYoung(); scheduleGcAfterNthAlloc(4, "young"); diff --git a/tests/runtime/common/spaceTypeTest.js b/tests/runtime/common/gc/spaceTypeTest.js similarity index 89% rename from tests/runtime/common/spaceTypeTest.js rename to tests/runtime/common/gc/spaceTypeTest.js index 5a942ae4d..1298456e0 100644 --- a/tests/runtime/common/spaceTypeTest.js +++ b/tests/runtime/common/gc/spaceTypeTest.js @@ -13,13 +13,7 @@ * limitations under the License. */ -function assert(value, message) { - if (value) { - return; - } - print("Assertion failed: " + message); - throw Error(); -} +import { assert } from 'common.abc'; function func() { diff --git a/tests/runtime/common/startGc.js b/tests/runtime/common/gc/startGc.js similarity index 88% rename from tests/runtime/common/startGc.js rename to tests/runtime/common/gc/startGc.js index 86fe9c865..7dc69f55e 100644 --- a/tests/runtime/common/startGc.js +++ b/tests/runtime/common/gc/startGc.js @@ -13,19 +13,7 @@ * limitations under the License. */ -function assert(value, message) { - if (value) { - return; - } - print("Assertion failed: " + message); - throw Error(); -} - -function newWeakRefInYoung() { - // use a separate function because temporary object 'Object' - // are kept in vreg and GC treat it as a root. - return new WeakRef(new Object()); -} +import { assert, newWeakRefInYoung } from 'common.abc'; // allocate an object of size in bytes at least 'sizeInBytes' function allocLargeObject() { -- Gitee