From c3cc7a602a351f4540b6c5fff212dd8c4e897d6f Mon Sep 17 00:00:00 2001 From: Evgeniy Nikeytsev Date: Tue, 8 Nov 2022 17:25:03 +0300 Subject: [PATCH] Update GC test framework with following changes: - add harness.js for js tests - add test to check that large strings are collected by GC - add test to check that CopylexenvDyn function is properly work with its pointers during GC Change-Id: I8239bf1579ce1aa25fb97eb651c25d413a580402 Signed-off-by: Evgeniy Nikeytsev --- tests/runtime/common/CMakeLists.txt | 14 +++++- tests/runtime/common/copyLexEnvDynTest.js | 33 +++++++++++++ tests/runtime/common/harness.js | 23 ++++++++++ tests/runtime/common/largeStrings.js | 56 +++++++++++++++++++++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 tests/runtime/common/copyLexEnvDynTest.js create mode 100644 tests/runtime/common/harness.js create mode 100644 tests/runtime/common/largeStrings.js diff --git a/tests/runtime/common/CMakeLists.txt b/tests/runtime/common/CMakeLists.txt index 24f5ce084..389f2f7a7 100644 --- a/tests/runtime/common/CMakeLists.txt +++ b/tests/runtime/common/CMakeLists.txt @@ -23,11 +23,20 @@ function(panda_add_ecma_test) get_filename_component(TEST_NAME "${ARG_FILE}" NAME_WE) get_filename_component(TEST_FILE "${ARG_FILE}" REALPATH) + get_filename_component(TEST_HARNESS "harness.js" REALPATH) set(TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}") set(BINARY_FILE "${TEST_DIR}/test.abc") + set(FULL_TEST_FILE "${TEST_DIR}/test.js") + + # Adding harness to test file and output as temp js file + + add_custom_command(OUTPUT ${FULL_TEST_FILE} + COMMAND cat "${TEST_HARNESS}" > "${FULL_TEST_FILE}" + COMMAND cat "${TEST_FILE}" >> "${FULL_TEST_FILE}" + DEPENDS ${TEST_FILE}) file(MAKE_DIRECTORY "${TEST_DIR}") - compile_file_ecma(FILE ${TEST_FILE} OUTPUT_FILE ${BINARY_FILE} WORKING_DIR ${TEST_DIR}) + compile_file_ecma(FILE ${FULL_TEST_FILE} OUTPUT_FILE ${BINARY_FILE} WORKING_DIR ${TEST_DIR}) set(OPTIONS "--load-runtimes=ecmascript" "${ARG_OPTIONS}") @@ -39,6 +48,7 @@ function(panda_add_ecma_test) DEPENDS ${TEST_FILE} WORKING_DIRECTORY ${TEST_DIR} COMMENT "Running ${TEST_NAME} test" + DEPENDS ${FULL_TEST_FILE} DEPENDS ${BINARY_FILE}) add_dependencies(${TEST_NAME} es2panda ark) @@ -49,6 +59,8 @@ endfunction() # 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 largeStrings.js OPTIONS "--gc-trigger-type=debug-never") +panda_add_ecma_test(FILE copyLexEnvDynTest.js OPTIONS "--gc-type=g1-gc" "--run-gc-in-place=true") add_subdirectory(helloworld) add_subdirectory(newobjdynrange) diff --git a/tests/runtime/common/copyLexEnvDynTest.js b/tests/runtime/common/copyLexEnvDynTest.js new file mode 100644 index 000000000..5a806679d --- /dev/null +++ b/tests/runtime/common/copyLexEnvDynTest.js @@ -0,0 +1,33 @@ +/* + * 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. + */ + +for (let a = 0; a < 1000; a++) { + function aaa() { + var x = a; + } + aaa(); + for (let b = 0; b < 500; b++) { + function bbb() { + var y = b; + } + bbb(); + for (let c = 0; c < 250; c++) { + function ccc() { + var z = c; + } + ccc(); + } + } +} \ No newline at end of file diff --git a/tests/runtime/common/harness.js b/tests/runtime/common/harness.js new file mode 100644 index 000000000..b18416b9b --- /dev/null +++ b/tests/runtime/common/harness.js @@ -0,0 +1,23 @@ +/* + * 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. + */ + +function assert(value, message) { + if (value) { + return + } + print("Assertion failed: " + message) + throw Error() +} + diff --git a/tests/runtime/common/largeStrings.js b/tests/runtime/common/largeStrings.js new file mode 100644 index 000000000..5282cf28e --- /dev/null +++ b/tests/runtime/common/largeStrings.js @@ -0,0 +1,56 @@ +/* + * 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. + */ + +const MIN_BIG_STRING_SIZE = 128 * 1024 * 1024 + 1 +const START_STR = "a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9" + +function newBigString() { + let newString = START_STR + START_STR; + while (newString.length < MIN_BIG_STRING_SIZE) { + newString += newString + } + return newString +} + +function makeArrayOfStrings() { + let string_count = 0 + let string_array = new Array() + string_array.length = 1 + while (string_count < string_array.length) { + string_array[string_count] = newBigString() + string_count++ + } + return string_array; +} + +function newWeakRefObjectString() { + return new WeakRef(makeArrayOfStrings()) +} + +for (let i = 0; i < 5; i++) { + let ref1 = newWeakRefObjectString() + assert(ref1.deref() != undefined, "Ref1 is already doesnt exist!") + + let ref2 = newWeakRefObjectString() + assert(ref2.deref() != undefined, "Ref2 is already doesnt exist!") + assert(ref1.deref() === undefined, "Check that ref1 is derefered") + + gc = startGC("full") + waitForFinishGC(gc) + + assert(ref2.deref() === undefined, "Check that ref2 is derefered") + let ref3 = makeArrayOfStrings() +} +let ref3 = makeArrayOfStrings() -- Gitee