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