1# Copyright (C) 2021 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. 13import("//build/test.gni") 14import("//developtools/hdc_standard/hdc.gni") 15hdc_path = "//developtools/hdc_standard/" 16module_output_path = "developtools/hdc_standard/" 17declare_args() { 18 hdc_unit_test = true 19} 20 21hdc_common_sources = [ 22 "${hdc_path}/src/common/async_cmd.cpp", 23 "${hdc_path}/src/common/auth.cpp", 24 "${hdc_path}/src/common/base.cpp", 25 "${hdc_path}/src/common/channel.cpp", 26 "${hdc_path}/src/common/debug.cpp", 27 "${hdc_path}/src/common/file.cpp", 28 "${hdc_path}/src/common/file_descriptor.cpp", 29 "${hdc_path}/src/common/forward.cpp", 30 "${hdc_path}/src/common/session.cpp", 31 "${hdc_path}/src/common/task.cpp", 32 "${hdc_path}/src/common/tcp.cpp", 33 "${hdc_path}/src/common/transfer.cpp", 34 "${hdc_path}/src/common/usb.cpp", 35] 36 37hdc_daemon_sources = [ 38 "${hdc_path}/src/daemon/daemon.cpp", 39 "${hdc_path}/src/daemon/daemon_app.cpp", 40 "${hdc_path}/src/daemon/daemon_forward.cpp", 41 "${hdc_path}/src/daemon/daemon_tcp.cpp", 42 "${hdc_path}/src/daemon/daemon_unity.cpp", 43 "${hdc_path}/src/daemon/daemon_usb.cpp", 44 "${hdc_path}/src/daemon/jdwp.cpp", 45 "${hdc_path}/src/daemon/shell.cpp", 46 "${hdc_path}/src/daemon/system_depend.cpp", 47] 48 49hdc_host_sources = [ 50 "${hdc_path}/src/host/client.cpp", 51 "${hdc_path}/src/host/host_app.cpp", 52 "${hdc_path}/src/host/host_forward.cpp", 53 "${hdc_path}/src/host/host_tcp.cpp", 54 "${hdc_path}/src/host/host_unity.cpp", 55 "${hdc_path}/src/host/host_usb.cpp", 56 "${hdc_path}/src/host/server.cpp", 57 "${hdc_path}/src/host/server_for_client.cpp", 58 "${hdc_path}/src/host/translate.cpp", 59] 60 61common_deps = [ 62 "//third_party/libusb:libusb", 63 "//third_party/libuv:uv_static", 64 "//third_party/lz4:liblz4_static", 65 "//third_party/openssl:libcrypto_static", 66 "//utils/native/base:utilsecurec", 67] 68 69config("hdc_ut_code_flag") { 70 cflags = code_check_flag 71} 72 73config("hdc_ut_config") { 74 defines = [] 75 include_dirs = [ "${hdc_path}/src/common" ] 76 77 cflags = [ 78 "-std=c++17", 79 "-fno-access-control", 80 "-g", 81 ] 82 ldflags = [] 83 84 if (hdc_test_coverage && is_ohos) { 85 cflags += [ 86 "-fprofile-arcs", 87 "-ftest-coverage", 88 ] 89 ldflags += [ "--coverage" ] 90 } 91} 92 93config("hdc_common_config") { 94 defines = [] 95 include_dirs = [ 96 "${hdc_path}/src/common", 97 "${hdc_path}/src/daemon", 98 "${hdc_path}/src/host", 99 "${hdc_path}/test/unittest/common/include", 100 "//third_party/libuv", # used in common.h 101 "//third_party/lz4/lib", # used in transfer.cpp 102 "//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include", 103 "//base/startup/init_lite/interfaces/innerkits/include", #daemon_unity.cpp 104 ] 105 106 if (hdc_support_uart) { 107 defines += [ "HDC_SUPPORT_UART" ] 108 } 109 110 defines += [ "HDC_UT" ] 111} 112 113config("hdc_host_common_config") { 114 defines = [ "HDC_HOST" ] 115 116 # both linux and ohos is same linux syscall 117 defines += [ "HOST_LINUX" ] 118 defines += [ "HARMONY_PROJECT" ] 119} 120 121ohos_source_set("hdc_common") { 122 use_exceptions = true 123 sources = hdc_common_sources 124 if (hdc_support_uart) { 125 sources += [ "${hdc_path}/src/common/uart.cpp" ] 126 } 127 public_deps = common_deps 128 public_configs = [ 129 ":hdc_common_config", 130 ":hdc_ut_config", 131 ] 132} 133 134ohos_source_set("hdc_daemon") { 135 use_exceptions = true 136 sources = hdc_common_sources 137 sources += hdc_daemon_sources 138 if (hdc_support_uart) { 139 sources += [ "${hdc_path}/src/common/uart.cpp" ] 140 sources += [ "${hdc_path}/src/daemon/daemon_uart.cpp" ] 141 } 142 public_deps = common_deps 143 public_configs = [ 144 ":hdc_common_config", 145 ":hdc_ut_config", 146 ] 147} 148 149ohos_source_set("hdc_host") { 150 use_exceptions = true 151 sources = hdc_common_sources 152 sources += hdc_host_sources 153 if (hdc_support_uart) { 154 sources += [ "${hdc_path}/src/common/uart.cpp" ] 155 sources += [ "${hdc_path}/src/host/host_uart.cpp" ] 156 } 157 public_deps = common_deps 158 public_configs = [ 159 ":hdc_common_config", 160 ":hdc_host_common_config", 161 ":hdc_ut_config", 162 ] 163} 164 165ohos_source_set("hdc_daemon_platform") { 166 public_configs = [ ":hdc_ut_config" ] 167 public_configs += [ "//third_party/googletest:gtest_config" ] 168 169 #defines = [ "HARMONY_PROJECT" ] 170 defines = [] 171 if (hdc_test_coverage && is_ohos) { 172 defines += [ "TEST_COVERAGE" ] 173 } 174 175 if (hdc_unit_test) { 176 defines += [ "HDC_UNIT_TEST" ] 177 } 178 if (js_jdwp_connect) { 179 defines += [ "JS_JDWP_CONNECT" ] 180 } 181 182 sources = [ 183 "${hdc_path}/src/daemon/daemon_unity.cpp", 184 "${hdc_path}/src/daemon/jdwp.cpp", 185 ] 186 187 public_deps = [ 188 "//third_party/libuv:uv_static", 189 "//third_party/openssl:libcrypto_static", 190 "//utils/native/base:utilsecurec", 191 ] 192 193 external_deps = [ 194 "init:libbegetutil", 195 "startup_l2:syspara", 196 ] 197 198 include_dirs = [ 199 "${hdc_path}/daemon", 200 "//utils/native/base/include", 201 "//third_party/openssl/include", 202 "//third_party/libuv", 203 ] 204 205 if (use_musl) { 206 include_dirs += [ 207 "//base/startup/init_lite/interfaces/innerkits/include", 208 "//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include", 209 ] 210 } 211} 212 213ohos_unittest("hdc_jdwp_unittest") { 214 module_out_path = module_output_path 215 public_configs = [ ":hdc_ut_config" ] 216 defines = [ "HARMONY_PROJECT" ] 217 if (hdc_test_coverage && is_ohos) { 218 defines += [ "TEST_COVERAGE" ] 219 } 220 if (hdc_unit_test) { 221 defines += [ "HDC_UNIT_TEST" ] 222 } 223 if (js_jdwp_connect) { 224 defines += [ "JS_JDWP_CONNECT" ] 225 } 226 public_deps = [ ":hdc_daemon_platform" ] 227 228 deps = [ 229 "//third_party/googletest:gmock_main", 230 "//third_party/googletest:gtest_main", 231 ] 232 233 sources = [ "unittest/common/HdcJdwpTest.cpp" ] 234 deps += [ ":hdc_common" ] 235 236 include_dirs = [ 237 "${hdc_path}/test/unittest/common/include", 238 "${hdc_path}/src/daemon", 239 "${hdc_path}/src/common", 240 "//third_party/libuv", 241 "//utils/native/base/include", 242 ] 243 244 if (is_linux) { 245 static_link = false 246 } 247 subsystem_name = "developtools" 248} 249 250ohos_unittest("hdc_uart_unittest") { 251 use_exceptions = true 252 module_out_path = module_output_path 253 resource_config_file = "unittest/resource/ohos_test.xml" 254 sources = [ 255 "unittest/common/daemon_uart_test.cpp", 256 "unittest/common/uart_test.cpp", 257 ] 258 259 configs = [ ":hdc_common_config" ] 260 configs += [ ":hdc_ut_code_flag" ] 261 deps = [ ":hdc_daemon" ] 262 263 deps += [ 264 "//third_party/googletest:gmock_main", 265 "//third_party/googletest:gtest_main", 266 ] 267} 268 269ohos_unittest("hdc_host_uart_unittest") { 270 use_exceptions = true 271 module_out_path = module_output_path 272 resource_config_file = "unittest/resource/ohos_test.xml" 273 sources = [ 274 "unittest/common/host_uart_test.cpp", 275 "unittest/common/uart_test.cpp", 276 ] 277 278 configs = [ 279 ":hdc_common_config", 280 ":hdc_host_common_config", 281 ":hdc_ut_code_flag", 282 ] 283 284 deps = [ ":hdc_host" ] 285 286 deps += [ 287 "//third_party/googletest:gmock_main", 288 "//third_party/googletest:gtest_main", 289 ] 290} 291 292group("HdcJdwpTest") { 293 testonly = true 294 deps = [ ":hdc_jdwp_unittest" ] 295} 296 297group("hdc_unittest") { 298 testonly = true 299 deps = [ 300 ":hdc_host_uart_unittest", 301 ":hdc_host_uart_unittest(${host_toolchain})", 302 ":hdc_jdwp_unittest", 303 ":hdc_uart_unittest", 304 ":hdc_uart_unittest(${host_toolchain})", 305 ] 306} 307