• 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]
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 = [
98    "faultloggerd:libunwinder_static",
99    "hilog:libhilog",
100  ]
101  cflags = [
102    "-Dprivate=public",  #allow test code access private members
103  ]
104
105  sources = sources_interface
106  sources += sources_base
107  if (is_linux) {
108    static_link = false
109  }
110}
111
112fuzz_cflags = [
113  "-O0",
114  "-fno-omit-frame-pointer",
115]
116
117fuzz_deps = [
118  "${hiperf_path}/:hiperf_platform_common",
119  "${hiperf_path}/:hiperf_platform_host",
120  "${hiperf_path}/:hiperf_platform_linux",
121  "${hiperf_path}/interfaces/innerkits/native:hiperf_client_static",
122]
123
124ohos_fuzztest("CommandLineFuzzTest") {
125  module_out_path = hiperf_fuzz_test_output_path
126  fuzz_config_file = "${hiperf_path}/test/fuzztest/commandline_fuzzer"
127  configs = [ ":hiperf_test_config" ]
128  cflags = fuzz_cflags
129  deps = fuzz_deps
130  external_deps = [
131    "faultloggerd:libunwinder",
132    "hilog:libhilog",
133  ]
134  defines = [ "FUZZER_TEST" ]
135  sources = [
136    "${hiperf_path}/src/main.cpp",
137    "fuzztest/commandline_fuzzer/CommandLine_fuzzer.cpp",
138  ]
139}
140
141ohos_fuzztest("LibReportFuzzTest") {
142  module_out_path = hiperf_fuzz_test_output_path
143  fuzz_config_file = "${hiperf_path}/test/fuzztest/libreport_fuzzer"
144  configs = [ ":hiperf_test_config" ]
145  cflags = fuzz_cflags
146  deps = fuzz_deps
147  external_deps = [ "hilog:libhilog" ]
148  defines = [ "FUZZER_TEST" ]
149  sources = [ "fuzztest/libreport_fuzzer/LibReport_fuzzer.cpp" ]
150}
151
152ohos_fuzztest("ClientApiFuzzTest") {
153  module_out_path = hiperf_fuzz_test_output_path
154  fuzz_config_file = "${hiperf_path}/test/fuzztest/clientapi_fuzzer"
155  configs = [ ":hiperf_test_config" ]
156  cflags = fuzz_cflags
157  deps = fuzz_deps
158  external_deps = [ "hilog:libhilog" ]
159  defines = [ "FUZZER_TEST" ]
160  sources = [ "fuzztest/clientapi_fuzzer/ClientApi_fuzzer.cpp" ]
161}
162
163ohos_fuzztest("PerfFileFuzzTest") {
164  module_out_path = hiperf_fuzz_test_output_path
165  fuzz_config_file = "${hiperf_path}/test/fuzztest/perffile_fuzzer"
166  resource_config_file = "fuzztest/resource/ohos_test.xml"
167  configs = [ ":hiperf_test_config" ]
168  cflags = fuzz_cflags
169  deps = fuzz_deps
170  external_deps = [
171    "faultloggerd:libunwinder",
172    "hilog:libhilog",
173  ]
174  defines = [ "FUZZER_TEST" ]
175  sources = [ "fuzztest/perffile_fuzzer/PerfFile_fuzzer.cpp" ]
176}
177
178group("hiperf_fuzztest") {
179  testonly = true
180  deps = [
181    ":ClientApiFuzzTest",
182    ":CommandLineFuzzTest",
183    ":LibReportFuzzTest",
184    ":PerfFileFuzzTest",
185  ]
186}
187
188group("hiperf_test") {
189  testonly = true
190  if (hiperf_target_host) {
191    deps = [
192      ":hiperf_fuzztest(${host_toolchain})",
193      ":hiperf_unittest(${host_toolchain})",
194    ]
195  } else {
196    deps = [ ":hiperf_unittest" ]
197  }
198  if (hiperf_test_fuzz) {
199    deps += [ ":hiperf_fuzztest" ]
200  }
201}
202