1# Copyright (c) 2021-2023 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 14if (CMAKE_CROSSCOMPILING) 15 return() 16endif() 17 18if(PANDA_WITH_BENCHMARKS) 19 add_custom_target(ets_microbenchmarks COMMENT "Running ets micro-benchmarks") 20 add_dependencies(benchmarks ets_microbenchmarks) 21 22 set(INTERPRETER_ARGUMENTS_LIST "cpp") 23 set(MODES_LIST "int" "jit" "aot") 24 25 26 if(PANDA_TARGET_ARM64 OR PANDA_TARGET_AMD64) 27 list(APPEND INTERPRETER_ARGUMENTS_LIST "irtoc") 28 if (PANDA_LLVM_INTERPRETER) 29 list(APPEND INTERPRETER_ARGUMENTS_LIST "llvm") 30 endif() 31 endif() 32 33 set(script_dir "${PANDA_ROOT}/plugins/ets/tests/scripts/micro-benchmarks") 34 35 string(TOLOWER "${CMAKE_BUILD_TYPE}" cm_build_type) 36 if ("${cm_build_type}" STREQUAL "") 37 set(cm_build_type "debug") 38 endif() 39 if ("${cm_build_type}" STREQUAL "debug") 40 set(benchmark_timeout "5s") 41 endif() 42 if ("${cm_build_type}" STREQUAL "fastverify") 43 set(benchmark_timeout "5s") 44 endif() 45 46 if (NOT "${benchmark_timeout}" STREQUAL "") 47 set(timeout_signal 10) 48 set(timeout_prefix "timeout --preserve-status --signal=${timeout_signal} --kill-after=10s ${benchmark_timeout}") 49 set(timeout_suffix "|| [ `expr \$? % 128` -eq ${timeout_signal} ]") 50 else() 51 set(timeout_prefix "") 52 set(timeout_suffix "") 53 endif() 54 55 foreach(mode_arg ${MODES_LIST}) 56 foreach(int_arg ${INTERPRETER_ARGUMENTS_LIST}) 57 set(launch_file "${CMAKE_CURRENT_BINARY_DIR}/launch_${mode_arg}_${int_arg}.sh") 58 set(error_file "${CMAKE_CURRENT_BINARY_DIR}/run_${mode_arg}_${int_arg}.err") 59 set(launcher 60 "${timeout_prefix}" 61 "python3 run_micro_benchmarks.py --bindir ${CMAKE_BINARY_DIR}/bin --interpreter-type=${int_arg} --mode=${mode_arg} --log-level=silence" 62 "${timeout_suffix}" 63 "2> ${error_file}" 64 ) 65 string(REPLACE ";" " " launcher "${launcher}") 66 file(GENERATE OUTPUT ${launch_file} CONTENT "${launcher}") 67 68 add_custom_target(ets_microbenchmarks_${mode_arg}_${int_arg} 69 COMMENT "Running ${ARG_TARGET}" 70 COMMAND . ${launch_file} || (cat ${error_file} && false) 71 WORKING_DIRECTORY ${script_dir} 72 DEPENDS ark etsstdlib ark_asm ark_aot 73 ) 74 add_dependencies(ets_microbenchmarks ets_microbenchmarks_${mode_arg}_${int_arg}) 75 endforeach() 76 endforeach() 77endif() 78 79add_dependencies(ets_tests sampler_etsnapi_test_suite) 80