1# Copyright (c) 2022-2024 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/config/features.gni")
15
16#####################hydra-fuzz###################
17import("//build/test.gni")
18import("//foundation/communication/netmanager_base/netmanager_base_config.gni")
19
20##############################fuzztest##########################################
21ohos_fuzztest("NetSysClientNetDiagFuzzTest") {
22  module_out_path = fuzz_test_path
23  fuzz_config_file =
24      "$NETMANAGER_BASE_ROOT/test/fuzztest/netsysclientnetdiag_fuzzer"
25  _cfi_blocklist_path = "$NETMANAGER_BASE_ROOT/test/fuzztest/netsysclientnetdiag_fuzzer/cfi_blocklist.txt"
26
27  include_dirs = [
28    "$NETCONNMANAGER_COMMON_DIR/include",
29    "$NETCONNMANAGER_SOURCE_DIR/include",
30    "$NETMANAGER_BASE_ROOT/services/netmanagernative/bpf/include",
31    "$NETMANAGER_BASE_ROOT/test/commonduplicatedcode",
32    "$NETMANAGER_BASE_ROOT/utils/log/include",
33    "$NETSYSNATIVE_INNERKITS_SOURCE_DIR",
34    "$INNERKITS_ROOT/netmanagernative/include",
35    "$NETSYSCONTROLLER_ROOT_DIR/include",
36    "$NETSYSNATIVE_SOURCE_DIR/include",
37    "$NETSYSNATIVE_SOURCE_DIR/include/manager",
38    "$NETSYSNATIVE_SOURCE_DIR/include/netsys",
39    "$NETSYSNATIVE_SOURCE_DIR/include/netsys/wrapper",
40    "$THIRD_PARTY_ROOT/cJSON/include",
41  ]
42
43  cflags = [
44    "-g",
45    "-O0",
46    "-Wno-unused-variable",
47    "-fno-omit-frame-pointer",
48  ]
49
50  if (!(use_libfuzzer || use_clang_coverage)) {
51    cflags += [
52      "-flto",
53      "-fsanitize=cfi",
54      "-fsanitize-cfi-cross-dso",
55      "-fvisibility=hidden",
56      "-fsanitize-blacklist=" +
57          rebase_path(_cfi_blocklist_path, root_build_dir),
58    ]
59  }
60
61  ldflags = []
62  if (!(use_libfuzzer || use_clang_coverage)) {
63    ldflags += [
64      "-flto",
65      "-fsanitize=cfi",
66      "-fsanitize-cfi-cross-dso",
67    ]
68  }
69
70  sources = [ "net_sys_client_netdiag_fuzzer.cpp" ]
71
72  deps = [
73    "$NETMANAGER_BASE_ROOT/services/netmanagernative:netsys_native_manager_static",
74    "$NETMANAGER_BASE_ROOT/services/netmanagernative/bpf:netsys_bpf_utils",
75    "$NETMANAGER_BASE_ROOT/utils:net_manager_common",
76    "$NETSYSCONTROLLER_ROOT_DIR:netsys_controller",
77  ]
78
79  defines = [
80    "HI_LOG_ENABLE",
81    "DH_LOG_TAG=\"NetSysClientNetDiagFuzzTest\"",
82    "LOG_DOMAIN=0xD004100",
83  ]
84
85  external_deps = [
86    "access_token:libaccesstoken_sdk",
87    "access_token:libnativetoken",
88    "access_token:libtoken_setproc",
89    "bundle_framework:appexecfwk_base",
90    "bundle_framework:appexecfwk_core",
91    "c_utils:utils",
92    "dhcp:dhcp_sdk",
93    "eventhandler:libeventhandler",
94    "ffrt:libffrt",
95    "hilog:libhilog",
96    "init:libbegetutil",
97    "ipc:ipc_core",
98    "safwk:system_ability_fwk",
99    "samgr:samgr_proxy",
100  ]
101}
102
103###############################################################################
104group("fuzztest") {
105  testonly = true
106
107  deps = [ ":NetSysClientNetDiagFuzzTest" ]
108}
109
110###############################################################################
111
112