• 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/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_deps = [
65  "//third_party/bounds_checking_function:libsec_static",
66  "//third_party/libuv:uv",
67  "//third_party/lz4:liblz4_static",
68  "//third_party/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    "//third_party/libuv",  # used in common.h
106    "//third_party/lz4/lib",  # used in transfer.cpp
107    "//base/startup/init/interfaces/innerkits/include",  #daemon_unity.cpp
108    "../../../base/startup/init/interfaces/innerkits/include/syspara",  #async_cmd.cpp
109  ]
110
111  if (hdc_support_uart) {
112    defines += [ "HDC_SUPPORT_UART" ]
113  }
114
115  defines += [ "HDC_UT" ]
116}
117
118config("hdc_host_common_config") {
119  defines = [ "HDC_HOST" ]
120
121  # both linux and ohos is same linux syscall
122  defines += [ "HOST_LINUX" ]
123  defines += [ "HARMONY_PROJECT" ]
124}
125
126ohos_source_set("hdc_common") {
127  use_exceptions = true
128  testonly = true
129  sources = hdc_common_sources
130  if (hdc_support_uart) {
131    sources += [ "${hdc_path}/src/common/uart.cpp" ]
132  }
133  public_deps = common_deps
134  public_configs = [
135    ":hdc_common_config",
136    ":hdc_ut_config",
137  ]
138  defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
139}
140
141ohos_source_set("hdc_daemon") {
142  use_exceptions = true
143  sources = hdc_common_sources
144  sources += hdc_daemon_sources
145  if (hdc_support_uart) {
146    include_dirs = [ "//commonlibrary/c_utils/base/include" ]
147    sources += [ "${hdc_path}/src/common/uart.cpp" ]
148    sources += [ "${hdc_path}/src/daemon/daemon_uart.cpp" ]
149  }
150  public_deps = common_deps
151  public_configs = [
152    ":hdc_common_config",
153    ":hdc_ut_config",
154  ]
155  defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
156}
157
158ohos_source_set("hdc_host") {
159  use_exceptions = true
160  sources = hdc_common_sources
161  sources += hdc_host_sources
162  if (hdc_support_uart) {
163    sources += [ "${hdc_path}/src/common/uart.cpp" ]
164    sources += [ "${hdc_path}/src/host/host_uart.cpp" ]
165  }
166  public_deps = common_deps
167  public_deps += [ "//third_party/libusb:libusb" ]
168  public_configs = [
169    ":hdc_common_config",
170    ":hdc_host_common_config",
171    ":hdc_ut_config",
172  ]
173  defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
174}
175
176ohos_source_set("hdc_daemon_platform") {
177  public_configs = [ ":hdc_ut_config" ]
178  public_configs += [ "//third_party/googletest:gtest_config" ]
179
180  #defines = [ "HARMONY_PROJECT" ]
181  defines = []
182  if (hdc_test_coverage && is_ohos) {
183    defines += [ "TEST_COVERAGE" ]
184  }
185
186  if (hdc_unit_test) {
187    defines += [ "HDC_UNIT_TEST" ]
188  }
189  if (js_jdwp_connect) {
190    defines += [ "JS_JDWP_CONNECT" ]
191  }
192
193  sources = [
194    "${hdc_path}/src/daemon/daemon_unity.cpp",
195    "${hdc_path}/src/daemon/jdwp.cpp",
196  ]
197
198  public_deps = [
199    "//third_party/bounds_checking_function:libsec_static",
200    "//third_party/libuv:uv",
201    "//third_party/openssl:libcrypto_static",
202  ]
203
204  external_deps = [ "init:libbegetutil" ]
205
206  include_dirs = [
207    "${hdc_path}/daemon",
208    "//third_party/bounds_checking_function/include",
209    "//third_party/openssl/include",
210    "//third_party/libuv",
211  ]
212}
213
214ohos_unittest("hdc_jdwp_unittest") {
215  module_out_path = module_output_path
216  public_configs = [ ":hdc_ut_config" ]
217  defines = [ "HARMONY_PROJECT" ]
218  if (hdc_test_coverage && is_ohos) {
219    defines += [ "TEST_COVERAGE" ]
220  }
221  if (hdc_unit_test) {
222    defines += [ "HDC_UNIT_TEST" ]
223  }
224  if (js_jdwp_connect) {
225    defines += [ "JS_JDWP_CONNECT" ]
226  }
227  public_deps = [ ":hdc_daemon_platform" ]
228
229  deps = [ "//third_party/googletest:gmock_main" ]
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    "//third_party/bounds_checking_function/include",
239    "//third_party/libuv",
240  ]
241
242  if (is_linux) {
243    static_link = false
244  }
245  subsystem_name = "developtools"
246  defines += [ "OPENSSL_SUPPRESS_DEPRECATED" ]
247}
248
249ohos_unittest("hdc_uart_unittest") {
250  use_exceptions = true
251  module_out_path = module_output_path
252  resource_config_file = "unittest/resource/ohos_test.xml"
253  sources = [
254    "unittest/common/daemon_uart_test.cpp",
255    "unittest/common/uart_test.cpp",
256  ]
257
258  configs = [ ":hdc_common_config" ]
259  configs += [ ":hdc_ut_code_flag" ]
260  deps = [ ":hdc_daemon" ]
261
262  deps += [ "//third_party/googletest:gmock_main" ]
263  defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
264}
265
266ohos_unittest("hdc_host_uart_unittest") {
267  use_exceptions = true
268  module_out_path = module_output_path
269  resource_config_file = "unittest/resource/ohos_test.xml"
270  sources = [
271    "unittest/common/host_uart_test.cpp",
272    "unittest/common/uart_test.cpp",
273  ]
274
275  configs = [
276    ":hdc_common_config",
277    ":hdc_host_common_config",
278    ":hdc_ut_code_flag",
279  ]
280
281  deps = [ ":hdc_host" ]
282
283  deps += [ "//third_party/googletest:gmock_main" ]
284  defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
285}
286
287group("HdcJdwpTest") {
288  testonly = true
289  deps = [ ":hdc_jdwp_unittest" ]
290}
291
292group("hdc_unittest") {
293  testonly = true
294  deps = [
295    ":hdc_host_uart_unittest",
296    ":hdc_host_uart_unittest(${host_toolchain})",
297    ":hdc_jdwp_unittest",
298    ":hdc_register_unittest",
299    ":hdc_uart_unittest",
300    ":hdc_uart_unittest(${host_toolchain})",
301  ]
302}
303
304config("hdc_test_config") {
305  cflags = code_check_flag
306  ldflags = []
307  defines = []
308
309  if (hdc_test_coverage && is_ohos) {
310    defines += [ "TEST_COVERAGE" ]
311    cflags += [
312      "-fprofile-arcs",
313      "-ftest-coverage",
314    ]
315    ldflags += [ "--coverage" ]
316  }
317  if (js_jdwp_connect) {
318    defines += [ "JS_JDWP_CONNECT" ]
319  }
320  include_dirs = [
321    "${hdc_path}/test/fuzztest/jdwpreadstream_fuzzer",
322    "${hdc_path}/src/daemon",
323    "${hdc_path}/src/common",
324    "//third_party/bounds_checking_function/include",
325    "//third_party/libuv/include",
326  ]
327}
328
329config("hdc_register_config") {
330  cflags = code_check_flag
331  ldflags = []
332  defines = [ "HDC_HILOG" ]
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}
346
347fuzz_cflags = [
348  "-O0",
349  "-Wno-unused-variable",
350  "-fno-omit-frame-pointer",
351]
352
353ohos_fuzztest("JdwpReadStreamFuzzTest") {
354  module_out_path = FUZZ_OUTPUT_PATH
355  fuzz_config_file = "${hdc_path}/test/fuzztest/jdwpreadstream_fuzzer"
356  configs = [ ":hdc_test_config" ]
357  cflags = fuzz_cflags
358  deps = [ "//third_party/libuv:uv" ]
359  sources = [
360    "${hdc_path}/src/daemon/jdwp.cpp",
361    "fuzztest/jdwpreadstream_fuzzer/JdwpReadStream_fuzzer.cpp",
362  ]
363  deps += [ ":hdc_common" ]
364}
365
366group("hdc_fuzztest") {
367  testonly = true
368  deps = [ ":JdwpReadStreamFuzzTest" ]
369}
370
371ohos_unittest("hdc_register_unittest") {
372  module_out_path = module_output_path
373  resource_config_file = "unittest/resource/ohos_test.xml"
374
375  sources = [
376    "${hdc_path}/src/register/hdc_connect.cpp",
377    "${hdc_path}/src/register/hdc_jdwp.cpp",
378    "unittest/register/register_test.cpp",
379  ]
380
381  include_dirs = [ "${hdc_path}/src/register/" ]
382
383  configs = [ ":hdc_register_config" ]
384
385  deps = [
386    "//third_party/googletest:gmock_main",
387    "//third_party/libuv:uv",
388  ]
389  external_deps = [
390    "c_utils:utils",
391    "hilog:libhilog",
392  ]
393
394  subsystem_name = "developtools"
395  part_name = "hdc"
396}
397