diff --git a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp index a89a2705f7a3848a6a57a87dee153a1821ad21b0..0ca566bd10425db2672878aae2329bb95e6cedf2 100644 --- a/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp +++ b/interfaces/ipc/test/addwhitelistinfoscallbackunittest/add_white_list_infos_call_back_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -353,10 +353,6 @@ HWTEST_F(AddWhiteListInfosCallbackTest, DistributedInputSinkStub01, testing::ext ret = sinkProxy.RegisterGetSinkScreenInfosCallback(sinkScreenCb); EXPECT_EQ(DH_SUCCESS, ret); - SrcScreenInfo srcScreenInfo {"devid_test", "uuid_test", 1, 1, 1860, 980, "srcphyid", 1, 980, 490}; - ret = sinkProxy.NotifyStartDScreen(srcScreenInfo); - EXPECT_EQ(DH_SUCCESS, ret); - std::string srcScreenInfoKey = "srcScreenInfoKey_test"; ret = sinkProxy.NotifyStopDScreen(srcScreenInfoKey); EXPECT_EQ(DH_SUCCESS, ret); diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp b/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp index c60c8d3f43c623cde977b93d20de2d3fe5040746..8820003640176a2b4e29112a1de57856ee2091af 100644 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp +++ b/services/sink/sinkmanager/test/sinkmanagerunittest/distributed_input_sinkmanager_test.cpp @@ -305,13 +305,6 @@ HWTEST_F(DistributedInputSinkManagerTest, UpdateSinkScreenInfoCache_01, testing: EXPECT_EQ(DH_SUCCESS, ret); } -HWTEST_F(DistributedInputSinkManagerTest, NotifyStartDScreen_01, testing::ext::TestSize.Level1) -{ - SrcScreenInfo srcScreenInfo {"devid_test", "uuid_test", 1, 1, 1860, 980, "srcphyid", 1, 980, 490}; - int32_t ret = sinkManager_->NotifyStartDScreen(srcScreenInfo); - EXPECT_EQ(DH_SUCCESS, ret); -} - HWTEST_F(DistributedInputSinkManagerTest, NotifyStopDScreen_01, testing::ext::TestSize.Level1) { std::string srcScreenInfoKey = ""; diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index a0c8a787c82eb1e1e7a68921bba581f70df6ba33..09f319e36958b6902c84d87bc1bdebd645363d55 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -15,6 +15,8 @@ group("fuzztest") { testonly = true deps = [ + "dinputsinkhandler_fuzzer:fuzztest", + "dinputsourcehandler_fuzzer:fuzztest", "distributedinputclient_fuzzer:fuzztest", "distributedinputkit_fuzzer:fuzztest", "distributedinputsinktransport_fuzzer:fuzztest", diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/BUILD.gn b/test/fuzztest/dinputsinkhandler_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..908aaa1b03f5423362389deb13e9758a72435537 --- /dev/null +++ b/test/fuzztest/dinputsinkhandler_fuzzer/BUILD.gn @@ -0,0 +1,84 @@ +# Copyright (c) 2021-2023 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("../../../distributedinput.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DinputSinkHandlerFuzzTest") { + module_out_path = "distributed_input/system" + + fuzz_config_file = + "${distributedinput_path}/test/fuzztest/dinputsinkhandler_fuzzer" + + include_dirs = [ + "include", + "${distributedinput_path}/interfaces/inner_kits/include", + "${distributedinput_path}/interfaces/ipc/include", + "${distributedinput_path}/services/source/sourcemanager/include", + "${distributedinput_path}/services/sink/sinkmanager/include", + "${distributedinput_path}/frameworks/include", + "${distributedinput_path}/sourcehandler/include", + "${distributedinput_path}/sinkhandler/include", + "${distributedinput_path}/inputdevicehandler/include", + "${service_common}/include", + "${common_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "//third_party/json/include", + "${fwk_interfaces_path}/include", + "${fwk_interfaces_path}/include/ipc", + "${services_source_path}/inputinject/include", + "${utils_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dinput_sink_handler_fuzzer.cpp" ] + + deps = [ + "${distributedinput_path}/sinkhandler:libdinput_sink_handler", + "//third_party/libevdev:libevdev", + ] + + external_deps = [ + "c_utils:utils", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DinputSinkHandlerFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DinputSinkHandlerFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/corpus/init b/test/fuzztest/dinputsinkhandler_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/dinputsinkhandler_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.cpp b/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e66a6b337cf382a2066c908d845458e0f457c1c --- /dev/null +++ b/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2023 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 "dinput_sink_handler_fuzzer.h" + +#include +#include +#include +#include +#include + +#include + +#include "constants_dinput.h" +#include "distributed_input_handler.h" +#include "distributed_input_kit.h" +#include "distributed_input_sink_handler.h" +#include "distributed_input_source_handler.h" +#include "i_distributed_sink_input.h" +#include "i_distributed_source_input.h" + +namespace OHOS { +namespace DistributedHardware { +void InitSinkFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string params(reinterpret_cast(data), size); + DistributedInput::DistributedInputSinkHandler::GetInstance().InitSink(params); +} + +void ReleaseSinkFuzzTest(const uint8_t* data, size_t size) +{ + (void)data; + (void)size; + DistributedInput::DistributedInputSinkHandler::GetInstance().ReleaseSink(); +} + +void SubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string dhId(reinterpret_cast(data), size); + std::string params(reinterpret_cast(data), size); + DistributedInput::DistributedInputSinkHandler::GetInstance().SubscribeLocalHardware(dhId, params); +} + +void UnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string dhId(reinterpret_cast(data), size); + DistributedInput::DistributedInputSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId); +} +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::InitSinkFuzzTest(data, size); + OHOS::DistributedHardware::ReleaseSinkFuzzTest(data, size); + OHOS::DistributedHardware::SubscribeLocalHardwareFuzzTest(data, size); + OHOS::DistributedHardware::UnsubscribeLocalHardwareFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.h b/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..5dd97ac8e86fe72b8db7beeeac99da78a1659608 --- /dev/null +++ b/test/fuzztest/dinputsinkhandler_fuzzer/dinput_sink_handler_fuzzer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 DINPUT_SINK_HANDLER_FUZZER_H +#define DINPUT_SINK_HANDLER_FUZZER_H + +#define FUZZ_PROJECT_NAME "dinputsinkhandler_fuzzer" + +#endif // DINPUT_SINK_HANDLER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/dinputsinkhandler_fuzzer/project.xml b/test/fuzztest/dinputsinkhandler_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/dinputsinkhandler_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/BUILD.gn b/test/fuzztest/dinputsourcehandler_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..76f3e60cd48c3fb4b3db9b31ec41a128c26558c8 --- /dev/null +++ b/test/fuzztest/dinputsourcehandler_fuzzer/BUILD.gn @@ -0,0 +1,84 @@ +# Copyright (c) 2023 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("../../../distributedinput.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DinputSourceHandlerFuzzTest") { + module_out_path = "distributed_input/system" + + fuzz_config_file = + "${distributedinput_path}/test/fuzztest/dinputsourcehandler_fuzzer" + + include_dirs = [ + "include", + "${distributedinput_path}/interfaces/inner_kits/include", + "${distributedinput_path}/interfaces/ipc/include", + "${distributedinput_path}/services/source/sourcemanager/include", + "${distributedinput_path}/services/sink/sinkmanager/include", + "${distributedinput_path}/frameworks/include", + "${distributedinput_path}/sourcehandler/include", + "${distributedinput_path}/sinkhandler/include", + "${distributedinput_path}/inputdevicehandler/include", + "${service_common}/include", + "${common_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "//third_party/json/include", + "${fwk_interfaces_path}/include", + "${fwk_interfaces_path}/include/ipc", + "${services_source_path}/inputinject/include", + "${utils_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dinput_source_handler_fuzzer.cpp" ] + + deps = [ + "${distributedinput_path}/sourcehandler:libdinput_source_handler", + "//third_party/libevdev:libevdev", + ] + + external_deps = [ + "c_utils:utils", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DinputSourceHandlerFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DinputSourceHandlerFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/corpus/init b/test/fuzztest/dinputsourcehandler_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/dinputsourcehandler_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.cpp b/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f5a5ba6d8ce01ff95880c41fc74b181a7fd887d7 --- /dev/null +++ b/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023 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 "dinput_source_handler_fuzzer.h" + +#include +#include +#include +#include +#include + +#include + +#include "constants_dinput.h" +#include "distributed_input_handler.h" +#include "distributed_input_kit.h" +#include "distributed_input_sink_handler.h" +#include "distributed_input_source_handler.h" +#include "i_distributed_sink_input.h" +#include "i_distributed_source_input.h" + +namespace OHOS { +namespace DistributedHardware { +class TestRegisterInputCallback : public OHOS::DistributedHardware::RegisterCallback { +public: + TestRegisterInputCallback() = default; + virtual ~TestRegisterInputCallback() = default; + virtual int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, + const std::string &data) override + { + return 0; + } +}; + +class TestUnregisterInputCallback : public OHOS::DistributedHardware::UnregisterCallback { +public: + TestUnregisterInputCallback() = default; + virtual ~TestUnregisterInputCallback() = default; + virtual int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status, + const std::string &data) override + { + return 0; + } +}; + +void InitSourceFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string params(reinterpret_cast(data), size); + DistributedInput::DistributedInputSourceHandler::GetInstance().InitSource(params); +} + +void ReleaseSourceFuzzTest(const uint8_t* data, size_t size) +{ + (void)data; + (void)size; + DistributedInput::DistributedInputSourceHandler::GetInstance().ReleaseSource(); +} + +void ConfigDistributedHardwareFuzzTest(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); + DistributedInput::DistributedInputSourceHandler::GetInstance().ConfigDistributedHardware(devId, dhId, key, value); +} +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::InitSourceFuzzTest(data, size); + OHOS::DistributedHardware::ReleaseSourceFuzzTest(data, size); + OHOS::DistributedHardware::ConfigDistributedHardwareFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.h b/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..dda0d85d3c9681c7b153fc959cb1e2603fb9398e --- /dev/null +++ b/test/fuzztest/dinputsourcehandler_fuzzer/dinput_source_handler_fuzzer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 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 DINPUT_SOURCE_HANDLER_FUZZER_H +#define DINPUT_SOURCE_HANDLER_FUZZER_H + +#define FUZZ_PROJECT_NAME "dinputsourcehandler_fuzzer" + +#endif // DINPUT_SOURCE_HANDLER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/dinputsourcehandler_fuzzer/project.xml b/test/fuzztest/dinputsourcehandler_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/dinputsourcehandler_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +