diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index aa8aa90ffa888b00a9466bfdd75222b9a8026435..04b933fa30363b6869ede8868e6f53c6cd84fb35 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -23,6 +23,5 @@ group("fuzztest") { "ipcserverclientproxy_fuzzer:fuzztest", "ipcserverlistener_fuzzer:fuzztest", "ipcserverstub_fuzzer:fuzztest", - "nativedevicemanagerjs_fuzzer:fuzztest", ] } diff --git a/test/fuzztest/devicemanagerimpl_fuzzer/BUILD.gn b/test/fuzztest/devicemanagerimpl_fuzzer/BUILD.gn index 38fe7317d18351bf18527e368c3307c96a49fde0..33fbe6d2e8948e3e7a1e12951ab1caad5e240fc2 100644 --- a/test/fuzztest/devicemanagerimpl_fuzzer/BUILD.gn +++ b/test/fuzztest/devicemanagerimpl_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("//foundation/distributedhardware/devicemanager/devicemanager.gni") ##############################fuzztest########################################## ohos_fuzztest("DeviceManagerImplFuzzTest") { - module_out_path = "devicemanager/devicemanagerimpl_fuzzer" + module_out_path = "device_manager_base/devicemanager" fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/devicemanagerimpl_fuzzer" include_dirs = [ @@ -96,8 +96,6 @@ ohos_fuzztest("DeviceManagerImplFuzzTest") { "${utils_path}:devicemanagerutils", "//foundation/ace/napi:ace_napi", "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", - "//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager", "//utils/native/base:utils", ] diff --git a/test/fuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp b/test/fuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp index b5bcdbaeb647eb940a195b7e8f060ef12f3ad7e7..8b3b0099dda2744234ab7913c5f5945e98905ef3 100644 --- a/test/fuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp +++ b/test/fuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp @@ -30,8 +30,6 @@ #include "dm_device_info.h" #include "dm_native_event.h" #include "dm_subscribe_info.h" -#include "napi/native_api.h" -#include "napi/native_node_api.h" #include "nlohmann/json.hpp" #include "native_devicemanager_js.h" #include "device_manager_impl_fuzzer.h" @@ -40,6 +38,39 @@ const int nCapabiltyBufferSize = 65; namespace OHOS { namespace DistributedHardware { +class DeviceDiscoveryCallbackTest : public DiscoveryCallback { +public: + DeviceDiscoveryCallbackTest() : DiscoveryCallback() {} + virtual ~DeviceDiscoveryCallbackTest() {} + virtual void OnDiscoverySuccess(uint16_t subscribeId) override {} + virtual void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) override {} + virtual void OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) override {} +}; + +class DmInitCallbackTest : public DmInitCallback { +public: + DmInitCallbackTest() : DmInitCallback() {} + virtual ~DmInitCallbackTest() override {} + virtual void OnRemoteDied() override {} +}; + +class DeviceStateCallbackTest : public DeviceStateCallback { +public: + DeviceStateCallbackTest() : DeviceStateCallback() {} + virtual ~DeviceStateCallbackTest() override {} + virtual void OnDeviceOnline(const DmDeviceInfo &deviceInfo) override {} + virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) override {} + virtual void OnDeviceOffline(const DmDeviceInfo &deviceInfo) override {} + virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) override {} +}; + +class DeviceManagerFaCallbackTest : public DeviceManagerFaCallback { +public: + DeviceManagerFaCallbackTest() : DeviceManagerFaCallback() {} + virtual ~DeviceManagerFaCallbackTest() override {} + virtual void OnCall(const std::string ¶mJson) override {} +}; + void InitDeviceManagerFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size <= 0)) { @@ -47,10 +78,9 @@ void InitDeviceManagerFuzzTest(const uint8_t* data, size_t size) } std::string packName(reinterpret_cast(data), size); std::string bundleName(reinterpret_cast(data), size); - napi_env env; - std::shared_ptr initCallback = std::make_shared(env, bundleName); + std::shared_ptr callback = std::make_shared(); - int32_t ret = DeviceManager::GetInstance().InitDeviceManager(packName, initCallback); + int32_t ret = DeviceManager::GetInstance().InitDeviceManager(packName, callback); ret = DeviceManager::GetInstance().UnInitDeviceManager(packName); } @@ -84,14 +114,12 @@ void DeviceDiscoveryFuzzTest(const uint8_t* data, size_t size) subInfo.isSameAccount = *(reinterpret_cast(data)); subInfo.isWakeRemote = *(reinterpret_cast(data)); strncpy_s(subInfo.capability, DM_MAX_DEVICE_CAPABILITY_LEN, (char*)data, nCapabiltyBufferSize); - napi_env env; std::string extra(reinterpret_cast(data), size); int16_t subscribeId = *(reinterpret_cast(data)); - std::shared_ptr discoverCallback = - std::make_shared(env, bundleName); + std::shared_ptr callback = std::make_shared(); int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(bundleName, - subInfo, extra, discoverCallback); + subInfo, extra, callback); ret = DeviceManager::GetInstance().StopDeviceDiscovery(bundleName, subscribeId); } @@ -105,12 +133,10 @@ void AuthenticateDeviceFuzzTest(const uint8_t* data, size_t size) int32_t authType = *(reinterpret_cast(data)); DmDeviceInfo deviceInfo; std::string extraString(reinterpret_cast(data), size); - napi_env env; - std::shared_ptr authCallback = - std::make_shared(env, pkgName); + std::shared_ptr callback = nullptr; DeviceManager::GetInstance().AuthenticateDevice(pkgName, - authType, deviceInfo, extraString, authCallback); + authType, deviceInfo, extraString, callback); } void UnAuthenticateDeviceFuzzTest(const uint8_t* data, size_t size) @@ -125,21 +151,6 @@ void UnAuthenticateDeviceFuzzTest(const uint8_t* data, size_t size) DeviceManager::GetInstance().UnAuthenticateDevice(bundleName, deviceId); } -void VerifyAuthenticationFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size <= 0)) { - return; - } - - std::string bundleName(reinterpret_cast(data), size); - std::string authParam(reinterpret_cast(data), size); - napi_env env; - std::shared_ptr verifyCallback = - std::make_shared(env, bundleName); - - DeviceManager::GetInstance().VerifyAuthentication(bundleName, authParam, verifyCallback); -} - void RegisterDeviceManagerFaCallbackFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size <= 0)) { @@ -148,8 +159,7 @@ void RegisterDeviceManagerFaCallbackFuzzTest(const uint8_t* data, size_t size) std::string bundleName(reinterpret_cast(data), size); std::string packageName(reinterpret_cast(data), size); - napi_env env; - auto callback = std::make_shared(env, bundleName); + std::shared_ptr callback = std::make_shared(); DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(packageName, callback); } @@ -219,12 +229,10 @@ void RegisterDevStateCallbackFuzzTest(const uint8_t* data, size_t size) return; } std::string bundleName(reinterpret_cast(data), size); - napi_env env; - auto callback = std::make_shared(env, bundleName); std::string extra(reinterpret_cast(data), size); int32_t ret = DeviceManager::GetInstance().RegisterDevStateCallback(bundleName, - extra, callback); + extra); ret = DeviceManager::GetInstance().UnRegisterDevStateCallback(bundleName); } } @@ -240,7 +248,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::DistributedHardware::DeviceDiscoveryFuzzTest(data, size); OHOS::DistributedHardware::AuthenticateDeviceFuzzTest(data, size); OHOS::DistributedHardware::UnAuthenticateDeviceFuzzTest(data, size); - OHOS::DistributedHardware::VerifyAuthenticationFuzzTest(data, size); OHOS::DistributedHardware::RegisterDeviceManagerFaCallbackFuzzTest(data, size); OHOS::DistributedHardware::UnRegisterDeviceManagerFaCallbackFuzzTest(data, size); OHOS::DistributedHardware::GetFaParamFuzzTest(data, size); diff --git a/test/fuzztest/devicemanagernotify_fuzzer/BUILD.gn b/test/fuzztest/devicemanagernotify_fuzzer/BUILD.gn index 69548dff3989602495853b3a50033ada929c0dfc..2ae2955a9c36c2c15b8b7fe3c7ee927ae09182bd 100644 --- a/test/fuzztest/devicemanagernotify_fuzzer/BUILD.gn +++ b/test/fuzztest/devicemanagernotify_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("//foundation/distributedhardware/devicemanager/devicemanager.gni") ##############################fuzztest########################################## ohos_fuzztest("DeviceManagerNotifyFuzzTest") { - module_out_path = "devicemanager/devicemanagernotify_fuzzer" + module_out_path = "device_manager_base/devicemanager" fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/devicemanagernotify_fuzzer" include_dirs = [ diff --git a/test/fuzztest/devicemanagerservice_fuzzer/BUILD.gn b/test/fuzztest/devicemanagerservice_fuzzer/BUILD.gn index d439df5b0ede9dfd2471dee24fde78eaf78740b7..f2a434fffb477163fcb8844b62c33f149fe2c136 100644 --- a/test/fuzztest/devicemanagerservice_fuzzer/BUILD.gn +++ b/test/fuzztest/devicemanagerservice_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("//foundation/distributedhardware/devicemanager/devicemanager.gni") ##############################fuzztest########################################## ohos_fuzztest("DeviceManagerServiceFuzzTest") { - module_out_path = "devicemanager/devicemanagerservice_fuzzer" + module_out_path = "device_manager_base/devicemanager" fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/devicemanagerservice_fuzzer" include_dirs = [ diff --git a/test/fuzztest/ipcclientmanager_fuzzer/BUILD.gn b/test/fuzztest/ipcclientmanager_fuzzer/BUILD.gn index 15cf7f82a349c998b5572d02bbd3bef08e1f6265..9674e392ad6efa96e940a63c250e0d1aac0f5fcb 100644 --- a/test/fuzztest/ipcclientmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/ipcclientmanager_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("//foundation/distributedhardware/devicemanager/devicemanager.gni") ##############################fuzztest########################################## ohos_fuzztest("IpcClientManagerFuzzTest") { - module_out_path = "devicemanager/ipcclientmanager_fuzzer" + module_out_path = "device_manager_base/devicemanager" fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/ipcclientmanager_fuzzer" include_dirs = [ diff --git a/test/fuzztest/ipccmdregister_fuzzer/BUILD.gn b/test/fuzztest/ipccmdregister_fuzzer/BUILD.gn index 67e7d9aebeb40e3a6670a4485c030c4848a31922..b549ab7e58663e1ae318d1d3ba7bde4b3d14028a 100644 --- a/test/fuzztest/ipccmdregister_fuzzer/BUILD.gn +++ b/test/fuzztest/ipccmdregister_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("//foundation/distributedhardware/devicemanager/devicemanager.gni") ##############################fuzztest########################################## ohos_fuzztest("IpcCmdRegisterFuzzTest") { - module_out_path = "devicemanager/ipccmdregister_fuzzer" + module_out_path = "device_manager_base/devicemanager" fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/ipccmdregister_fuzzer" include_dirs = [ diff --git a/test/fuzztest/ipcserverclientproxy_fuzzer/BUILD.gn b/test/fuzztest/ipcserverclientproxy_fuzzer/BUILD.gn index 1fda761613356350a177bb8792cdf36b0ae6fcb3..c3871de0eaf0e4e7e985d1ecc740446f3a2cbbb9 100644 --- a/test/fuzztest/ipcserverclientproxy_fuzzer/BUILD.gn +++ b/test/fuzztest/ipcserverclientproxy_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("//foundation/distributedhardware/devicemanager/devicemanager.gni") ##############################fuzztest########################################## ohos_fuzztest("IpcServerClientProxyFuzzTest") { - module_out_path = "devicemanager/ipcserverclientproxy_fuzzer" + module_out_path = "device_manager_base/devicemanager" fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/ipcserverclientproxy_fuzzer" include_dirs = [ diff --git a/test/fuzztest/ipcserverlistener_fuzzer/BUILD.gn b/test/fuzztest/ipcserverlistener_fuzzer/BUILD.gn index b16367492c8f0a4ec54ecf2ffc66275a274d07ae..be87aea1995fec971056218cd167345dcf2bb879 100644 --- a/test/fuzztest/ipcserverlistener_fuzzer/BUILD.gn +++ b/test/fuzztest/ipcserverlistener_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("//foundation/distributedhardware/devicemanager/devicemanager.gni") ##############################fuzztest########################################## ohos_fuzztest("IpcServerListenerFuzzTest") { - module_out_path = "devicemanager/ipcserverlistener_fuzzer" + module_out_path = "device_manager_base/devicemanager" fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/ipcserverlistener_fuzzer" include_dirs = [ diff --git a/test/fuzztest/ipcserverstub_fuzzer/BUILD.gn b/test/fuzztest/ipcserverstub_fuzzer/BUILD.gn index 157c1ed703727cbe291771b10dacacf78fb00f6e..9ca31aa17ee06369397eeb1e43ffefd8b21ef85d 100644 --- a/test/fuzztest/ipcserverstub_fuzzer/BUILD.gn +++ b/test/fuzztest/ipcserverstub_fuzzer/BUILD.gn @@ -18,7 +18,7 @@ import("//foundation/distributedhardware/devicemanager/devicemanager.gni") ##############################fuzztest########################################## ohos_fuzztest("IpcServerStubFuzzTest") { - module_out_path = "devicemanager/ipcserverstub_fuzzer" + module_out_path = "device_manager_base/devicemanager" fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/ipcserverstub_fuzzer" include_dirs = [ diff --git a/test/fuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp b/test/fuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp index b05ae5c91d2207c88062b544e57de1ae560ed484..e6e4bac8e7c937ccb4fe4de0efcd6eaf95fbe4ba 100644 --- a/test/fuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp +++ b/test/fuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp @@ -43,15 +43,17 @@ void IpcServerStubFuzzTest(const uint8_t* data, size_t size) MessageParcel reply; MessageOption option; std::string pkgName(reinterpret_cast(data), size); - std::shared_ptr req = std::make_shared(); + sptr listener = nullptr; + std::shared_ptr req = nullptr; std::shared_ptr rsp = std::make_shared(); - sptr listener = data1.ReadRemoteObject(); - int32_t ret = IpcServerStub::GetInstance().OnRemoteRequest(code, data1, reply, option); - ret = IpcServerStub::GetInstance().SendCmd(code, req, rsp); - ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); - ret = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName); - sptr ipcPtr = IpcServerStub::GetInstance().GetDmListener(pkgName); + IpcServerStub::GetInstance().OnStart(); + IpcServerStub::GetInstance().OnRemoteRequest(code, data1, reply, option); + IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener); + IpcServerStub::GetInstance().GetDmListener(pkgName); + IpcServerStub::GetInstance().SendCmd(code, req, rsp); + IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName); + IpcServerStub::GetInstance().OnStop(); } } } diff --git a/test/fuzztest/nativedevicemanagerjs_fuzzer/BUILD.gn b/test/fuzztest/nativedevicemanagerjs_fuzzer/BUILD.gn deleted file mode 100644 index 9fd2afcb2e7057045bbb65568fe1dcef3522af0a..0000000000000000000000000000000000000000 --- a/test/fuzztest/nativedevicemanagerjs_fuzzer/BUILD.gn +++ /dev/null @@ -1,143 +0,0 @@ -# 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/distributedhardware/devicemanager/devicemanager.gni") - -##############################fuzztest########################################## -ohos_fuzztest("NativeDevicemanagerJsFuzzTest") { - module_out_path = "devicemanager/nativedevicemanagerjs_fuzzer" - fuzz_config_file = "//foundation/distributedhardware/devicemanager/test/fuzztest/nativedevicemanagerjs_fuzzer" - - include_dirs = [ - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include", - "//foundation/distributedhardware/devicemanager/interfaces/kits/js/include", - "//third_party/node/src", - "//foundation/ace/napi/native_engine", - "//foundation/ace/napi/interfaces/kits", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "${innerkits_path}/native_cpp/include", - "${innerkits_path}/native_cpp/include/ipc/standard", - "${innerkits_path}/native_cpp/include/ipc", - "${innerkits_path}/native_cpp/include/notify", - "//third_party/json/include", - "${common_path}/include", - "${common_path}/include/ipc", - "${common_path}/include/ipc/model", - "${utils_path}/include", - "${utils_path}/include/ipc/standard", - "${services_path}/include/dependency/timer", - "${services_path}/include/dependency/softbus", - "${services_path}/include/authentication", - "${services_path}/include/adapter", - "${services_path}/include", - "${services_path}/include/ipc/standard", - "${services_path}/include/discovery", - "${services_path}/include/dependency/hichain", - "${services_path}/include/deviceinfo", - "${services_path}/include/devicestate", - "//foundation/communication/dsoftbus/interfaces/kits/bus_center", - "//foundation/communication/softbus_lite/interfaces/kits/transport", - "//foundation/communication/dsoftbus/interfaces/kits/common", - "//foundation/communication/dsoftbus/interfaces/kits/discovery", - "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", - "//foundation/distributedhardware/devicemanager/test/unittest/mock", - "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", - "//foundation/distributedhardware/devicemanager/ext/mini/services/devicemanagerservice/include/dispatch", - "//foundation/distributedhardware/devicemanager/ext/profile/include", - "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", - "//foundation/distributedhardware/devicemanager/ext/mini/common/include", - "//base/security/deviceauth/interfaces/innerkits", - "${services_path}/include/ability", - "${services_path}/include/config", - "//utils/native/lite/include", - "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog", - "//third_party/bounds_checking_function/include", - "//foundation/communication/ipc_lite/interfaces/kits", - "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", - "//third_party/json/include", - "//foundation/appexecfwk/appexecfwk_lite/interfaces/kits/bundle_lite", - "//foundation/ace/napi/interfaces/innerkits/napi", - "//foundation/ace/napi/interfaces/innerkits", - "//third_party/jsframework/runtime/main/extend", - "//foundation/windowmanager/interfaces/kits", - "//third_party/jsframework/runtime/main/extend/systemplugin", - "//third_party/node/benchmark", - "//foundation/windowmanager/interfaces/kits/napi/screen_runtime", - "//third_party/libuv/include", - ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - sources = [ "native_devicemanager_js_fuzzer.cpp" ] - - deps = [ - "${innerkits_path}/native_cpp:devicemanagersdk", - "${utils_path}:devicemanagerutils", - "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", - "//base/security/deviceauth/services:deviceauth_sdk", - "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", - "//foundation/aafwk/standard/interfaces/innerkits/want:want", - "//foundation/aafwk/standard/services/abilitymgr:abilityms", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", - "//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"NativeDevicemanagerJsFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "common_event_service:cesfwk_core", - "common_event_service:cesfwk_innerkits", - "dsoftbus_standard:softbus_client", - "eventhandler:libeventhandler", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - "samgr_standard:samgr_proxy", - "startup_l2:syspara", - ] - - public_deps = [ - "${innerkits_path}/native_cpp:devicemanagersdk", - "${utils_path}:devicemanagerutils", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", - "//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest", - "//utils/native/base:utils", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - - deps = [ ":NativeDevicemanagerJsFuzzTest" ] -} -############################################################################### diff --git a/test/fuzztest/nativedevicemanagerjs_fuzzer/corpus/init b/test/fuzztest/nativedevicemanagerjs_fuzzer/corpus/init deleted file mode 100644 index 59aefb51c6e5a670d20c9bda3030fcdf8db29e5a..0000000000000000000000000000000000000000 --- a/test/fuzztest/nativedevicemanagerjs_fuzzer/corpus/init +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2020-2021 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 \ No newline at end of file diff --git a/test/fuzztest/nativedevicemanagerjs_fuzzer/native_devicemanager_js_fuzzer.cpp b/test/fuzztest/nativedevicemanagerjs_fuzzer/native_devicemanager_js_fuzzer.cpp deleted file mode 100644 index e9ac34f9259548c453087f94820e471e4cc697f6..0000000000000000000000000000000000000000 --- a/test/fuzztest/nativedevicemanagerjs_fuzzer/native_devicemanager_js_fuzzer.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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 -#include "native_devicemanager_js.h" -#include "device_manager.h" -#include "dm_constants.h" -#include "dm_log.h" -#include "device_manager_callback.h" -#include "dm_app_image_info.h" -#include "dm_device_info.h" -#include "dm_native_event.h" -#include "dm_subscribe_info.h" -#include "napi/native_api.h" -#include "napi/native_node_api.h" -#include "nlohmann/json.hpp" -#include "native_devicemanager_js_fuzzer.h" - -namespace OHOS { -namespace DistributedHardware { -void NativeDeviceManagerStaticFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size <= 0)) { - return; - } - napi_env env = *(reinterpret_cast(data)); - napi_callback_info info = *(reinterpret_cast(data)); - std::string buldleName(reinterpret_cast(data), size); - DeviceManagerNapi *deviceManagerNapiPtr = DeviceManagerNapi::GetDeviceManagerNapi(buldleName); - if (deviceManagerNapiPtr == nullptr) { - return; - } - - napi_value result = deviceManagerNapiPtr->CreateDeviceManager(env, info); - result = deviceManagerNapiPtr->GetTrustedDeviceListSync(env, info); - result = deviceManagerNapiPtr->AuthenticateDevice(env, info); - result = deviceManagerNapiPtr->VerifyAuthInfo(env, info); - result = deviceManagerNapiPtr->JsOn(env, info); - result = deviceManagerNapiPtr->JsOff(env, info); - result = deviceManagerNapiPtr->ReleaseDeviceManager(env, info); -} - -void NativeDeviceManagerOnFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size <= 0)) { - return; - } - std::string buldleName(reinterpret_cast(data), size); - std::string token(reinterpret_cast(data), size); - int32_t reason = *(reinterpret_cast(data)); - uint16_t subscribeId = *(reinterpret_cast(data)); - DmNapiDevStateChangeAction action = *(reinterpret_cast(data)); - DmDeviceInfo deviceInfo = *(reinterpret_cast(data)); - - uv_work_t *work = new (std::nothrow) uv_work_t; - std::unique_ptr jsCallback_; - jsCallback_ = std::make_unique(buldleName, 0, 0, deviceInfo); - work->data = reinterpret_cast(jsCallback_.get()); - DmNapiStateJsCallback *callback = reinterpret_cast(work->data); - delete work; - - DeviceManagerNapi *deviceManagerNapiPtr = DeviceManagerNapi::GetDeviceManagerNapi(buldleName); - if (deviceManagerNapiPtr == nullptr) { - return; - } - deviceManagerNapiPtr->OnDeviceStateChange(action, callback->deviceInfo_); - deviceManagerNapiPtr->OnDeviceFound(subscribeId, callback->deviceInfo_); - deviceManagerNapiPtr->OnDiscoveryFailed(subscribeId, reason); - deviceManagerNapiPtr->OnAuthResult(buldleName, token, reason, reason); - deviceManagerNapiPtr->OnVerifyResult(buldleName, reason, reason); - deviceManagerNapiPtr->OnDmfaCall(buldleName); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::NativeDeviceManagerStaticFuzzTest(data, size); - OHOS::DistributedHardware::NativeDeviceManagerOnFuzzTest(data, size); - return 0; -} \ No newline at end of file diff --git a/test/fuzztest/nativedevicemanagerjs_fuzzer/native_devicemanager_js_fuzzer.h b/test/fuzztest/nativedevicemanagerjs_fuzzer/native_devicemanager_js_fuzzer.h deleted file mode 100644 index 89ec6f7ed3986065e56183290471b2c31d147c02..0000000000000000000000000000000000000000 --- a/test/fuzztest/nativedevicemanagerjs_fuzzer/native_devicemanager_js_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 NATIVE_DEVICEMANAGER_JS_FUZZER_H -#define NATIVE_DEVICEMANAGER_JS_FUZZER_H - -#define FUZZ_PROJECT_NAME "nativedevicemanagerjs_fuzzer" - -#endif // NATIVE_DEVICEMANAGER_JS_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/nativedevicemanagerjs_fuzzer/project.xml b/test/fuzztest/nativedevicemanagerjs_fuzzer/project.xml deleted file mode 100644 index 27c26d11b7d89f7aef7835fb5f95f9e5ecaf6f9d..0000000000000000000000000000000000000000 --- a/test/fuzztest/nativedevicemanagerjs_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - \ No newline at end of file