1# Copyright (c) 2021-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 14if (PANDA_TARGET_ARM32 OR PANDA_QEMU_BUILD) 15 return() 16endif() 17 18add_custom_target(sampler_test_suite COMMENT "Running sampler etsnapi tests") 19 20if(CMAKE_CROSSCOMPILING) 21 ExternalProject_Get_Property(panda_host_tools binary_dir) 22 23 set(aspt_converter_target panda_host_tools-build) 24 set(aspt_converter_bin "${binary_dir}/tools/sampler/aspt_converter") 25else() 26 set(aspt_converter_target aspt_converter) 27 set(aspt_converter_bin $<TARGET_FILE:${aspt_converter_target}>) 28endif() 29 30set(ETS_COMPILE_ARGUMENTS --gen-stdlib=false --extension=ets --opt-level=0) 31 32set(RUNTIME_ARGUMENTS 33 --boot-panda-files=${PANDA_BINARY_ROOT}/plugins/ets/etsstdlib.abc 34 --load-runtimes=ets 35 --sampling-profiler-create 36 --sampling-profiler-startup-run 37 --sampling-profiler-interval=200 38) 39 40set(COMPILER_ARGUMENTS_LIST 41 "false" 42 "true" 43) 44 45set(INTERPRETER_ARGUMENTS_LIST 46 "cpp" 47 "irtoc" 48) 49 50set(testing_dir "${CMAKE_CURRENT_BINARY_DIR}") 51 52# Compile Ets tests 53add_custom_target(sampler_es2panda 54 COMMAND ${es2panda_bin} ${ETS_COMPILE_ARGUMENTS} --output ${testing_dir}/SamplerTest.abc ${CMAKE_CURRENT_SOURCE_DIR}/SamplerTest.ets 55 WORKING_DIRECTORY "${testing_dir}" 56 DEPENDS ${es2panda_target} 57) 58 59set(ETS_ENTRY_POINT "main") 60if (CMAKE_BUILD_TYPE STREQUAL "Release") 61 set(ETS_ENTRY_POINT "release_main") 62endif() 63 64# NOTE(kurnevichstanislav): fix SIGSEGV in sampler tests with TaskManager (#14278) 65set(RUNTIME_ARGUMENTS ${RUNTIME_ARGUMENTS} --workers-type=threadpool) 66 67foreach(c_arg ${COMPILER_ARGUMENTS_LIST}) 68 foreach(i_arg ${INTERPRETER_ARGUMENTS_LIST}) 69 # Run tests 70 add_custom_target(sampler_run_${c_arg}_${i_arg} 71 COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:ark> ${RUNTIME_ARGUMENTS} --compiler-enable-jit=${c_arg} --interpreter-type=${i_arg} --sampling-profiler-output-file=${testing_dir}/stack_output_${c_arg}_${i_arg}.aspt ${testing_dir}/SamplerTest.abc SamplerTest.ETSGLOBAL::${ETS_ENTRY_POINT} 72 WORKING_DIRECTORY "${testing_dir}" 73 DEPENDS ark etsstdlib sampler_es2panda 74 ) 75 76 add_custom_target(sampler_run_aspt_converter_${c_arg}_${i_arg} 77 COMMAND ${aspt_converter_bin} --input=${testing_dir}/stack_output_${c_arg}_${i_arg}.aspt --output=${testing_dir}/traceout_${c_arg}_${i_arg}.csv --cold-graph-enable=true 78 WORKING_DIRECTORY "${testing_dir}" 79 DEPENDS sampler_run_${c_arg}_${i_arg} ${aspt_converter_target} 80 ) 81 82 add_custom_target(sampler_trace_check_${c_arg}_${i_arg} 83 COMMAND python3 ${PANDA_ETS_PLUGIN_SOURCE}/tests/runtime/tooling/sampler/managed/sampler_traces_check.py --file=${testing_dir}/traceout_${c_arg}_${i_arg}.csv 84 WORKING_DIRECTORY "${testing_dir}" 85 DEPENDS sampler_run_aspt_converter_${c_arg}_${i_arg} 86 ) 87 88 add_dependencies(sampler_test_suite sampler_trace_check_${c_arg}_${i_arg}) 89 endforeach() 90endforeach() 91 92add_custom_target(sampler_run_aspt_converter_module_dump_mode 93 COMMAND ${aspt_converter_bin} --input=${testing_dir}/stack_output_false_cpp.aspt --dump-modules --output=${testing_dir}/modules.txt 94 WORKING_DIRECTORY "${testing_dir}" 95 DEPENDS sampler_run_false_cpp ${aspt_converter_target} 96) 97 98add_custom_target(sampler_aspt_converter_module_file_check 99 COMMAND python3 ${PANDA_ETS_PLUGIN_SOURCE}/tests/runtime/tooling/sampler/managed/sampler_module_file_check.py --file=${testing_dir}/modules.txt --bindir=${PANDA_BINARY_ROOT} 100 WORKING_DIRECTORY "${testing_dir}" 101 DEPENDS sampler_run_aspt_converter_module_dump_mode 102) 103 104add_dependencies(sampler_test_suite sampler_aspt_converter_module_file_check) 105 106# NOTE: Add tests only if sanitizers are disabled to avoid conflicts with sanitizers' signal stack 107if (PANDA_USE_CUSTOM_SIGNAL_STACK) 108 add_dependencies(ets_tests sampler_test_suite) 109endif() 110