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/compress.cpp", 29 "${hdc_path}/src/common/debug.cpp", 30 "${hdc_path}/src/common/decompress.cpp", 31 "${hdc_path}/src/common/entry.cpp", 32 "${hdc_path}/src/common/file.cpp", 33 "${hdc_path}/src/common/file_descriptor.cpp", 34 "${hdc_path}/src/common/forward.cpp", 35 "${hdc_path}/src/common/header.cpp", 36 "${hdc_path}/src/common/heartbeat.cpp", 37 "${hdc_path}/src/common/session.cpp", 38 "${hdc_path}/src/common/task.cpp", 39 "${hdc_path}/src/common/tcp.cpp", 40 "${hdc_path}/src/common/tlv.cpp", 41 "${hdc_path}/src/common/transfer.cpp", 42 "${hdc_path}/src/common/usb.cpp", 43 "${hdc_path}/src/common/uv_status.cpp", 44] 45 46hdc_daemon_sources = [ 47 "${hdc_path}/src/daemon/daemon.cpp", 48 "${hdc_path}/src/daemon/daemon_app.cpp", 49 "${hdc_path}/src/daemon/daemon_forward.cpp", 50 "${hdc_path}/src/daemon/daemon_tcp.cpp", 51 "${hdc_path}/src/daemon/daemon_unity.cpp", 52 "${hdc_path}/src/daemon/daemon_usb.cpp", 53 "${hdc_path}/src/daemon/jdwp.cpp", 54 "${hdc_path}/src/daemon/shell.cpp", 55 "${hdc_path}/src/daemon/system_depend.cpp", 56] 57 58hdc_host_sources = [ 59 "${hdc_path}/src/host/client.cpp", 60 "${hdc_path}/src/host/host_app.cpp", 61 "${hdc_path}/src/host/host_forward.cpp", 62 "${hdc_path}/src/host/host_tcp.cpp", 63 "${hdc_path}/src/host/host_unity.cpp", 64 "${hdc_path}/src/host/host_updater.cpp", 65 "${hdc_path}/src/host/host_usb.cpp", 66 "${hdc_path}/src/host/server.cpp", 67 "${hdc_path}/src/host/server_for_client.cpp", 68 "${hdc_path}/src/host/translate.cpp", 69] 70 71common_external_deps = [ 72 "bounds_checking_function:libsec_static", 73 "libuv:uv", 74 "lz4:liblz4_static", 75 "openssl:libcrypto_static", 76 "openssl:libssl_static", 77] 78 79config("hdc_ut_code_flag") { 80 cflags = code_check_flag 81} 82 83config("hdc_ut_config") { 84 defines = [ 85 "TEST_HASH", 86 "HDC_MSG_HASH=\"TEST\"", 87 ] 88 include_dirs = [ "${hdc_path}/src/common" ] 89 90 cflags = [ 91 "-std=c++17", 92 "-fno-access-control", 93 "-g", 94 ] 95 ldflags = [] 96 97 if (hdc_test_coverage && is_ohos) { 98 cflags += [ 99 "-fprofile-arcs", 100 "-ftest-coverage", 101 ] 102 ldflags += [ "--coverage" ] 103 } 104} 105 106config("hdc_common_config") { 107 defines = [ "HDC_UT" ] 108 include_dirs = [ 109 "${hdc_path}/src/common", 110 "${hdc_path}/src/daemon", 111 "${hdc_path}/src/host", 112 "${hdc_path}/test/unittest/common/include", 113 ] 114 115 if (hdc_support_uart) { 116 defines += [ "HDC_SUPPORT_UART" ] 117 } 118} 119 120config("hdc_host_common_config") { 121 defines = [ "HDC_HOST" ] 122 123 # both linux and ohos is same linux syscall 124 defines += [ "HOST_LINUX" ] 125 defines += [ "HARMONY_PROJECT" ] 126 127 include_dirs = [ 128 "${hdc_path}/src/common", 129 "${hdc_path}/src/daemon", 130 "${hdc_path}/src/host", 131 "${hdc_path}/test/unittest/common/include", 132 "${hdc_path}/test/unittest/daemon/include", 133 "${hdc_path}/test/unittest/host/include", 134 ] 135} 136 137ohos_source_set("hdc_common") { 138 use_exceptions = true 139 testonly = true 140 sources = hdc_common_sources 141 if (hdc_support_uart) { 142 sources += [ "${hdc_path}/src/common/uart.cpp" ] 143 } 144 external_deps = common_external_deps 145 external_deps += [ "init:libbegetutil" ] 146 public_configs = [ 147 ":hdc_common_config", 148 ":hdc_ut_config", 149 ] 150 defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] 151 if (hdc_fuzz_test) { 152 defines += [ 153 "FUZZ_TEST", 154 "HDC_HILOG", 155 ] 156 external_deps += [ "hilog:libhilog" ] 157 } 158} 159 160ohos_source_set("hdc_daemon") { 161 use_exceptions = true 162 sources = hdc_common_sources 163 sources += hdc_daemon_sources 164 subsystem_name = "developtools" 165 part_name = "hdc" 166 if (hdc_support_uart) { 167 sources += [ "${hdc_path}/src/common/uart.cpp" ] 168 sources += [ "${hdc_path}/src/daemon/daemon_uart.cpp" ] 169 } 170 external_deps = common_external_deps 171 external_deps += [ 172 "init:libbegetutil", 173 "c_utils:utils", 174 ] 175 public_configs = [ 176 ":hdc_common_config", 177 ":hdc_ut_config", 178 ] 179 defines = [ 180 "HARMONY_PROJECT", 181 "OPENSSL_SUPPRESS_DEPRECATED", 182 ] 183} 184 185ohos_source_set("hdc_host") { 186 use_exceptions = true 187 sources = hdc_common_sources 188 sources += hdc_host_sources 189 subsystem_name = "developtools" 190 part_name = "hdc" 191 if (hdc_support_uart) { 192 sources += [ "${hdc_path}/src/common/uart.cpp" ] 193 sources += [ "${hdc_path}/src/host/host_uart.cpp" ] 194 } 195 external_deps = common_external_deps 196 external_deps += [ "libusb:libusb" ] 197 public_configs = [ 198 ":hdc_common_config", 199 ":hdc_host_common_config", 200 ":hdc_ut_config", 201 ] 202 defines = [ 203 "HARMONY_PROJECT", 204 "OPENSSL_SUPPRESS_DEPRECATED", 205 ] 206} 207 208ohos_source_set("hdc_daemon_platform") { 209 testonly = true 210 public_configs = [ ":hdc_ut_config" ] 211 212 #defines = [ "HARMONY_PROJECT" ] 213 defines = [] 214 if (hdc_test_coverage && is_ohos) { 215 defines += [ "TEST_COVERAGE" ] 216 } 217 218 if (hdc_unit_test) { 219 defines += [ "HDC_UNIT_TEST" ] 220 } 221 if (js_jdwp_connect) { 222 defines += [ "JS_JDWP_CONNECT" ] 223 } 224 225 sources = [ 226 "${hdc_path}/src/daemon/daemon_unity.cpp", 227 "${hdc_path}/src/daemon/jdwp.cpp", 228 ] 229 230 external_deps = [ 231 "bounds_checking_function:libsec_static", 232 "googletest:gtest", 233 "libuv:uv", 234 "openssl:libcrypto_static", 235 ] 236 237 include_dirs = [ "${hdc_path}/daemon" ] 238} 239 240ohos_unittest("hdc_jdwp_unittest") { 241 module_out_path = module_output_path 242 public_configs = [ ":hdc_ut_config" ] 243 defines = [ "HARMONY_PROJECT" ] 244 if (hdc_test_coverage && is_ohos) { 245 defines += [ "TEST_COVERAGE" ] 246 } 247 if (hdc_unit_test) { 248 defines += [ "HDC_UNIT_TEST" ] 249 } 250 if (js_jdwp_connect) { 251 defines += [ "JS_JDWP_CONNECT" ] 252 } 253 public_deps = [ ":hdc_daemon_platform" ] 254 255 sources = [ 256 "${hdc_path}/src/daemon/system_depend.cpp", 257 "unittest/common/HdcJdwpTest.cpp", 258 ] 259 deps = [ ":hdc_common" ] 260 261 include_dirs = [ 262 "${hdc_path}/test/unittest/common/include", 263 "${hdc_path}/src/daemon", 264 "${hdc_path}/src/common", 265 ] 266 267 external_deps = common_external_deps 268 external_deps += [ 269 "googletest:gmock_main", 270 "init:libbegetutil", 271 "hilog:libhilog", 272 ] 273 274 if (is_linux) { 275 static_link = false 276 } 277 subsystem_name = "developtools" 278 defines += [ "OPENSSL_SUPPRESS_DEPRECATED" ] 279} 280 281ohos_unittest("hdc_uart_unittest") { 282 use_exceptions = true 283 module_out_path = module_output_path 284 resource_config_file = "unittest/resource/ohos_test.xml" 285 public_configs = [ ":hdc_ut_config" ] 286 sources = [ 287 "${hdc_path}/src/common/header.cpp", 288 "${hdc_path}/src/common/entry.cpp", 289 "${hdc_path}/src/common/decompress.cpp", 290 "unittest/common/daemon_uart_test.cpp", 291 "unittest/common/uart_test.cpp", 292 ] 293 294 configs = [ 295 ":hdc_common_config", 296 ":hdc_ut_code_flag", 297 ":hdc_ut_config", 298 ] 299 deps = [ ":hdc_daemon" ] 300 external_deps = common_external_deps 301 external_deps += [ 302 "libusb:libusb", 303 "googletest:gmock_main", 304 ] 305} 306 307ohos_unittest("hdc_host_base_unittest") { 308 use_exceptions = true 309 module_out_path = module_output_path 310 resource_config_file = "unittest/resource/ohos_test.xml" 311 defines = [ "HDC_HOST" ] 312 if (is_ohos) { 313 defines += [ "HOST_OHOS" ] 314 } 315 if (hdc_support_uart) { 316 defines += [ "HDC_SUPPORT_UART" ] 317 } 318 sources = hdc_common_sources 319 sources += [ 320 "${hdc_path}/src/daemon/daemon_app.cpp", 321 "${hdc_path}/src/host/host_app.cpp", 322 "${hdc_path}/src/host/server_for_client.cpp", 323 "${hdc_path}/src/host/server.cpp", 324 "${hdc_path}/src/host/host_tcp.cpp", 325 "${hdc_path}/src/host/host_uart.cpp", 326 "${hdc_path}/src/host/host_usb.cpp", 327 "${hdc_path}/src/host/host_forward.cpp", 328 "${hdc_path}/src/host/host_unity.cpp", 329 "${hdc_path}/src/host/host_updater.cpp", 330 "${hdc_path}/src/host/host_shell_option.cpp", 331 "${hdc_path}/src/host/translate.cpp", 332 "${hdc_path}/src/common/server_cmd_log.cpp", 333 "${hdc_path}/src/common/uart.cpp", 334 "unittest/daemon/daemon_app_test.cpp", 335 "unittest/common/define_test.cpp", 336 "unittest/host/host_app_test.cpp", 337 "unittest/host/main_test.cpp", 338 "unittest/host/host_uds_server_test.cpp", 339 "unittest/host/host_fport_listen_ip_test.cpp", 340 ] 341 342 configs = [ 343 ":hdc_host_common_config", 344 ":hdc_ut_code_flag", 345 ":hdc_ut_config", 346 ] 347 348 external_deps = common_external_deps 349 external_deps += [ 350 "googletest:gmock_main", 351 "init:libbegetutil", 352 "libusb:libusb", 353 ] 354} 355 356ohos_unittest("hdc_host_uart_unittest") { 357 use_exceptions = true 358 module_out_path = module_output_path 359 resource_config_file = "unittest/resource/ohos_test.xml" 360 sources = [ 361 "${hdc_path}/src/common/header.cpp", 362 "${hdc_path}/src/common/entry.cpp", 363 "${hdc_path}/src/common/compress.cpp", 364 "unittest/common/host_uart_test.cpp", 365 "unittest/common/uart_test.cpp", 366 ] 367 368 configs = [ 369 ":hdc_common_config", 370 ":hdc_host_common_config", 371 ":hdc_ut_code_flag", 372 ] 373 374 deps = [ ":hdc_host" ] 375 376 defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] 377 external_deps = common_external_deps 378 external_deps += [ 379 "libusb:libusb", 380 "googletest:gmock_main", 381 ] 382} 383 384ohos_unittest("hdc_ssl_unittest") { 385 use_exceptions = true 386 module_out_path = module_output_path 387 resource_config_file = "unittest/resource/ohos_test.xml" 388 sources = hdc_common_sources 389 sources += [ 390 "${hdc_path}/src/common/hdc_ssl.cpp", 391 "${hdc_path}/src/host/host_ssl.cpp", 392 "${hdc_path}/src/daemon/daemon_ssl.cpp", 393 "unittest/common/hdc_ssl_ut.cpp", 394 ] 395 396 configs = [ 397 ":hdc_common_config", 398 ":hdc_ut_code_flag", 399 ":hdc_ut_config", 400 ] 401 external_deps = common_external_deps 402 external_deps += [ 403 "googletest:gmock_main", 404 "init:libbegetutil", 405 "huks:libhukssdk", 406 "openssl:libcrypto_static", 407 "openssl:libssl_static", 408 ] 409 defines = [ "HDC_SUPPORT_ENCRYPT_TCP" ] 410} 411 412ohos_unittest("hdc_base_unittest") { 413 use_exceptions = true 414 module_out_path = module_output_path 415 resource_config_file = "unittest/resource/ohos_test.xml" 416 sources = hdc_common_sources 417 sources += [ 418 "${hdc_path}/src/common/server_cmd_log.cpp", 419 "${hdc_path}/src/common/uart.cpp", 420 "${hdc_path}/src/common/password.cpp", 421 "${hdc_path}/src/common/hdc_huks.cpp", 422 "unittest/common/base_ut.cpp", 423 "unittest/common/file_ut.cpp", 424 "unittest/common/forward_ut.cpp", 425 "unittest/common/heartbeat_ut.cpp", 426 "unittest/common/hdc_huks_ut.cpp", 427 "unittest/common/password_ut.cpp", 428 "unittest/common/server_cmd_log_ut.cpp", 429 "unittest/common/transfer_ut.cpp", 430 "unittest/common/tlv_ut.cpp", 431 "unittest/common/uv_status_ut.cpp", 432 ] 433 434 configs = [ 435 ":hdc_common_config", 436 ":hdc_ut_code_flag", 437 ":hdc_ut_config", 438 ] 439 external_deps = common_external_deps 440 external_deps += [ 441 "googletest:gmock_main", 442 "init:libbegetutil", 443 "huks:libhukssdk", 444 ] 445 defines = [ "HDC_SUPPORT_ENCRYPT_PRIVATE_KEY" ] 446} 447 448group("HdcJdwpTest") { 449 testonly = true 450 deps = [ ":hdc_jdwp_unittest" ] 451} 452 453group("hdc_unittest") { 454 testonly = true 455 deps = [ 456 ":hdc_base_unittest", 457 ":hdc_host_uart_unittest", 458 ":hdc_jdwp_unittest", 459 ":hdc_register_unittest", 460 ":hdc_ssl_unittest", 461 ":hdc_uart_unittest", 462 ":hdc_host_base_unittest", 463 ":hdc_credential_unittest", 464 ] 465} 466 467config("hdc_test_config") { 468 cflags = code_check_flag 469 ldflags = [] 470 defines = [ "HARMONY_PROJECT" ] 471 472 if (hdc_test_coverage && is_ohos) { 473 defines += [ "TEST_COVERAGE" ] 474 cflags += [ 475 "-fprofile-arcs", 476 "-ftest-coverage", 477 ] 478 ldflags += [ "--coverage" ] 479 } 480 if (js_jdwp_connect) { 481 defines += [ "JS_JDWP_CONNECT" ] 482 } 483 include_dirs = [ 484 "${hdc_path}/test/fuzztest/jdwpreadstream_fuzzer", 485 "${hdc_path}/test/fuzztest/forwardreadstream_fuzzer", 486 "${hdc_path}/src/daemon", 487 "${hdc_path}/src/common", 488 ] 489} 490 491config("hdc_register_config") { 492 cflags = code_check_flag 493 ldflags = [] 494 defines = [ "HDC_HILOG" ] 495 496 if (hdc_test_coverage && is_ohos) { 497 defines += [ "TEST_COVERAGE" ] 498 cflags += [ 499 "-fprofile-arcs", 500 "-ftest-coverage", 501 ] 502 ldflags += [ "--coverage" ] 503 } 504 if (js_jdwp_connect) { 505 defines += [ "JS_JDWP_CONNECT" ] 506 } 507} 508 509fuzz_cflags = [ 510 "-O0", 511 "-Wno-unused-variable", 512 "-fno-omit-frame-pointer", 513] 514 515ohos_fuzztest("JdwpReadStreamFuzzTest") { 516 module_out_path = FUZZ_OUTPUT_PATH 517 fuzz_config_file = "${hdc_path}/test/fuzztest/jdwpreadstream_fuzzer" 518 configs = [ ":hdc_test_config" ] 519 cflags = fuzz_cflags 520 sources = [ 521 "${hdc_path}/src/daemon/jdwp.cpp", 522 "${hdc_path}/src/daemon/system_depend.cpp", 523 "fuzztest/jdwpreadstream_fuzzer/JdwpReadStream_fuzzer.cpp", 524 ] 525 deps = [ ":hdc_common" ] 526 external_deps = common_external_deps 527 external_deps += [ 528 "hilog:libhilog", 529 "init:libbeget_proxy", 530 "init:libbegetutil", 531 ] 532} 533 534ohos_fuzztest("ForwardReadStreamFuzzTest") { 535 module_out_path = FUZZ_OUTPUT_PATH 536 fuzz_config_file = "${hdc_path}/test/fuzztest/forwardreadstream_fuzzer" 537 configs = [ ":hdc_test_config" ] 538 cflags = fuzz_cflags 539 sources = [ "fuzztest/forwardreadstream_fuzzer/ForwardReadStream_fuzzer.cpp" ] 540 deps = [ ":hdc_common" ] 541 subsystem_name = "developtools" 542 part_name = "hdc" 543 external_deps = common_external_deps 544 external_deps += [ "hilog:libhilog" ] 545} 546 547group("hdc_fuzztest") { 548 testonly = true 549 deps = [ 550 ":ForwardReadStreamFuzzTest", 551 ":JdwpReadStreamFuzzTest", 552 ] 553} 554 555ohos_unittest("hdc_register_unittest") { 556 module_out_path = module_output_path 557 resource_config_file = "unittest/resource/ohos_test.xml" 558 subsystem_name = "developtools" 559 part_name = "hdc" 560 sources = [ 561 "${hdc_path}/src/register/hdc_connect.cpp", 562 "${hdc_path}/src/register/hdc_jdwp.cpp", 563 "unittest/register/register_test.cpp", 564 ] 565 566 include_dirs = [ "${hdc_path}/src/register/" ] 567 568 configs = [ ":hdc_register_config" ] 569 external_deps = common_external_deps 570 external_deps += [ 571 "c_utils:utils", 572 "googletest:gmock_main", 573 "hilog:libhilog", 574 "init:libbeget_proxy", 575 "init:libbegetutil", 576 ] 577} 578 579ohos_unittest("hdc_credential_unittest") { 580 use_exceptions = true 581 module_out_path = module_output_path 582 resource_config_file = "unittest/resource/ohos_test.xml" 583 subsystem_name = "developtools" 584 part_name = "hdc" 585 sources = [ 586 "${hdc_path}/src/common/base.cpp", 587 "${hdc_path}/credential/credential_base.cpp", 588 "unittest/credential/credential_base_test.cpp", 589 ] 590 include_dirs = [ 591 "${hdc_path}/credential", 592 "${hdc_path}/test/unittest/credential/include", 593 ] 594 595 configs = [ 596 ":hdc_common_config", 597 ":hdc_ut_code_flag", 598 ":hdc_ut_config", 599 ] 600 601 external_deps = [ 602 "openssl:libcrypto_shared", 603 "bounds_checking_function:libsec_shared", 604 "libuv:uv", 605 ] 606}