1# Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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/ohos.gni")
15import("../build/test.gni")
16import("../build/ts.gni")
17import("test_ts.gni")
18
19if (is_test) {
20  ohos_unittest("trace_streamer_ut") {
21    sources = [
22      "unittest/base/export_test.cpp",  # Don't comment, for common method
23      "unittest/ebpf/bio_parser_test.cpp",
24      "unittest/ebpf/ebpf_file_system_test.cpp",
25      "unittest/ebpf/ebpf_parser_test.cpp",
26      "unittest/ebpf/paged_memory_parser_test.cpp",
27      "unittest/filter/animation_filter_test.cpp",
28      "unittest/filter/app_start_filter_test.cpp",
29      "unittest/filter/binder_filter_test.cpp",
30      "unittest/filter/clock_filter_test.cpp",
31      "unittest/filter/cpu_filter_test.cpp",
32      "unittest/filter/filter_filter_test.cpp",
33      "unittest/filter/frame_filter_test.cpp",
34      "unittest/filter/irq_filter_test.cpp",
35      "unittest/filter/measure_filter_test.cpp",
36      "unittest/filter/process_filter_test.cpp",
37      "unittest/filter/slice_filter_test.cpp",
38      "unittest/filter/task_pool_filter_test.cpp",
39      "unittest/interface/rpc_server_test.cpp",
40      "unittest/interface/split_file_data_test.cpp",
41      "unittest/interface/wasm_func_test.cpp",
42      "unittest/pbreader/parser_pbreader_test.cpp",
43      "unittest/pbreader/proto_reader_test.cpp",
44      "unittest/pbreader_parser/arkts/js_cpu_profiler_test.cpp",
45      "unittest/pbreader_parser/arkts/js_memory_test.cpp",
46      "unittest/pbreader_parser/diskio_parser_test.cpp",
47      "unittest/pbreader_parser/hidump_parser_test.cpp",
48      "unittest/pbreader_parser/hilog_parser_test.cpp",
49      "unittest/pbreader_parser/hisys_event_parser_test.cpp",
50      "unittest/pbreader_parser/htrace_binder_event_test.cpp",
51      "unittest/pbreader_parser/htrace_cpu_detail_parser_test.cpp",
52      "unittest/pbreader_parser/htrace_event_parser_test.cpp",
53      "unittest/pbreader_parser/htrace_irq_event_test.cpp",
54      "unittest/pbreader_parser/native_memory/native_hook_parser_test.cpp",
55      "unittest/pbreader_parser/pbreader_cpu_data_parser_test.cpp",
56      "unittest/pbreader_parser/pbreader_ffrt_parser_test.cpp",
57      "unittest/pbreader_parser/pbreader_mem_parser_test.cpp",
58      "unittest/pbreader_parser/pbreader_network_parser_test.cpp",
59      "unittest/pbreader_parser/pbreader_process_parser_test.cpp",
60      "unittest/pbreader_parser/pbreader_sys_mem_parser_test.cpp",
61      "unittest/pbreader_parser/pbreader_sys_vmem_parser_test.cpp",
62      "unittest/pbreader_parser/smaps_parser_test.cpp",
63      "unittest/ptreader_parser/event_parser_test.cpp",
64      "unittest/ptreader_parser/ptreader_parser_test.cpp",
65      "unittest/query/query_file_test.cpp",
66      "unittest/query/query_metrics_test.cpp",
67      "unittest/query/span_join_test.cpp",
68      "unittest/query/sqllite_prepar_cache_data_test.cpp",
69      "unittest/rawtrace/ftrace_field_processor_test.cpp",
70      "unittest/rawtrace/rawtrace_cpu_detail_parse_test.cpp",
71      "unittest/rawtrace/rawtrace_parser_test.cpp",
72      "unittest/table/table_test.cpp",
73    ]
74
75    deps = [
76      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/smartperf_host:ts_all_sph_cpp",
77      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/cpu_data:ts_cpu_data_cpp",
78      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/diskio_data:ts_diskio_data_cpp",
79      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/ffrt_profiler:ts_ffrt_profiler_cpp",
80      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/ftrace_data/${device_kernel_version}:ts_ftrace_data_cpp",
81      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/hidump_data:ts_hidump_data_cpp",
82      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/hilog_data:ts_hilog_data_cpp",
83      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/hisysevent_data:ts_hisysevent_data_cpp",
84      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/js_memory:ts_js_memory_data_cpp",
85      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/memory_data:ts_memory_data_cpp",
86      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/native_hook:ts_native_hook_cpp",
87      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/network_data:ts_network_data_cpp",
88      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/process_data:ts_process_data_cpp",
89      "${OHOS_TRACE_STREAMER_PROTOS_DIR}/protos/types/plugins/test_data:test_data_cpp",
90      "${SRC}/parser/rawtrace_parser:rawtrace_parser",
91      "${THIRD_PARTY}/bounds_checking_function:libsec_static",
92      "${THIRD_PARTY}/googletest:gtest",
93      "${THIRD_PARTY}/googletest:gtest_main",
94      "${THIRD_PARTY}/protobuf:protobuf_lite_static",
95      "${THIRD_PARTY}/protobuf:protobuf_static",
96      "../src:trace_streamer_source",
97      "../src/parser/pbreader_parser:pbreader_parser_src",
98      "../src/proto_reader:proto_reader",
99    ]
100    public_configs = []
101    if (enable_stream_extend) {
102      sources +=
103          [ "${EXTEND_TEST}/unittest/pbreader/pbreader_stream_parser_test.cpp" ]
104      public_configs +=
105          [ "${EXTEND_SRC}/parser/pbreader_stream_parser:pbreader_stream_cfg" ]
106      deps +=
107          [ "${EXTEND_SRC}/parser/pbreader_stream_parser:stream_extend_parser" ]
108    }
109    include_dirs = [
110      "${SRC}",
111      "${SRC}/trace_data",
112      "${SRC}/table",
113      "${SRC}/table/base",
114      "${SRC}/filter",
115      "${SRC}/metrics",
116      "${SRC}/base",
117      "${SRC}/rpc",
118      "${SRC}/metrics",
119      "${SRC}/include",
120      "${SRC}/trace_streamer",
121      "${SRC}/parser/ptreader_parser",
122      "${SRC}/parser/ptreader_parser/bytrace_parser",
123      "${SRC}/parser",
124      "${SRC}/cfg",
125      "${SRC}/metrics",
126      "${SRC}/parser/ebpf_parser",
127      "${SRC}/parser/hiperf_parser",
128      "${SRC}/parser/hiperf_parser/include",
129      "${SRC}/proto_reader",
130      "${SRC}/proto_reader/include",
131      "${SRC}/table/base/include",
132      "..",
133      "unittest/base",
134      "${THIRD_PARTY}/googletest/googletest/include/gtest",
135      "${THIRD_PARTY}/protobuf/src",
136      "${THIRD_PARTY}/protobuf/src/google/protobuf",
137      "${THIRD_PARTY}/json/single_include/nlohmann",
138      "${THIRD_PARTY}/perf_include/libbpf",
139      "${THIRD_PARTY}/perf_include/include",
140      "${THIRD_PARTY}/perf_include",
141      "${THIRD_PARTY}/perf_include/linux",
142      "${THIRD_PARTY}/sqlite/include",
143      "${THIRD_PARTY}/bounds_checking_function/include",
144      "${THIRD_PARTY}/json/single_include/nlohmann",
145      "${SRC}/parser/pbreader_parser",
146      "${SRC}/parser/pbreader_parser/htrace_parser",
147      "${SRC}/proto_reader",
148      "${SRC}/proto_reader/include",
149      "${SRC}/metrics",
150      "${SRC}/parser/rawtrace_parser",
151    ]
152
153    cflags = [
154      "-Wno-inconsistent-missing-override",
155      "-Dprivate=public",  #allow test code access private members
156      "-Dprotected=public",  #allow test code access protect members
157      "-fprofile-arcs",
158      "-ftest-coverage",
159      "-Wno-unused-command-line-argument",
160      "-Wno-format",
161      "-Wno-unused-const-variable",
162      "-Wno-unused-variable",
163      "-Wno-used-but-marked-unused",
164    ]
165    ldflags = [
166      "-fprofile-arcs",
167      "-ftest-coverage",
168      "--coverage",
169    ]
170    cflags += [
171      # clang coverage options:
172      "--coverage",
173      "-mllvm",
174      "-limited-coverage-experimental=true",
175      "-fno-use-cxa-atexit",
176      "-DIS_UT",
177    ]
178    if (is_mac) {
179      lib_dirs = [ "/usr/local/opt/llvm/lib" ]
180    }
181    libs = [ "LLVMCore" ]
182  }
183}
184
185# this is the dest for ohos.build
186if (is_test) {
187  group("unittest") {
188    testonly = true
189    deps = [ ":trace_streamer_ut" ]
190  }
191} else if (target == "fuzz") {
192  group("fuzztest") {
193    testonly = true
194    deps = [
195      "test_fuzzer/bytrace_fuzzer:fuzztest",
196      "test_fuzzer/htrace_fuzzer:fuzztest",
197      "test_fuzzer/selector_fuzzer:fuzztest",
198    ]
199  }
200}
201