add wifi fuzz test

Signed-off-by: yiyajun <yiyajun@huawei.com>
This commit is contained in:
yiyajun 2022-11-20 11:46:00 +08:00
parent 053c22654e
commit f8a21f1868
6 changed files with 159 additions and 0 deletions

View File

@ -0,0 +1,49 @@
# Copyright (C) 2022 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/wifi/wifi/wifi.gni")
module_output_path = "wifi/wifi_sta"
##############################fuzztest##########################################
ohos_fuzztest("WifiCP2PFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "$WIFI_ROOT_DIR/test/fuzztest/frameworks/native/c_adapter/wificp2p_fuzzer"
include_dirs = [
"$WIFI_ROOT_DIR/frameworks/native/include",
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper",
"$WIFI_ROOT_DIR/test/fuzztest/fuzz_common_func",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "wificp2p_fuzzer.cpp" ]
deps = [ "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" ]
external_deps = [
"c_utils:utils",
"ipc:ipc_core",
]
part_name = "wifi"
subsystem_name = "communication"
}

View File

@ -0,0 +1,16 @@
/*
* Copyright (C) 2022 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.
*/
FUZZ

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,47 @@
/*
* Copyright (C) 2022 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.
*/
#include <cstddef>
#include <cstdint>
#include <cstring>
#include "securec.h"
#include "wificp2p_fuzzer.h"
#include "../../../../../../interfaces/kits/c/wifi_p2p.h"
namespace OHOS {
namespace Wifi {
bool WifiCP2PFuzzerTest(const uint8_t* data, size_t size)
{
(void)EnableP2p();
(void)DisableP2p();
(void)DiscoverDevices();
(void)StopDiscoverDevices();
(void)DiscoverServices();
(void)StopDiscoverServices();
(void)StopP2pListen();
(void)RemoveGroup();
(void)P2pCancelConnect();
(void)UnregisterCfgChangCallback();
return true;
}
} // namespace Wifi
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
OHOS::Wifi::WifiCP2PFuzzerTest(data, size);
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (C) 2022 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.
*/
#ifndef WIFI_C_P2P__H
#define WIFI_C_P2P__H
#define FUZZ_PROJECT_NAME "wificp2p_fuzzer"
#endif

View File

@ -18,6 +18,7 @@ group("fuzztest") {
deps += [
"../frameworks/native/c_adapter/wifichid2d_fuzzer:WifiCHotSpotFuzzTest",
"../frameworks/native/c_adapter/wificp2p_fuzzer:WifiCP2PFuzzTest",
"adddeviceconfig_fuzzer:AddDeviceConfigFuzzTest",
"connecttodevice_fuzzer:ConnectToDeviceFuzzTest",
"disablewifi_fuzzer:DisableWifiFuzzTest",