1# Copyright (c) 2025 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14# now plugin tests with sanitizers triggers CI failure, which could not be reproduce locally, will be fixed in future 15if (PANDA_ENABLE_ADDRESS_SANITIZER OR PANDA_ENABLE_THREAD_SANITIZER) 16 return() 17endif() 18 19# how_to_test_mode 20set(COMPILE_MODE "COMPILE") 21set(RUNTIME_MODE "RUNTIME") 22set(EXPECTED_MODE "EXPECTED") 23 24# how_to_compile_mode 25set(LIBRARY_PLUGIN "LIB") 26set(EXECUTABLE_PLUGIN "EXE") 27 28set(COMMON_SOURCE_FILES 29 "../plugin/util.cpp" 30) 31 32set(PLUGIN_UT_TESTS 33 #"test_name test_sts_file how_to_test_mode plugin_file_extension(c|cpp) how_to_compile_mode" 34 "plugin_ut_variables_api compile.ets ${COMPILE_MODE} cpp ${EXECUTABLE_PLUGIN}" 35 "plugin_ut_new_array_instance_expression_api compile.ets ${COMPILE_MODE} cpp ${EXECUTABLE_PLUGIN}" 36 "plugin_ut_binary_expression_api compile.ets ${COMPILE_MODE} cpp ${EXECUTABLE_PLUGIN}" 37) 38 39set(RUNTIME_ARGUMENTS 40 --boot-panda-files=${PANDA_BINARY_ROOT}/plugins/ets/etsstdlib.abc${EXTRA_BOOT_PANDAFILES} 41 --load-runtimes=ets 42 --compiler-enable-jit=true 43) 44 45set(ENTRY_POINT ETSGLOBAL::main) 46 47foreach(TEST_DATA IN ITEMS ${PLUGIN_UT_TESTS}) 48 string(REPLACE " " ";" TEST_DATA_ELEM "${TEST_DATA}") 49 list(GET TEST_DATA_ELEM 0 TEST_NAME) 50 list(GET TEST_DATA_ELEM 3 EXTENSION) 51 52 panda_add_executable(${TEST_NAME} ${TEST_NAME}.${EXTENSION} ${COMMON_SOURCE_FILES} OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 53 panda_add_sanitizers(TARGET ${TEST_NAME} SANITIZERS ${PANDA_SANITIZERS_LIST}) 54 55 panda_target_include_directories(${TEST_NAME} 56 PRIVATE "${ES2PANDA_PATH}" 57 PRIVATE ${OUTPUT_DIR} 58 ) 59 panda_target_link_libraries(${TEST_NAME} es2panda-public) 60endforeach() 61 62add_custom_target(es2panda-plugin-ut-test) 63 64foreach(TEST_DATA IN ITEMS ${PLUGIN_UT_TESTS}) 65 string(REPLACE " " ";" TEST_DATA_ELEM "${TEST_DATA}") 66 list(GET TEST_DATA_ELEM 0 TEST_NAME) 67 list(GET TEST_DATA_ELEM 1 TEST_STS_FILE) 68 list(GET TEST_DATA_ELEM 2 TEST_MODE) 69 70 add_custom_target(es2panda-plugin-ut-test-compile-${TEST_NAME} 71 COMMAND ${CMAKE_COMMAND} -E env 72 LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${PANDA_RUN_PREFIX} 73 ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME} $<TARGET_FILE:es2panda> 74 --extension=ets --ets-unnamed --output="${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.abc" 75 "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_STS_FILE}" > "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.out" 2>&1 76 ) 77 78 add_dependencies(es2panda-plugin-ut-test-compile-${TEST_NAME} es2panda ${TEST_NAME} es2panda-lib) 79 if(${TEST_MODE} STREQUAL ${EXPECTED_MODE}) 80 add_custom_target(es2panda-plugin-ut-test-expected-${TEST_NAME} 81 COMMAND ${CMAKE_COMMAND} -E compare_files 82 "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.out" "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_NAME}-expected.txt" 83 ) 84 add_dependencies(es2panda-plugin-ut-test-expected-${TEST_NAME} es2panda-plugin-ut-test-compile-${TEST_NAME} es2panda-lib) 85 add_dependencies(es2panda-plugin-ut-test es2panda-plugin-ut-test-expected-${TEST_NAME}) 86 endif() 87 if(${TEST_MODE} STREQUAL ${RUNTIME_MODE}) 88 add_custom_target(es2panda-plugin-ut-test-runtime-${TEST_NAME} 89 COMMAND ${CMAKE_COMMAND} -E env 90 LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${PANDA_RUN_PREFIX} $<TARGET_FILE:ark> 91 ${RUNTIME_ARGUMENTS} "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}.abc" ${ENTRY_POINT} 92 > "${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME}-runtime.out" 93 ) 94 add_dependencies(es2panda-plugin-ut-test-runtime-${TEST_NAME} es2panda-plugin-ut-test-compile-${TEST_NAME} ark es2panda-lib) 95 add_dependencies(es2panda-plugin-ut-test es2panda-plugin-ut-test-runtime-${TEST_NAME}) 96 endif() 97 if(${TEST_MODE} STREQUAL ${COMPILE_MODE}) 98 add_dependencies(es2panda-plugin-ut-test es2panda-plugin-ut-test-compile-${TEST_NAME}) 99 endif() 100endforeach() 101 102add_custom_target(update-es2panda-plugin-ut-test-expected) 103 104foreach(TEST_DATA IN ITEMS ${PLUGIN_UT_TESTS}) 105 string(REPLACE " " ";" TEST_DATA_ELEM "${TEST_DATA}") 106 list(GET TEST_DATA_ELEM 0 TEST_NAME) 107 list(GET TEST_DATA_ELEM 1 TEST_STS_FILE) 108 list(GET TEST_DATA_ELEM 2 TEST_MODE) 109 if(${TEST_MODE} STREQUAL ${EXPECTED_MODE}) 110 add_custom_target(update-es2panda-plugin-ut-test-expected-${TEST_NAME} 111 COMMAND ${CMAKE_COMMAND} -E env 112 LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${PANDA_RUN_PREFIX} 113 ${CMAKE_CURRENT_BINARY_DIR}/${TEST_NAME} $<TARGET_FILE:es2panda> 114 "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_STS_FILE}" > 115 "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_NAME}-expected.txt") 116 117 add_dependencies(update-es2panda-plugin-ut-test-expected-${TEST_NAME} es2panda ${TEST_NAME} es2panda-lib) 118 add_dependencies(update-es2panda-plugin-ut-test-expected update-es2panda-plugin-ut-test-expected-${TEST_NAME}) 119 endif() 120endforeach() 121 122add_dependencies(es2panda_tests es2panda-plugin-ut-test) 123