diff --git a/bundle.json b/bundle.json
index dce07b821405036303ffcc5e34cd2aa96c496b1f..d06408362570a42ca4965c2ea74207ada2ab0225 100644
--- a/bundle.json
+++ b/bundle.json
@@ -47,7 +47,10 @@
"test": [
"//foundation/distributedhardware/distributedhardwarefwk/utils/test/unittest:utils_test",
"//foundation/distributedhardware/distributedhardwarefwk/services/distributedhardwarefwkserviceimpl/test/unittest:svrimpl_test",
- "//foundation/distributedhardware/distributedhardwarefwk/services/distributedhardwarefwkservice/test/unittest:test"
+ "//foundation/distributedhardware/distributedhardwarefwk/services/distributedhardwarefwkserviceimpl/test/fuzztest:fuzztest",
+ "//foundation/distributedhardware/distributedhardwarefwk/services/distributedhardwarefwkservice/test/unittest:test",
+ "//foundation/distributedhardware/distributedhardwarefwk/services/distributedhardwarefwkservice/test/fuzztest:fuzztest",
+ "//foundation/distributedhardware/distributedhardwarefwk/utils/test/fuzztest:fuzztest"
]
}
}
diff --git a/services/distributedhardwarefwkservice/test/fuzztest/BUILD.gn b/services/distributedhardwarefwkservice/test/fuzztest/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..ef3fb4a00118bb31f856ed872dda17a00a23d637
--- /dev/null
+++ b/services/distributedhardwarefwkservice/test/fuzztest/BUILD.gn
@@ -0,0 +1,18 @@
+# Copyright (c) 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.
+
+group("fuzztest") {
+ testonly = true
+
+ deps = [ "test_accessmanager_fuzzer:fuzztest" ]
+}
diff --git a/services/distributedhardwarefwkservice/test/fuzztest/test_accessmanager_fuzzer/BUILD.gn b/services/distributedhardwarefwkservice/test/fuzztest/test_accessmanager_fuzzer/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..23b577d6a5d705d06f24883c66ff00f98f05c2c8
--- /dev/null
+++ b/services/distributedhardwarefwkservice/test/fuzztest/test_accessmanager_fuzzer/BUILD.gn
@@ -0,0 +1,73 @@
+# Copyright (c) 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.
+
+#####################hydra-fuzz###################
+import("//build/config/features.gni")
+import("//build/test.gni")
+import(
+ "//foundation/distributedhardware/distributedhardwarefwk/distributedhardwarefwk.gni")
+
+##############################fuzztest##########################################
+ohos_fuzztest("test_accessmanager_fuzzer") {
+ module_out_path = "distributed_hardware_fwk/test_accessmanager_fuzzer"
+
+ include_dirs = [
+ "//utils/native/base/include",
+ "//utils/system/safwk/native/include",
+ "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp/include",
+ "//foundation/distributedhardware/devicemanager/common/include",
+ "${utils_path}/include",
+ "${utils_path}/include/log",
+ "${common_path}/utils/include",
+ "${common_path}/log/include",
+ "${services_path}/distributedhardwarefwkservice/include",
+ "${services_path}/distributedhardwarefwkservice/include/accessmanager",
+ ]
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources = [ "test_accessmanager_fuzzer.cpp" ]
+
+ deps = [
+ "${utils_path}:distributedhardwareutils",
+ "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk",
+ "//foundation/distributedhardware/distributedhardwarefwk/services/distributedhardwarefwkservice:distributedhardwarefwksvr",
+ "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
+ ]
+
+ defines = [
+ "HI_LOG_ENABLE",
+ "DH_LOG_TAG=\"test_accessmanager_fuzzer\"",
+ "LOG_DOMAIN=0xD004100",
+ ]
+
+ external_deps = [
+ "bundle_framework:appexecfwk_base",
+ "bundle_framework:appexecfwk_core",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
+ "startup_l2:syspara",
+ ]
+}
+
+###############################################################################
+group("fuzztest") {
+ testonly = true
+
+ deps = [ ":test_accessmanager_fuzzer" ]
+}
+###############################################################################
diff --git a/services/distributedhardwarefwkservice/test/fuzztest/test_accessmanager_fuzzer/project.xml b/services/distributedhardwarefwkservice/test/fuzztest/test_accessmanager_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..85e7ef2c1cc6471e288306f6e3dcea5287a78b0e
--- /dev/null
+++ b/services/distributedhardwarefwkservice/test/fuzztest/test_accessmanager_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/services/distributedhardwarefwkservice/test/fuzztest/test_accessmanager_fuzzer/test_accessmanager_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/test_accessmanager_fuzzer/test_accessmanager_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a3cfe4fdf4b325fac6295e63a7ebf460907f4373
--- /dev/null
+++ b/services/distributedhardwarefwkservice/test/fuzztest/test_accessmanager_fuzzer/test_accessmanager_fuzzer.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#include "test_accessmanager_fuzzer.h"
+
+#include
+#include
+#include
+#include
+#include
+
+#include "access_manager.h"
+#include "distributed_hardware_errno.h"
+#include "distributed_hardware_manager_factory.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+constexpr uint16_t TEST_DEV_TYPE_PAD = 0x11;
+
+void AccessManagerFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ std::string networkId(reinterpret_cast(data), size);
+ std::string uuid(reinterpret_cast(data), size);
+
+ DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(
+ networkId, uuid, TEST_DEV_TYPE_PAD);
+}
+}
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::DistributedHardware::AccessManagerFuzzTest(data, size);
+ return 0;
+}
+
diff --git a/services/distributedhardwarefwkservice/test/fuzztest/test_accessmanager_fuzzer/test_accessmanager_fuzzer.h b/services/distributedhardwarefwkservice/test/fuzztest/test_accessmanager_fuzzer/test_accessmanager_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..e1a1e61c873cdb774583babec8ec8d5716f66fe8
--- /dev/null
+++ b/services/distributedhardwarefwkservice/test/fuzztest/test_accessmanager_fuzzer/test_accessmanager_fuzzer.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef TEST_ACCESSMANAGER_FUZZER_H
+#define TEST_ACCESSMANAGER_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "test_accessmanager_fuzzer"
+
+#endif
+
diff --git a/services/distributedhardwarefwkserviceimpl/test/fuzztest/BUILD.gn b/services/distributedhardwarefwkserviceimpl/test/fuzztest/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..55d6ff748c8f69b65d5152d764594749efa0aae3
--- /dev/null
+++ b/services/distributedhardwarefwkserviceimpl/test/fuzztest/BUILD.gn
@@ -0,0 +1,21 @@
+# Copyright (c) 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.
+
+group("fuzztest") {
+ testonly = true
+
+ deps = [
+ "test_componentmanager_fuzzer:fuzztest",
+ "test_resourcemanager_fuzzer:fuzztest",
+ ]
+}
diff --git a/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_componentmanager_fuzzer/BUILD.gn b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_componentmanager_fuzzer/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..7bab9f46029b05265c7ff263447819f1e4b66f78
--- /dev/null
+++ b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_componentmanager_fuzzer/BUILD.gn
@@ -0,0 +1,61 @@
+# Copyright (c) 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.
+
+#####################hydra-fuzz###################
+import("//build/config/features.gni")
+import("//build/test.gni")
+import(
+ "//foundation/distributedhardware/distributedhardwarefwk/distributedhardwarefwk.gni")
+
+##############################fuzztest##########################################
+ohos_fuzztest("test_componentmanager_fuzzer") {
+ module_out_path = "distributed_hardware_fwk/test_componentmanager_fuzzer"
+
+ include_dirs = [
+ "${utils_path}/include",
+ "${utils_path}/include/log",
+ "${services_path}/distributedhardwarefwkserviceimpl/include",
+ "${services_path}/distributedhardwarefwkserviceimpl/include/componentmanager",
+ "${services_path}/distributedhardwarefwkserviceimpl/include/utils",
+ "${common_path}/utils/include",
+ "${common_path}/log/include",
+ "//utils/native/base/include",
+ ]
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources = [ "test_componentmanager_fuzzer.cpp" ]
+
+ deps = [
+ "//foundation/distributedhardware/distributedhardwarefwk/services/distributedhardwarefwkserviceimpl:distributedhardwarefwksvr_impl",
+ "//foundation/distributedhardware/distributedhardwarefwk/utils:distributedhardwareutils",
+ ]
+
+ defines = [
+ "HI_LOG_ENABLE",
+ "DH_LOG_TAG=\"test_componentmanager_fuzzer\"",
+ "LOG_DOMAIN=0xD004100",
+ ]
+
+ external_deps = [ "ipc:ipc_core" ]
+}
+
+###############################################################################
+group("fuzztest") {
+ testonly = true
+ deps = [ ":test_componentmanager_fuzzer" ]
+}
+###############################################################################
diff --git a/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_componentmanager_fuzzer/project.xml b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_componentmanager_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..85e7ef2c1cc6471e288306f6e3dcea5287a78b0e
--- /dev/null
+++ b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_componentmanager_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_componentmanager_fuzzer/test_componentmanager_fuzzer.cpp b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_componentmanager_fuzzer/test_componentmanager_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..dabf9a3ee994fa52b8e7816f9eb8712934538d53
--- /dev/null
+++ b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_componentmanager_fuzzer/test_componentmanager_fuzzer.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#include "test_componentmanager_fuzzer.h"
+
+#include
+#include
+
+#include "component_disable.h"
+#include "component_enable.h"
+#include "component_manager.h"
+#include "constants.h"
+#include "distributed_hardware_errno.h"
+#include "distributed_hardware_log.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+void ComponentManagerFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ std::string networkId(reinterpret_cast(data), size);
+ std::string uuid(reinterpret_cast(data), size);
+ std::string dhId(reinterpret_cast(data), size);
+
+ ComponentManager::GetInstance().Init();
+ ComponentManager::GetInstance().Enable(networkId, uuid, dhId);
+ ComponentManager::GetInstance().Disable(networkId, uuid, dhId);
+ ComponentManager::GetInstance().UnInit();
+}
+}
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::DistributedHardware::ComponentManagerFuzzTest(data, size);
+ return 0;
+}
+
diff --git a/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_componentmanager_fuzzer/test_componentmanager_fuzzer.h b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_componentmanager_fuzzer/test_componentmanager_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..1914d24d443de16da735a138bbd16e291e02829c
--- /dev/null
+++ b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_componentmanager_fuzzer/test_componentmanager_fuzzer.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef TEST_COMPONENTMANAGER_FUZZER_H
+#define TEST_COMPONENTMANAGER_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "test_componentmanager_fuzzer"
+
+#endif
diff --git a/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_resourcemanager_fuzzer/BUILD.gn b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_resourcemanager_fuzzer/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..62620243a5198407deee981cb47d357915c47be8
--- /dev/null
+++ b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_resourcemanager_fuzzer/BUILD.gn
@@ -0,0 +1,72 @@
+# Copyright (c) 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.
+
+#####################hydra-fuzz###################
+import("//build/config/features.gni")
+import("//build/test.gni")
+import(
+ "//foundation/distributedhardware/distributedhardwarefwk/distributedhardwarefwk.gni")
+
+##############################fuzztest##########################################
+ohos_fuzztest("test_resourcemanager_fuzzer") {
+ module_out_path = "distributed_hardware_fwk/test_resourcemanager_fuzzer"
+
+ include_dirs = [
+ "${utils_path}/include",
+ "${utils_path}/include/log",
+ "${utils_path}/include/eventbus",
+ "${services_path}/distributedhardwarefwkserviceimpl/include",
+ "${services_path}/distributedhardwarefwkserviceimpl/include/resourcemanager",
+ "${services_path}/distributedhardwarefwkserviceimpl/include/utils",
+ "${common_path}/utils/include",
+ "${common_path}/log/include",
+ "//utils/native/base/include",
+ "//third_party/json/include",
+ "//utils/native/base/include",
+ "//utils/system/safwk/native/include",
+ ]
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources = [ "test_resourcemanager_fuzzer.cpp" ]
+
+ deps = [
+ "//foundation/distributedhardware/distributedhardwarefwk/services/distributedhardwarefwkserviceimpl:distributedhardwarefwksvr_impl",
+ "//foundation/distributedhardware/distributedhardwarefwk/utils:distributedhardwareutils",
+ "//utils/native/base:utils",
+ ]
+
+ defines = [
+ "HI_LOG_ENABLE",
+ "DH_LOG_TAG=\"test_resourcemanager_fuzzer\"",
+ "LOG_DOMAIN=0xD004100",
+ ]
+
+ external_deps = [
+ "bundle_framework:appexecfwk_base",
+ "bundle_framework:appexecfwk_core",
+ "distributeddatamgr:distributeddata_inner",
+ "eventhandler:libeventhandler",
+ "hiviewdfx_hilog_native:libhilog",
+ ]
+}
+
+###############################################################################
+group("fuzztest") {
+ testonly = true
+ deps = [ ":test_resourcemanager_fuzzer" ]
+}
+###############################################################################
diff --git a/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_resourcemanager_fuzzer/project.xml b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_resourcemanager_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..85e7ef2c1cc6471e288306f6e3dcea5287a78b0e
--- /dev/null
+++ b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_resourcemanager_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_resourcemanager_fuzzer/test_resourcemanager_fuzzer.cpp b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_resourcemanager_fuzzer/test_resourcemanager_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bc901eeb07c85c59af8f19b450d84965b88f42b1
--- /dev/null
+++ b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_resourcemanager_fuzzer/test_resourcemanager_fuzzer.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#include "test_resourcemanager_fuzzer.h"
+
+#include
+#include
+#include
+#include
+
+#include "capability_info.h"
+#include "capability_info_manager.h"
+#include "dh_context.h"
+#include "distributed_hardware_errno.h"
+#include "distributed_hardware_log.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+constexpr uint16_t DHTYPE_SIZE = 5;
+const DHType dhTypeFuzz[DHTYPE_SIZE] = {
+ DHType::CAMERA, DHType::MIC, DHType::SPEAKER, DHType::DISPLAY, DHType::BUTTON
+};
+
+void ResourceManagerFuzzTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size < sizeof(uint16_t))) {
+ return;
+ }
+
+ std::string dhId(reinterpret_cast(data), size);
+ std::string devId(reinterpret_cast(data), size);
+ std::string devName(reinterpret_cast(data), size);
+ uint16_t devType = *(reinterpret_cast(data));
+ DHType dhType = dhTypeFuzz[data[0] % DHTYPE_SIZE];
+ std::string dhAttrs(reinterpret_cast(data), size);
+
+ std::shared_ptr capInfo =
+ std::make_shared(dhId, devId, devName, devType, dhType, dhAttrs);
+ std::vector> resInfos;
+ resInfos.emplace_back(capInfo);
+
+ CapabilityInfoManager::GetInstance()->AddCapability(resInfos);
+
+ std::shared_ptr info;
+ CapabilityInfoManager::GetInstance()->GetCapability(capInfo->GetDeviceId(), capInfo->GetDHId(), info);
+ CapabilityInfoManager::GetInstance()->GetDataByKey(capInfo->GetKey(), info);
+
+ CapabilityInfoMap capMap;
+ CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(capInfo->GetDeviceId(), capMap);
+ CapabilityInfoManager::GetInstance()->RemoveCapabilityInfoByKey(capInfo->GetKey());
+}
+}
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::DistributedHardware::ResourceManagerFuzzTest(data, size);
+ return 0;
+}
+
diff --git a/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_resourcemanager_fuzzer/test_resourcemanager_fuzzer.h b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_resourcemanager_fuzzer/test_resourcemanager_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..48761b3c15347704976944ef0fb8603d0368f6c1
--- /dev/null
+++ b/services/distributedhardwarefwkserviceimpl/test/fuzztest/test_resourcemanager_fuzzer/test_resourcemanager_fuzzer.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef TEST_RESOURCEMANAGER_FUZZER_H
+#define TEST_RESOURCEMANAGER_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "test_resourcemanager_fuzzer"
+
+#endif
diff --git a/utils/test/fuzztest/BUILD.gn b/utils/test/fuzztest/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..d90b4188259bed25c651edfb4455c78435831ef7
--- /dev/null
+++ b/utils/test/fuzztest/BUILD.gn
@@ -0,0 +1,18 @@
+# Copyright (c) 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.
+
+group("fuzztest") {
+ testonly = true
+
+ deps = [ "test_utils_fuzzer:fuzztest" ]
+}
diff --git a/utils/test/fuzztest/test_utils_fuzzer/BUILD.gn b/utils/test/fuzztest/test_utils_fuzzer/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..c684397aa12b55bb06695d80b62320051a7022c2
--- /dev/null
+++ b/utils/test/fuzztest/test_utils_fuzzer/BUILD.gn
@@ -0,0 +1,46 @@
+# Copyright (c) 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.
+
+#####################hydra-fuzz###################
+import("//build/config/features.gni")
+import("//build/test.gni")
+import(
+ "//foundation/distributedhardware/distributedhardwarefwk/distributedhardwarefwk.gni")
+
+##############################fuzztest##########################################
+ohos_fuzztest("test_utils_fuzzer") {
+ module_out_path = "distributed_hardware_fwk/test_utils_fuzzer"
+
+ include_dirs = [
+ "${utils_path}/include",
+ "${utils_path}/include/log",
+ "${common_path}/utils/include",
+ "//utils/native/base/include",
+ ]
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources = [ "test_utils_fuzzer.cpp" ]
+
+ deps = [ "//foundation/distributedhardware/distributedhardwarefwk/utils:distributedhardwareutils" ]
+}
+
+###############################################################################
+group("fuzztest") {
+ testonly = true
+ deps = [ ":test_utils_fuzzer" ]
+}
+###############################################################################
diff --git a/utils/test/fuzztest/test_utils_fuzzer/project.xml b/utils/test/fuzztest/test_utils_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..85e7ef2c1cc6471e288306f6e3dcea5287a78b0e
--- /dev/null
+++ b/utils/test/fuzztest/test_utils_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/utils/test/fuzztest/test_utils_fuzzer/test_utils_fuzzer.cpp b/utils/test/fuzztest/test_utils_fuzzer/test_utils_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..aa03d3be0919f6eab213dfa889974da04b4ac627
--- /dev/null
+++ b/utils/test/fuzztest/test_utils_fuzzer/test_utils_fuzzer.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#include "test_utils_fuzzer.h"
+
+#include
+#include
+
+#include "anonymous_string.h"
+#include "dh_utils_tool.h"
+
+namespace OHOS {
+namespace DistributedHardware {
+void GetAnonyStringTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ std::string str(reinterpret_cast(data), size);
+ std::string anonyStr = GetAnonyString(str);
+}
+
+void GetAnonyInt32Test(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size < sizeof(int32_t))) {
+ return;
+ }
+
+ int32_t i = *(reinterpret_cast(data));
+ std::string anonyStr = GetAnonyInt32(i);
+}
+
+void UtilsToolTest(const uint8_t* data, size_t size)
+{
+ if ((data == nullptr) || (size <= 0)) {
+ return;
+ }
+
+ std::string networkId(reinterpret_cast(data), size);
+ std::string uuid(reinterpret_cast(data), size);
+ std::string uuidStr = GetUUIDBySoftBus(networkId);
+ std::string deviceIdStr = GetDeviceIdByUUID(uuid);
+}
+}
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::DistributedHardware::GetAnonyStringTest(data, size);
+ OHOS::DistributedHardware::GetAnonyInt32Test(data, size);
+ OHOS::DistributedHardware::UtilsToolTest(data, size);
+ return 0;
+}
+
diff --git a/utils/test/fuzztest/test_utils_fuzzer/test_utils_fuzzer.h b/utils/test/fuzztest/test_utils_fuzzer/test_utils_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..7ac240e99fb6526f6a5acc653e6607a4155ca9b5
--- /dev/null
+++ b/utils/test/fuzztest/test_utils_fuzzer/test_utils_fuzzer.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 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.
+ */
+
+#ifndef TEST_UTILS_FUZZER_H
+#define TEST_UTILS_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "test_utils_fuzzer"
+
+#endif