• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2021-2022 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.
13
14import("//build/test.gni")
15import("../hiperf.gni")
16
17module_output_path = "hiperf/hiperf"
18
19sources_base = [
20  "unittest/common/native/hiperf_client_test.cpp",
21  "unittest/common/native/command_test.cpp",
22  "unittest/common/native/cpu_usage_test.cpp",
23  "unittest/common/native/perf_events_test.cpp",
24  "unittest/common/native/perf_event_record_test.cpp",
25  "unittest/common/native/perf_file_format_test.cpp",
26  "unittest/common/native/perf_file_writer_test.cpp",
27  "unittest/common/native/subcommand_test.cpp",
28  "unittest/common/native/utilities_test.cpp",
29  "unittest/common/native/register_test.cpp",
30  "unittest/common/native/option_test.cpp",
31  "unittest/common/native/perf_file_reader_test.cpp",
32  "unittest/common/native/virtual_thread_test.cpp",
33  "unittest/common/native/virtual_runtime_test.cpp",
34  "unittest/common/native/callstack_test.cpp",
35  "unittest/common/native/ring_buffer_test.cpp",
36  "unittest/common/native/symbols_file_test.cpp",
37  "unittest/common/native/tracked_command_test.cpp",
38  "unittest/common/native/dwarf_test.cpp",
39  "unittest/common/native/subcommand_help_test.cpp",
40  "unittest/common/native/subcommand_list_test.cpp",
41  "unittest/common/native/subcommand_dump_test.cpp",
42  "unittest/common/native/hashlist_test.cpp",
43  "unittest/common/native/report_test.cpp",
44  "unittest/common/native/report_json_file_test.cpp",
45  "unittest/common/native/unique_stack_table_test.cpp",
46  "unittest/common/native/spe_decoder_test.cpp",
47  "unittest/common/native/test_utilities.cpp",
48]
49
50if (hiperf_debug) {
51  sources_base += [ "unittest/common/native/debug_logger_test.cpp" ]
52  sources_base += [ "unittest/common/native/option_debug_test.cpp" ]
53}
54
55if (!hiperf_target_static) {
56  sources_base += [ "unittest/common/native/report_protobuf_file_test.cpp" ]
57}
58
59sources_interface = [
60  "unittest/common/native/subcommand_record_test.cpp",
61  "unittest/common/native/subcommand_stat_test.cpp",
62  "unittest/common/native/subcommand_report_test.cpp",
63  "unittest/common/native/test_hiperf_event_listener.cpp",
64]
65
66common_deps = [
67  "${hiperf_path}/:hiperf_platform_common",
68  "${hiperf_path}/:hiperf_platform_linux",
69  "${hiperf_path}/interfaces/innerkits/native:hiperf_client_static",
70]
71
72if (!ohos_indep_compiler_enable) {
73  common_deps += [ "${hiperf_path}/:hiperf_platform_host" ]
74  sources_interface += [ "unittest/common/native/hiperf_libreport_test.cpp" ]
75}
76
77config("hiperf_test_config") {
78  cflags = code_check_flag
79  ldflags = []
80  defines = []
81
82  if (hiperf_test_coverage && is_ohos) {
83    defines += [ "TEST_COVERAGE" ]
84    cflags += [
85      "-fprofile-arcs",
86      "-ftest-coverage",
87    ]
88    ldflags += [ "--coverage" ]
89  }
90
91  defines += [ "DEFAULT_LOG_LEVEL=LEVEL_INFO" ]
92
93  include_dirs = [ "${hiperf_path}/test/unittest/common/native/include" ]
94}
95
96ohos_unittest("hiperf_unittest") {
97  configs = [ ":hiperf_test_config" ]
98  module_out_path = module_output_path
99  resource_config_file = "unittest/resource/ohos_test.xml"
100  deps = [ "${hiperf_path}/interfaces/innerkits/native:hiperf_client_static" ]
101  use_exceptions = true
102
103  public_configs = [ "${hiperf_path}/:hiperf_inner_config" ]
104
105  defines = [
106    "SUPPORT_PERF_EVENT",
107    "HIPERF_UNITTEST",
108  ]
109
110  public_deps = []
111  external_deps = [
112    "bounds_checking_function:libsec_shared",
113    "c_utils:utils",
114    "faultloggerd:libunwinder",
115    "googletest:gmock",
116    "hilog:libhilog",
117    "hisysevent:libhisysevent",
118    "hisysevent:libhisyseventmanager",
119    "ipc:ipc_single",
120    "protobuf:protobuf_lite",
121    "zlib:libz",
122  ]
123
124  cflags = [
125    "-Dprivate=public",  #allow test code access private members
126    "-Dprotected=public",  #allow test code access protected members
127  ]
128
129  sources = sources_interface
130  sources += sources_base
131
132  sources += [
133    "./../src/command.cpp",
134    "./../src/command_reporter.cpp",
135    "./../src/dwarf_encoding.cpp",
136    "./../src/hiperf_libreport.cpp",
137    "./../src/ipc_utilities.cpp",
138    "./../src/option.cpp",
139    "./../src/perf_event_record.cpp",
140    "./../src/perf_events.cpp",
141    "./../src/perf_file_format.cpp",
142    "./../src/perf_file_reader.cpp",
143    "./../src/perf_file_writer.cpp",
144    "./../src/register.cpp",
145    "./../src/report.cpp",
146    "./../src/report_json_file.cpp",
147    "./../src/ring_buffer.cpp",
148    "./../src/spe_decoder.cpp",
149    "./../src/subcommand.cpp",
150    "./../src/subcommand_dump.cpp",
151    "./../src/subcommand_help.cpp",
152    "./../src/subcommand_list.cpp",
153    "./../src/subcommand_record.cpp",
154    "./../src/subcommand_report.cpp",
155    "./../src/subcommand_stat.cpp",
156    "./../src/symbols_file.cpp",
157    "./../src/tracked_command.cpp",
158    "./../src/unique_stack_table.cpp",
159    "./../src/utilities.cpp",
160    "./../src/virtual_runtime.cpp",
161    "./../src/virtual_thread.cpp",
162  ]
163
164  if (is_ohos) {
165    sources += [ "./../src/callstack.cpp" ]
166    external_deps += [
167      "init:libbegetutil",
168      "ipc:ipc_core",
169      "samgr:samgr_proxy",
170    ]
171  }
172
173  if (is_linux) {
174    static_link = false
175  }
176
177  if (hiperf_use_libunwinder) {
178    defines += [ "HAVE_LIBUNWINDER=1" ]
179  }
180
181  if (!hiperf_target_static) {
182    public_configs += [ "${hiperf_path}/:protobuf_config" ]
183    public_deps += [ "${hiperf_path}/:proto_file_cpp" ]
184    sources += [ "./../src/report_protobuf_file.cpp" ]
185  }
186
187  if (hiperf_debug) {
188    sources += [
189      "./../src/debug_logger.cpp",
190      "./../src/option_debug.cpp",
191    ]
192  }
193
194  if (is_ohos && hiperf_use_syspara) {
195    public_configs += [ "${hiperf_path}/:hiperf_syspara_config" ]
196  }
197}
198
199fuzz_cflags = [
200  "-O0",
201  "-fno-omit-frame-pointer",
202]
203
204ohos_fuzztest("CommandLineFuzzTest") {
205  module_out_path = hiperf_fuzz_test_output_path
206  fuzz_config_file = "${hiperf_path}/test/fuzztest/commandline_fuzzer"
207  configs = [ ":hiperf_test_config" ]
208  cflags = fuzz_cflags
209  deps = common_deps
210  external_deps = [
211    "bounds_checking_function:libsec_shared",
212    "c_utils:utils",
213    "faultloggerd:libunwinder",
214    "hilog:libhilog",
215    "ipc:ipc_single",
216    "protobuf:protobuf_lite",
217  ]
218  defines = [ "FUZZER_TEST" ]
219  sources = [
220    "${hiperf_path}/src/main.cpp",
221    "fuzztest/commandline_fuzzer/CommandLine_fuzzer.cpp",
222  ]
223}
224
225ohos_fuzztest("LibReportFuzzTest") {
226  module_out_path = hiperf_fuzz_test_output_path
227  fuzz_config_file = "${hiperf_path}/test/fuzztest/libreport_fuzzer"
228  configs = [ ":hiperf_test_config" ]
229  cflags = fuzz_cflags
230  deps = common_deps
231  external_deps = [
232    "bounds_checking_function:libsec_shared",
233    "c_utils:utils",
234    "hilog:libhilog",
235    "ipc:ipc_single",
236    "protobuf:protobuf_lite",
237  ]
238  defines = [ "FUZZER_TEST" ]
239  sources = [ "fuzztest/libreport_fuzzer/LibReport_fuzzer.cpp" ]
240}
241
242ohos_fuzztest("ClientApiFuzzTest") {
243  module_out_path = hiperf_fuzz_test_output_path
244  fuzz_config_file = "${hiperf_path}/test/fuzztest/clientapi_fuzzer"
245  configs = [ ":hiperf_test_config" ]
246  cflags = fuzz_cflags
247  deps = common_deps
248  external_deps = [
249    "bounds_checking_function:libsec_shared",
250    "c_utils:utils",
251    "hilog:libhilog",
252    "ipc:ipc_single",
253    "protobuf:protobuf_lite",
254  ]
255  defines = [ "FUZZER_TEST" ]
256  sources = [ "fuzztest/clientapi_fuzzer/ClientApi_fuzzer.cpp" ]
257}
258
259ohos_fuzztest("SpeDecoderFuzzTest") {
260  module_out_path = hiperf_fuzz_test_output_path
261  fuzz_config_file = "${hiperf_path}/test/fuzztest/spedecoder_fuzzer"
262  configs = [ ":hiperf_test_config" ]
263  cflags = fuzz_cflags
264  deps = common_deps
265  external_deps = [
266    "bounds_checking_function:libsec_shared",
267    "c_utils:utils",
268    "hilog:libhilog",
269    "ipc:ipc_single",
270    "protobuf:protobuf_lite",
271  ]
272  defines = [ "FUZZER_TEST" ]
273  sources = [ "fuzztest/spedecoder_fuzzer/SpeDecoder_fuzzer.cpp" ]
274}
275
276ohos_fuzztest("PerfFileFuzzTest") {
277  module_out_path = hiperf_fuzz_test_output_path
278  fuzz_config_file = "${hiperf_path}/test/fuzztest/perffile_fuzzer"
279  resource_config_file = "fuzztest/resource/ohos_test.xml"
280  configs = [ ":hiperf_test_config" ]
281  cflags = fuzz_cflags
282  deps = common_deps
283  external_deps = [
284    "bounds_checking_function:libsec_shared",
285    "c_utils:utils",
286    "faultloggerd:libunwinder",
287    "hilog:libhilog",
288    "ipc:ipc_single",
289    "protobuf:protobuf_lite",
290  ]
291  defines = [ "FUZZER_TEST" ]
292  sources = [ "fuzztest/perffile_fuzzer/PerfFile_fuzzer.cpp" ]
293}
294
295ohos_fuzztest("PerfFileFormatFuzzTest") {
296  module_out_path = hiperf_fuzz_test_output_path
297  fuzz_config_file = "${hiperf_path}/test/fuzztest/perffileformat_fuzzer"
298  configs = [ ":hiperf_test_config" ]
299  cflags = fuzz_cflags
300  deps = common_deps
301  external_deps = [
302    "bounds_checking_function:libsec_shared",
303    "c_utils:utils",
304    "faultloggerd:libunwinder",
305    "hilog:libhilog",
306    "ipc:ipc_single",
307    "protobuf:protobuf_lite",
308  ]
309  defines = [ "FUZZER_TEST" ]
310  sources = [ "fuzztest/perffileformat_fuzzer/PerfFileFormat_fuzzer.cpp" ]
311}
312
313group("hiperf_fuzztest") {
314  testonly = true
315  deps = [
316    ":ClientApiFuzzTest",
317    ":CommandLineFuzzTest",
318    ":PerfFileFormatFuzzTest",
319    ":PerfFileFuzzTest",
320    ":SpeDecoderFuzzTest",
321  ]
322  if (!ohos_indep_compiler_enable) {
323    deps += [ ":LibReportFuzzTest" ]
324  }
325}
326
327group("hiperf_test") {
328  testonly = true
329  if (hiperf_target_host && !ohos_indep_compiler_enable) {
330    deps = [
331      ":hiperf_fuzztest(${host_toolchain})",
332      ":hiperf_unittest(${host_toolchain})",
333    ]
334  } else {
335    deps = [ ":hiperf_unittest" ]
336  }
337  if (hiperf_test_fuzz) {
338    deps += [ ":hiperf_fuzztest" ]
339  }
340}
341