• 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/elf_parser_test.cpp",
30  "unittest/common/native/register_test.cpp",
31  "unittest/common/native/option_test.cpp",
32  "unittest/common/native/perf_file_reader_test.cpp",
33  "unittest/common/native/virtual_thread_test.cpp",
34  "unittest/common/native/virtual_runtime_test.cpp",
35  "unittest/common/native/callstack_test.cpp",
36  "unittest/common/native/ring_buffer_test.cpp",
37  "unittest/common/native/symbols_file_test.cpp",
38  "unittest/common/native/tracked_command_test.cpp",
39  "unittest/common/native/dwarf_test.cpp",
40  "unittest/common/native/subcommand_help_test.cpp",
41  "unittest/common/native/subcommand_list_test.cpp",
42  "unittest/common/native/subcommand_dump_test.cpp",
43  "unittest/common/native/hashlist_test.cpp",
44  "unittest/common/native/report_test.cpp",
45  "unittest/common/native/report_json_file_test.cpp",
46]
47
48if (hiperf_debug) {
49  sources_base += [ "unittest/common/native/debug_logger_test.cpp" ]
50  sources_base += [ "unittest/common/native/option_debug_test.cpp" ]
51}
52
53if (!hiperf_target_static) {
54  sources_base += [ "unittest/common/native/report_protobuf_file_test.cpp" ]
55}
56
57sources_interface = [
58  "unittest/common/native/subcommand_record_test.cpp",
59  "unittest/common/native/subcommand_stat_test.cpp",
60  "unittest/common/native/subcommand_report_test.cpp",
61  "unittest/common/native/hiperf_libreport_test.cpp",
62]
63
64common_deps = [
65  "${hiperf_path}/:hiperf_platform_common",
66  "${hiperf_path}/:hiperf_platform_host",
67  "${hiperf_path}/:hiperf_platform_linux",
68  "${hiperf_path}/interfaces/innerkits/native:hiperf_client_static",
69  "//third_party/googletest:gmock_main",
70  "//third_party/googletest:gtest_main",
71]
72
73config("hiperf_test_config") {
74  cflags = code_check_flag
75  ldflags = []
76  defines = []
77
78  if (hiperf_test_coverage && is_ohos) {
79    defines += [ "TEST_COVERAGE" ]
80    cflags += [
81      "-fprofile-arcs",
82      "-ftest-coverage",
83    ]
84    ldflags += [ "--coverage" ]
85  }
86
87  defines += [ "DEFAULT_LOG_LEVEL=LEVEL_INFO" ]
88
89  include_dirs = [ "${hiperf_path}/test/unittest/common/native/include" ]
90}
91
92ohos_unittest("hiperf_unittest") {
93  configs = [ ":hiperf_test_config" ]
94  module_out_path = module_output_path
95  resource_config_file = "unittest/resource/ohos_test.xml"
96  deps = common_deps
97  external_deps = [ "hilog:libhilog" ]
98  cflags = [
99    "-Dprivate=public",  #allow test code access private members
100  ]
101
102  sources = sources_interface
103  sources += sources_base
104  if (is_linux) {
105    static_link = false
106  }
107}
108
109fuzz_cflags = [
110  "-O0",
111  "-fno-omit-frame-pointer",
112]
113
114fuzz_deps = [
115  "${hiperf_path}/:hiperf_platform_common",
116  "${hiperf_path}/:hiperf_platform_host",
117  "${hiperf_path}/:hiperf_platform_linux",
118  "${hiperf_path}/interfaces/innerkits/native:hiperf_client_static",
119]
120
121ohos_fuzztest("CommandLineFuzzTest") {
122  module_out_path = module_output_path
123  fuzz_config_file = "${hiperf_path}/test/fuzztest/commandline_fuzzer"
124  configs = [ ":hiperf_test_config" ]
125  cflags = fuzz_cflags
126  deps = fuzz_deps
127  external_deps = [ "hilog:libhilog" ]
128  defines = [ "FUZZER_TEST" ]
129  sources = [
130    "${hiperf_path}/src/main.cpp",
131    "fuzztest/commandline_fuzzer/CommandLine_fuzzer.cpp",
132  ]
133}
134
135ohos_fuzztest("LibReportFuzzTest") {
136  module_out_path = module_output_path
137  fuzz_config_file = "${hiperf_path}/test/fuzztest/libreport_fuzzer"
138  configs = [ ":hiperf_test_config" ]
139  cflags = fuzz_cflags
140  deps = fuzz_deps
141  external_deps = [ "hilog:libhilog" ]
142  defines = [ "FUZZER_TEST" ]
143  sources = [ "fuzztest/libreport_fuzzer/LibReport_fuzzer.cpp" ]
144}
145
146ohos_fuzztest("ClientApiFuzzTest") {
147  module_out_path = module_output_path
148  fuzz_config_file = "${hiperf_path}/test/fuzztest/clientapi_fuzzer"
149  configs = [ ":hiperf_test_config" ]
150  cflags = fuzz_cflags
151  deps = fuzz_deps
152  external_deps = [ "hilog:libhilog" ]
153  defines = [ "FUZZER_TEST" ]
154  sources = [ "fuzztest/clientapi_fuzzer/ClientApi_fuzzer.cpp" ]
155}
156
157ohos_fuzztest("PerfFileFuzzTest") {
158  module_out_path = module_output_path
159  fuzz_config_file = "${hiperf_path}/test/fuzztest/perffile_fuzzer"
160  resource_config_file = "fuzztest/resource/ohos_test.xml"
161  configs = [ ":hiperf_test_config" ]
162  cflags = fuzz_cflags
163  deps = fuzz_deps
164  external_deps = [ "hilog:libhilog" ]
165  defines = [ "FUZZER_TEST" ]
166  sources = [ "fuzztest/perffile_fuzzer/PerfFile_fuzzer.cpp" ]
167}
168
169ohos_fuzztest("ElfParserFuzzTest") {
170  module_out_path = module_output_path
171  fuzz_config_file = "${hiperf_path}/test/fuzztest/elfparser_fuzzer"
172  resource_config_file = "fuzztest/resource/ohos_test.xml"
173  configs = [ ":hiperf_test_config" ]
174  cflags = fuzz_cflags
175  deps = fuzz_deps
176  external_deps = [ "hilog:libhilog" ]
177  defines = [ "FUZZER_TEST" ]
178  sources = [ "fuzztest/elfparser_fuzzer/ElfParser_fuzzer.cpp" ]
179}
180
181group("hiperf_fuzztest") {
182  testonly = true
183  deps = [
184    ":ClientApiFuzzTest",
185    ":CommandLineFuzzTest",
186    ":ElfParserFuzzTest",
187    ":LibReportFuzzTest",
188    ":PerfFileFuzzTest",
189  ]
190}
191
192group("hiperf_test") {
193  testonly = true
194  if (hiperf_target_host) {
195    deps = [
196      ":hiperf_fuzztest(${host_toolchain})",
197      ":hiperf_unittest(${host_toolchain})",
198    ]
199  } else {
200    deps = [ ":hiperf_unittest" ]
201  }
202  if (hiperf_test_fuzz) {
203    deps += [ ":hiperf_fuzztest" ]
204  }
205}
206