# Copyright (c) 2022-2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
import("//foundation/communication/netmanager_ext/netmanager_ext_config.gni")
##############################fuzztest##########################################
EXT_SECURITY_PATH = "../../.."

ohos_fuzztest("EthernetClientFuzzTest") {
  module_out_path = fuzz_test_path
  fuzz_config_file =
      "$NETMANAGER_EXT_ROOT/test/ethernetmanager/fuzztest/ethernetclient_fuzzer"

  include_dirs = [
    "$EXT_INNERKITS_ROOT/include",
    "$EXT_INNERKITS_ROOT/ethernetclient/include",
    "$EXT_INNERKITS_ROOT/ethernetclient/include/proxy",
    "$EXT_SECURITY_PATH/security",
    "$NETMANAGER_EXT_ROOT/utils/log/include",
    "$ETHERNETMANAGER_SOURCE_DIR/include",
    "$BASE_INNERKITS_ROOT/netmanagernative/include",
    "$BASE_INNERKITS_ROOT/include",
    "$BASE_INNERKITS_ROOT/dnsresolverclient/include",
    "$BASE_INNERKITS_ROOT/netconnclient/include",
    "$NETSYSCONTROLLER_ROOT_DIR/include",
    "$NETCONNMANAGER_COMMON_DIR/include",
    "$ETHERNETMANAGER_SOURCE_DIR/include/stub",
  ]

  cflags = [
    "-g",
    "-O0",
    "-Wno-unused-variable",
    "-fno-omit-frame-pointer",
    "-flto",
    "-fsanitize=cfi",
    "-fsanitize-cfi-cross-dso",
    "-fvisibility=hidden",
  ]

  ldflags = [
    "-flto",
    "-fsanitize=cfi",
    "-fsanitize-cfi-cross-dso",
  ]

  sources = [
    "$EXT_SECURITY_PATH/security/netmanager_ext_test_security.cpp",
    "ethernet_client_fuzzer.cpp",
  ]

  deps = [
    "$ETHERNETMANAGER_SOURCE_DIR:ethernet_manager",
    "$EXT_INNERKITS_ROOT/ethernetclient:ethernet_manager_if",
    "$NETMANAGER_EXT_ROOT/utils:net_manager_ext_common",
    "$NETSYSCONTROLLER_ROOT_DIR:netsys_controller",
  ]

  external_deps = [
    "access_token:libaccesstoken_sdk",
    "access_token:libnativetoken",
    "access_token:libtoken_setproc",
    "cJSON:cjson",
    "c_utils:utils",
    "dhcp:dhcp_sdk",
    "ffrt:libffrt",
    "ipc:ipc_core",
  ]
  external_deps += [ "hilog:libhilog" ]

  defines = [
    "NETMGR_LOG_TAG = \"EthernetManager\"",
    "LOG_DOMAIN = 0xD0015B0",
  ]
}

###############################################################################
group("fuzztest") {
  testonly = true

  deps = [ ":EthernetClientFuzzTest" ]
}
###############################################################################