• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2024 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=sts --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-enable
36    --sampling-profiler-interval=200
37)
38
39set(COMPILER_ARGUMENTS_LIST
40    "false"
41    "true"
42)
43
44set(INTERPRETER_ARGUMENTS_LIST
45    "cpp"
46    "irtoc"
47)
48
49set(testing_dir "${CMAKE_CURRENT_BINARY_DIR}")
50
51# Compile Ets tests
52add_custom_target(sampler_es2panda
53    COMMAND ${es2panda_bin} ${ETS_COMPILE_ARGUMENTS} --output ${testing_dir}/SamplerTest.abc ${CMAKE_CURRENT_SOURCE_DIR}/SamplerTest.sts
54    WORKING_DIRECTORY "${testing_dir}"
55    DEPENDS ${es2panda_target}
56)
57
58set(ETS_ENTRY_POINT "main")
59if (CMAKE_BUILD_TYPE STREQUAL "Release")
60    set(ETS_ENTRY_POINT "release_main")
61endif()
62
63# NOTE(kurnevichstanislav): fix SIGSEGV in sampler tests with TaskManager (#14278)
64set(RUNTIME_ARGUMENTS ${RUNTIME_ARGUMENTS} --workers-type=threadpool)
65
66foreach(c_arg ${COMPILER_ARGUMENTS_LIST})
67    foreach(i_arg ${INTERPRETER_ARGUMENTS_LIST})
68        # Run tests
69        add_custom_target(sampler_run_${c_arg}_${i_arg}
70            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 ETSGLOBAL::${ETS_ENTRY_POINT}
71            WORKING_DIRECTORY "${testing_dir}"
72            DEPENDS ark etsstdlib sampler_es2panda
73        )
74
75        add_custom_target(sampler_run_aspt_converter_${c_arg}_${i_arg}
76            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
77            WORKING_DIRECTORY "${testing_dir}"
78            DEPENDS sampler_run_${c_arg}_${i_arg} ${aspt_converter_target}
79        )
80
81        add_custom_target(sampler_trace_check_${c_arg}_${i_arg}
82            COMMAND python3 ${PANDA_ETS_PLUGIN_SOURCE}/tests/runtime/tooling/sampler/sampler_traces_check.py --file=${testing_dir}/traceout_${c_arg}_${i_arg}.csv
83            WORKING_DIRECTORY "${testing_dir}"
84            DEPENDS sampler_run_aspt_converter_${c_arg}_${i_arg}
85        )
86
87        add_dependencies(sampler_test_suite sampler_trace_check_${c_arg}_${i_arg})
88    endforeach()
89endforeach()
90
91add_custom_target(sampler_run_aspt_converter_module_dump_mode
92    COMMAND ${aspt_converter_bin} --input=${testing_dir}/stack_output_false_cpp.aspt --dump-modules --output=${testing_dir}/modules.txt
93    WORKING_DIRECTORY "${testing_dir}"
94    DEPENDS sampler_run_false_cpp ${aspt_converter_target}
95)
96
97add_custom_target(sampler_aspt_converter_module_file_check
98    COMMAND python3 ${PANDA_ETS_PLUGIN_SOURCE}/tests/runtime/tooling/sampler/sampler_module_file_check.py --file=${testing_dir}/modules.txt --bindir=${PANDA_BINARY_ROOT}
99    WORKING_DIRECTORY "${testing_dir}"
100    DEPENDS sampler_run_aspt_converter_module_dump_mode
101)
102
103add_dependencies(sampler_test_suite sampler_aspt_converter_module_file_check)
104
105# NOTE: Add tests only if sanitizers are disabled to avoid conflicts with sanitizers' signal stack
106if (PANDA_USE_CUSTOM_SIGNAL_STACK)
107    add_dependencies(ets_tests sampler_test_suite)
108endif()
109