diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index d6d3d2c..7f8f4a2 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -15,10 +15,16 @@ group("fuzztest") { testonly = true deps = [ - "dcamerasinkhandleripc_fuzzer:fuzztest", - "dcamerasinkloadcallback_fuzzer:fuzztest", - "dcamerasinkproxy_fuzzer:fuzztest", - "dcamerasourcehandleripc_fuzzer:fuzztest", - "dcamerasourceloadcallback_fuzzer:fuzztest", + "onsourcelocaldmsdied_fuzzer:fuzztest", + "sourcehandlerconfigdistributedhardware_fuzzer:fuzztest", + "sourcehandlerinitsource_fuzzer:fuzztest", + "sourcehandlerregisterdistributedhardware_fuzzer:fuzztest", + "sourcehandlerunregisterdistributedhardware_fuzzer:fuzztest", + "sourceonloadsystemabilityfail_fuzzer:fuzztest", + "sourceonloadsystemabilitysuccess_fuzzer:fuzztest", + "sourceproxydcameranotify_fuzzer:fuzztest", + "sourceproxyinitsource_fuzzer:fuzztest", + "sourceproxyregisterdistributedhardware_fuzzer:fuzztest", + "sourceproxyunregisterdistributedhardware_fuzzer:fuzztest", ] } diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/BUILD.gn similarity index 85% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/BUILD.gn rename to interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/BUILD.gn index 8243642..6d9d072 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/BUILD.gn @@ -18,10 +18,11 @@ import( "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") ##############################fuzztest########################################## -ohos_fuzztest("DCameraSourceHandlerIpcFuzzTest") { - module_out_path = "distributed_camera/dcamerasourcehandleripc" +ohos_fuzztest("OnSourceLocalDmsDiedFuzzTest") { + module_out_path = "distributed_camera/onsourcelocaldmsdied" - fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer" + fuzz_config_file = + "${innerkits_path}/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer" include_dirs = [ "//utils/system/safwk/native/include", @@ -45,7 +46,7 @@ ohos_fuzztest("DCameraSourceHandlerIpcFuzzTest") { "-fno-omit-frame-pointer", ] - sources = [ "dcamera_source_handler_ipc_fuzzer.cpp" ] + sources = [ "onsourcelocaldmsdied_fuzzer.cpp" ] deps = [ "${fwk_utils_path}:distributedhardwareutils", @@ -55,7 +56,7 @@ ohos_fuzztest("DCameraSourceHandlerIpcFuzzTest") { defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DCameraSourceHandlerIpcFuzzTest\"", + "DH_LOG_TAG=\"OnSourceLocalDmsDiedFuzzTest\"", "LOG_DOMAIN=0xD004100", ] @@ -71,6 +72,6 @@ ohos_fuzztest("DCameraSourceHandlerIpcFuzzTest") { ############################################################################### group("fuzztest") { testonly = true - deps = [ ":DCameraSourceHandlerIpcFuzzTest" ] + deps = [ ":OnSourceLocalDmsDiedFuzzTest" ] } ############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/corpus/init similarity index 100% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/corpus/init rename to interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/corpus/init diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/dcamera_source_handler_ipc_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/onsourcelocaldmsdied_fuzzer.cpp similarity index 74% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/dcamera_source_handler_ipc_fuzzer.cpp rename to interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/onsourcelocaldmsdied_fuzzer.cpp index 471e321..11ab8dc 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/dcamera_source_handler_ipc_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/onsourcelocaldmsdied_fuzzer.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "dcamera_source_handler_ipc_fuzzer.h" +#include "onsourcelocaldmsdied_fuzzer.h" #include #include @@ -26,21 +26,19 @@ namespace OHOS { namespace DistributedHardware { -void DCameraSourceHandlerIpcFuzzTest(const uint8_t* data, size_t size) +void OnSourceLocalDmsDiedFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size <= 0)) { return; } + int32_t saId = *(reinterpret_cast(data)); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); + sptr remoteObject = samgr->GetSystemAbility(saId); wptr remote (remoteObject); - DCameraSourceHandlerIpc::GetInstance().Init(); - DCameraSourceHandlerIpc::GetInstance().GetSourceLocalDHMS(); DCameraSourceHandlerIpc::GetInstance().OnSourceLocalDmsDied(remote); - DCameraSourceHandlerIpc::GetInstance().UnInit(); } } } @@ -49,6 +47,6 @@ void DCameraSourceHandlerIpcFuzzTest(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::DistributedHardware::DCameraSourceHandlerIpcFuzzTest(data, size); + OHOS::DistributedHardware::OnSourceLocalDmsDiedFuzzTest(data, size); return 0; } \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/dcamera_sink_proxy_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/onsourcelocaldmsdied_fuzzer.h similarity index 82% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/dcamera_sink_proxy_fuzzer.h rename to interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/onsourcelocaldmsdied_fuzzer.h index 2b956a3..a8fe409 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/dcamera_sink_proxy_fuzzer.h +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/onsourcelocaldmsdied_fuzzer.h @@ -13,9 +13,9 @@ * limitations under the License. */ -#ifndef DCAMERA_SINK_PROXY_FUZZER_H -#define DCAMERA_SINK_PROXY_FUZZER_H +#ifndef ONSOURCELOCALDMSDIED_FUZZER_H +#define ONSOURCELOCALDMSDIED_FUZZER_H -#define FUZZ_PROJECT_NAME "dcamera_sink_proxy_fuzzer" +#define FUZZ_PROJECT_NAME "onsourcelocaldmsdied_fuzzer" #endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/project.xml similarity index 100% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/project.xml rename to interfaces/inner_kits/native_cpp/test/fuzztest/onsourcelocaldmsdied_fuzzer/project.xml diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000..28b35b0 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,75 @@ +# 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/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceHandlerConfigDistributedHardwareFuzzTest") { + module_out_path = "distributed_camera/sourcehandlerconfigdistributedhardware" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_source/include", + "${innerkits_path}/native_cpp/camera_source/include/callback", + "${fwk_services_path}/distributedhardwarefwkserviceimpl/include/componentmanager", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "sourcehandlerconfigdistributedhardware_fuzzer.cpp" ] + + deps = [ + "${fwk_services_path}/distributedhardwarefwkserviceimpl/:distributedhardwarefwksvr_impl", + "${fwk_utils_path}:distributedhardwareutils", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceHandlerConfigDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceHandlerConfigDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/corpus/init similarity index 100% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/corpus/init rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/corpus/init diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/project.xml similarity index 100% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/project.xml rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/project.xml diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/sourcehandlerconfigdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/sourcehandlerconfigdistributedhardware_fuzzer.cpp new file mode 100644 index 0000000..4691183 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/sourcehandlerconfigdistributedhardware_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * 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 "sourcehandlerconfigdistributedhardware_fuzzer.h" + +#include +#include + +#include "dcamera_source_handler.h" +#include "distributed_camera_constants.h" +#include "component_enable.h" +#include "component_disable.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "refbase.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceHandlerConfigDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < 0)) { + return; + } + std::string devId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string key(reinterpret_cast(data), size); + std::string value(reinterpret_cast(data), size); + + DCameraSourceHandler::GetInstance().ConfigDistributedHardware(devId, dhId, key, value); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceHandlerConfigDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/sourcehandlerconfigdistributedhardware_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/sourcehandlerconfigdistributedhardware_fuzzer.h new file mode 100644 index 0000000..198433a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerconfigdistributedhardware_fuzzer/sourcehandlerconfigdistributedhardware_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 SOURCEHANDLERCONFIGDISTRIBUTEDHARDWARE_FUZZER_H +#define SOURCEHANDLERCONFIGDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourcehandlerconfigdistributedhardware_fuzzer" + +#endif diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/BUILD.gn similarity index 69% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/BUILD.gn rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/BUILD.gn index 32b8530..1aced34 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/BUILD.gn @@ -18,18 +18,13 @@ import( "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") ##############################fuzztest########################################## -ohos_fuzztest("DCameraSinkHandlerIpcFuzzTest") { - module_out_path = "distributed_camera/dcamerasinkhandleripc" +ohos_fuzztest("SourceHandlerInitSourceFuzzTest") { + module_out_path = "distributed_camera/sourcehandlerinitsource" - fuzz_config_file = - "${innerkits_path}/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer" include_dirs = [ - "//utils/native/base/include", "//utils/system/safwk/native/include", - "${fwk_utils_path}/include/log", - "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", "${fwk_common_path}/utils/include", ] @@ -37,7 +32,9 @@ ohos_fuzztest("DCameraSinkHandlerIpcFuzzTest") { "include", "${common_path}/include", "${common_path}/include/constants", - "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_source/include", + "${innerkits_path}/native_cpp/camera_source/include/callback", + "${fwk_services_path}/distributedhardwarefwkserviceimpl/include/componentmanager", ] cflags = [ @@ -47,22 +44,22 @@ ohos_fuzztest("DCameraSinkHandlerIpcFuzzTest") { "-fno-omit-frame-pointer", ] - sources = [ "dcamera_sink_handler_ipc_fuzzer.cpp" ] + sources = [ "sourcehandlerinitsource_fuzzer.cpp" ] deps = [ + "${fwk_services_path}/distributedhardwarefwkserviceimpl/:distributedhardwarefwksvr_impl", "${fwk_utils_path}:distributedhardwareutils", - "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", "//utils/native/base:utils", ] defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DCameraSinkHandlerIpcFuzzTest\"", + "DH_LOG_TAG=\"SourceHandlerInitSourceFuzzTest\"", "LOG_DOMAIN=0xD004100", ] external_deps = [ - "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", @@ -73,6 +70,6 @@ ohos_fuzztest("DCameraSinkHandlerIpcFuzzTest") { ############################################################################### group("fuzztest") { testonly = true - deps = [ ":DCameraSinkHandlerIpcFuzzTest" ] + deps = [ ":SourceHandlerInitSourceFuzzTest" ] } ############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/corpus/init similarity index 100% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/corpus/init rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/corpus/init diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/project.xml similarity index 100% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/project.xml rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/project.xml diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/sourcehandlerinitsource_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/sourcehandlerinitsource_fuzzer.cpp new file mode 100644 index 0000000..1531b46 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/sourcehandlerinitsource_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 "sourcehandlerinitsource_fuzzer.h" + +#include +#include + +#include "dcamera_source_handler.h" +#include "distributed_camera_constants.h" +#include "component_enable.h" +#include "component_disable.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "refbase.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceHandlerInitSourceFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < 0)) { + return; + } + std::string params(reinterpret_cast(data), size); + + DCameraSourceHandler::GetInstance().InitSource(params); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceHandlerInitSourceFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/dcamera_sink_load_callback_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/sourcehandlerinitsource_fuzzer.h similarity index 80% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/dcamera_sink_load_callback_fuzzer.h rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/sourcehandlerinitsource_fuzzer.h index d79eee8..252a075 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/dcamera_sink_load_callback_fuzzer.h +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerinitsource_fuzzer/sourcehandlerinitsource_fuzzer.h @@ -13,10 +13,9 @@ * limitations under the License. */ -#ifndef DCAMERA_SINK_LOAD_CALLBACK_FUZZER_H -#define DCAMERA_SINK_LOAD_CALLBACK_FUZZER_H +#ifndef SOURCEHANDLERINITSOURCE_FUZZER_H +#define SOURCEHANDLERINITSOURCE_FUZZER_H -#define FUZZ_PROJECT_NAME "dcamera_sink_load_callback_fuzzer" +#define FUZZ_PROJECT_NAME "sourcehandlerinitsource_fuzzer" #endif - diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000..b100dc5 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# 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/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceHandlerRegisterDistributedHardwareFuzzTest") { + module_out_path = + "distributed_camera/sourcehandlerregisterdistributedhardware" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_source/include", + "${innerkits_path}/native_cpp/camera_source/include/callback", + "${fwk_services_path}/distributedhardwarefwkserviceimpl/include/componentmanager", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "sourcehandlerregisterdistributedhardware_fuzzer.cpp" ] + + deps = [ + "${fwk_services_path}/distributedhardwarefwkserviceimpl/:distributedhardwarefwksvr_impl", + "${fwk_utils_path}:distributedhardwareutils", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceHandlerRegisterDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceHandlerRegisterDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/corpus/init similarity index 100% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/corpus/init rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/corpus/init diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/project.xml similarity index 100% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/project.xml rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/project.xml diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_fuzzer.cpp new file mode 100644 index 0000000..69c4693 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_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 "sourcehandlerregisterdistributedhardware_fuzzer.h" + +#include +#include + +#include "dcamera_source_handler.h" +#include "distributed_camera_constants.h" +#include "component_enable.h" +#include "component_disable.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "refbase.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceHandlerRegisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < 0)) { + return; + } + std::string devId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string version(reinterpret_cast(data), size); + std::string attrs(reinterpret_cast(data), size); + EnableParam param; + param.version = version; + param.attrs = attrs; + std::shared_ptr callback = std::make_shared(); + + DCameraSourceHandler::GetInstance().RegisterDistributedHardware(devId, dhId, param, callback); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceHandlerRegisterDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_fuzzer.h new file mode 100644 index 0000000..87355db --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerregisterdistributedhardware_fuzzer/sourcehandlerregisterdistributedhardware_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 SOURCEHANDLERREGITSERDISTRIBUTEDHARDWARE_FUZZER_H +#define SOURCEHANDLERREGITSERDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourcehandlerregisterdistributedhardware_fuzzer " + +#endif diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000..2b106da --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# 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/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceHandlerUnregisterDistributedHardwareFuzzTest") { + module_out_path = + "distributed_camera/sourcehandlerunregisterdistributedhardware" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_source/include", + "${innerkits_path}/native_cpp/camera_source/include/callback", + "${fwk_services_path}/distributedhardwarefwkserviceimpl/include/componentmanager", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "sourcehandlerunregisterdistributedhardware_fuzzer.cpp" ] + + deps = [ + "${fwk_services_path}/distributedhardwarefwkserviceimpl/:distributedhardwarefwksvr_impl", + "${fwk_utils_path}:distributedhardwareutils", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceHandlerUnregisterDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceHandlerUnregisterDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/corpus/init similarity index 100% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/corpus/init rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/corpus/init diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/project.xml similarity index 100% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/project.xml rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/project.xml diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_fuzzer.cpp new file mode 100644 index 0000000..e9fa52c --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * 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 "sourcehandlerunregisterdistributedhardware_fuzzer.h" + +#include +#include + +#include "dcamera_source_handler.h" +#include "distributed_camera_constants.h" +#include "component_enable.h" +#include "component_disable.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "refbase.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceHandlerUnregisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < 0)) { + return; + } + std::string devId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::shared_ptr uncallback = std::make_shared(); + + DCameraSourceHandler::GetInstance().UnregisterDistributedHardware(devId, dhId, uncallback); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceHandlerUnregisterDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_fuzzer.h new file mode 100644 index 0000000..f0b673a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourcehandlerunregisterdistributedhardware_fuzzer/sourcehandlerunregisterdistributedhardware_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 SOURCEHANDLERUNREGITSERDISTRIBUTEDHARDWARE_FUZZER_H +#define SOURCEHANDLERUNREGITSERDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourcehandlerunregisterdistributedhardware_fuzzer " + +#endif diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/BUILD.gn similarity index 85% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/BUILD.gn rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/BUILD.gn index 972f3cb..5f68d8a 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/BUILD.gn @@ -18,10 +18,10 @@ import( "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") ##############################fuzztest########################################## -ohos_fuzztest("DCameraSourceLoadCallbackFuzzTest") { - module_out_path = "distributed_camera/dcamerasourceloadcallback" +ohos_fuzztest("SourceOnLoadSystemAbilityFailFuzzTest") { + module_out_path = "distributed_camera/sourceonloadsystemabilityfail" - fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer" include_dirs = [ "//utils/system/safwk/native/include", @@ -43,7 +43,7 @@ ohos_fuzztest("DCameraSourceLoadCallbackFuzzTest") { "-fno-omit-frame-pointer", ] - sources = [ "dcamera_source_load_callback_fuzzer.cpp" ] + sources = [ "sourceonloadsystemabilityfail_fuzzer.cpp" ] deps = [ "${fwk_utils_path}:distributedhardwareutils", @@ -53,7 +53,7 @@ ohos_fuzztest("DCameraSourceLoadCallbackFuzzTest") { defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DCameraSourceLoadCallbackFuzzTest\"", + "DH_LOG_TAG=\"SourceOnLoadSystemAbilityFailFuzzTest\"", "LOG_DOMAIN=0xD004100", ] @@ -68,6 +68,6 @@ ohos_fuzztest("DCameraSourceLoadCallbackFuzzTest") { ############################################################################### group("fuzztest") { testonly = true - deps = [ ":DCameraSourceLoadCallbackFuzzTest" ] + deps = [ ":SourceOnLoadSystemAbilityFailFuzzTest" ] } ############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_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/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/dcamera_sink_load_callback_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/sourceonloadsystemabilityfail_fuzzer.cpp similarity index 64% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/dcamera_sink_load_callback_fuzzer.cpp rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/sourceonloadsystemabilityfail_fuzzer.cpp index fa97f98..9831500 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/dcamera_sink_load_callback_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/sourceonloadsystemabilityfail_fuzzer.cpp @@ -13,33 +13,28 @@ * limitations under the License. */ -#include "dcamera_sink_load_callback_fuzzer.h" +#include "sourceonloadsystemabilityfail_fuzzer.h" #include #include -#include "dcamera_sink_load_callback.h" -#include "dcamera_sink_handler.h" +#include "dcamera_source_load_callback.h" +#include "dcamera_source_handler.h" #include "distributed_camera_constants.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { -void DCameraSinkLoadCallbackFuzzTest(const uint8_t* data, size_t size) +void SourceOnLoadSystemAbilityFailFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < (sizeof(int32_t)))) { return; } int32_t systemAbilityId = *(reinterpret_cast(data)); std::string params(reinterpret_cast(data), size); - std::shared_ptr callback = std::make_shared(params); + std::shared_ptr callback = std::make_shared(params); - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); - - callback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); callback->OnLoadSystemAbilityFail(systemAbilityId); } } @@ -49,6 +44,6 @@ void DCameraSinkLoadCallbackFuzzTest(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::DistributedHardware::DCameraSinkLoadCallbackFuzzTest(data, size); + OHOS::DistributedHardware::SourceOnLoadSystemAbilityFailFuzzTest(data, size); return 0; } \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/sourceonloadsystemabilityfail_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/sourceonloadsystemabilityfail_fuzzer.h new file mode 100644 index 0000000..4704f31 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilityfail_fuzzer/sourceonloadsystemabilityfail_fuzzer.h @@ -0,0 +1,22 @@ +/* + * 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 SOURCEONLOADSYSTEMABLITYFAIL_FUZZER_H +#define SOURCEONLOADSYSTEMABLITYFAIL_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceonloadsystemabilityfail_fuzzer" + +#endif + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/BUILD.gn similarity index 75% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/BUILD.gn rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/BUILD.gn index 3b9dd8c..3312c6e 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/BUILD.gn @@ -18,13 +18,14 @@ import( "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") ##############################fuzztest########################################## -ohos_fuzztest("DCameraSinkLoadCallbackFuzzTest") { - module_out_path = "distributed_camera/dcamerasinkloadcallback" +ohos_fuzztest("SourceOnLoadSystemAbilitySuccessFuzzTest") { + module_out_path = "distributed_camera/sourceonloadsystemabilitysuccess" - fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/dcamerasinkloadcallback_fuzzer" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer" include_dirs = [ "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/camera_source/include/callback", "${fwk_common_path}/utils/include", ] @@ -32,7 +33,7 @@ ohos_fuzztest("DCameraSinkLoadCallbackFuzzTest") { "include", "${common_path}/include", "${common_path}/include/constants", - "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_source/include", ] cflags = [ @@ -42,17 +43,17 @@ ohos_fuzztest("DCameraSinkLoadCallbackFuzzTest") { "-fno-omit-frame-pointer", ] - sources = [ "dcamera_sink_load_callback_fuzzer.cpp" ] + sources = [ "sourceonloadsystemabilitysuccess_fuzzer.cpp" ] deps = [ "${fwk_utils_path}:distributedhardwareutils", - "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", "//utils/native/base:utils", ] defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DCameraSinkLoadCallbackFuzzTest\"", + "DH_LOG_TAG=\"SourceOnLoadSystemAbilitySuccessFuzzTest\"", "LOG_DOMAIN=0xD004100", ] @@ -67,6 +68,6 @@ ohos_fuzztest("DCameraSinkLoadCallbackFuzzTest") { ############################################################################### group("fuzztest") { testonly = true - deps = [ ":DCameraSinkLoadCallbackFuzzTest" ] + deps = [ ":SourceOnLoadSystemAbilitySuccessFuzzTest" ] } ############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_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/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/dcamera_source_load_callback_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/sourceonloadsystemabilitysuccess_fuzzer.cpp similarity index 81% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/dcamera_source_load_callback_fuzzer.cpp rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/sourceonloadsystemabilitysuccess_fuzzer.cpp index ad4ef5a..90201f9 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/dcamera_source_load_callback_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/sourceonloadsystemabilitysuccess_fuzzer.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "dcamera_source_load_callback_fuzzer.h" +#include "sourceonloadsystemabilitysuccess_fuzzer.h" #include #include @@ -26,7 +26,7 @@ namespace OHOS { namespace DistributedHardware { -void DCameraSourceLoadCallbackFuzzTest(const uint8_t* data, size_t size) +void SourceOnLoadSystemAbilitySuccessFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < (sizeof(int32_t)))) { return; @@ -37,10 +37,9 @@ void DCameraSourceLoadCallbackFuzzTest(const uint8_t* data, size_t size) sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); + sptr remoteObject = samgr->GetSystemAbility(systemAbilityId); callback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); - callback->OnLoadSystemAbilityFail(systemAbilityId); } } } @@ -49,7 +48,6 @@ void DCameraSourceLoadCallbackFuzzTest(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::DistributedHardware::DCameraSourceLoadCallbackFuzzTest(data, size); + OHOS::DistributedHardware::SourceOnLoadSystemAbilitySuccessFuzzTest(data, size); return 0; -} - +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/sourceonloadsystemabilitysuccess_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/sourceonloadsystemabilitysuccess_fuzzer.h new file mode 100644 index 0000000..3e35dfd --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceonloadsystemabilitysuccess_fuzzer/sourceonloadsystemabilitysuccess_fuzzer.h @@ -0,0 +1,22 @@ +/* + * 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 SOURCEONLOADSYSTEMABLITYSUCESS_FUZZER_H +#define SOURCEONLOADSYSTEMABLITYSUCESS_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceonloadsystemabilitysuccess_fuzzer" + +#endif + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/BUILD.gn new file mode 100644 index 0000000..f987401 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/BUILD.gn @@ -0,0 +1,73 @@ +# 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/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceProxyDCameraNotifyFuzzTest") { + module_out_path = "distributed_camera/sourceproxydcameranotify" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/camera_source/include/callback", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_source/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "sourceproxydcameranotify_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceProxyDCameraNotifyFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceProxyDCameraNotifyFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_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/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/dcamera_sink_proxy_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp similarity index 55% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/dcamera_sink_proxy_fuzzer.cpp rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp index 85395ac..8015efd 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/dcamera_sink_proxy_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.cpp @@ -13,47 +13,40 @@ * limitations under the License. */ -#include "dcamera_sink_proxy_fuzzer.h" - -#include -#include +#include "sourceproxydcameranotify_fuzzer.h" +#include "dcamera_source_callback.h" #include "distributed_camera_constants.h" -#include "distributed_camera_sink_proxy.h" +#include "distributed_camera_source_proxy.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { -void DCameraSinkProxyFuzzTest(const uint8_t* data, size_t size) +void SourceProxyDCameraNotifyFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size <= 0)) { return; } - std::string param(reinterpret_cast(data), size); std::string dhId(reinterpret_cast(data), size); std::string params(reinterpret_cast(data), size); std::string devId(reinterpret_cast(data), size); - std::string channelInfo(reinterpret_cast(data), size); - std::string cameraInfo(reinterpret_cast(data), size); - std::string openInfo(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + std::string events(reinterpret_cast(data), size); + std::string version(reinterpret_cast(data), size); + std::string attrs(reinterpret_cast(data), size); + EnableParam param; + param.version = version; + param.attrs = attrs; sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); - std::shared_ptr dCSinkProxy = - std::make_shared(remoteObject); - - dCSinkProxy->InitSink(param); - dCSinkProxy->SubscribeLocalHardware(dhId, params); - dCSinkProxy->ChannelNeg(dhId, channelInfo); - dCSinkProxy->GetCameraInfo(dhId, cameraInfo); - dCSinkProxy->OpenChannel(dhId, openInfo); - dCSinkProxy->CloseChannel(dhId); - dCSinkProxy->UnsubscribeLocalHardware(dhId); - dCSinkProxy->StopCapture(dhId); - dCSinkProxy->ReleaseSink(); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); + std::shared_ptr dCSourceProxy = + std::make_shared(remoteObject); + sptr callback = new DCameraSourceCallback(); + dCSourceProxy->DCameraNotify(devId, dhId, events); } } } @@ -62,7 +55,7 @@ void DCameraSinkProxyFuzzTest(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::DistributedHardware::DCameraSinkProxyFuzzTest(data, size); + OHOS::DistributedHardware::SourceProxyDCameraNotifyFuzzTest(data, size); return 0; } diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/dcamera_sink_handler_ipc_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.h similarity index 81% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/dcamera_sink_handler_ipc_fuzzer.h rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.h index 0e64ca3..8954516 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/dcamera_sink_handler_ipc_fuzzer.h +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxydcameranotify_fuzzer/sourceproxydcameranotify_fuzzer.h @@ -13,9 +13,9 @@ * limitations under the License. */ -#ifndef DCAMERA_SINK_HANDLER_IPC_FUZZER_H -#define DCAMERA_SINK_HANDLER_IPC_FUZZER_H +#ifndef SOURCEPROXYDCAMERANOTIFY_FUZZER_H +#define SOURCEPROXYDCAMERANOTIFY_FUZZER_H -#define FUZZ_PROJECT_NAME "dcamera_sink_handler_ipc_fuzzer" +#define FUZZ_PROJECT_NAME "sourceproxydcameranotify_fuzzer" #endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/BUILD.gn similarity index 74% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/BUILD.gn rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/BUILD.gn index 25fc2d2..53b891b 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# 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 @@ -18,14 +18,15 @@ import( "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") ##############################fuzztest########################################## -ohos_fuzztest("DCameraSinkProxyFuzzTest") { - module_out_path = "distributed_camera/dcamerasinkproxy" +ohos_fuzztest("SourceProxyInitSourceFuzzTest") { + module_out_path = "distributed_camera/sourceproxyinitsource" fuzz_config_file = - "${innerkits_path}/native_cpp/test/fuzztest/dcamerasinkproxy_fuzzer" + "${innerkits_path}/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer" include_dirs = [ "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/camera_source/include/callback", "${fwk_common_path}/utils/include", ] @@ -33,7 +34,7 @@ ohos_fuzztest("DCameraSinkProxyFuzzTest") { "include", "${common_path}/include", "${common_path}/include/constants", - "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_source/include", ] cflags = [ @@ -43,17 +44,17 @@ ohos_fuzztest("DCameraSinkProxyFuzzTest") { "-fno-omit-frame-pointer", ] - sources = [ "dcamera_sink_proxy_fuzzer.cpp" ] + sources = [ "sourceproxyinitsource_fuzzer.cpp" ] deps = [ "${common_path}:distributed_camera_utils", - "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", "//utils/native/base:utils", ] defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"DCameraSinkProxyFuzzTest\"", + "DH_LOG_TAG=\"SourceProxyInitSourceFuzzTest\"", "LOG_DOMAIN=0xD004100", ] @@ -68,6 +69,6 @@ ohos_fuzztest("DCameraSinkProxyFuzzTest") { ############################################################################### group("fuzztest") { testonly = true - deps = [ ":DCameraSinkProxyFuzzTest" ] + deps = [ ":SourceProxyInitSourceFuzzTest" ] } ############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_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/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/dcamera_sink_handler_ipc_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/sourceproxyinitsource_fuzzer.cpp similarity index 65% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/dcamera_sink_handler_ipc_fuzzer.cpp rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/sourceproxyinitsource_fuzzer.cpp index 0948021..b364885 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasinkhandleripc_fuzzer/dcamera_sink_handler_ipc_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/sourceproxyinitsource_fuzzer.cpp @@ -13,34 +13,31 @@ * limitations under the License. */ -#include "dcamera_sink_handler_ipc_fuzzer.h" +#include "sourceproxyinitsource_fuzzer.h" -#include -#include - -#include "dcamera_sink_handler.h" -#include "dcamera_sink_handler_ipc.h" +#include "dcamera_source_callback.h" #include "distributed_camera_constants.h" +#include "distributed_camera_source_proxy.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" namespace OHOS { namespace DistributedHardware { -void DCameraSinkHandlerIpcFuzzTest(const uint8_t* data, size_t size) +void SourceProxyInitSourceFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size <= 0)) { return; } + std::string params(reinterpret_cast(data), size); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); - wptr remote (remoteObject); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); + std::shared_ptr dCSourceProxy = + std::make_shared(remoteObject); + sptr callback = new DCameraSourceCallback(); - DCameraSinkHandlerIpc::GetInstance().Init(); - DCameraSinkHandlerIpc::GetInstance().GetSinkLocalDHMS(); - DCameraSinkHandlerIpc::GetInstance().OnSinkLocalDmsDied(remote); - DCameraSinkHandlerIpc::GetInstance().UnInit(); + dCSourceProxy->InitSource(params, callback); } } } @@ -49,7 +46,7 @@ void DCameraSinkHandlerIpcFuzzTest(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - OHOS::DistributedHardware::DCameraSinkHandlerIpcFuzzTest(data, size); + OHOS::DistributedHardware::SourceProxyInitSourceFuzzTest(data, size); return 0; } diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/dcamera_source_handler_ipc_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/sourceproxyinitsource_fuzzer.h similarity index 80% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/dcamera_source_handler_ipc_fuzzer.h rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/sourceproxyinitsource_fuzzer.h index 6bc5b69..72717d8 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourcehandleripc_fuzzer/dcamera_source_handler_ipc_fuzzer.h +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/sourceproxyinitsource_fuzzer.h @@ -13,9 +13,9 @@ * limitations under the License. */ -#ifndef DCAMERA_SOURCE_HANDLER_IPC_FUZZER_H -#define DCAMERA_SOURCE_HANDLER_IPC_FUZZER_H +#ifndef SOURCEPROXYINITSOURCE_FUZZER_H +#define SOURCEPROXYINITSOURCE_FUZZER_H -#define FUZZ_PROJECT_NAME "dcamera_source_handler_ipc_fuzzer" +#define FUZZ_PROJECT_NAME "sourceproxyinitsource_fuzzer" #endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000..f1faabb --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,73 @@ +# 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/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceProxyRegisterDistributedHardwareFuzzTest") { + module_out_path = "distributed_camera/sourceproxyregisterdistributedhardware" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/camera_source/include/callback", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_source/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "sourceproxyregisterdistributedhardware_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceProxyRegisterDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceProxyRegisterDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_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/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/sourceproxyregisterdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/sourceproxyregisterdistributedhardware_fuzzer.cpp new file mode 100644 index 0000000..1690223 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/sourceproxyregisterdistributedhardware_fuzzer.cpp @@ -0,0 +1,60 @@ +/* + * 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 "sourceproxyregisterdistributedhardware_fuzzer.h" + +#include "dcamera_source_callback.h" +#include "distributed_camera_constants.h" +#include "distributed_camera_source_proxy.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceProxyRegisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string dhId(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + std::string version(reinterpret_cast(data), size); + std::string attrs(reinterpret_cast(data), size); + EnableParam param; + param.version = version; + param.attrs = attrs; + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); + std::shared_ptr dCSourceProxy = + std::make_shared(remoteObject); + sptr callback = new DCameraSourceCallback(); + + dCSourceProxy->RegisterDistributedHardware(devId, dhId, reqId, param); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceProxyRegisterDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/dcamera_source_load_callback_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/sourceproxyregisterdistributedhardware_fuzzer.h similarity index 76% rename from interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/dcamera_source_load_callback_fuzzer.h rename to interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/sourceproxyregisterdistributedhardware_fuzzer.h index e50a28e..32475cd 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/dcamerasourceloadcallback_fuzzer/dcamera_source_load_callback_fuzzer.h +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyregisterdistributedhardware_fuzzer/sourceproxyregisterdistributedhardware_fuzzer.h @@ -13,9 +13,9 @@ * limitations under the License. */ -#ifndef DCAMERA_SOURCE_HANDLER_IPC_FUZZER_H -#define DCAMERA_SOURCE_HANDLER_IPC_FUZZER_H +#ifndef SOURCEPROXYREGISTERDISTRIBUTEDHARDWARE_FUZZER_H +#define SOURCEPROXYREGISTERDISTRIBUTEDHARDWARE_FUZZER_H -#define FUZZ_PROJECT_NAME "dcamera_source_load_callback_fuzzer" +#define FUZZ_PROJECT_NAME "sourceproxyregisterdistributedhardware_fuzzer" #endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000..ec27178 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,74 @@ +# 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/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceProxyUnregisterDistributedHardwareFuzzTest") { + module_out_path = + "distributed_camera/sourceproxyunregisterdistributedhardware" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${innerkits_path}/native_cpp/camera_source/include/callback", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_source/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "sourceproxyunregisterdistributedhardware_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_source:distributed_camera_source_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceProxyUnregisterDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceProxyUnregisterDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/corpus/init new file mode 100644 index 0000000..bc977bd --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_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/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/sourceproxyunregisterdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/sourceproxyunregisterdistributedhardware_fuzzer.cpp new file mode 100644 index 0000000..b68a614 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/sourceproxyunregisterdistributedhardware_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * 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 "sourceproxyunregisterdistributedhardware_fuzzer.h" + +#include "dcamera_source_callback.h" +#include "distributed_camera_constants.h" +#include "distributed_camera_source_proxy.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceProxyUnregisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string dhId(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID); + std::shared_ptr dCSourceProxy = + std::make_shared(remoteObject); + + dCSourceProxy->UnregisterDistributedHardware(devId, dhId, reqId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceProxyUnregisterDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/sourceproxyunregisterdistributedhardware_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/sourceproxyunregisterdistributedhardware_fuzzer.h new file mode 100644 index 0000000..c9f7207 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyunregisterdistributedhardware_fuzzer/sourceproxyunregisterdistributedhardware_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 SOURCEPROXYUNREGISTERDISTRIBUTEDHARDWARE_FUZZER_H +#define SOURCEPROXYUNREGISTERDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceproxyunregisterdistributedhardware_fuzzer" + +#endif \ No newline at end of file