diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn
new file mode 100644
index 0000000..3f7253d
--- /dev/null
+++ b/test/fuzztest/BUILD.gn
@@ -0,0 +1,691 @@
+# 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.
+
+import("//base/usb/usb_manager/usbmgr.gni")
+import("//build/config/features.gni")
+import("//build/test.gni")
+
+module_output_path = "${usb_manager_part_name}/usb_fuzztest_test"
+
+config("module_private_config") {
+ visibility = [ ":*" ]
+
+ configs = [ "${utils_path}:utils_config" ]
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ include_dirs = [
+ "include",
+ "common/include",
+ "${usb_manager_path}/test/common/include/",
+ ]
+}
+
+ohos_fuzztest("UsbMgrRequestRightFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrrequestright_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrrequestright_fuzzer/usbmgrrequestright_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrHasRightFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file = "${usb_manager_path}/test/fuzztest/usbmgrhasright_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrhasright_fuzzer/usbmgrhasright_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrRemoveRightFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrremoveright_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrremoveright_fuzzer/usbmgrremoveright_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrGetSupportedModesFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrgetsupportedmodes_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources =
+ [ "usbmgrgetsupportedmodes_fuzzer/usbmgrgetsupportedmodes_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrSetPortRoleFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrsetportrole_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrsetportrole_fuzzer/usbmgrsetportrole_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrSetCurrentFunctionsFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [
+ "usbmgrsetcurrentfunctions_fuzzer/usbmgrsetcurrentfunctions_fuzzer.cpp",
+ ]
+}
+
+ohos_fuzztest("UsbMgrUsbFunctionsFromStringFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrusbfunctionsfromstring_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrusbfunctionsfromstring_fuzzer/usbmgrusbfunctionsfromstring_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrUsbFunctionsToStringFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrusbfunctionstostring_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [
+ "usbmgrusbfunctionstostring_fuzzer/usbmgrusbfunctionstostring_fuzzer.cpp",
+ ]
+}
+
+ohos_fuzztest("UsbMgrClaimInterfaceFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrclaiminterface_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrclaiminterface_fuzzer/usbmgrclaiminterface_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrReleaseInterfaceFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrreleaseinterface_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources =
+ [ "usbmgrreleaseinterface_fuzzer/usbmgrreleaseinterface_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrBulkTransferFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrbultransfer_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrbultransfer_fuzzer/usbmgrbultransfer_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrControlTransferFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrcontroltransfer_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrcontroltransfer_fuzzer/usbmgrcontroltransfer_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrSetConfigurationFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrsetconfiguration_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources =
+ [ "usbmgrsetconfiguration_fuzzer/usbmgrsetconfiguration_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrSetInterfaceFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrsetinterface_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrsetinterface_fuzzer/usbmgrsetinterface_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrGetRawDescriptorsFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrgetrawdescriptors_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources =
+ [ "usbmgrgetrawdescriptors_fuzzer/usbmgrgetrawdescriptors_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrGetFileDescriptorFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrgetfiledescriptor_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources =
+ [ "usbmgrgetfiledescriptor_fuzzer/usbmgrgetfiledescriptor_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrCloseFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file = "${usb_manager_path}/test/fuzztest/usbmgrclose_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrclose_fuzzer/usbmgrclose_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrPipeRequestWaitFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrpiperequestwait_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrpiperequestwait_fuzzer/usbmgrpiperequestwait_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrRequestInitializeFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrrequestinitialize_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources =
+ [ "usbmgrrequestinitialize_fuzzer/usbmgrrequestinitialize_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrRequestQueueFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrrequestqueue_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrrequestqueue_fuzzer/usbmgrrequestqueue_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrRequestFreeFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrrequestfree_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [ "usbmgrrequestfree_fuzzer/usbmgrrequestfree_fuzzer.cpp" ]
+}
+
+ohos_fuzztest("UsbMgrRegBulkCallbackFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrregbulkcallback_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [
+ "common/src/usb_common_fuzz.cpp",
+ "usbmgrregbulkcallback_fuzzer/usbmgrregbulkcallback_fuzzer.cpp",
+ ]
+}
+
+ohos_fuzztest("UsbMgrUnRegBulkCallbackFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file =
+ "${usb_manager_path}/test/fuzztest/usbmgrunregbulkcallback_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [
+ "${usb_manager_path}/test/common/src/usb_callback_test.cpp",
+ "common/src/usb_common_fuzz.cpp",
+ "usbmgrunregbulkcallback_fuzzer/usbmgrunregbulkcallback_fuzzer.cpp",
+ ]
+}
+
+ohos_fuzztest("UsbMgrBulkReadFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file = "${usb_manager_path}/test/fuzztest/usbmgrbulkread_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [
+ "${usb_manager_path}/test/common/src/usb_callback_test.cpp",
+ "common/src/usb_common_fuzz.cpp",
+ "usbmgrbulkread_fuzzer/usbmgrbulkread_fuzzer.cpp",
+ ]
+}
+
+ohos_fuzztest("UsbMgrBulkWriteFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file = "${usb_manager_path}/test/fuzztest/usbmgrbulkwrite_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [
+ "${usb_manager_path}/test/common/src/usb_callback_test.cpp",
+ "common/src/usb_common_fuzz.cpp",
+ "usbmgrbulkwrite_fuzzer/usbmgrbulkwrite_fuzzer.cpp",
+ ]
+}
+
+ohos_fuzztest("UsbMgrBulkCancelFuzzTest") {
+ module_out_path = module_output_path
+
+ fuzz_config_file = "${usb_manager_path}/test/fuzztest/usbmgrbulkcancel_fuzzer"
+
+ configs = [ ":module_private_config" ]
+
+ deps = [
+ "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
+ "${usb_manager_path}/services:usbservice",
+ ]
+
+ external_deps = [
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "usb_device_driver:usbd_client",
+ "utils_base:utils",
+ ]
+
+ sources = [
+ "${usb_manager_path}/test/common/src/usb_callback_test.cpp",
+ "common/src/usb_common_fuzz.cpp",
+ "usbmgrbulkcancel_fuzzer/usbmgrbulkcancel_fuzzer.cpp",
+ ]
+}
+
+group("fuzztest") {
+ testonly = true
+ deps = []
+ deps += [
+ ":UsbMgrBulkCancelFuzzTest",
+ ":UsbMgrBulkReadFuzzTest",
+ ":UsbMgrBulkTransferFuzzTest",
+ ":UsbMgrBulkWriteFuzzTest",
+ ":UsbMgrClaimInterfaceFuzzTest",
+ ":UsbMgrCloseFuzzTest",
+ ":UsbMgrControlTransferFuzzTest",
+ ":UsbMgrGetFileDescriptorFuzzTest",
+ ":UsbMgrGetRawDescriptorsFuzzTest",
+ ":UsbMgrGetSupportedModesFuzzTest",
+ ":UsbMgrHasRightFuzzTest",
+ ":UsbMgrPipeRequestWaitFuzzTest",
+ ":UsbMgrRegBulkCallbackFuzzTest",
+ ":UsbMgrReleaseInterfaceFuzzTest",
+ ":UsbMgrRemoveRightFuzzTest",
+ ":UsbMgrRequestFreeFuzzTest",
+ ":UsbMgrRequestInitializeFuzzTest",
+ ":UsbMgrRequestQueueFuzzTest",
+ ":UsbMgrRequestRightFuzzTest",
+ ":UsbMgrSetConfigurationFuzzTest",
+ ":UsbMgrSetCurrentFunctionsFuzzTest",
+ ":UsbMgrSetInterfaceFuzzTest",
+ ":UsbMgrSetPortRoleFuzzTest",
+ ":UsbMgrUnRegBulkCallbackFuzzTest",
+ ":UsbMgrUsbFunctionsFromStringFuzzTest",
+ ":UsbMgrUsbFunctionsToStringFuzzTest",
+ ]
+}
diff --git a/test/fuzztest/usbmgrbulkcancel_fuzzer/corpus/init b/test/fuzztest/usbmgrbulkcancel_fuzzer/corpus/init
new file mode 100644
index 0000000..bc977bd
--- /dev/null
+++ b/test/fuzztest/usbmgrbulkcancel_fuzzer/corpus/init
@@ -0,0 +1,14 @@
+# 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
\ No newline at end of file
diff --git a/test/fuzztest/usbmgrbulkcancel_fuzzer/project.xml b/test/fuzztest/usbmgrbulkcancel_fuzzer/project.xml
new file mode 100644
index 0000000..6e8ad2c
--- /dev/null
+++ b/test/fuzztest/usbmgrbulkcancel_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/test/fuzztest/usbmgrbulkcancel_fuzzer/usbmgrbulkcancel_fuzzer.cpp b/test/fuzztest/usbmgrbulkcancel_fuzzer/usbmgrbulkcancel_fuzzer.cpp
new file mode 100644
index 0000000..b482b23
--- /dev/null
+++ b/test/fuzztest/usbmgrbulkcancel_fuzzer/usbmgrbulkcancel_fuzzer.cpp
@@ -0,0 +1,98 @@
+/*
+ * 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 "usbmgrbulkcancel_fuzzer.h"
+
+#include
+#include
+
+#include "iremote_object.h"
+#include "ashmem.h"
+#include "usb_errors.h"
+#include "usb_callback_test.h"
+#include "usb_common_fuzz.h"
+namespace {
+const uint32_t ASHMEM_MAX_SIZE = 1024;
+const uint32_t MEM_DATA = 1024 * 1024;
+}
+namespace OHOS {
+namespace USB {
+ sptr GetSharedMem()
+ {
+ sptr asmptr = Ashmem::CreateAshmem("ttashmem001", MEM_DATA);
+ if (asmptr == nullptr) {
+ USB_HILOGE(MODULE_USB_SERVICE, "InitAshmemOne CreateAshmem failed");
+ return nullptr;
+ }
+
+ asmptr->MapReadAndWriteAshmem();
+
+ std::array tdata;
+ tdata.fill('Y');
+ uint32_t offset = 0;
+ uint32_t tlen = 0;
+ while (offset < MEM_DATA) {
+ tlen = (MEM_DATA - offset) < ASHMEM_MAX_SIZE ? (MEM_DATA - offset) : ASHMEM_MAX_SIZE;
+ asmptr->WriteToAshmem(tdata.data(), tlen, offset);
+ offset += tlen;
+ }
+ return asmptr;
+ }
+
+ bool UsbMgrBulkCancelFuzzTest(const uint8_t* data, size_t /* size */)
+ {
+ auto[res, pipe, interface] = UsbMgrPrepareFuzzEnv();
+ if (!res) {
+ USB_HILOGE(MODULE_USB_SERVICE, "prepare error");
+ return false;
+ }
+
+ auto& usbSrvClient = UsbSrvClient::GetInstance();
+ sptr cb = new UsbCallbackTest();
+ USBEndpoint point = interface.GetEndpoints().at(1);
+ auto ret = usbSrvClient.RegBulkCallback(pipe, point, cb);
+ if (ret != UEC_OK) {
+ USB_HILOGE(MODULE_USB_SERVICE, "RegBulkCallback failed ret=%{public}d", ret);
+ return false;
+ }
+
+ auto sharedMem = GetSharedMem();
+ if (sharedMem == nullptr) {
+ USB_HILOGE(MODULE_USB_SERVICE, "GetSharedMem failed ret=%{public}d", ret);
+ return false;
+ }
+
+ ret = usbSrvClient.BulkWrite(pipe, point, sharedMem);
+ if (ret != UEC_OK) {
+ USB_HILOGE(MODULE_USB_SERVICE, "BulkWrite failed ret=%{public}d", ret);
+ return false;
+ }
+
+ if (usbSrvClient.BulkCancel(reinterpret_cast(data),
+ reinterpret_cast(data)) == UEC_OK) {
+ return false;
+ }
+ return true;
+ }
+} // USB
+} // OHOS
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::USB::UsbMgrBulkCancelFuzzTest(data, size);
+ return 0;
+}
diff --git a/test/fuzztest/usbmgrbulkcancel_fuzzer/usbmgrbulkcancel_fuzzer.h b/test/fuzztest/usbmgrbulkcancel_fuzzer/usbmgrbulkcancel_fuzzer.h
new file mode 100644
index 0000000..f03f7d1
--- /dev/null
+++ b/test/fuzztest/usbmgrbulkcancel_fuzzer/usbmgrbulkcancel_fuzzer.h
@@ -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 USBMGRBULKCANCEL_FUZZER_H
+#define USBMGRBULKCANCEL_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "usbmgrbulkcancel_fuzzer"
+
+#endif // USBMGRBULKCANCEL_FUZZER_H
diff --git a/test/fuzztest/usbmgrbulkread_fuzzer/corpus/init b/test/fuzztest/usbmgrbulkread_fuzzer/corpus/init
new file mode 100644
index 0000000..bc977bd
--- /dev/null
+++ b/test/fuzztest/usbmgrbulkread_fuzzer/corpus/init
@@ -0,0 +1,14 @@
+# 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
\ No newline at end of file
diff --git a/test/fuzztest/usbmgrbulkread_fuzzer/project.xml b/test/fuzztest/usbmgrbulkread_fuzzer/project.xml
new file mode 100644
index 0000000..6e8ad2c
--- /dev/null
+++ b/test/fuzztest/usbmgrbulkread_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/test/fuzztest/usbmgrbulkread_fuzzer/usbmgrbulkread_fuzzer.cpp b/test/fuzztest/usbmgrbulkread_fuzzer/usbmgrbulkread_fuzzer.cpp
new file mode 100644
index 0000000..6da64d1
--- /dev/null
+++ b/test/fuzztest/usbmgrbulkread_fuzzer/usbmgrbulkread_fuzzer.cpp
@@ -0,0 +1,57 @@
+/*
+ * 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 "usbmgrbulkread_fuzzer.h"
+
+#include "iremote_object.h"
+#include "usb_errors.h"
+#include "usb_callback_test.h"
+#include "usb_common_fuzz.h"
+
+namespace OHOS {
+namespace USB {
+ bool UsbMgrBulkReadFuzzTest(const uint8_t* data, size_t /* size */)
+ {
+ auto[res, pipe, interface] = UsbMgrPrepareFuzzEnv();
+ if (!res) {
+ USB_HILOGE(MODULE_USB_SERVICE, "prepare error");
+ return false;
+ }
+
+ auto& usbSrvClient = UsbSrvClient::GetInstance();
+ sptr cb = new UsbCallbackTest();
+ auto ret = usbSrvClient.RegBulkCallback(pipe, interface.GetEndpoints().at(1), cb);
+ if (ret != UEC_OK) {
+ USB_HILOGE(MODULE_USB_SERVICE, "RegBulkCallback failed ret=%{public}d", ret);
+ return false;
+ }
+
+ if (usbSrvClient.BulkRead(reinterpret_cast(data),
+ reinterpret_cast(data), reinterpret_cast&>(data)) == UEC_OK) {
+ return false;
+ }
+ return true;
+ }
+} // USB
+} // OHOS
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::USB::UsbMgrBulkReadFuzzTest(data, size);
+ return 0;
+}
+
diff --git a/test/fuzztest/usbmgrbulkread_fuzzer/usbmgrbulkread_fuzzer.h b/test/fuzztest/usbmgrbulkread_fuzzer/usbmgrbulkread_fuzzer.h
new file mode 100644
index 0000000..4f1233c
--- /dev/null
+++ b/test/fuzztest/usbmgrbulkread_fuzzer/usbmgrbulkread_fuzzer.h
@@ -0,0 +1,20 @@
+/*
+ * 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 USBMGRBULKREAD_FUZZER_H
+#define USBMGRBULKREAD_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "usbmgrbulkread_fuzzer"
+
+#endif // USBMGRBULKREAD_FUZZER_H
diff --git a/test/fuzztest/usbmgrbulkwrite_fuzzer/corpus/init b/test/fuzztest/usbmgrbulkwrite_fuzzer/corpus/init
new file mode 100644
index 0000000..bc977bd
--- /dev/null
+++ b/test/fuzztest/usbmgrbulkwrite_fuzzer/corpus/init
@@ -0,0 +1,14 @@
+# 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
\ No newline at end of file
diff --git a/test/fuzztest/usbmgrbulkwrite_fuzzer/project.xml b/test/fuzztest/usbmgrbulkwrite_fuzzer/project.xml
new file mode 100644
index 0000000..6e8ad2c
--- /dev/null
+++ b/test/fuzztest/usbmgrbulkwrite_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/test/fuzztest/usbmgrbulkwrite_fuzzer/usbmgrbulkwrite_fuzzer.cpp b/test/fuzztest/usbmgrbulkwrite_fuzzer/usbmgrbulkwrite_fuzzer.cpp
new file mode 100644
index 0000000..c903502
--- /dev/null
+++ b/test/fuzztest/usbmgrbulkwrite_fuzzer/usbmgrbulkwrite_fuzzer.cpp
@@ -0,0 +1,57 @@
+/*
+ * 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 "usbmgrbulkwrite_fuzzer.h"
+
+#include "iremote_object.h"
+#include "usb_errors.h"
+#include "usb_callback_test.h"
+#include "usb_common_fuzz.h"
+
+namespace OHOS {
+namespace USB {
+ bool UsbMgrBulkWriteFuzzTest(const uint8_t* data, size_t /* size */)
+ {
+ auto[res, pipe, interface] = UsbMgrPrepareFuzzEnv();
+ if (!res) {
+ USB_HILOGE(MODULE_USB_SERVICE, "prepare error");
+ return false;
+ }
+
+ auto& usbSrvClient = UsbSrvClient::GetInstance();
+ sptr cb = new UsbCallbackTest();
+ auto ret = usbSrvClient.RegBulkCallback(pipe, interface.GetEndpoints().at(1), cb);
+ if (ret != UEC_OK) {
+ USB_HILOGE(MODULE_USB_SERVICE, "RegBulkCallback failed ret=%{public}d", ret);
+ return false;
+ }
+
+ if (usbSrvClient.BulkWrite(reinterpret_cast(data),
+ reinterpret_cast(data), reinterpret_cast&>(data)) == UEC_OK) {
+ return false;
+ }
+ return true;
+ }
+} // USB
+} // OHOS
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::USB::UsbMgrBulkWriteFuzzTest(data, size);
+ return 0;
+}
+
diff --git a/test/fuzztest/usbmgrbulkwrite_fuzzer/usbmgrbulkwrite_fuzzer.h b/test/fuzztest/usbmgrbulkwrite_fuzzer/usbmgrbulkwrite_fuzzer.h
new file mode 100644
index 0000000..a3b9257
--- /dev/null
+++ b/test/fuzztest/usbmgrbulkwrite_fuzzer/usbmgrbulkwrite_fuzzer.h
@@ -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 USBMGRBULKWRITE_FUZZER_H
+#define USBMGRBULKWRITE_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "usbmgrbulkwrite_fuzzer"
+
+#endif // USBMGRBULKWRITE_FUZZER_H
diff --git a/test/fuzztest/usbmgrsetconfiguration_fuzzer/corpus/init b/test/fuzztest/usbmgrsetconfiguration_fuzzer/corpus/init
new file mode 100644
index 0000000..bc977bd
--- /dev/null
+++ b/test/fuzztest/usbmgrsetconfiguration_fuzzer/corpus/init
@@ -0,0 +1,14 @@
+# 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
\ No newline at end of file
diff --git a/test/fuzztest/usbmgrsetconfiguration_fuzzer/project.xml b/test/fuzztest/usbmgrsetconfiguration_fuzzer/project.xml
new file mode 100644
index 0000000..6e8ad2c
--- /dev/null
+++ b/test/fuzztest/usbmgrsetconfiguration_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/test/fuzztest/usbmgrsetconfiguration_fuzzer/usbmgrsetconfiguration_fuzzer.cpp b/test/fuzztest/usbmgrsetconfiguration_fuzzer/usbmgrsetconfiguration_fuzzer.cpp
new file mode 100644
index 0000000..e5fe39d
--- /dev/null
+++ b/test/fuzztest/usbmgrsetconfiguration_fuzzer/usbmgrsetconfiguration_fuzzer.cpp
@@ -0,0 +1,58 @@
+/*
+ * 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 "usbmgrsetconfiguration_fuzzer.h"
+
+#include "usb_srv_client.h"
+#include "usb_errors.h"
+
+namespace OHOS {
+namespace USB {
+ bool UsbMgrSetConfigurationFuzzTest(const uint8_t* data, size_t /* size */)
+ {
+ std::vector devList;
+ auto &usbSrvClient = UsbSrvClient::GetInstance();
+ auto ret = usbSrvClient.GetDevices(devList);
+ if (ret != UEC_OK || devList.empty()) {
+ USB_HILOGE(MODULE_USB_SERVICE, "get devices failed ret=%{public}d", ret);
+ return false;
+ }
+
+ USBDevicePipe pipe;
+ UsbDevice device = devList.front();
+ usbSrvClient.RequestRight(device.GetName());
+ ret = usbSrvClient.OpenDevice(device, pipe);
+ if (ret != UEC_OK) {
+ USB_HILOGE(MODULE_USB_SERVICE, "open device failed ret=%{public}d", ret);
+ return false;
+ }
+
+ if (usbSrvClient.SetConfiguration(reinterpret_cast(data),
+ reinterpret_cast(data)) == UEC_OK) {
+ return false;
+ }
+ return true;
+ }
+} // USB
+} // OHOS
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::USB::UsbMgrSetConfigurationFuzzTest(data, size);
+ return 0;
+}
+
diff --git a/test/fuzztest/usbmgrsetconfiguration_fuzzer/usbmgrsetconfiguration_fuzzer.h b/test/fuzztest/usbmgrsetconfiguration_fuzzer/usbmgrsetconfiguration_fuzzer.h
new file mode 100644
index 0000000..0ba2b87
--- /dev/null
+++ b/test/fuzztest/usbmgrsetconfiguration_fuzzer/usbmgrsetconfiguration_fuzzer.h
@@ -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 USBMGRSETCONFIGURATION_FUZZER_H
+#define USBMGRSETCONFIGURATION_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "usbmgrsetconfiguration_fuzzer"
+
+#endif // USBMGRSETCONFIGURATION_FUZZER_H
diff --git a/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer/corpus/init b/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer/corpus/init
new file mode 100644
index 0000000..bc977bd
--- /dev/null
+++ b/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer/corpus/init
@@ -0,0 +1,14 @@
+# 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
\ No newline at end of file
diff --git a/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer/project.xml b/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer/project.xml
new file mode 100644
index 0000000..6e8ad2c
--- /dev/null
+++ b/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer/usbmgrsetcurrentfunctions_fuzzer.cpp b/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer/usbmgrsetcurrentfunctions_fuzzer.cpp
new file mode 100644
index 0000000..91c4023
--- /dev/null
+++ b/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer/usbmgrsetcurrentfunctions_fuzzer.cpp
@@ -0,0 +1,50 @@
+/*
+ * 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 "usbmgrsetcurrentfunctions_fuzzer.h"
+
+#include "usb_srv_client.h"
+#include "usb_errors.h"
+
+namespace {
+ const int32_t MAX_FUNC_NUM = 6;
+}
+
+namespace OHOS {
+namespace USB {
+ bool UsbMgrSetCurrentFunctionsFuzzTest(const uint8_t* data, size_t /* size */)
+ {
+ auto &usbSrvClient = UsbSrvClient::GetInstance();
+ int32_t func = reinterpret_cast(data);
+ if (func <= MAX_FUNC_NUM) {
+ func += MAX_FUNC_NUM;
+ }
+
+ if (usbSrvClient.SetCurrentFunctions(func) == UEC_OK) {
+ return false;
+ }
+ return true;
+ }
+} // USB
+} // OHOS
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::USB::UsbMgrSetCurrentFunctionsFuzzTest(data, size);
+ return 0;
+}
+
diff --git a/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer/usbmgrsetcurrentfunctions_fuzzer.h b/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer/usbmgrsetcurrentfunctions_fuzzer.h
new file mode 100644
index 0000000..c10fc1a
--- /dev/null
+++ b/test/fuzztest/usbmgrsetcurrentfunctions_fuzzer/usbmgrsetcurrentfunctions_fuzzer.h
@@ -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 USBMGRSETCURRENTFUNCTIONS_FUZZER_H
+#define USBMGRSETCURRENTFUNCTIONS_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "usbmgrsetcurrentfunctions_fuzzer"
+
+#endif // USBMGRSETCURRENTFUNCTIONS_FUZZER_H
diff --git a/test/fuzztest/usbmgrsetinterface_fuzzer/corpus/init b/test/fuzztest/usbmgrsetinterface_fuzzer/corpus/init
new file mode 100644
index 0000000..bc977bd
--- /dev/null
+++ b/test/fuzztest/usbmgrsetinterface_fuzzer/corpus/init
@@ -0,0 +1,14 @@
+# 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
\ No newline at end of file
diff --git a/test/fuzztest/usbmgrsetinterface_fuzzer/project.xml b/test/fuzztest/usbmgrsetinterface_fuzzer/project.xml
new file mode 100644
index 0000000..6e8ad2c
--- /dev/null
+++ b/test/fuzztest/usbmgrsetinterface_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/test/fuzztest/usbmgrsetinterface_fuzzer/usbmgrsetinterface_fuzzer.cpp b/test/fuzztest/usbmgrsetinterface_fuzzer/usbmgrsetinterface_fuzzer.cpp
new file mode 100644
index 0000000..fae6c5e
--- /dev/null
+++ b/test/fuzztest/usbmgrsetinterface_fuzzer/usbmgrsetinterface_fuzzer.cpp
@@ -0,0 +1,65 @@
+/*
+ * 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 "usbmgrsetinterface_fuzzer.h"
+
+#include "usb_srv_client.h"
+#include "usb_errors.h"
+
+namespace OHOS {
+namespace USB {
+ bool UsbMgrSetInterfaceFuzzTest(const uint8_t* data, size_t /* size */)
+ {
+ std::vector devList;
+ auto &usbSrvClient = UsbSrvClient::GetInstance();
+ auto ret = usbSrvClient.GetDevices(devList);
+ if (ret != UEC_OK || devList.empty()) {
+ USB_HILOGE(MODULE_USB_SERVICE, "get devices failed ret=%{public}d", ret);
+ return false;
+ }
+
+ USBDevicePipe pipe;
+ UsbDevice device = devList.front();
+ usbSrvClient.RequestRight(device.GetName());
+ ret = usbSrvClient.OpenDevice(device, pipe);
+ if (ret != UEC_OK) {
+ USB_HILOGE(MODULE_USB_SERVICE, "open device failed ret=%{public}d", ret);
+ return false;
+ }
+
+ UsbInterface interface = devList.front().GetConfigs().front().GetInterfaces().front();
+ ret = usbSrvClient.ClaimInterface(pipe, interface, true);
+ if (ret != UEC_OK) {
+ USB_HILOGE(MODULE_USB_SERVICE, "ClaimInterface failed ret=%{public}d", ret);
+ return false;
+ }
+
+ if (usbSrvClient.SetInterface(reinterpret_cast(data),
+ reinterpret_cast(data)) == UEC_OK) {
+ return false;
+ }
+ return true;
+ }
+} // USB
+} // OHOS
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::USB::UsbMgrSetInterfaceFuzzTest(data, size);
+ return 0;
+}
+
diff --git a/test/fuzztest/usbmgrsetinterface_fuzzer/usbmgrsetinterface_fuzzer.h b/test/fuzztest/usbmgrsetinterface_fuzzer/usbmgrsetinterface_fuzzer.h
new file mode 100644
index 0000000..b6095e8
--- /dev/null
+++ b/test/fuzztest/usbmgrsetinterface_fuzzer/usbmgrsetinterface_fuzzer.h
@@ -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 USBMGRSETINTERFACE_FUZZER_H
+#define USBMGRSETINTERFACE_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "usbmgrsetinterface_fuzzer"
+
+#endif // USBMGRSETINTERFACE_FUZZER_H
diff --git a/test/fuzztest/usbmgrsetportrole_fuzzer/corpus/init b/test/fuzztest/usbmgrsetportrole_fuzzer/corpus/init
new file mode 100644
index 0000000..bc977bd
--- /dev/null
+++ b/test/fuzztest/usbmgrsetportrole_fuzzer/corpus/init
@@ -0,0 +1,14 @@
+# 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
\ No newline at end of file
diff --git a/test/fuzztest/usbmgrsetportrole_fuzzer/project.xml b/test/fuzztest/usbmgrsetportrole_fuzzer/project.xml
new file mode 100644
index 0000000..6e8ad2c
--- /dev/null
+++ b/test/fuzztest/usbmgrsetportrole_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 1000
+
+ 300
+
+ 4096
+
+
diff --git a/test/fuzztest/usbmgrsetportrole_fuzzer/usbmgrsetportrole_fuzzer.cpp b/test/fuzztest/usbmgrsetportrole_fuzzer/usbmgrsetportrole_fuzzer.cpp
new file mode 100644
index 0000000..3368a37
--- /dev/null
+++ b/test/fuzztest/usbmgrsetportrole_fuzzer/usbmgrsetportrole_fuzzer.cpp
@@ -0,0 +1,42 @@
+/*
+ * 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 "usbmgrsetportrole_fuzzer.h"
+
+#include "usb_srv_client.h"
+#include "usb_errors.h"
+
+namespace OHOS {
+namespace USB {
+ bool UsbMgrSetPortRoleFuzzTest(const uint8_t* data, size_t /* size */)
+ {
+ auto &usbSrvClient = UsbSrvClient::GetInstance();
+ if (usbSrvClient.SetPortRole(reinterpret_cast(data), reinterpret_cast(data),
+ reinterpret_cast(data)) == UEC_OK) {
+ return false;
+ }
+ return true;
+ }
+} // USB
+} // OHOS
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::USB::UsbMgrSetPortRoleFuzzTest(data, size);
+ return 0;
+}
+
diff --git a/test/fuzztest/usbmgrsetportrole_fuzzer/usbmgrsetportrole_fuzzer.h b/test/fuzztest/usbmgrsetportrole_fuzzer/usbmgrsetportrole_fuzzer.h
new file mode 100644
index 0000000..c8f1e66
--- /dev/null
+++ b/test/fuzztest/usbmgrsetportrole_fuzzer/usbmgrsetportrole_fuzzer.h
@@ -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 USBMGRSETPORTROLE_FUZZER_H
+#define USBMGRSETPORTROLE_FUZZER_H
+
+#define FUZZ_PROJECT_NAME "usbmgrsetportrole_fuzzer"
+
+#endif // USBMGRSETPORTROLE_FUZZER_H