• 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 = "developtools/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]
48
49if (hiperf_debug) {
50  sources_base += [ "unittest/common/native/debug_logger_test.cpp" ]
51  sources_base += [ "unittest/common/native/option_debug_test.cpp" ]
52}
53
54if (!hiperf_target_static) {
55  sources_base += [ "unittest/common/native/report_protobuf_file_test.cpp" ]
56}
57
58sources_interface = [
59  "unittest/common/native/subcommand_record_test.cpp",
60  "unittest/common/native/subcommand_stat_test.cpp",
61  "unittest/common/native/subcommand_report_test.cpp",
62  "unittest/common/native/hiperf_libreport_test.cpp",
63]
64
65common_deps = [
66  "${hiperf_path}/:hiperf_platform_common",
67  "${hiperf_path}/:hiperf_platform_host",
68  "${hiperf_path}/:hiperf_platform_linux",
69  "${hiperf_path}/interfaces/innerkits/native:hiperf_client_static",
70  "//third_party/googletest:gmock_main",
71  "//third_party/googletest:gtest_main",
72]
73
74config("hiperf_test_config") {
75  cflags = code_check_flag
76  ldflags = []
77  defines = []
78
79  if (hiperf_test_coverage && is_ohos) {
80    defines += [ "TEST_COVERAGE" ]
81    cflags += [
82      "-fprofile-arcs",
83      "-ftest-coverage",
84    ]
85    ldflags += [ "--coverage" ]
86  }
87
88  defines += [ "DEFAULT_LOG_LEVEL=LEVEL_INFO" ]
89
90  include_dirs = [ "${hiperf_path}/test/unittest/common/native/include" ]
91}
92
93ohos_unittest("hiperf_unittest") {
94  configs = [ ":hiperf_test_config" ]
95  module_out_path = module_output_path
96  resource_config_file = "unittest/resource/ohos_test.xml"
97  deps = common_deps
98  external_deps = [
99    "bounds_checking_function:libsec_shared",
100    "faultloggerd:libunwinder_static",
101    "hilog:libhilog",
102  ]
103  cflags = [
104    "-Dprivate=public",  #allow test code access private members
105  ]
106  sources = sources_interface
107  sources += sources_base
108  if (is_linux) {
109    static_link = false
110  }
111}
112
113fuzz_cflags = [
114  "-O0",
115  "-fno-omit-frame-pointer",
116]
117
118fuzz_deps = [
119  "${hiperf_path}/:hiperf_platform_common",
120  "${hiperf_path}/:hiperf_platform_host",
121  "${hiperf_path}/:hiperf_platform_linux",
122  "${hiperf_path}/interfaces/innerkits/native:hiperf_client_static",
123]
124
125ohos_fuzztest("CommandLineFuzzTest") {
126  module_out_path = hiperf_fuzz_test_output_path
127  fuzz_config_file = "${hiperf_path}/test/fuzztest/commandline_fuzzer"
128  configs = [ ":hiperf_test_config" ]
129  cflags = fuzz_cflags
130  deps = fuzz_deps
131  external_deps = [
132    "bounds_checking_function:libsec_shared",
133    "faultloggerd:libunwinder",
134    "hilog:libhilog",
135  ]
136  defines = [ "FUZZER_TEST" ]
137  sources = [
138    "${hiperf_path}/src/main.cpp",
139    "fuzztest/commandline_fuzzer/CommandLine_fuzzer.cpp",
140  ]
141}
142
143ohos_fuzztest("LibReportFuzzTest") {
144  module_out_path = hiperf_fuzz_test_output_path
145  fuzz_config_file = "${hiperf_path}/test/fuzztest/libreport_fuzzer"
146  configs = [ ":hiperf_test_config" ]
147  cflags = fuzz_cflags
148  deps = fuzz_deps
149  external_deps = [
150    "bounds_checking_function:libsec_shared",
151    "hilog:libhilog",
152  ]
153  defines = [ "FUZZER_TEST" ]
154  sources = [ "fuzztest/libreport_fuzzer/LibReport_fuzzer.cpp" ]
155}
156
157ohos_fuzztest("ClientApiFuzzTest") {
158  module_out_path = hiperf_fuzz_test_output_path
159  fuzz_config_file = "${hiperf_path}/test/fuzztest/clientapi_fuzzer"
160  configs = [ ":hiperf_test_config" ]
161  cflags = fuzz_cflags
162  deps = fuzz_deps
163  external_deps = [
164    "bounds_checking_function:libsec_shared",
165    "hilog:libhilog",
166  ]
167  defines = [ "FUZZER_TEST" ]
168  sources = [ "fuzztest/clientapi_fuzzer/ClientApi_fuzzer.cpp" ]
169}
170
171ohos_fuzztest("SpeDecoderFuzzTest") {
172  module_out_path = hiperf_fuzz_test_output_path
173  fuzz_config_file = "${hiperf_path}/test/fuzztest/spedecoder_fuzzer"
174  configs = [ ":hiperf_test_config" ]
175  cflags = fuzz_cflags
176  deps = fuzz_deps
177  external_deps = [
178    "bounds_checking_function:libsec_shared",
179    "hilog:libhilog",
180  ]
181  defines = [ "FUZZER_TEST" ]
182  sources = [ "fuzztest/spedecoder_fuzzer/SpeDecoder_fuzzer.cpp" ]
183}
184
185ohos_fuzztest("PerfFileFuzzTest") {
186  module_out_path = hiperf_fuzz_test_output_path
187  fuzz_config_file = "${hiperf_path}/test/fuzztest/perffile_fuzzer"
188  resource_config_file = "fuzztest/resource/ohos_test.xml"
189  configs = [ ":hiperf_test_config" ]
190  cflags = fuzz_cflags
191  deps = fuzz_deps
192  external_deps = [
193    "bounds_checking_function:libsec_shared",
194    "faultloggerd:libunwinder",
195    "hilog:libhilog",
196  ]
197  defines = [ "FUZZER_TEST" ]
198  sources = [ "fuzztest/perffile_fuzzer/PerfFile_fuzzer.cpp" ]
199}
200
201ohos_fuzztest("PerfFileFormatFuzzTest") {
202  module_out_path = hiperf_fuzz_test_output_path
203  fuzz_config_file = "${hiperf_path}/test/fuzztest/perffileformat_fuzzer"
204  configs = [ ":hiperf_test_config" ]
205  cflags = fuzz_cflags
206  deps = fuzz_deps
207  external_deps = [
208    "bounds_checking_function:libsec_shared",
209    "faultloggerd:libunwinder_static",
210    "hilog:libhilog",
211  ]
212  defines = [ "FUZZER_TEST" ]
213  sources = [ "fuzztest/perffileformat_fuzzer/PerfFileFormat_fuzzer.cpp" ]
214}
215
216group("hiperf_fuzztest") {
217  testonly = true
218  deps = [
219    ":ClientApiFuzzTest",
220    ":CommandLineFuzzTest",
221    ":LibReportFuzzTest",
222    ":PerfFileFormatFuzzTest",
223    ":PerfFileFuzzTest",
224    ":SpeDecoderFuzzTest",
225  ]
226}
227
228group("hiperf_test") {
229  testonly = true
230  if (hiperf_target_host) {
231    deps = [
232      ":hiperf_fuzztest(${host_toolchain})",
233      ":hiperf_unittest(${host_toolchain})",
234    ]
235  } else {
236    deps = [ ":hiperf_unittest" ]
237  }
238  if (hiperf_test_fuzz) {
239    deps += [ ":hiperf_fuzztest" ]
240  }
241}
242