1# Copyright (C) 2021-2022 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 14import("//build/test.gni") 15import("../hiperf.gni") 16 17module_output_path = "hiperf/hiperf" 18 19sources_base = [ 20 "unittest/common/native/hiperf_client_test.cpp", 21 "unittest/common/native/hiperf_local_test.cpp", 22 "unittest/common/native/command_test.cpp", 23 "unittest/common/native/cpu_usage_test.cpp", 24 "unittest/common/native/perf_events_test.cpp", 25 "unittest/common/native/perf_event_record_test.cpp", 26 "unittest/common/native/perf_file_format_test.cpp", 27 "unittest/common/native/perf_file_writer_test.cpp", 28 "unittest/common/native/subcommand_test.cpp", 29 "unittest/common/native/utilities_test.cpp", 30 "unittest/common/native/register_test.cpp", 31 "unittest/common/native/option_test.cpp", 32 "unittest/common/native/perf_file_reader_test.cpp", 33 "unittest/common/native/virtual_thread_test.cpp", 34 "unittest/common/native/virtual_runtime_test.cpp", 35 "unittest/common/native/callstack_test.cpp", 36 "unittest/common/native/ring_buffer_test.cpp", 37 "unittest/common/native/symbols_file_test.cpp", 38 "unittest/common/native/tracked_command_test.cpp", 39 "unittest/common/native/dwarf_test.cpp", 40 "unittest/common/native/subcommand_help_test.cpp", 41 "unittest/common/native/subcommand_list_test.cpp", 42 "unittest/common/native/subcommand_dump_test.cpp", 43 "unittest/common/native/hashlist_test.cpp", 44 "unittest/common/native/report_test.cpp", 45 "unittest/common/native/report_json_file_test.cpp", 46 "unittest/common/native/unique_stack_table_test.cpp", 47 "unittest/common/native/spe_decoder_test.cpp", 48 "unittest/common/native/test_utilities.cpp", 49 "unittest/common/native/perf_pipe_test.cpp", 50] 51 52if (hiperf_debug) { 53 sources_base += [ "unittest/common/native/debug_logger_test.cpp" ] 54 sources_base += [ "unittest/common/native/option_debug_test.cpp" ] 55} 56 57if (!hiperf_target_static) { 58 sources_base += [ "unittest/common/native/report_protobuf_file_test.cpp" ] 59} 60 61sources_interface = [ 62 "unittest/common/native/subcommand_record_test.cpp", 63 "unittest/common/native/subcommand_stat_test.cpp", 64 "unittest/common/native/subcommand_report_test.cpp", 65 "unittest/common/native/test_hiperf_event_listener.cpp", 66] 67 68common_deps = [ 69 "${hiperf_path}/:hiperf_platform_common", 70 "${hiperf_path}/:hiperf_platform_linux", 71 "${hiperf_path}/interfaces/innerkits/native/hiperf_client:hiperf_client_static", 72] 73 74if (!ohos_indep_compiler_enable) { 75 common_deps += [ "${hiperf_path}/:hiperf_platform_host" ] 76 sources_interface += [ "unittest/common/native/hiperf_libreport_test.cpp" ] 77} 78 79config("hiperf_test_config") { 80 cflags = code_check_flag 81 ldflags = [] 82 defines = [] 83 84 if (hiperf_test_coverage && is_ohos) { 85 defines += [ "TEST_COVERAGE" ] 86 cflags += [ 87 "-fprofile-arcs", 88 "-ftest-coverage", 89 ] 90 ldflags += [ "--coverage" ] 91 } 92 93 defines += [ "DEFAULT_LOG_LEVEL=LEVEL_INFO" ] 94 95 include_dirs = [ "${hiperf_path}/test/unittest/common/native/include" ] 96} 97 98ohos_unittest("hiperf_unittest") { 99 configs = [ ":hiperf_test_config" ] 100 module_out_path = module_output_path 101 resource_config_file = "unittest/resource/ohos_test.xml" 102 deps = [ 103 "${hiperf_path}/interfaces/innerkits/native/hiperf_client:hiperf_client_static", 104 "${hiperf_path}/interfaces/innerkits/native/hiperf_local:hiperf_local", 105 ] 106 use_exceptions = true 107 108 public_configs = [ "${hiperf_path}/:hiperf_inner_config" ] 109 110 defines = [ 111 "SUPPORT_PERF_EVENT", 112 "HIPERF_UNITTEST", 113 "CONFIG_HAS_CCM", 114 ] 115 116 public_deps = [] 117 external_deps = [ 118 "abseil-cpp:absl_container", 119 "abseil-cpp:absl_cord", 120 "abseil-cpp:absl_log", 121 "abseil-cpp:absl_strings", 122 "bounds_checking_function:libsec_shared", 123 "cJSON:cjson", 124 "c_utils:utils", 125 "config_policy:configpolicy_util", 126 "faultloggerd:libdfx_dumpcatcher", 127 "faultloggerd:libunwinder", 128 "googletest:gmock", 129 "hilog:libhilog", 130 "hisysevent:libhisysevent", 131 "hisysevent:libhisyseventmanager", 132 "ipc:ipc_single", 133 "protobuf:protobuf_lite", 134 "zlib:libz", 135 ] 136 137 cflags = [ 138 "-Dprivate=public", #allow test code access private members 139 "-Dprotected=public", #allow test code access protected members 140 ] 141 142 sources = sources_interface 143 sources += sources_base 144 145 sources += [ 146 "./../src/command.cpp", 147 "./../src/command_reporter.cpp", 148 "./../src/dwarf_encoding.cpp", 149 "./../src/hiperf_libreport.cpp", 150 "./../src/ipc_utilities.cpp", 151 "./../src/option.cpp", 152 "./../src/perf_event_record.cpp", 153 "./../src/perf_events.cpp", 154 "./../src/perf_file_format.cpp", 155 "./../src/perf_file_reader.cpp", 156 "./../src/perf_file_writer.cpp", 157 "./../src/perf_pipe.cpp", 158 "./../src/register.cpp", 159 "./../src/report.cpp", 160 "./../src/report_json_file.cpp", 161 "./../src/ring_buffer.cpp", 162 "./../src/spe_decoder.cpp", 163 "./../src/subcommand.cpp", 164 "./../src/subcommand_dump.cpp", 165 "./../src/subcommand_help.cpp", 166 "./../src/subcommand_list.cpp", 167 "./../src/subcommand_record.cpp", 168 "./../src/subcommand_report.cpp", 169 "./../src/subcommand_stat.cpp", 170 "./../src/symbols_file.cpp", 171 "./../src/tracked_command.cpp", 172 "./../src/unique_stack_table.cpp", 173 "./../src/utilities.cpp", 174 "./../src/virtual_runtime.cpp", 175 "./../src/virtual_thread.cpp", 176 ] 177 178 if (is_ohos) { 179 sources += [ "./../src/callstack.cpp" ] 180 external_deps += [ 181 "init:libbegetutil", 182 "ipc:ipc_core", 183 "samgr:samgr_proxy", 184 ] 185 } 186 187 if (is_linux) { 188 static_link = false 189 } 190 191 if (hiperf_use_libunwinder) { 192 defines += [ "HAVE_LIBUNWINDER=1" ] 193 } 194 195 if (!hiperf_target_static) { 196 public_configs += [ "${hiperf_path}/:protobuf_config" ] 197 public_deps += [ "${hiperf_path}/:proto_file_cpp" ] 198 sources += [ "./../src/report_protobuf_file.cpp" ] 199 } 200 201 if (hiperf_debug) { 202 sources += [ 203 "./../src/debug_logger.cpp", 204 "./../src/option_debug.cpp", 205 ] 206 } 207 208 if (is_ohos && hiperf_use_syspara) { 209 public_configs += [ "${hiperf_path}/:hiperf_syspara_config" ] 210 } 211} 212 213fuzz_cflags = [ 214 "-O0", 215 "-fno-omit-frame-pointer", 216] 217 218ohos_fuzztest("CommandLineFuzzTest") { 219 module_out_path = hiperf_fuzz_test_output_path 220 fuzz_config_file = "${hiperf_path}/test/fuzztest/commandline_fuzzer" 221 configs = [ ":hiperf_test_config" ] 222 cflags = fuzz_cflags 223 deps = common_deps 224 external_deps = [ 225 "abseil-cpp:absl_container", 226 "abseil-cpp:absl_cord", 227 "abseil-cpp:absl_log", 228 "abseil-cpp:absl_strings", 229 "bounds_checking_function:libsec_shared", 230 "c_utils:utils", 231 "faultloggerd:libunwinder", 232 "hilog:libhilog", 233 "ipc:ipc_single", 234 "protobuf:protobuf_lite", 235 ] 236 defines = [ "FUZZER_TEST" ] 237 sources = [ 238 "${hiperf_path}/src/main.cpp", 239 "fuzztest/commandline_fuzzer/CommandLine_fuzzer.cpp", 240 ] 241} 242 243ohos_fuzztest("LibReportFuzzTest") { 244 module_out_path = hiperf_fuzz_test_output_path 245 fuzz_config_file = "${hiperf_path}/test/fuzztest/libreport_fuzzer" 246 configs = [ ":hiperf_test_config" ] 247 cflags = fuzz_cflags 248 deps = common_deps 249 external_deps = [ 250 "bounds_checking_function:libsec_shared", 251 "c_utils:utils", 252 "hilog:libhilog", 253 "ipc:ipc_single", 254 "protobuf:protobuf_lite", 255 ] 256 defines = [ "FUZZER_TEST" ] 257 sources = [ "fuzztest/libreport_fuzzer/LibReport_fuzzer.cpp" ] 258} 259 260ohos_fuzztest("ClientApiFuzzTest") { 261 module_out_path = hiperf_fuzz_test_output_path 262 fuzz_config_file = "${hiperf_path}/test/fuzztest/clientapi_fuzzer" 263 configs = [ ":hiperf_test_config" ] 264 cflags = fuzz_cflags 265 deps = common_deps 266 external_deps = [ 267 "abseil-cpp:absl_container", 268 "abseil-cpp:absl_cord", 269 "abseil-cpp:absl_log", 270 "abseil-cpp:absl_strings", 271 "bounds_checking_function:libsec_shared", 272 "c_utils:utils", 273 "hilog:libhilog", 274 "ipc:ipc_single", 275 "protobuf:protobuf_lite", 276 ] 277 defines = [ "FUZZER_TEST" ] 278 sources = [ "fuzztest/clientapi_fuzzer/ClientApi_fuzzer.cpp" ] 279} 280 281ohos_fuzztest("SpeDecoderFuzzTest") { 282 module_out_path = hiperf_fuzz_test_output_path 283 fuzz_config_file = "${hiperf_path}/test/fuzztest/spedecoder_fuzzer" 284 configs = [ ":hiperf_test_config" ] 285 cflags = fuzz_cflags 286 deps = common_deps 287 external_deps = [ 288 "abseil-cpp:absl_container", 289 "abseil-cpp:absl_cord", 290 "abseil-cpp:absl_log", 291 "abseil-cpp:absl_strings", 292 "bounds_checking_function:libsec_shared", 293 "c_utils:utils", 294 "hilog:libhilog", 295 "ipc:ipc_single", 296 "protobuf:protobuf_lite", 297 ] 298 defines = [ "FUZZER_TEST" ] 299 sources = [ "fuzztest/spedecoder_fuzzer/SpeDecoder_fuzzer.cpp" ] 300} 301 302ohos_fuzztest("PerfFileFuzzTest") { 303 module_out_path = hiperf_fuzz_test_output_path 304 fuzz_config_file = "${hiperf_path}/test/fuzztest/perffile_fuzzer" 305 resource_config_file = "fuzztest/resource/ohos_test.xml" 306 configs = [ ":hiperf_test_config" ] 307 cflags = fuzz_cflags 308 deps = common_deps 309 external_deps = [ 310 "abseil-cpp:absl_container", 311 "abseil-cpp:absl_cord", 312 "abseil-cpp:absl_log", 313 "abseil-cpp:absl_strings", 314 "bounds_checking_function:libsec_shared", 315 "c_utils:utils", 316 "faultloggerd:libunwinder", 317 "hilog:libhilog", 318 "ipc:ipc_single", 319 "protobuf:protobuf_lite", 320 ] 321 defines = [ "FUZZER_TEST" ] 322 sources = [ "fuzztest/perffile_fuzzer/PerfFile_fuzzer.cpp" ] 323} 324 325ohos_fuzztest("PerfFileFormatFuzzTest") { 326 module_out_path = hiperf_fuzz_test_output_path 327 fuzz_config_file = "${hiperf_path}/test/fuzztest/perffileformat_fuzzer" 328 configs = [ ":hiperf_test_config" ] 329 cflags = fuzz_cflags 330 deps = common_deps 331 external_deps = [ 332 "abseil-cpp:absl_container", 333 "abseil-cpp:absl_cord", 334 "abseil-cpp:absl_log", 335 "abseil-cpp:absl_strings", 336 "bounds_checking_function:libsec_shared", 337 "c_utils:utils", 338 "faultloggerd:libunwinder", 339 "hilog:libhilog", 340 "ipc:ipc_single", 341 "protobuf:protobuf_lite", 342 ] 343 defines = [ "FUZZER_TEST" ] 344 sources = [ "fuzztest/perffileformat_fuzzer/PerfFileFormat_fuzzer.cpp" ] 345} 346 347group("hiperf_fuzztest") { 348 testonly = true 349 deps = [ 350 ":ClientApiFuzzTest", 351 ":CommandLineFuzzTest", 352 ":PerfFileFormatFuzzTest", 353 ":PerfFileFuzzTest", 354 ":SpeDecoderFuzzTest", 355 ] 356 if (!ohos_indep_compiler_enable) { 357 deps += [ ":LibReportFuzzTest" ] 358 } 359} 360 361group("hiperf_test") { 362 testonly = true 363 if (hiperf_target_host && !ohos_indep_compiler_enable) { 364 deps = [ 365 ":hiperf_fuzztest(${host_toolchain})", 366 ":hiperf_unittest(${host_toolchain})", 367 ] 368 } else { 369 deps = [ ":hiperf_unittest" ] 370 } 371 if (hiperf_test_fuzz) { 372 deps += [ ":hiperf_fuzztest" ] 373 } 374} 375