• 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  ]
109
110  if (hdc_support_uart) {
111    defines += [ "HDC_SUPPORT_UART" ]
112  }
113
114  defines += [ "HDC_UT" ]
115}
116
117config("hdc_host_common_config") {
118  defines = [ "HDC_HOST" ]
119
120  # both linux and ohos is same linux syscall
121  defines += [ "HOST_LINUX" ]
122  defines += [ "HARMONY_PROJECT" ]
123}
124
125ohos_source_set("hdc_common") {
126  use_exceptions = true
127  sources = hdc_common_sources
128  if (hdc_support_uart) {
129    sources += [ "${hdc_path}/src/common/uart.cpp" ]
130  }
131  public_deps = common_deps
132  public_configs = [
133    ":hdc_common_config",
134    ":hdc_ut_config",
135  ]
136  defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
137}
138
139ohos_source_set("hdc_daemon") {
140  use_exceptions = true
141  sources = hdc_common_sources
142  sources += hdc_daemon_sources
143  if (hdc_support_uart) {
144    include_dirs = [ "//commonlibrary/c_utils/base/include" ]
145    sources += [ "${hdc_path}/src/common/uart.cpp" ]
146    sources += [ "${hdc_path}/src/daemon/daemon_uart.cpp" ]
147  }
148  public_deps = common_deps
149  public_configs = [
150    ":hdc_common_config",
151    ":hdc_ut_config",
152  ]
153  defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
154}
155
156ohos_source_set("hdc_host") {
157  use_exceptions = true
158  sources = hdc_common_sources
159  sources += hdc_host_sources
160  if (hdc_support_uart) {
161    sources += [ "${hdc_path}/src/common/uart.cpp" ]
162    sources += [ "${hdc_path}/src/host/host_uart.cpp" ]
163  }
164  public_deps = common_deps
165  public_deps += [ "//third_party/libusb:libusb" ]
166  public_configs = [
167    ":hdc_common_config",
168    ":hdc_host_common_config",
169    ":hdc_ut_config",
170  ]
171  defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
172}
173
174ohos_source_set("hdc_daemon_platform") {
175  public_configs = [ ":hdc_ut_config" ]
176  public_configs += [ "//third_party/googletest:gtest_config" ]
177
178  #defines = [ "HARMONY_PROJECT" ]
179  defines = []
180  if (hdc_test_coverage && is_ohos) {
181    defines += [ "TEST_COVERAGE" ]
182  }
183
184  if (hdc_unit_test) {
185    defines += [ "HDC_UNIT_TEST" ]
186  }
187  if (js_jdwp_connect) {
188    defines += [ "JS_JDWP_CONNECT" ]
189  }
190
191  sources = [
192    "${hdc_path}/src/daemon/daemon_unity.cpp",
193    "${hdc_path}/src/daemon/jdwp.cpp",
194  ]
195
196  public_deps = [
197    "//third_party/bounds_checking_function:libsec_static",
198    "//third_party/libuv:uv",
199    "//third_party/openssl:libcrypto_static",
200  ]
201
202  external_deps = [ "init:libbegetutil" ]
203
204  include_dirs = [
205    "${hdc_path}/daemon",
206    "//third_party/bounds_checking_function/include",
207    "//third_party/openssl/include",
208    "//third_party/libuv",
209  ]
210}
211
212ohos_unittest("hdc_jdwp_unittest") {
213  module_out_path = module_output_path
214  public_configs = [ ":hdc_ut_config" ]
215  defines = [ "HARMONY_PROJECT" ]
216  if (hdc_test_coverage && is_ohos) {
217    defines += [ "TEST_COVERAGE" ]
218  }
219  if (hdc_unit_test) {
220    defines += [ "HDC_UNIT_TEST" ]
221  }
222  if (js_jdwp_connect) {
223    defines += [ "JS_JDWP_CONNECT" ]
224  }
225  public_deps = [ ":hdc_daemon_platform" ]
226
227  deps = [
228    "//third_party/googletest:gmock_main",
229    "//third_party/googletest:gtest_main",
230  ]
231
232  sources = [ "unittest/common/HdcJdwpTest.cpp" ]
233  deps += [ ":hdc_common" ]
234
235  include_dirs = [
236    "${hdc_path}/test/unittest/common/include",
237    "${hdc_path}/src/daemon",
238    "${hdc_path}/src/common",
239    "//third_party/bounds_checking_function/include",
240    "//third_party/libuv",
241  ]
242
243  if (is_linux) {
244    static_link = false
245  }
246  subsystem_name = "developtools"
247  defines += [ "OPENSSL_SUPPRESS_DEPRECATED" ]
248}
249
250ohos_unittest("hdc_uart_unittest") {
251  use_exceptions = true
252  module_out_path = module_output_path
253  resource_config_file = "unittest/resource/ohos_test.xml"
254  sources = [
255    "unittest/common/daemon_uart_test.cpp",
256    "unittest/common/uart_test.cpp",
257  ]
258
259  configs = [ ":hdc_common_config" ]
260  configs += [ ":hdc_ut_code_flag" ]
261  deps = [ ":hdc_daemon" ]
262
263  deps += [
264    "//third_party/googletest:gmock_main",
265    "//third_party/googletest:gtest_main",
266  ]
267  defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
268}
269
270ohos_unittest("hdc_host_uart_unittest") {
271  use_exceptions = true
272  module_out_path = module_output_path
273  resource_config_file = "unittest/resource/ohos_test.xml"
274  sources = [
275    "unittest/common/host_uart_test.cpp",
276    "unittest/common/uart_test.cpp",
277  ]
278
279  configs = [
280    ":hdc_common_config",
281    ":hdc_host_common_config",
282    ":hdc_ut_code_flag",
283  ]
284
285  deps = [ ":hdc_host" ]
286
287  deps += [
288    "//third_party/googletest:gmock_main",
289    "//third_party/googletest:gtest_main",
290  ]
291  defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
292}
293
294group("HdcJdwpTest") {
295  testonly = true
296  deps = [ ":hdc_jdwp_unittest" ]
297}
298
299group("hdc_unittest") {
300  testonly = true
301  deps = [
302    ":hdc_host_uart_unittest",
303    ":hdc_host_uart_unittest(${host_toolchain})",
304    ":hdc_jdwp_unittest",
305    ":hdc_uart_unittest",
306    ":hdc_uart_unittest(${host_toolchain})",
307  ]
308}
309
310config("hdc_test_config") {
311  cflags = code_check_flag
312  ldflags = []
313  defines = []
314
315  if (hdc_test_coverage && is_ohos) {
316    defines += [ "TEST_COVERAGE" ]
317    cflags += [
318      "-fprofile-arcs",
319      "-ftest-coverage",
320    ]
321    ldflags += [ "--coverage" ]
322  }
323  if (js_jdwp_connect) {
324    defines += [ "JS_JDWP_CONNECT" ]
325  }
326  include_dirs = [
327    "${hdc_path}/test/fuzztest/jdwpreadstream_fuzzer",
328    "${hdc_path}/src/daemon",
329    "${hdc_path}/src/common",
330    "//third_party/bounds_checking_function/include",
331    "//third_party/libuv/include",
332  ]
333}
334
335fuzz_cflags = [
336  "-O0",
337  "-Wno-unused-variable",
338  "-fno-omit-frame-pointer",
339]
340
341ohos_fuzztest("JdwpReadStreamFuzzTest") {
342  module_out_path = module_output_path
343  fuzz_config_file = "${hdc_path}/test/fuzztest/jdwpreadstream_fuzzer"
344  configs = [ ":hdc_test_config" ]
345  cflags = fuzz_cflags
346  deps = [ "//third_party/libuv:uv" ]
347  sources = [
348    "${hdc_path}/src/daemon/jdwp.cpp",
349    "fuzztest/jdwpreadstream_fuzzer/JdwpReadStream_fuzzer.cpp",
350  ]
351  deps += [ ":hdc_common" ]
352}
353
354group("hdc_fuzztest") {
355  testonly = true
356  deps = [ ":JdwpReadStreamFuzzTest" ]
357}
358