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/hdc.gni") 15hdc_path = "//developtools/hdc/" 16module_output_path = "developtools/hdc/" 17declare_args() { 18 hdc_unit_test = true 19 hdc_fuzz_test = true 20} 21 22hdc_common_sources = [ 23 "${hdc_path}/src/common/async_cmd.cpp", 24 "${hdc_path}/src/common/auth.cpp", 25 "${hdc_path}/src/common/base.cpp", 26 "${hdc_path}/src/common/channel.cpp", 27 "${hdc_path}/src/common/circle_buffer.cpp", 28 "${hdc_path}/src/common/debug.cpp", 29 "${hdc_path}/src/common/file.cpp", 30 "${hdc_path}/src/common/file_descriptor.cpp", 31 "${hdc_path}/src/common/forward.cpp", 32 "${hdc_path}/src/common/session.cpp", 33 "${hdc_path}/src/common/task.cpp", 34 "${hdc_path}/src/common/tcp.cpp", 35 "${hdc_path}/src/common/transfer.cpp", 36 "${hdc_path}/src/common/usb.cpp", 37] 38 39hdc_daemon_sources = [ 40 "${hdc_path}/src/daemon/daemon.cpp", 41 "${hdc_path}/src/daemon/daemon_app.cpp", 42 "${hdc_path}/src/daemon/daemon_forward.cpp", 43 "${hdc_path}/src/daemon/daemon_tcp.cpp", 44 "${hdc_path}/src/daemon/daemon_unity.cpp", 45 "${hdc_path}/src/daemon/daemon_usb.cpp", 46 "${hdc_path}/src/daemon/jdwp.cpp", 47 "${hdc_path}/src/daemon/shell.cpp", 48 "${hdc_path}/src/daemon/system_depend.cpp", 49] 50 51hdc_host_sources = [ 52 "${hdc_path}/src/host/client.cpp", 53 "${hdc_path}/src/host/host_app.cpp", 54 "${hdc_path}/src/host/host_forward.cpp", 55 "${hdc_path}/src/host/host_tcp.cpp", 56 "${hdc_path}/src/host/host_unity.cpp", 57 "${hdc_path}/src/host/host_updater.cpp", 58 "${hdc_path}/src/host/host_usb.cpp", 59 "${hdc_path}/src/host/server.cpp", 60 "${hdc_path}/src/host/server_for_client.cpp", 61 "${hdc_path}/src/host/translate.cpp", 62] 63 64common_external_deps = [ 65 "bounds_checking_function:libsec_static", 66 "libuv:uv", 67 "lz4:liblz4_static", 68 "openssl:libcrypto_static", 69] 70 71config("hdc_ut_code_flag") { 72 cflags = code_check_flag 73} 74 75config("hdc_ut_config") { 76 defines = [ 77 "TEST_HASH", 78 "HDC_MSG_HASH=\"TEST\"", 79 ] 80 include_dirs = [ "${hdc_path}/src/common" ] 81 82 cflags = [ 83 "-std=c++17", 84 "-fno-access-control", 85 "-g", 86 ] 87 ldflags = [] 88 89 if (hdc_test_coverage && is_ohos) { 90 cflags += [ 91 "-fprofile-arcs", 92 "-ftest-coverage", 93 ] 94 ldflags += [ "--coverage" ] 95 } 96} 97 98config("hdc_common_config") { 99 defines = [] 100 include_dirs = [ 101 "${hdc_path}/src/common", 102 "${hdc_path}/src/daemon", 103 "${hdc_path}/src/host", 104 "${hdc_path}/test/unittest/common/include", 105 ] 106 107 if (hdc_support_uart) { 108 defines += [ "HDC_SUPPORT_UART" ] 109 } 110 111 defines += [ "HDC_UT" ] 112} 113 114config("hdc_host_common_config") { 115 defines = [ "HDC_HOST" ] 116 117 # both linux and ohos is same linux syscall 118 defines += [ "HOST_LINUX" ] 119 defines += [ "HARMONY_PROJECT" ] 120} 121 122ohos_source_set("hdc_common") { 123 use_exceptions = true 124 testonly = true 125 sources = hdc_common_sources 126 if (hdc_support_uart) { 127 sources += [ "${hdc_path}/src/common/uart.cpp" ] 128 } 129 public_external_deps = common_external_deps 130 external_deps = [ "init:libbegetutil" ] 131 public_configs = [ 132 ":hdc_common_config", 133 ":hdc_ut_config", 134 ] 135 defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] 136} 137 138ohos_source_set("hdc_daemon") { 139 use_exceptions = true 140 sources = hdc_common_sources 141 sources += hdc_daemon_sources 142 if (hdc_support_uart) { 143 sources += [ "${hdc_path}/src/common/uart.cpp" ] 144 sources += [ "${hdc_path}/src/daemon/daemon_uart.cpp" ] 145 } 146 public_external_deps = common_external_deps 147 external_deps = [ "init:libbegetutil" ] 148 public_configs = [ 149 ":hdc_common_config", 150 ":hdc_ut_config", 151 ] 152 defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] 153} 154 155ohos_source_set("hdc_host") { 156 use_exceptions = true 157 sources = hdc_common_sources 158 sources += hdc_host_sources 159 if (hdc_support_uart) { 160 sources += [ "${hdc_path}/src/common/uart.cpp" ] 161 sources += [ "${hdc_path}/src/host/host_uart.cpp" ] 162 } 163 public_external_deps = common_external_deps 164 public_external_deps += [ "libusb:libusb" ] 165 public_configs = [ 166 ":hdc_common_config", 167 ":hdc_host_common_config", 168 ":hdc_ut_config", 169 ] 170 defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] 171} 172 173ohos_source_set("hdc_daemon_platform") { 174 testonly = true 175 public_configs = [ ":hdc_ut_config" ] 176 177 #defines = [ "HARMONY_PROJECT" ] 178 defines = [] 179 if (hdc_test_coverage && is_ohos) { 180 defines += [ "TEST_COVERAGE" ] 181 } 182 183 if (hdc_unit_test) { 184 defines += [ "HDC_UNIT_TEST" ] 185 } 186 if (js_jdwp_connect) { 187 defines += [ "JS_JDWP_CONNECT" ] 188 } 189 190 sources = [ 191 "${hdc_path}/src/daemon/daemon_unity.cpp", 192 "${hdc_path}/src/daemon/jdwp.cpp", 193 ] 194 195 public_external_deps = [ 196 "bounds_checking_function:libsec_static", 197 "googletest:gtest", 198 "libuv:uv", 199 "openssl:libcrypto_static", 200 ] 201 202 external_deps = [ "init:libbegetutil" ] 203 204 include_dirs = [ "${hdc_path}/daemon" ] 205} 206 207ohos_unittest("hdc_jdwp_unittest") { 208 module_out_path = module_output_path 209 public_configs = [ ":hdc_ut_config" ] 210 defines = [ "HARMONY_PROJECT" ] 211 if (hdc_test_coverage && is_ohos) { 212 defines += [ "TEST_COVERAGE" ] 213 } 214 if (hdc_unit_test) { 215 defines += [ "HDC_UNIT_TEST" ] 216 } 217 if (js_jdwp_connect) { 218 defines += [ "JS_JDWP_CONNECT" ] 219 } 220 public_deps = [ ":hdc_daemon_platform" ] 221 222 sources = [ "unittest/common/HdcJdwpTest.cpp" ] 223 deps = [ ":hdc_common" ] 224 225 include_dirs = [ 226 "${hdc_path}/test/unittest/common/include", 227 "${hdc_path}/src/daemon", 228 "${hdc_path}/src/common", 229 ] 230 external_deps = [ "googletest:gmock_main" ] 231 232 if (is_linux) { 233 static_link = false 234 } 235 subsystem_name = "developtools" 236 defines += [ "OPENSSL_SUPPRESS_DEPRECATED" ] 237 external_deps += [ 238 "bounds_checking_function:libsec_static", 239 "libuv:uv", 240 ] 241} 242 243ohos_unittest("hdc_uart_unittest") { 244 use_exceptions = true 245 module_out_path = module_output_path 246 resource_config_file = "unittest/resource/ohos_test.xml" 247 sources = [ 248 "unittest/common/daemon_uart_test.cpp", 249 "unittest/common/uart_test.cpp", 250 ] 251 252 configs = [ ":hdc_common_config" ] 253 configs += [ ":hdc_ut_code_flag" ] 254 deps = [ ":hdc_daemon" ] 255 defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] 256 257 external_deps = [ "googletest:gmock_main" ] 258} 259 260ohos_unittest("hdc_host_uart_unittest") { 261 use_exceptions = true 262 module_out_path = module_output_path 263 resource_config_file = "unittest/resource/ohos_test.xml" 264 sources = [ 265 "unittest/common/host_uart_test.cpp", 266 "unittest/common/uart_test.cpp", 267 ] 268 269 configs = [ 270 ":hdc_common_config", 271 ":hdc_host_common_config", 272 ":hdc_ut_code_flag", 273 ] 274 275 deps = [ ":hdc_host" ] 276 277 defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] 278 279 external_deps = [ "googletest:gmock_main" ] 280} 281 282group("HdcJdwpTest") { 283 testonly = true 284 deps = [ ":hdc_jdwp_unittest" ] 285} 286 287group("hdc_unittest") { 288 testonly = true 289 deps = [ 290 ":hdc_host_uart_unittest", 291 ":hdc_host_uart_unittest(${host_toolchain})", 292 ":hdc_jdwp_unittest", 293 ":hdc_register_unittest", 294 ":hdc_uart_unittest", 295 ":hdc_uart_unittest(${host_toolchain})", 296 ] 297} 298 299config("hdc_test_config") { 300 cflags = code_check_flag 301 ldflags = [] 302 defines = [ "HARMONY_PROJECT" ] 303 304 if (hdc_test_coverage && is_ohos) { 305 defines += [ "TEST_COVERAGE" ] 306 cflags += [ 307 "-fprofile-arcs", 308 "-ftest-coverage", 309 ] 310 ldflags += [ "--coverage" ] 311 } 312 if (js_jdwp_connect) { 313 defines += [ "JS_JDWP_CONNECT" ] 314 } 315 include_dirs = [ 316 "${hdc_path}/test/fuzztest/jdwpreadstream_fuzzer", 317 "${hdc_path}/test/fuzztest/forwardreadstream_fuzzer", 318 "${hdc_path}/src/daemon", 319 "${hdc_path}/src/common", 320 ] 321} 322 323config("hdc_register_config") { 324 cflags = code_check_flag 325 ldflags = [] 326 defines = [ "HDC_HILOG" ] 327 328 if (hdc_test_coverage && is_ohos) { 329 defines += [ "TEST_COVERAGE" ] 330 cflags += [ 331 "-fprofile-arcs", 332 "-ftest-coverage", 333 ] 334 ldflags += [ "--coverage" ] 335 } 336 if (js_jdwp_connect) { 337 defines += [ "JS_JDWP_CONNECT" ] 338 } 339} 340 341fuzz_cflags = [ 342 "-O0", 343 "-Wno-unused-variable", 344 "-fno-omit-frame-pointer", 345] 346 347ohos_fuzztest("JdwpReadStreamFuzzTest") { 348 module_out_path = FUZZ_OUTPUT_PATH 349 fuzz_config_file = "${hdc_path}/test/fuzztest/jdwpreadstream_fuzzer" 350 configs = [ ":hdc_test_config" ] 351 cflags = fuzz_cflags 352 sources = [ 353 "${hdc_path}/src/daemon/jdwp.cpp", 354 "${hdc_path}/src/daemon/system_depend.cpp", 355 "fuzztest/jdwpreadstream_fuzzer/JdwpReadStream_fuzzer.cpp", 356 ] 357 deps = [ ":hdc_common" ] 358 external_deps = [ 359 "init:libbeget_proxy", 360 "init:libbegetutil", 361 ] 362 public_external_deps = [ 363 "bounds_checking_function:libsec_static", 364 "libuv:uv", 365 ] 366} 367 368ohos_fuzztest("ForwardReadStreamFuzzTest") { 369 module_out_path = FUZZ_OUTPUT_PATH 370 fuzz_config_file = "${hdc_path}/test/fuzztest/forwardreadstream_fuzzer" 371 configs = [ ":hdc_test_config" ] 372 cflags = fuzz_cflags 373 external_deps = [ "libuv:uv" ] 374 sources = [ "fuzztest/forwardreadstream_fuzzer/ForwardReadStream_fuzzer.cpp" ] 375 deps = [ ":hdc_common" ] 376 subsystem_name = "developtools" 377 part_name = "hdc" 378} 379 380group("hdc_fuzztest") { 381 testonly = true 382 deps = [ 383 ":ForwardReadStreamFuzzTest", 384 ":JdwpReadStreamFuzzTest", 385 ] 386} 387 388ohos_unittest("hdc_register_unittest") { 389 module_out_path = module_output_path 390 resource_config_file = "unittest/resource/ohos_test.xml" 391 392 sources = [ 393 "${hdc_path}/src/register/hdc_connect.cpp", 394 "${hdc_path}/src/register/hdc_jdwp.cpp", 395 "unittest/register/register_test.cpp", 396 ] 397 398 include_dirs = [ "${hdc_path}/src/register/" ] 399 400 configs = [ ":hdc_register_config" ] 401 402 external_deps = [ 403 "c_utils:utils", 404 "googletest:gmock_main", 405 "hilog:libhilog", 406 "init:libbeget_proxy", 407 "init:libbegetutil", 408 "libuv:uv", 409 ] 410 411 subsystem_name = "developtools" 412 part_name = "hdc" 413} 414