From 24a150cd85ed5f39bff23364d362fa2d7d546f41 Mon Sep 17 00:00:00 2001 From: chen0088 Date: Tue, 6 Feb 2024 15:33:13 +0800 Subject: [PATCH] add fuzz Signed-off-by: chen0088 --- .../native_cpp/test/sinkfuzztest/BUILD.gn | 1 + .../BUILD.gn | 76 +++++++++++++++++++ .../corpus/init | 14 ++++ .../project.xml | 25 ++++++ ...handlerregisterprivacyresources_fuzzer.cpp | 43 +++++++++++ ...nkhandlerregisterprivacyresources_fuzzer.h | 21 +++++ 6 files changed, 180 insertions(+) create mode 100644 interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.h diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/BUILD.gn index 25554c04..ab7866b2 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/BUILD.gn @@ -22,6 +22,7 @@ group("fuzztest") { "onsinklocalcamsrvdied_fuzzer:fuzztest", "sinkhandlerinitsink_fuzzer:fuzztest", "sinkhandlerpausedistributedhardware_fuzzer:fuzztest", + "sinkhandlerregisterprivacyresources_fuzzer:fuzztest", "sinkhandlerreleasesink_fuzzer:fuzztest", "sinkhandlerresumedistributedhardware_fuzzer:fuzztest", "sinkhandlerstopdistributedhardware_fuzzer:fuzztest", diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn new file mode 100644 index 00000000..b081a381 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2024 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################### +base_root = "../../../../../../../../../" +import("//build/config/features.gni") +import("//build/test.gni") +import( + "$base_root/foundation/distributedhardware/distributed_camera/distributedcamera.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkHandlerRegisterPrivacyResourcesFuzzTest") { + module_out_path = + "${fuzz_test_output_path}/sinkhandlerregisterprivacyresources" + + fuzz_config_file = "${innerkits_path}/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer" + + include_dirs = [ + "${innerkits_path}/native_cpp", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${common_path}/include/constants", + "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", + "${innerkits_path}/native_cpp/test/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "sinkhandlerregisterprivacyresources_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkHandlerRegisterPrivacyResourcesFuzzTest\"", + "LOG_DOMAIN=0xD004150", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkHandlerRegisterPrivacyResourcesFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/corpus/init new file mode 100644 index 00000000..e7c3fecd --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2024 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/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp new file mode 100644 index 00000000..d6e785c9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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 "sinkhandlerregisterprivacyresources_fuzzer.h" + +#include "dcamera_sink_handler.h" +#include "distributed_camera_constants.h" +#include "mock_component_resourceinfo.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkHandlerRegisterPrivacyResourcesFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::shared_ptr callback = std::make_shared(); + + DCameraSinkHandler::GetInstance().RegisterPrivacyResources(callback); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkHandlerRegisterPrivacyResourcesFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.h b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.h new file mode 100644 index 00000000..7dd95976 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 SINKHANDLERREGISTERPRIVACYRESOURCES_FUZZER_H +#define SINKHANDLERREGISTERPRIVACYRESOURCES_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkhandlerregisterprivacyresources_fuzzer" + +#endif \ No newline at end of file -- Gitee