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