diff --git a/tests/runtime/common/CMakeLists.txt b/tests/runtime/common/CMakeLists.txt index 24f5ce08446b4c98a6ec789cc1133e62e8f5a37b..389f2f7a75680df3120994d26e841b7798df8e7d 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 0000000000000000000000000000000000000000..5a806679d8e49a759e8040e39c83b35e0f473017 --- /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 0000000000000000000000000000000000000000..b18416b9bf33112cd2f27d9b82a40c0fd2192cdd --- /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 0000000000000000000000000000000000000000..5282cf28e72aa0b6f2c21ae34b3c02c834fc655b --- /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()