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