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("//developtools/hiperf/hiperf.gni") 16 17module_output_path = "developtools/hiperf" 18 19sources_base = [ 20 "unittest/common/native/hiperf_client_test.cpp", 21 "unittest/common/native/command_test.cpp", 22 "unittest/common/native/perf_events_test.cpp", 23 "unittest/common/native/perf_event_record_test.cpp", 24 "unittest/common/native/perf_file_format_test.cpp", 25 "unittest/common/native/perf_file_writer_test.cpp", 26 "unittest/common/native/subcommand_test.cpp", 27 "unittest/common/native/utilities_test.cpp", 28 "unittest/common/native/elf_parser_test.cpp", 29 "unittest/common/native/register_test.cpp", 30 "unittest/common/native/option_test.cpp", 31 "unittest/common/native/perf_file_reader_test.cpp", 32 "unittest/common/native/virtual_thread_test.cpp", 33 "unittest/common/native/virtual_runtime_test.cpp", 34 "unittest/common/native/callstack_test.cpp", 35 "unittest/common/native/ring_buffer_test.cpp", 36 "unittest/common/native/symbols_file_test.cpp", 37 "unittest/common/native/tracked_command_test.cpp", 38 "unittest/common/native/dwarf_test.cpp", 39 "unittest/common/native/subcommand_help_test.cpp", 40 "unittest/common/native/subcommand_list_test.cpp", 41 "unittest/common/native/subcommand_dump_test.cpp", 42 "unittest/common/native/hashlist_test.cpp", 43 "unittest/common/native/report_test.cpp", 44 "unittest/common/native/report_json_file_test.cpp", 45] 46 47if (hiperf_debug) { 48 sources_base += [ "unittest/common/native/debug_logger_test.cpp" ] 49 sources_base += [ "unittest/common/native/option_debug_test.cpp" ] 50} 51 52if (!hiperf_target_static) { 53 sources_base += [ "unittest/common/native/report_protobuf_file_test.cpp" ] 54} 55 56sources_interface = [ 57 "unittest/common/native/subcommand_record_test.cpp", 58 "unittest/common/native/subcommand_stat_test.cpp", 59 "unittest/common/native/subcommand_report_test.cpp", 60 "unittest/common/native/hiperf_libreport_test.cpp", 61] 62 63common_deps = [ 64 "${hiperf_path}/:hiperf_platform_common", 65 "${hiperf_path}/:hiperf_platform_host", 66 "${hiperf_path}/:hiperf_platform_linux", 67 "${hiperf_path}/interfaces/innerkits/native:hiperf_client_static", 68 "//third_party/googletest:gmock_main", 69 "//third_party/googletest:gtest_main", 70] 71 72config("hiperf_test_config") { 73 cflags = code_check_flag 74 ldflags = [] 75 defines = [] 76 77 if (hiperf_test_coverage && is_ohos) { 78 defines += [ "TEST_COVERAGE" ] 79 cflags += [ 80 "-fprofile-arcs", 81 "-ftest-coverage", 82 ] 83 ldflags += [ "--coverage" ] 84 } 85 86 defines += [ "DEFAULT_LOG_LEVEL=LEVEL_VERBOSE" ] 87 88 include_dirs = [ 89 "${hiperf_path}/test/unittest/common/native/include", 90 "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", 91 ] 92} 93 94ohos_unittest("hiperf_unittest") { 95 configs = [ ":hiperf_test_config" ] 96 module_out_path = module_output_path 97 resource_config_file = "unittest/resource/ohos_test.xml" 98 deps = common_deps 99 100 sources = sources_interface 101 sources += sources_base 102 if (is_linux) { 103 static_link = false 104 } 105} 106 107fuzz_cflags = [ 108 "-g", 109 "-O0", 110 "-Wno-unused-variable", 111 "-fno-omit-frame-pointer", 112] 113 114ohos_fuzztest("hiperf_commandline_fuzztest") { 115 module_out_path = module_output_path 116 configs = [ ":hiperf_test_config" ] 117 cflags = fuzz_cflags 118 deps = common_deps 119 defines = [ "FUZZER_TEST" ] 120 sources = [ 121 "${hiperf_path}/src/main.cpp", 122 "fuzztest/CommandLine_fuzzer/CommandLine_fuzzer.cpp", 123 ] 124} 125 126ohos_fuzztest("hiperf_libreport_fuzztest") { 127 module_out_path = module_output_path 128 configs = [ ":hiperf_test_config" ] 129 cflags = fuzz_cflags 130 deps = common_deps 131 defines = [ "FUZZER_TEST" ] 132 sources = [ "fuzztest/LibReport_fuzzer/LibReport_fuzzer.cpp" ] 133} 134 135ohos_fuzztest("hiperf_client_api_fuzztest") { 136 module_out_path = module_output_path 137 configs = [ ":hiperf_test_config" ] 138 cflags = fuzz_cflags 139 deps = common_deps 140 defines = [ "FUZZER_TEST" ] 141 sources = [ "fuzztest/ClientApi_fuzzer/ClientApi_fuzzer.cpp" ] 142} 143 144ohos_fuzztest("hiperf_perf_file_fuzztest") { 145 module_out_path = module_output_path 146 resource_config_file = "fuzztest/resource/ohos_test.xml" 147 configs = [ ":hiperf_test_config" ] 148 cflags = fuzz_cflags 149 deps = common_deps 150 defines = [ "FUZZER_TEST" ] 151 sources = [ "fuzztest/PerfFile_fuzzer/PerfFile_fuzzer.cpp" ] 152} 153 154ohos_fuzztest("hiperf_elf_parser_fuzztest") { 155 module_out_path = module_output_path 156 resource_config_file = "fuzztest/resource/ohos_test.xml" 157 configs = [ ":hiperf_test_config" ] 158 cflags = fuzz_cflags 159 deps = common_deps 160 defines = [ "FUZZER_TEST" ] 161 sources = [ "fuzztest/ElfParser_fuzzer/ElfParser_fuzzer.cpp" ] 162} 163 164group("hiperf_fuzztest") { 165 testonly = true 166 deps = [ 167 ":hiperf_client_api_fuzztest", 168 ":hiperf_commandline_fuzztest", 169 ":hiperf_elf_parser_fuzztest", 170 ":hiperf_libreport_fuzztest", 171 ":hiperf_perf_file_fuzztest", 172 ] 173} 174 175group("hiperf_test") { 176 testonly = true 177 if (hiperf_target_host) { 178 deps = [ 179 ":hiperf_fuzztest(${host_toolchain})", 180 ":hiperf_unittest(${host_toolchain})", 181 ] 182 } else { 183 deps = [ ":hiperf_unittest" ] 184 } 185 if (hiperf_test_fuzz) { 186 deps += [ ":hiperf_fuzztest" ] 187 } 188} 189