1800b99b8Sopenharmony_ci# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
2800b99b8Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
3800b99b8Sopenharmony_ci# you may not use this file except in compliance with the License.
4800b99b8Sopenharmony_ci# You may obtain a copy of the License at
5800b99b8Sopenharmony_ci#
6800b99b8Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
7800b99b8Sopenharmony_ci#
8800b99b8Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
9800b99b8Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
10800b99b8Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11800b99b8Sopenharmony_ci# See the License for the specific language governing permissions and
12800b99b8Sopenharmony_ci# limitations under the License.
13800b99b8Sopenharmony_ci
14800b99b8Sopenharmony_ciimport("//base/hiviewdfx/faultloggerd/faultloggerd.gni")
15800b99b8Sopenharmony_ciimport("//build/config/features.gni")
16800b99b8Sopenharmony_ciimport("//build/test.gni")
17800b99b8Sopenharmony_cimodule_output_path = "faultloggerd/unwind"
18800b99b8Sopenharmony_ci
19800b99b8Sopenharmony_ciohos_unittest("test_unwind") {
20800b99b8Sopenharmony_ci  module_out_path = module_output_path
21800b99b8Sopenharmony_ci  visibility = [ "*:*" ]
22800b99b8Sopenharmony_ci  include_dirs = [
23800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/common",
24800b99b8Sopenharmony_ci    "$faultloggerd_path/test/unittest/unwind/include",
25800b99b8Sopenharmony_ci    "$faultloggerd_path/test/utils",
26800b99b8Sopenharmony_ci  ]
27800b99b8Sopenharmony_ci  configs = [ "$faultloggerd_common_path/build:coverage_flags" ]
28800b99b8Sopenharmony_ci  defines = [ "DFX_LOG_UNWIND" ]
29800b99b8Sopenharmony_ci  sources = [
30800b99b8Sopenharmony_ci    "accessors_test.cpp",
31800b99b8Sopenharmony_ci    "ark_test.cpp",
32800b99b8Sopenharmony_ci    "elf_imitate.cpp",
33800b99b8Sopenharmony_ci    "elf_test.cpp",
34800b99b8Sopenharmony_ci    "fp_unwinder_test.cpp",
35800b99b8Sopenharmony_ci    "instr_statistic_test.cpp",
36800b99b8Sopenharmony_ci    "maps_test.cpp",
37800b99b8Sopenharmony_ci    "memory_test.cpp",
38800b99b8Sopenharmony_ci    "regs_test.cpp",
39800b99b8Sopenharmony_ci    "signal_test.cpp",
40800b99b8Sopenharmony_ci    "symbols_test.cpp",
41800b99b8Sopenharmony_ci    "unwinder_test.cpp",
42800b99b8Sopenharmony_ci    "xz_util_test.cpp",
43800b99b8Sopenharmony_ci  ]
44800b99b8Sopenharmony_ci  deps = [
45800b99b8Sopenharmony_ci    "$faultloggerd_common_path/dfxlog:dfx_hilog",
46800b99b8Sopenharmony_ci    "$faultloggerd_common_path/dfxutil:dfx_util",
47800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/procinfo:libdfx_procinfo",
48800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder:libunwinder_src",
49800b99b8Sopenharmony_ci    "$faultloggerd_path/test/utils:dfx_test_util",
50800b99b8Sopenharmony_ci  ]
51800b99b8Sopenharmony_ci  resource_config_file = "$faultloggerd_path/test/resource/ohos_test.xml"
52800b99b8Sopenharmony_ci  external_deps = [
53800b99b8Sopenharmony_ci    "bounds_checking_function:libsec_shared",
54800b99b8Sopenharmony_ci    "c_utils:utils",
55800b99b8Sopenharmony_ci    "googletest:gtest_main",
56800b99b8Sopenharmony_ci    "hilog:libhilog",
57800b99b8Sopenharmony_ci  ]
58800b99b8Sopenharmony_ci}
59800b99b8Sopenharmony_ci
60800b99b8Sopenharmony_ciohos_unittest("test_unwind_pac") {
61800b99b8Sopenharmony_ci  module_out_path = module_output_path
62800b99b8Sopenharmony_ci  visibility = [ "*:*" ]
63800b99b8Sopenharmony_ci  include_dirs = [
64800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/common",
65800b99b8Sopenharmony_ci    "$faultloggerd_path/test/unittest/unwind/include",
66800b99b8Sopenharmony_ci  ]
67800b99b8Sopenharmony_ci  configs = [ "$faultloggerd_common_path/build:coverage_flags" ]
68800b99b8Sopenharmony_ci  defines = [ "DFX_LOG_UNWIND" ]
69800b99b8Sopenharmony_ci  sources = [ "unwinder_pac_test.cpp" ]
70800b99b8Sopenharmony_ci  deps = [
71800b99b8Sopenharmony_ci    "$faultloggerd_common_path/dfxlog:dfx_hilog",
72800b99b8Sopenharmony_ci    "$faultloggerd_common_path/dfxutil:dfx_util",
73800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder:libunwinder_src",
74800b99b8Sopenharmony_ci  ]
75800b99b8Sopenharmony_ci  branch_protector_ret = "pac_ret"
76800b99b8Sopenharmony_ci  external_deps = [
77800b99b8Sopenharmony_ci    "bounds_checking_function:libsec_shared",
78800b99b8Sopenharmony_ci    "c_utils:utils",
79800b99b8Sopenharmony_ci    "googletest:gtest_main",
80800b99b8Sopenharmony_ci    "hilog:libhilog",
81800b99b8Sopenharmony_ci  ]
82800b99b8Sopenharmony_ci}
83800b99b8Sopenharmony_ci
84800b99b8Sopenharmony_ciohos_unittest("test_unwind_separate_code") {
85800b99b8Sopenharmony_ci  module_out_path = module_output_path
86800b99b8Sopenharmony_ci  visibility = [ "*:*" ]
87800b99b8Sopenharmony_ci  include_dirs = [
88800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/common",
89800b99b8Sopenharmony_ci    "$faultloggerd_path/test/unittest/unwind/include",
90800b99b8Sopenharmony_ci  ]
91800b99b8Sopenharmony_ci  configs = [ "$faultloggerd_common_path/build:coverage_flags" ]
92800b99b8Sopenharmony_ci  defines = [ "DFX_LOG_UNWIND" ]
93800b99b8Sopenharmony_ci  ldflags = [ "-Wl,-z,separate-code" ]
94800b99b8Sopenharmony_ci  sources = [ "unwinder_pac_test.cpp" ]
95800b99b8Sopenharmony_ci  deps = [
96800b99b8Sopenharmony_ci    "$faultloggerd_common_path/dfxlog:dfx_hilog",
97800b99b8Sopenharmony_ci    "$faultloggerd_common_path/dfxutil:dfx_util",
98800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder:libunwinder_src",
99800b99b8Sopenharmony_ci  ]
100800b99b8Sopenharmony_ci  external_deps = [
101800b99b8Sopenharmony_ci    "bounds_checking_function:libsec_shared",
102800b99b8Sopenharmony_ci    "c_utils:utils",
103800b99b8Sopenharmony_ci    "googletest:gtest_main",
104800b99b8Sopenharmony_ci    "hilog:libhilog",
105800b99b8Sopenharmony_ci  ]
106800b99b8Sopenharmony_ci}
107800b99b8Sopenharmony_ci
108800b99b8Sopenharmony_ciohos_unittest("test_exidx") {
109800b99b8Sopenharmony_ci  module_out_path = module_output_path
110800b99b8Sopenharmony_ci  visibility = [ "*:*" ]
111800b99b8Sopenharmony_ci  include_dirs = [
112800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/common",
113800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/include",
114800b99b8Sopenharmony_ci  ]
115800b99b8Sopenharmony_ci  configs = [ "$faultloggerd_common_path/build:coverage_flags" ]
116800b99b8Sopenharmony_ci  defines = [
117800b99b8Sopenharmony_ci    "DFX_LOG_UNWIND",
118800b99b8Sopenharmony_ci    "DFX_UNWIND_ERROR",
119800b99b8Sopenharmony_ci    "is_ohos=${is_ohos}",
120800b99b8Sopenharmony_ci    "TEST_ARM_EXIDX",
121800b99b8Sopenharmony_ci  ]
122800b99b8Sopenharmony_ci  sources = [
123800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/arch_util.cpp",
124800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/arm_exidx.cpp",
125800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_accessors.cpp",
126800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_ark.cpp",
127800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_config.cpp",
128800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_elf.cpp",
129800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_elf_parser.cpp",
130800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_frame_formatter.cpp",
131800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_instructions.cpp",
132800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_map.cpp",
133800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_maps.cpp",
134800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_memory.cpp",
135800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_mmap.cpp",
136800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_ptrace.cpp",
137800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_regs.cpp",
138800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_regs_arm.cpp",
139800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_symbols.cpp",
140800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_xz_utils.cpp",
141800b99b8Sopenharmony_ci    "arm_exidx_test.cpp",
142800b99b8Sopenharmony_ci  ]
143800b99b8Sopenharmony_ci  deps = [
144800b99b8Sopenharmony_ci    "$faultloggerd_common_path/dfxlog:dfx_hilog",
145800b99b8Sopenharmony_ci    "$faultloggerd_common_path/dfxutil:dfx_util",
146800b99b8Sopenharmony_ci    "$faultloggerd_common_path/trace:dfx_trace_dlsym",
147800b99b8Sopenharmony_ci  ]
148800b99b8Sopenharmony_ci  public_external_deps = [ "lzma:lzma_shared" ]
149800b99b8Sopenharmony_ci  external_deps = [
150800b99b8Sopenharmony_ci    "bounds_checking_function:libsec_shared",
151800b99b8Sopenharmony_ci    "c_utils:utils",
152800b99b8Sopenharmony_ci    "googletest:gtest_main",
153800b99b8Sopenharmony_ci    "hilog:libhilog",
154800b99b8Sopenharmony_ci  ]
155800b99b8Sopenharmony_ci}
156800b99b8Sopenharmony_ci
157800b99b8Sopenharmony_ciohos_unittest("test_dwarf") {
158800b99b8Sopenharmony_ci  module_out_path = module_output_path
159800b99b8Sopenharmony_ci  visibility = [ "*:*" ]
160800b99b8Sopenharmony_ci  defines = [
161800b99b8Sopenharmony_ci    "ALLOW_TO_STDERR",
162800b99b8Sopenharmony_ci    "DFX_LOG_UNWIND",
163800b99b8Sopenharmony_ci    "DFX_LOG_HILOG_BASE",
164800b99b8Sopenharmony_ci  ]
165800b99b8Sopenharmony_ci  include_dirs = [
166800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/common",
167800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/include",
168800b99b8Sopenharmony_ci  ]
169800b99b8Sopenharmony_ci  configs = [ "$faultloggerd_path/common/build:coverage_flags" ]
170800b99b8Sopenharmony_ci  sources = [
171800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dwarf_cfa_instructions.cpp",
172800b99b8Sopenharmony_ci    "dwarf_test.cpp",
173800b99b8Sopenharmony_ci  ]
174800b99b8Sopenharmony_ci  cflags_cc = [ "-Dprivate=public" ]
175800b99b8Sopenharmony_ci
176800b99b8Sopenharmony_ci  deps = [
177800b99b8Sopenharmony_ci    "$faultloggerd_common_path/dfxlog:dfx_hilog_base",
178800b99b8Sopenharmony_ci    "$faultloggerd_common_path/dfxutil:dfx_util",
179800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder:libunwinder_base",
180800b99b8Sopenharmony_ci  ]
181800b99b8Sopenharmony_ci
182800b99b8Sopenharmony_ci  resource_config_file = "$faultloggerd_path/test/resource/ohos_test.xml"
183800b99b8Sopenharmony_ci  external_deps = [
184800b99b8Sopenharmony_ci    "bounds_checking_function:libsec_shared",
185800b99b8Sopenharmony_ci    "c_utils:utils",
186800b99b8Sopenharmony_ci    "googletest:gtest_main",
187800b99b8Sopenharmony_ci    "hilog:libhilog_base",
188800b99b8Sopenharmony_ci  ]
189800b99b8Sopenharmony_ci}
190800b99b8Sopenharmony_ci
191800b99b8Sopenharmony_ciohos_unittest("test_unwind_supporting") {
192800b99b8Sopenharmony_ci  module_out_path = module_output_path
193800b99b8Sopenharmony_ci  visibility = [ "*:*" ]
194800b99b8Sopenharmony_ci  include_dirs = [
195800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/common",
196800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/include",
197800b99b8Sopenharmony_ci  ]
198800b99b8Sopenharmony_ci  defines = [ "is_ohos=${is_ohos}" ]
199800b99b8Sopenharmony_ci  sources = [
200800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/arch_util.cpp",
201800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_ark.cpp",
202800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_hap.cpp",
203800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_maps.cpp",
204800b99b8Sopenharmony_ci    "$faultloggerd_interfaces_path/innerkits/unwinder/dfx_memory.cpp",
205800b99b8Sopenharmony_ci    "arch_util_test.cpp",
206800b99b8Sopenharmony_ci    "dfx_hap_test.cpp",
207800b99b8Sopenharmony_ci  ]
208800b99b8Sopenharmony_ci  deps = [
209800b99b8Sopenharmony_ci    "$faultloggerd_common_path/dfxlog:dfx_hilog",
210800b99b8Sopenharmony_ci    "$faultloggerd_common_path/dfxutil:dfx_util",
211800b99b8Sopenharmony_ci    "$faultloggerd_common_path/trace:dfx_trace_dlsym",
212800b99b8Sopenharmony_ci  ]
213800b99b8Sopenharmony_ci  external_deps = [
214800b99b8Sopenharmony_ci    "c_utils:utils",
215800b99b8Sopenharmony_ci    "hilog:libhilog",
216800b99b8Sopenharmony_ci  ]
217800b99b8Sopenharmony_ci}
218800b99b8Sopenharmony_ci
219800b99b8Sopenharmony_cigroup("unittest") {
220800b99b8Sopenharmony_ci  testonly = true
221800b99b8Sopenharmony_ci  deps = [
222800b99b8Sopenharmony_ci    ":test_unwind",
223800b99b8Sopenharmony_ci    ":test_unwind_pac",
224800b99b8Sopenharmony_ci    ":test_unwind_separate_code",
225800b99b8Sopenharmony_ci    ":test_unwind_supporting",
226800b99b8Sopenharmony_ci  ]
227800b99b8Sopenharmony_ci  if (target_cpu == "arm") {
228800b99b8Sopenharmony_ci    deps += [ ":test_exidx" ]
229800b99b8Sopenharmony_ci  }
230800b99b8Sopenharmony_ci  if (target_cpu == "arm64") {
231800b99b8Sopenharmony_ci    deps += [ ":test_dwarf" ]
232800b99b8Sopenharmony_ci  }
233800b99b8Sopenharmony_ci}
234