1# Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 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("../../../base/config.gni") 16import("native_daemon.gni") 17 18module_output_path = "${OHOS_PROFILER_TEST_MODULE_OUTPUT_PATH}/device" 19 20sources_base = [ 21 "unittest/common/native/callstack_test.cpp", 22 "unittest/common/native/debug_logger_test.cpp", 23 "unittest/common/native/hashlist_test.cpp", 24 "unittest/common/native/hook_manager_test.cpp", 25 "unittest/common/native/hook_record_factory_test.cpp", 26 "unittest/common/native/hook_service_test.cpp", 27 "unittest/common/native/register_test.cpp", 28 "unittest/common/native/stack_preprocess_test.cpp", 29 "unittest/common/native/stack_builder_test.cpp", 30 "unittest/common/native/symbols_file_test.cpp", 31 "unittest/common/native/utilities_test.cpp", 32 "unittest/common/native/virtual_thread_test.cpp", 33 "unittest/common/native/virtual_runtime_test.cpp", 34 "../../api/src/buffer_writer.cpp", 35 "../../api/src/command_poller.cpp", 36 "../../api/src/writer_adapter.cpp", 37 "../src/hook_manager.cpp", 38 "../src/hook_record.cpp", 39 "../src/hook_record_factory.cpp", 40 "../src/call_stack.cpp", 41 "../src/debug_logger.cpp", 42 "../src/dwarf_encoding.cpp", 43 "../src/get_thread_id.cpp", 44 "../src/hook_service.cpp", 45 "../src/register.cpp", 46 "../src/stack_builder.cpp", 47 "../src/stack_data_repeater.cpp", 48 "../src/stack_preprocess.cpp", 49 "../src/symbols_file.cpp", 50 "../src/utilities.cpp", 51 "../src/virtual_runtime.cpp", 52 "../src/virtual_thread.cpp", 53 "${OHOS_PROFILER_DIR}/device/plugins/native_daemon/native_memory_profiler_sa/src/native_memory_profiler_sa_config.cpp", 54 "${OHOS_PROFILER_DIR}/device/plugins/native_daemon/native_memory_profiler_sa/src/native_memory_profiler_sa_death_recipient.cpp", 55 "${OHOS_PROFILER_DIR}/device/plugins/native_daemon/native_memory_profiler_sa/src/native_memory_profiler_sa_service.cpp", 56 "${OHOS_PROFILER_DIR}/device/plugins/native_daemon/native_memory_profiler_sa/src/native_memory_profiler_sa_stub.cpp", 57 "${OHOS_PROFILER_DIR}/device/services/profiler_service/src/trace_file_helper.cpp", 58 "${OHOS_PROFILER_DIR}/device/services/profiler_service/src/trace_file_writer.cpp", 59] 60 61common_deps = [ 62 "${OHOS_PROFILER_DIR}/device/plugins/network_profiler/service:network_profiler_service", 63 "${OHOS_PROFILER_DIR}/device/services/shared_memory:shared_memory_source", 64 "${OHOS_PROFILER_DIR}/proto_encoder:proto_encoder_source", 65 "${OHOS_PROFILER_DIR}/protos/services:plugin_service_proto", 66 "${OHOS_PROFILER_DIR}/protos/services:profiler_service_all_type_source", 67 "${OHOS_PROFILER_DIR}/protos/types/plugins/native_hook:native_hook_cpp", 68 "${OHOS_PROFILER_DIR}/protos/types/plugins/native_hook:native_hook_cpp_standard", 69 "../../../base:hiprofiler_base", 70] 71 72config("native_daemon_test_config") { 73 cflags = code_check_flag 74 ldflags = [] 75 defines = [] 76 77 cflags += [ 78 "-Dprivate=public", 79 "-Dprotected=public", 80 ] # allow test code access private members 81 if (native_daemon_test_coverage && is_ohos) { 82 defines += [ "TEST_COVERAGE" ] 83 cflags += [ 84 "-fprofile-arcs", 85 "-ftest-coverage", 86 ] 87 ldflags += [ "--coverage" ] 88 } 89 90 defines += [ "DEFAULT_LOG_LEVEL=LEVEL_VERBOSE" ] 91 defines += [ 92 "HAVE_LIBUNWINDER=1", 93 "HIPERF_DEBUG", 94 "HIPERF_DEBUG_PRINTF", 95 "CONFIG_NO_HILOG", 96 ] 97 defines += [ "target_cpu_${target_cpu}" ] 98 99 include_dirs = [ 100 "../include", 101 "../../../base/include", 102 "../src/", 103 "../../api/include", 104 "../../api/src", 105 "../../native_hook/include", 106 "../../native_hook/src", 107 "${OHOS_PROFILER_DIR}/interfaces/kits", 108 "${OHOS_PROFILER_DIR}/device/services/ipc/include", 109 "${OHOS_PROFILER_DIR}/device/services/shared_memory/include", 110 "${native_daemon_path}/test/unittest/common/native/include", 111 "${native_daemon_path}/include", 112 "${OHOS_PROFILER_DIR}/device/plugins/native_daemon/native_memory_profiler_sa/include", 113 "${OHOS_PROFILER_DIR}/device/plugins/native_daemon/native_memory_profiler_sa/util/include", 114 "${OHOS_PROFILER_DIR}/device/services/profiler_service/src", 115 ] 116} 117 118ohos_unittest("native_daemon_ut") { 119 configs = [ ":native_daemon_test_config" ] 120 module_out_path = module_output_path 121 resource_config_file = "${OHOS_PROFILER_DIR}/device/ohos_test.xml" 122 deps = common_deps 123 use_exceptions = true 124 sources = sources_base 125 if (is_linux) { 126 static_link = false 127 } 128 external_deps = [ 129 "ability_base:extractortool", 130 "access_token:libaccesstoken_sdk", 131 "access_token:libtokensetproc_shared", 132 "bounds_checking_function:libsec_shared", 133 "cJSON:cjson", 134 "c_utils:utils", 135 "faultloggerd:libunwinder", 136 "googletest:gtest", 137 "hisysevent:libhisysevent", 138 "init:libbegetutil", 139 "ipc:ipc_core", 140 "openssl:libcrypto_shared", 141 "protobuf:protobuf_lite", 142 "safwk:system_ability_fwk", 143 "samgr:samgr_proxy", 144 "zlib:libz", 145 ] 146 defines = [ "ENABLE_HAP_EXTRACTOR" ] 147 if (current_toolchain != host_toolchain) { 148 defines += [ "HAVE_HILOG" ] 149 external_deps += [ "hilog:libhilog" ] 150 } 151} 152 153group("unittest") { 154 testonly = true 155 if (native_daemon_target_host) { 156 deps = [ ":native_daemon_ut(${host_toolchain})" ] 157 } else { 158 deps = [ ":native_daemon_ut" ] 159 } 160} 161