diff --git a/bundle.json b/bundle.json index d60cc4590c9a26f2cca66e7b8516de2ba6e2c046..bf7c1623c4242e4dc66778a408fc53e2d44a41fb 100644 --- a/bundle.json +++ b/bundle.json @@ -47,8 +47,7 @@ "c_utils", "window_manager", "distributed_hardware_fwk", - "libjpeg-turbo", - "json" + "libjpeg-turbo" ], "third_party": [] }, diff --git a/common/BUILD.gn b/common/BUILD.gn index 96cc038b20a4d51e5d7d57f0a335a0a498469471..74c7be178dcabbd7709fa155f4184b3ed93f48a7 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -50,8 +50,6 @@ ohos_shared_library("distributed_screen_utils") { "json:nlohmann_json_static", ] - public_external_deps = [ "json:nlohmann_json_static" ] - defines = [ "HI_LOG_ENABLE", "DH_LOG_TAG=\"dscreenutil\"", diff --git a/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp b/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp index 9c09b2a345ca91fa5b527e53364db325286cf359..dcdd9240c278bffd9b47f3d4ab0de61e14a0b547 100644 --- a/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp +++ b/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp @@ -102,6 +102,12 @@ void DScreenSinkHandler::FinishStartSA(const std::string ¶ms, const sptr lock(proxyMutex_); + if (remoteObject == nullptr) { + DHLOGE("remoteObject is nullptr."); + ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, + "remoteObject is nullptr."); + return; + } if (sinkSvrRecipient_ == nullptr) { DHLOGE("sinkSvrRecipient is nullptr."); ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, @@ -220,4 +226,4 @@ IDistributedHardwareSink *GetSinkHardwareHandler() return &DScreenSinkHandler::GetInstance(); } } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp b/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp index 8468baeda8a4b033a9e04bab20103b9b4c272a80..8d6c7221268a1e00b8235a09c35a39f702f74c13 100644 --- a/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp +++ b/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp @@ -97,6 +97,12 @@ void DScreenSourceHandler::FinishStartSA(const std::string ¶ms, const sptr lock(proxyMutex_); + if (remoteObject == nullptr) { + DHLOGE("remoteObject is nullptr."); + ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, + "remoteObject is nullptr."); + return; + } if (sourceSvrRecipient_ == nullptr) { DHLOGE("sourceSvrRecipient is nullptr."); ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.cpp index e6a5e6fcfd1cd3cccafc2e983166f5ef6ad50853..ece8a40a8c397aabdadb621cc017403b4cbf11d3 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.cpp @@ -29,8 +29,13 @@ void InitSinkFuzzTest(const uint8_t* data, size_t size) } std::string params(reinterpret_cast(data), size); + std::string networkId(reinterpret_cast(data), size); DScreenSinkHandler::GetInstance().InitSink(params); + DScreenSinkHandler::GetInstance().PauseDistributedHardware(networkId); + DScreenSinkHandler::GetInstance().ResumeDistributedHardware(networkId); + DScreenSinkHandler::GetInstance().StopDistributedHardware(networkId); + DScreenSinkHandler::GetInstance().ReleaseSink(); } } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.cpp index 33937b9390af64086c16f428cf72be603f5577e4..819d93529702214f59e075ef8999c3a0b02e6303 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.cpp @@ -47,6 +47,7 @@ void InitSinkFuzzTest(const uint8_t* data, size_t size) std::shared_ptr dscreenSinkProxy = std::make_shared(remoteObject); dscreenSinkProxy->InitSink(params); + dscreenSinkProxy->ReleaseSink(); } } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerinitsource_fuzzer/initsource_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerinitsource_fuzzer/initsource_fuzzer.cpp index 2d40347a2c3e7dcd537f0528486730c668cd95ae..bfa212bf17dfe70aefd59b2360c2bb0e16b52df1 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerinitsource_fuzzer/initsource_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_handler/handlerinitsource_fuzzer/initsource_fuzzer.cpp @@ -31,6 +31,7 @@ void InitSourceFuzzTest(const uint8_t* data, size_t size) std::string params(reinterpret_cast(data), size); DScreenSourceHandler::GetInstance().InitSource(params); + DScreenSourceHandler::GetInstance().ReleaseSource(); } } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensinktest/BUILD.gn b/interfaces/innerkits/native_cpp/test/unittest/screensinktest/BUILD.gn index 56a525ca4c92a4cf8f75e0c120560e6ba009d111..4752e7e62cd0bfb68231e52c5ac20edd4d18a12a 100644 --- a/interfaces/innerkits/native_cpp/test/unittest/screensinktest/BUILD.gn +++ b/interfaces/innerkits/native_cpp/test/unittest/screensinktest/BUILD.gn @@ -48,15 +48,13 @@ ohos_unittest("ScreenSinkTest") { "${common_path}/test/unittest/resource:dscreen_unittest_public_config", ] - deps = [ - "${interfaces_path}/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] + deps = [ "${interfaces_path}/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk" ] external_deps = [ "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", + "googletest:gmock", + "googletest:gtest_main", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensinktest/src/dscreen_sink_handler_test.cpp b/interfaces/innerkits/native_cpp/test/unittest/screensinktest/src/dscreen_sink_handler_test.cpp index 6cfc342bf2c10d410733e14a0d9901fa13a65840..d2bc2f2a8de0646bd762301057498fbb014899f6 100644 --- a/interfaces/innerkits/native_cpp/test/unittest/screensinktest/src/dscreen_sink_handler_test.cpp +++ b/interfaces/innerkits/native_cpp/test/unittest/screensinktest/src/dscreen_sink_handler_test.cpp @@ -64,6 +64,21 @@ HWTEST_F(DScreenSinkHandlerTest, InitSink_002, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, ret); } +/** + * @tc.name: FinishStartSA_001 + * @tc.desc: Verify the FinishStartSA function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenSinkHandlerTest, FinishStartSA_001, TestSize.Level1) +{ + const std::string param = ""; + sptr remoteObject = nullptr; + DScreenSinkHandler::GetInstance().dScreenSinkProxy_ = nullptr; + DScreenSinkHandler::GetInstance().FinishStartSA(param, remoteObject); + EXPECT_EQ(DScreenSinkHandler::GetInstance().dScreenSinkProxy_, nullptr); +} + /** * @tc.name: LocalHardware_001 * @tc.desc: Verify the SubscribeLocalHardware function. diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/BUILD.gn b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/BUILD.gn index 331104b75b2dbc9ee8c74ac56b4481e8dfed5336..582577baa707e204100a4c05da2481d99f3fdbbf 100644 --- a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/BUILD.gn +++ b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/BUILD.gn @@ -52,15 +52,13 @@ ohos_unittest("ScreenSourceTest") { "${common_path}/test/unittest/resource:dscreen_unittest_public_config", ] - deps = [ - "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] + deps = [ "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk" ] external_deps = [ "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", + "googletest:gmock", + "googletest:gtest_main", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp index df780acf1250c53e5fd98b5a31cf944dcab7b1e4..ed8856f2327ef757f6e7097ccd14a47c48bfc951 100644 --- a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp +++ b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp @@ -68,6 +68,21 @@ HWTEST_F(DScreenSourceHandlerTest, InitSource_002, TestSize.Level1) } +/** + * @tc.name: FinishStartSA_001 + * @tc.desc: Verify the FinishStartSA function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenSourceHandlerTest, FinishStartSA_001, TestSize.Level1) +{ + const std::string param = ""; + sptr remoteObject = nullptr; + DScreenSourceHandler::GetInstance().dScreenSourceProxy_ = nullptr; + DScreenSourceHandler::GetInstance().FinishStartSA(param, remoteObject); + EXPECT_EQ(DScreenSourceHandler::GetInstance().dScreenSourceProxy_, nullptr); +} + /** * @tc.name: RegisterDistributedHardware_001 * @tc.desc: Verify the RegisterDistributedHardware function. diff --git a/screenhandler/include/dscreen_handler.h b/screenhandler/include/dscreen_handler.h index c53faf559e256dd1ef81d1d1e9c94a5a235a1291..fb7b7e06ba6783addb2e5e8fc10b6978a9222db2 100644 --- a/screenhandler/include/dscreen_handler.h +++ b/screenhandler/include/dscreen_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 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 @@ -37,7 +37,6 @@ public: int32_t Initialize() override; std::vector QueryMeta() override; std::vector Query() override; - std::vector RealQuery(); std::map QueryExtraInfo() override; bool IsSupportPlugin() override; void RegisterPluginListener(std::shared_ptr listener) override; diff --git a/screenhandler/src/dscreen_handler.cpp b/screenhandler/src/dscreen_handler.cpp index f400116f6efce5ca0f30afad79cc32b62b6b6438..36a29ecd1dce391359f363db3956171b5257a696 100644 --- a/screenhandler/src/dscreen_handler.cpp +++ b/screenhandler/src/dscreen_handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 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 @@ -126,19 +126,12 @@ void DScreenHandler::UnPluginHardware(const std::string &dhId) std::vector DScreenHandler::QueryMeta() { - DHLOGI("DScreenHandler query meta hardware info"); - return RealQuery(); + return {}; } std::vector DScreenHandler::Query() { - DHLOGI("DScreenHandler query full hardware info"); - return RealQuery(); -} - -std::vector DScreenHandler::RealQuery() -{ - DHLOGI("DScreenHandler RealQuery"); + DHLOGI("DScreenHandler query hardware info"); std::vector dhItemVec; std::vector> screens; Rosen::ScreenManager::GetInstance().GetAllScreens(screens); diff --git a/screenhandler/test/unittest/screenhandler/BUILD.gn b/screenhandler/test/unittest/screenhandler/BUILD.gn index 6fc2f86bcdaa568479ba30e948d8751c77bfea2e..1d6d96d815e2fdf4453a8c71fe69fd3ac2e7a4a3 100644 --- a/screenhandler/test/unittest/screenhandler/BUILD.gn +++ b/screenhandler/test/unittest/screenhandler/BUILD.gn @@ -42,16 +42,15 @@ ohos_unittest("DscreenHandlerTest") { "${common_path}/test/unittest/resource:dscreen_unittest_public_config", ] - deps = [ - "${distributedscreen_path}/screenhandler:distributed_screen_handler", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] + deps = + [ "${distributedscreen_path}/screenhandler:distributed_screen_handler" ] external_deps = [ "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", + "googletest:gmock", + "googletest:gtest_main", "graphic_2d:libgraphic_utils", "graphic_surface:surface", "hilog:libhilog", diff --git a/services/common/databuffer/src/data_buffer.cpp b/services/common/databuffer/src/data_buffer.cpp index 36a5ea413fa7269d96e7e1f1ea3a4d55d70cf9ea..0a48e140509efd290d07678bb8a6fb44a8ae97a3 100644 --- a/services/common/databuffer/src/data_buffer.cpp +++ b/services/common/databuffer/src/data_buffer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -132,4 +132,4 @@ int32_t DataBuffer::GetData(int32_t offset, int32_t datasize, uint8_t* &output) return DH_SUCCESS; } } // namespace DistributedHardware -} // namespcae OHOS \ No newline at end of file +} // namespace OHOS \ No newline at end of file diff --git a/services/common/screen_channel/include/iscreen_channel.h b/services/common/screen_channel/include/iscreen_channel.h index 24d5c4935f651867bb378b4745f27332d6d3924e..b2e74395662013a84c97825c185f40949a0009f3 100644 --- a/services/common/screen_channel/include/iscreen_channel.h +++ b/services/common/screen_channel/include/iscreen_channel.h @@ -28,7 +28,7 @@ public: virtual ~IScreenChannel() = default; virtual int32_t CreateSession(const std::shared_ptr &listener) = 0; virtual int32_t ReleaseSession() = 0; - virtual int32_t OpenSession(const std::shared_ptr &listener) = 0; + virtual int32_t OpenSession(const std::shared_ptr listener) = 0; virtual int32_t CloseSession() = 0; virtual int32_t SendData(const std::shared_ptr &data) = 0; virtual void SetJpegSessionFlag(bool flag) = 0; diff --git a/services/common/test/unittest/databuffer/BUILD.gn b/services/common/test/unittest/databuffer/BUILD.gn index 63275332e5a8671487ae49af49864c6b0127d991..6b962131eae674772a9e724d566da4cc035d1150 100644 --- a/services/common/test/unittest/databuffer/BUILD.gn +++ b/services/common/test/unittest/databuffer/BUILD.gn @@ -46,13 +46,13 @@ ohos_unittest("DataBufferTest") { "${common_path}/test/unittest/resource:dscreen_unittest_public_config", ] - deps = [ - "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] + deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] - external_deps = [ "distributed_hardware_fwk:distributedhardwareutils" ] + external_deps = [ + "distributed_hardware_fwk:distributedhardwareutils", + "googletest:gmock", + "googletest:gtest_main", + ] } group("data_buffer_test") { diff --git a/services/common/test/unittest/utils/BUILD.gn b/services/common/test/unittest/utils/BUILD.gn index 58f2bbfc972350e0204e618effa44569b9dbed24..8ff1370f6243776a67999e4052a54fa10aa131c5 100644 --- a/services/common/test/unittest/utils/BUILD.gn +++ b/services/common/test/unittest/utils/BUILD.gn @@ -49,16 +49,15 @@ ohos_unittest("UtilsTest") { "${common_path}/test/unittest/resource:dscreen_unittest_public_config", ] - deps = [ - "${services_path}/screenservice/sinkservice:distributed_screen_sink", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] + deps = + [ "${services_path}/screenservice/sinkservice:distributed_screen_sink" ] external_deps = [ "distributed_hardware_fwk:distributed_av_sender", "distributed_hardware_fwk:distributedhardwareutils", "distributed_hardware_fwk:libdhfwk_sdk", + "googletest:gmock", + "googletest:gtest_main", ] } diff --git a/services/screenclient/test/unittest/BUILD.gn b/services/screenclient/test/unittest/BUILD.gn index 0e19567d2339b6b89a0225ff0e0890fb67d15375..057379e38fb8e6ee9ed925d90a2597afaad336a7 100644 --- a/services/screenclient/test/unittest/BUILD.gn +++ b/services/screenclient/test/unittest/BUILD.gn @@ -48,13 +48,13 @@ ohos_unittest("ScreenClientTest") { deps = [ "${common_path}:distributed_screen_utils", "${distributedscreen_path}/services/screenclient:distributed_screen_client", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", ] external_deps = [ "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", + "googletest:gmock", + "googletest:gtest_main", "graphic_2d:librender_service_client", "graphic_surface:surface", "input:libmmi-client", diff --git a/services/screenservice/sinkservice/BUILD.gn b/services/screenservice/sinkservice/BUILD.gn index 6db4bea6f71766aed5d3a4ecdbe6548a0cdf3e5a..350eeae32d5f1dd033a9fc04fd8f28deb04dbb2b 100644 --- a/services/screenservice/sinkservice/BUILD.gn +++ b/services/screenservice/sinkservice/BUILD.gn @@ -98,8 +98,6 @@ ohos_shared_library("distributed_screen_sink") { "window_manager:libdm", ] - public_external_deps = [ "json:nlohmann_json_static" ] - subsystem_name = "distributedhardware" part_name = "distributed_screen" diff --git a/services/screenservice/sinkservice/screenregionmgr/1.0/src/screenregion.cpp b/services/screenservice/sinkservice/screenregionmgr/1.0/src/screenregion.cpp index 3624f72208b3579ff36229f2ec4adfc019515ff9..d6fe6b310588439dcbf6766452ea86432f8f391d 100644 --- a/services/screenservice/sinkservice/screenregionmgr/1.0/src/screenregion.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/1.0/src/screenregion.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -179,24 +179,16 @@ int32_t ScreenRegion::Stop() return DH_SUCCESS; } - if (sinkTrans_ == nullptr) { + if (sinkTrans_ != nullptr) { + (void)sinkTrans_->Stop(); + (void)sinkTrans_->Release(); + } else { DHLOGE("sink trans not init."); + (void)ScreenClient::GetInstance().RemoveWindow(windowId_); return ERR_DH_SCREEN_SA_SINKTRANS_NOT_INIT; } - int32_t ret = sinkTrans_->Stop(); - if (ret != DH_SUCCESS) { - DHLOGE("sink trans stop failed."); - return ret; - } - - ret = sinkTrans_->Release(); - if (ret != DH_SUCCESS) { - DHLOGE("sink trans release failed."); - return ret; - } - - ret = ScreenClient::GetInstance().RemoveWindow(windowId_); + int32_t ret = ScreenClient::GetInstance().RemoveWindow(windowId_); if (ret != DH_SUCCESS) { DHLOGE("remove window failed."); return ret; diff --git a/services/screenservice/sinkservice/screenregionmgr/2.0/include/screenregion.h b/services/screenservice/sinkservice/screenregionmgr/2.0/include/screenregion.h index e21fcded7e376b62b767ed5f783a46dedcb520bf..e06470bcc6072e307d4f65cdea6fd95f19cda7d7 100644 --- a/services/screenservice/sinkservice/screenregionmgr/2.0/include/screenregion.h +++ b/services/screenservice/sinkservice/screenregionmgr/2.0/include/screenregion.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -56,6 +56,8 @@ private: int32_t StopReceiverEngine(); int32_t SetUp(const std::string &content); int32_t ConfigWindow(); + int32_t SetReceiverAdapterParameters(); + int32_t SetAlignedHeight(); bool CheckContentJson(json &contentJson); void PublishMessage(const DHTopic topic, const uint64_t &screenId, const std::string &remoteDevId, const int32_t &windowId, std::shared_ptr windowProperty); diff --git a/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregion.cpp b/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregion.cpp index 410fcb0b85764f3c64c05ecb1dfe87e7cee8bf38..78269dce181f7c3d45085aada8c3d65196983cba 100644 --- a/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregion.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregion.cpp @@ -151,35 +151,19 @@ int32_t ScreenRegion::SetUp(const std::string &content) DHLOGE("config dscreen region window failed."); return ret; } - std::string codecType; - if (videoParam_->GetCodecType() == VIDEO_CODEC_TYPE_VIDEO_H265) { - codecType = MIME_VIDEO_H265; - } else if (videoParam_->GetCodecType() == VIDEO_CODEC_TYPE_VIDEO_H264) { - codecType = MIME_VIDEO_H264; - } else { - codecType = MIME_VIDEO_RAW; - } - std::string pixelFormat; - if (videoParam_->GetVideoFormat() == VIDEO_DATA_FORMAT_YUVI420) { - pixelFormat = VIDEO_FORMAT_YUVI420; - } else if (videoParam_->GetVideoFormat() == VIDEO_DATA_FORMAT_NV12) { - pixelFormat = VIDEO_FORMAT_NV12; - } else if (videoParam_->GetVideoFormat() == VIDEO_DATA_FORMAT_NV21) { - pixelFormat = VIDEO_FORMAT_NV21; - } else { - pixelFormat = VIDEO_FORMAT_RGBA8888; + + ret = SetReceiverAdapterParameters(); + if (ret != DH_SUCCESS) { + DHLOGE("Failed to set receiver adapter parameters, error code: %{public}d", ret); + return ret; } - receiverAdapter_->SetParameter(AVTransTag::VIDEO_CODEC_TYPE, codecType); - receiverAdapter_->SetParameter(AVTransTag::VIDEO_PIXEL_FORMAT, pixelFormat); - receiverAdapter_->SetParameter(AVTransTag::VIDEO_WIDTH, std::to_string(videoParam_->GetVideoWidth())); - receiverAdapter_->SetParameter(AVTransTag::VIDEO_HEIGHT, std::to_string(videoParam_->GetVideoHeight())); - receiverAdapter_->SetParameter(AVTransTag::VIDEO_FRAME_RATE, std::to_string(videoParam_->GetFps())); - receiverAdapter_->SetParameter(AVTransTag::ENGINE_READY, OWNER_NAME_D_SCREEN); - alignedHeight_ = videoParam_->GetVideoHeight(); - if (alignedHeight_ % ALIGNEDBITS != 0) { - alignedHeight_ = ((alignedHeight_ / ALIGNEDBITS) +1) * ALIGNEDBITS; + ret = SetAlignedHeight(); + if (ret != DH_SUCCESS) { + DHLOGE("Failed to set aligned height, error code: %{public}d", ret); + return ret; } + return DH_SUCCESS; } @@ -222,6 +206,61 @@ int32_t ScreenRegion::ConfigWindow() return DH_SUCCESS; } +int32_t ScreenRegion::SetReceiverAdapterParameters() +{ + if (videoParam_ == nullptr) { + DHLOGE("videoParam is nullptr."); + return ERR_DH_AV_TRANS_NULL_VALUE; + } + + if (receiverAdapter_ == nullptr) { + DHLOGE("receiverAdapter is nullptr."); + return ERR_DH_AV_TRANS_NULL_VALUE; + } + + std::string codecType; + if (videoParam_->GetCodecType() == VIDEO_CODEC_TYPE_VIDEO_H265) { + codecType = MIME_VIDEO_H265; + } else if (videoParam_->GetCodecType() == VIDEO_CODEC_TYPE_VIDEO_H264) { + codecType = MIME_VIDEO_H264; + } else { + codecType = MIME_VIDEO_RAW; + } + std::string pixelFormat; + if (videoParam_->GetVideoFormat() == VIDEO_DATA_FORMAT_YUVI420) { + pixelFormat = VIDEO_FORMAT_YUVI420; + } else if (videoParam_->GetVideoFormat() == VIDEO_DATA_FORMAT_NV12) { + pixelFormat = VIDEO_FORMAT_NV12; + } else if (videoParam_->GetVideoFormat() == VIDEO_DATA_FORMAT_NV21) { + pixelFormat = VIDEO_FORMAT_NV21; + } else { + pixelFormat = VIDEO_FORMAT_RGBA8888; + } + receiverAdapter_->SetParameter(AVTransTag::VIDEO_CODEC_TYPE, codecType); + receiverAdapter_->SetParameter(AVTransTag::VIDEO_PIXEL_FORMAT, pixelFormat); + receiverAdapter_->SetParameter(AVTransTag::VIDEO_WIDTH, std::to_string(videoParam_->GetVideoWidth())); + receiverAdapter_->SetParameter(AVTransTag::VIDEO_HEIGHT, std::to_string(videoParam_->GetVideoHeight())); + receiverAdapter_->SetParameter(AVTransTag::VIDEO_FRAME_RATE, std::to_string(videoParam_->GetFps())); + receiverAdapter_->SetParameter(AVTransTag::ENGINE_READY, OWNER_NAME_D_SCREEN); + + return DH_SUCCESS; +} + +int32_t ScreenRegion::SetAlignedHeight() +{ + if (videoParam_ == nullptr) { + DHLOGE("video parameter is nullptr."); + return ERR_DH_AV_TRANS_NULL_VALUE; + } + + alignedHeight_ = videoParam_->GetVideoHeight(); + if (alignedHeight_ % ALIGNEDBITS != 0) { + alignedHeight_ = ((alignedHeight_ / ALIGNEDBITS) + 1) * ALIGNEDBITS; + } + + return DH_SUCCESS; +} + void ScreenRegion::PublishMessage(const DHTopic topic, const uint64_t &screenId, const std::string &remoteDevId, const int32_t &windowId, std::shared_ptr windowProperty) { @@ -230,6 +269,12 @@ void ScreenRegion::PublishMessage(const DHTopic topic, const uint64_t &screenId, DHLOGE("GetDHFwkKit fail."); return; } + + if (windowProperty == nullptr) { + DHLOGE("windowProperty is nullptr."); + return; + } + json messageJosn; std::string message; messageJosn[SOURCE_WIN_ID] = screenId; @@ -268,6 +313,12 @@ void ScreenRegion::OnEngineMessage(const std::shared_ptr &messag json paramJson; paramJson[KEY_DEV_ID] = remoteDevId_; auto avMessage = std::make_shared(msgType, paramJson.dump(), remoteDevId_); + + if (receiverAdapter_ == nullptr) { + DHLOGE("av transport receiver adapter is nullptr."); + return; + } + receiverAdapter_->SendMessageToRemote(avMessage); } else if (message->type_ == DScreenMsgType::STOP_MIRROR) { StopReceiverEngine(); @@ -335,8 +386,8 @@ void ScreenRegion::OnEngineDataDone(const std::shared_ptr &buffer DHLOGE("received video buffer data is nullptr."); return; } - if (windowSurface_ == nullptr) { - DHLOGE("window surface is nullptr."); + if ((windowSurface_ == nullptr) || (videoParam_ == nullptr)) { + DHLOGE("windowSurface or videoParam is nullptr."); return; } sptr wsBuffer = nullptr; @@ -411,4 +462,4 @@ bool ScreenRegion::CheckContentJson(json &contentJson) } } // namespace V1_0 } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregionmgr.cpp b/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregionmgr.cpp index 93da68f3db1886986795d80b76ca41186dfd62dd..b81e56461bfb83ed04ce06dbc5be6981d2c19247 100644 --- a/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregionmgr.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregionmgr.cpp @@ -156,10 +156,6 @@ void ScreenRegionManager::GetScreenDumpInfo(std::string &result) int32_t ScreenRegionManager::LoadAVReceiverEngineProvider() { DHLOGI("LoadAVReceiverEngineProvider enter"); - if ((RECEIVER_SO_NAME.length() == 0) || (RECEIVER_SO_NAME.length() > PATH_MAX)) { - DHLOGE("File canonicalization failed, so name: %{public}s.", RECEIVER_SO_NAME.c_str()); - return ERR_DH_AV_TRANS_LOAD_ERROR; - } void *pHandler = dlopen(RECEIVER_SO_NAME.c_str(), RTLD_LAZY | RTLD_NODELETE); if (pHandler == nullptr) { DHLOGE("so: %{public}s load failed, failed reason : %{public}s", RECEIVER_SO_NAME.c_str(), dlerror()); @@ -179,10 +175,6 @@ int32_t ScreenRegionManager::LoadAVReceiverEngineProvider() int32_t ScreenRegionManager::UnloadAVReceiverEngineProvider() { DHLOGI("UnloadAVReceiverEngineProvider enter"); - if ((RECEIVER_SO_NAME.length() == 0) || (RECEIVER_SO_NAME.length() > PATH_MAX)) { - DHLOGE("File canonicalization failed, so name: %{public}s.", RECEIVER_SO_NAME.c_str()); - return ERR_DH_AV_TRANS_LOAD_ERROR; - } void *pHandler = dlopen(RECEIVER_SO_NAME.c_str(), RTLD_LAZY | RTLD_NODELETE); if (pHandler != nullptr) { dlclose(pHandler); @@ -205,4 +197,4 @@ int32_t EngineProviderListener::OnProviderEvent(const AVTransEvent& event) } } // namespace V2_0 } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/screenservice/sourceservice/BUILD.gn b/services/screenservice/sourceservice/BUILD.gn index 97da3dd8f6be69224997c9352f38f7ff1a0d0871..4061c4fb4728bfc06f3b1983729ac6cce82de5c2 100644 --- a/services/screenservice/sourceservice/BUILD.gn +++ b/services/screenservice/sourceservice/BUILD.gn @@ -106,8 +106,6 @@ ohos_shared_library("distributed_screen_source") { "window_manager:libdm", ] - public_external_deps = [ "json:nlohmann_json_static" ] - subsystem_name = "distributedhardware" part_name = "distributed_screen" diff --git a/services/screenservice/sourceservice/dscreenmgr/1.0/src/dscreen.cpp b/services/screenservice/sourceservice/dscreenmgr/1.0/src/dscreen.cpp index 8e862c449a29519a42ce89f52f6880b084503590..5c4951f7a2eaa46c79387b30690bf3758142cf0f 100644 --- a/services/screenservice/sourceservice/dscreenmgr/1.0/src/dscreen.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/1.0/src/dscreen.cpp @@ -156,8 +156,12 @@ void DScreen::TaskThreadLoop() std::shared_ptr task; { std::unique_lock lock(taskQueueMtx_); - taskQueueCond_.wait_for(lock, std::chrono::seconds(TASK_WAIT_SECONDS), + auto status = taskQueueCond_.wait_for(lock, std::chrono::seconds(TASK_WAIT_SECONDS), [this]() { return !taskQueue_.empty(); }); + if (!status) { + DHLOGD("Task queue wait timeout after %{public}d seconds.", TASK_WAIT_SECONDS); + continue; + } if (taskQueue_.empty()) { continue; } diff --git a/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen.cpp b/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen.cpp index e68a659d822b2d5140b48269f16c8d73338e50e9..458a8dcd4939347f5412d7f1459e9f8842e337de 100644 --- a/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen.cpp @@ -599,8 +599,12 @@ void DScreen::TaskThreadLoop() std::shared_ptr task; { std::unique_lock lock(taskQueueMtx_); - taskQueueCond_.wait_for(lock, std::chrono::seconds(TASK_WAIT_SECONDS), + auto status = taskQueueCond_.wait_for(lock, std::chrono::seconds(TASK_WAIT_SECONDS), [this]() { return !taskQueue_.empty(); }); + if (!status) { + DHLOGD("Task queue wait timeout after %{public}d seconds.", TASK_WAIT_SECONDS); + continue; + } if (taskQueue_.empty()) { continue; } diff --git a/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen_manager.cpp b/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen_manager.cpp index 2ccb802ab21a39b7566de78e4709a2b1206ac1a2..91bd7ee21c3b062954f8d62f6e06621932eb33e9 100644 --- a/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen_manager.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen_manager.cpp @@ -397,10 +397,6 @@ void DScreenManager::PublishMessage(const DHTopic topic, const std::shared_ptr PATH_MAX)) { - DHLOGE("File canonicalization failed, so name: %{public}s.", SENDER_SO_NAME.c_str()); - return ERR_DH_AV_TRANS_LOAD_ERROR; - } void *pHandler = dlopen(SENDER_SO_NAME.c_str(), RTLD_LAZY | RTLD_NODELETE); if (pHandler == nullptr) { DHLOGE("so: %{public}s load failed, failed reason : %{public}s", SENDER_SO_NAME.c_str(), dlerror()); @@ -420,10 +416,6 @@ int32_t DScreenManager::LoadAVSenderEngineProvider() int32_t DScreenManager::UnloadAVSenderEngineProvider() { DHLOGI("UnloadAVSenderEngineProvider enter"); - if ((SENDER_SO_NAME.length() == 0) || (SENDER_SO_NAME.length() > PATH_MAX)) { - DHLOGE("File canonicalization failed, so name: %{public}s.", SENDER_SO_NAME.c_str()); - return ERR_DH_AV_TRANS_LOAD_ERROR; - } void *pHandler = dlopen(SENDER_SO_NAME.c_str(), RTLD_LAZY | RTLD_NODELETE); if (pHandler != nullptr) { dlclose(pHandler); @@ -433,4 +425,4 @@ int32_t DScreenManager::UnloadAVSenderEngineProvider() } } // namespace V2_0 } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/screenservice/test/fuzztest/BUILD.gn b/services/screenservice/test/fuzztest/BUILD.gn index 4d55ed50920207d89a6408c48432e79078143ba7..a4905fb7c5e9be1e444a63cc154995fdb5bbb999 100644 --- a/services/screenservice/test/fuzztest/BUILD.gn +++ b/services/screenservice/test/fuzztest/BUILD.gn @@ -16,7 +16,7 @@ group("fuzztest") { deps = [ "sinkservice/dscreenservice/dscreensinkstub_fuzzer:fuzztest", - "sourceservice/dscreenmgr/onchange_fuzzer:fuzztest", + "sourceservice/dscreenmgr/dscreenmanager_fuzzer:fuzztest", "sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer:fuzztest", "sourceservice/dscreenservice/dscreensourceservice_fuzzer:fuzztest", "sourceservice/dscreenservice/dscreensourcestub_fuzzer:fuzztest", diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/BUILD.gn b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/BUILD.gn similarity index 91% rename from services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/BUILD.gn rename to services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/BUILD.gn index be9d7eaa253b5340bc29de0fd7335ccf79ce09a2..885e1a59bb134f6b26b8a8896f6c5f0bf5663021 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/BUILD.gn +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/BUILD.gn @@ -17,10 +17,10 @@ import("//build/test.gni") import("../../../../../../../distributedscreen.gni") ##############################fuzztest########################################## -ohos_fuzztest("OnChangeFuzzTest") { +ohos_fuzztest("DScreenManagerFuzzTest") { module_out_path = "${fuzz_test_path}/sourceservice" - fuzz_config_file = "${services_path}/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer" + fuzz_config_file = "${services_path}/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer" include_dirs = [ "./dscreenservice/include/callback", @@ -37,7 +37,7 @@ ohos_fuzztest("OnChangeFuzzTest") { configs = [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - sources = [ "onchange_fuzzer.cpp" ] + sources = [ "dscreenmanager_fuzzer.cpp" ] deps = [ "${services_path}/screenservice/sourceservice:distributed_screen_source", @@ -45,7 +45,7 @@ ohos_fuzztest("OnChangeFuzzTest") { defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"OnChangeFuzzTest\"", + "DH_LOG_TAG=\"DScreenManagerFuzzTest\"", "LOG_DOMAIN=0xD004140", ] @@ -64,6 +64,6 @@ ohos_fuzztest("OnChangeFuzzTest") { ############################################################################### group("fuzztest") { testonly = true - deps = [ ":OnChangeFuzzTest" ] + deps = [ ":DScreenManagerFuzzTest" ] } ############################################################################### diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/corpus/init b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/corpus/init similarity index 100% rename from services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/corpus/init rename to services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/corpus/init diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..221aeab3cf2009be0507fd505ebcf08b2da45816 --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2023-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 "dscreenmanager_fuzzer.h" + +#include +#include + +#include "1.0/include/dscreen_manager.h" + +namespace OHOS { +namespace DistributedHardware { +namespace V1_0 { +void OnChangeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint64_t))) { + return; + } + std::vector screenIds; + uint64_t screenIdOne = *(reinterpret_cast(data)); + screenIds.emplace_back(screenIdOne); + Rosen::ScreenGroupChangeEvent event = Rosen::ScreenGroupChangeEvent::ADD_TO_GROUP; + DScreenGroupListener dScreenGroupListener; + dScreenGroupListener.OnChange(screenIds, event); +} + +void HandleScreenChangeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t))) { + return; + } + + uint32_t eventValue = *(reinterpret_cast(data)) % 3; + if ((eventValue != static_cast(Rosen::ScreenGroupChangeEvent::ADD_TO_GROUP)) || + (eventValue != static_cast(Rosen::ScreenGroupChangeEvent::REMOVE_FROM_GROUP)) || + (eventValue != static_cast(Rosen::ScreenGroupChangeEvent::CHANGE_GROUP))) { + return; + } + + std::shared_ptr dScreenCallback = std::make_shared(); + std::shared_ptr dScreen = std::make_shared("devId000", "dhId000", dScreenCallback); + Rosen::ScreenGroupChangeEvent event = static_cast(eventValue); + + std::shared_ptr dscreenManager = std::make_shared(); + dscreenManager->HandleScreenChange(dScreen, event); +} + +void AddToGroupFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint64_t))) { + return; + } + + uint64_t screenId = *(reinterpret_cast(data)); + std::shared_ptr dScreenCallback = std::make_shared(); + std::shared_ptr dScreen = std::make_shared("devId000", "dhId000", dScreenCallback); + + std::shared_ptr dscreenManager = std::make_shared(); + dscreenManager->AddToGroup(dScreen, screenId); + dscreenManager->RemoveFromGroup(dScreen, screenId); +} + +void DScreenCallbackOnRegResultFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + + std::string screenId(reinterpret_cast(data), size); + int32_t status = *(reinterpret_cast(data)); + std::string dataStr(reinterpret_cast(data), size); + + std::shared_ptr dScreenCallback = std::make_shared(); + std::shared_ptr dScreen = std::make_shared("devId000", "dhId000", dScreenCallback); + dScreenCallback->OnRegResult(dScreen, screenId, status, dataStr); + dScreenCallback->OnUnregResult(dScreen, screenId, status, dataStr); +} + +void DScreenManagerOnUnregResultFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + + std::string reqId(reinterpret_cast(data), size); + int32_t status = *(reinterpret_cast(data)); + std::string dataStr(reinterpret_cast(data), size); + + std::shared_ptr dScreenCallback = std::make_shared(); + std::shared_ptr dScreen = std::make_shared("devId000", "dhId000", dScreenCallback); + std::shared_ptr dscreenManager = std::make_shared(); + dscreenManager->OnRegResult(dScreen, reqId, status, dataStr); + dscreenManager->OnUnregResult(dScreen, reqId, status, dataStr); +} + +void NotifyRemoteScreenServiceFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + + std::string devId(reinterpret_cast(data), size); + int32_t eventCode = *(reinterpret_cast(data)); + std::string eventContent(reinterpret_cast(data), size); + + std::shared_ptr dscreenManager = std::make_shared(); + dscreenManager->NotifyRemoteScreenService(devId, eventCode, eventContent); +} + +void HandleNotifySetUpResultFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + std::string remoteDevId(reinterpret_cast(data), size); + std::string eventContent(reinterpret_cast(data), size); + + std::shared_ptr dscreenManager = std::make_shared(); + dscreenManager->HandleNotifySetUpResult(remoteDevId, eventContent); +} + +} // namespace V1_0 +} // 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::V1_0::OnChangeFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::HandleScreenChangeFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::AddToGroupFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::DScreenCallbackOnRegResultFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::DScreenManagerOnUnregResultFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::NotifyRemoteScreenServiceFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::HandleNotifySetUpResultFuzzTest(data, size); + return 0; +} diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.h b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.h similarity index 93% rename from services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.h rename to services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.h index 26a3775e9a3c6f24fa58f6a5b4a6b82eb29c106e..91d433d33d08e29a9888b5b7241f8cd2f1a86cad 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.h +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.h @@ -16,6 +16,6 @@ #ifndef ONCHANGE_FUZZER_H #define ONCHANGE_FUZZER_H -#define FUZZ_PROJECT_NAME "onchange_fuzzer" +#define FUZZ_PROJECT_NAME "dscreenmanager_fuzzer" #endif \ No newline at end of file diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/project.xml b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/project.xml similarity index 100% rename from services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/project.xml rename to services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/project.xml diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.cpp b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.cpp deleted file mode 100644 index 44c0b0d86167a323a5348b619fdb926eaf8f17e8..0000000000000000000000000000000000000000 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2023-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 "onchange_fuzzer.h" - -#include -#include - -#include "1.0/include/dscreen_manager.h" - -namespace OHOS { -namespace DistributedHardware { -namespace V1_0 { -void OnChangeFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(uint64_t))) { - return; - } - std::vector screenIds; - uint64_t screenIdOne = *(reinterpret_cast(data)); - screenIds.emplace_back(screenIdOne); - Rosen::ScreenGroupChangeEvent event = Rosen::ScreenGroupChangeEvent::ADD_TO_GROUP; - DScreenGroupListener dScreenGroupListener; - dScreenGroupListener.OnChange(screenIds, event); -} -} // namespace V1_0 -} // 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::V1_0::OnChangeFuzzTest(data, size); - return 0; -} - diff --git a/services/screenservice/test/unittest/sinkservice/dscreenservice/BUILD.gn b/services/screenservice/test/unittest/sinkservice/dscreenservice/BUILD.gn index f29179a574b4feb1648b7480d3da0fe1c07bbd06..16472d9f4829fb2b27adfb43b2993a0abc875cc4 100644 --- a/services/screenservice/test/unittest/sinkservice/dscreenservice/BUILD.gn +++ b/services/screenservice/test/unittest/sinkservice/dscreenservice/BUILD.gn @@ -47,12 +47,12 @@ ohos_unittest("DScreenSinkStubTest") { deps = [ "${interfaces_path}/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk", "${services_path}/screenservice/sinkservice:distributed_screen_sink", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", ] external_deps = [ "c_utils:utils", + "googletest:gmock", + "googletest:gtest_main", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregion_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregion_test.cpp index 29a019704b6dd700d61844525d6336c52436e235..1d22cc310a8d329ade64e955d99bc6223523964a 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregion_test.cpp +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregion_test.cpp @@ -266,7 +266,7 @@ HWTEST_F(ScreenRegionTestV1, Stop_003, TestSize.Level1) screenRegion_->sinkTrans_ = std::make_shared(); int32_t ret = screenRegion_->Stop(); - EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, ret); + EXPECT_NE(ERR_DH_SCREEN_SA_SINKTRANS_NOT_INIT, ret); } } // namespace V1_0 } // namespace DistributedHardware diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregion_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregion_test.cpp index b63b7f1c34720312fd95b8c60a7676129b3dceb4..e17ecea06fe5b7853a2d61804e834d38ff6a3ce7 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregion_test.cpp +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregion_test.cpp @@ -16,6 +16,7 @@ #include "2.0/include/screenregion_test.h" #include "dscreen_constants.h" #include "engine_test_utils.h" +#include "iconsumer_surface.h" #include "screen_client.h" using namespace testing; @@ -34,7 +35,12 @@ void ScreenRegionTestV2::SetUp(void) screenRegion_ = std::make_shared(remoteDevId); } -void ScreenRegionTestV2::TearDown(void) {} +void ScreenRegionTestV2::TearDown(void) +{ + if (screenRegion_ != nullptr) { + screenRegion_ = nullptr; + } +} /** * @tc.name: OnEngineEvent_001 @@ -48,6 +54,8 @@ HWTEST_F(ScreenRegionTestV2, OnEngineEvent_001, TestSize.Level1) const std::string content = "OnEngineEvent_001"; screenRegion_->receiverAdapter_ = nullptr; screenRegion_->OnEngineEvent(event, content); + event = DScreenEventType::TRANS_CHANNEL_CLOSED; + screenRegion_->OnEngineEvent(event, content); EXPECT_EQ(ERR_DH_AV_TRANS_NULL_VALUE, screenRegion_->StopReceiverEngine()); } @@ -299,14 +307,36 @@ HWTEST_F(ScreenRegionTestV2, StopReceiverEngine_002, TestSize.Level1) /** * @tc.name: SetUp_001 - * @tc.desc: Verify the SetUp function failed. + * @tc.desc: Verify the SetUp function. * @tc.type: FUNC * @tc.require: Issue Number */ HWTEST_F(ScreenRegionTestV2, SetUp_001, TestSize.Level1) { - const std::string content = "SetUp_001"; + std::string content = "invalidJsonString"; + EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, screenRegion_->SetUp(content)); + + json contentJson; + content = contentJson.dump(); + EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, screenRegion_->SetUp(content)); + + contentJson[KEY_SCREEN_ID] = 12345; + content = contentJson.dump(); EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, screenRegion_->SetUp(content)); + + VideoParam param; + contentJson[KEY_VIDEO_PARAM] = param; + content = contentJson.dump(); + EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, screenRegion_->SetUp(content)); + + DScreenMapRelation dScreenMapRelation; + contentJson[KEY_MAPRELATION] = dScreenMapRelation; + content = contentJson.dump(); + screenRegion_->receiverAdapter_ = nullptr; + EXPECT_EQ(ERR_DH_AV_TRANS_NULL_VALUE, screenRegion_->SetUp(content)); + + screenRegion_->receiverAdapter_ = std::make_shared(); + EXPECT_EQ(DH_SUCCESS, screenRegion_->SetUp(content)); } /** @@ -335,6 +365,113 @@ HWTEST_F(ScreenRegionTestV2, ConfigWindow_002, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, screenRegion_->ConfigWindow()); } +/** + * @tc.name: SetReceiverAdapterParameters_001 + * @tc.desc: Verify the SetReceiverAdapterParameters function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionTestV2, SetReceiverAdapterParameters_001, TestSize.Level1) +{ + screenRegion_->videoParam_ = nullptr; + int32_t ret = screenRegion_->SetReceiverAdapterParameters(); + EXPECT_EQ(ret, ERR_DH_AV_TRANS_NULL_VALUE); + + screenRegion_->videoParam_ = std::make_shared(); + screenRegion_->receiverAdapter_ = nullptr; + ret = screenRegion_->SetReceiverAdapterParameters(); + EXPECT_EQ(ret, ERR_DH_AV_TRANS_NULL_VALUE); + + uint8_t codecType = VIDEO_CODEC_TYPE_VIDEO_H265; + uint8_t videoFormat = VIDEO_DATA_FORMAT_YUVI420; + screenRegion_->receiverAdapter_ = std::make_shared(); + screenRegion_->videoParam_->SetCodecType(codecType); + screenRegion_->videoParam_->SetVideoFormat(videoFormat); + ret = screenRegion_->SetReceiverAdapterParameters(); + EXPECT_EQ(ret, DH_SUCCESS); + + codecType = VIDEO_CODEC_TYPE_VIDEO_MPEG4; + videoFormat = VIDEO_DATA_FORMAT_RGBA8888; + screenRegion_->videoParam_->SetCodecType(codecType); + screenRegion_->videoParam_->SetVideoFormat(videoFormat); + ret = screenRegion_->SetReceiverAdapterParameters(); + EXPECT_EQ(ret, DH_SUCCESS); + + videoFormat = VIDEO_DATA_FORMAT_NV21; + screenRegion_->videoParam_->SetCodecType(codecType); + screenRegion_->videoParam_->SetVideoFormat(videoFormat); + ret = screenRegion_->SetReceiverAdapterParameters(); + EXPECT_EQ(ret, DH_SUCCESS); +} + +/** + * @tc.name: SetAlignedHeight_001 + * @tc.desc: Verify the SetAlignedHeight function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionTestV2, SetAlignedHeight_001, TestSize.Level1) +{ + sptr wsBuffer = nullptr; + std::shared_ptr buffer = nullptr; + screenRegion_->GetWSBuffer(wsBuffer, buffer); + + wsBuffer = SurfaceBuffer::Create(); + screenRegion_->GetWSBuffer(wsBuffer, buffer); + + buffer = std::make_shared(); + screenRegion_->videoParam_ = nullptr; + screenRegion_->windowSurface_ = nullptr; + screenRegion_->GetWSBuffer(wsBuffer, buffer); + + int32_t ret = screenRegion_->SetAlignedHeight(); + EXPECT_EQ(ret, ERR_DH_AV_TRANS_NULL_VALUE); + + uint32_t height = 31; + screenRegion_->videoParam_ = std::make_shared(); + screenRegion_->videoParam_->SetVideoHeight(height); + screenRegion_->GetWSBuffer(wsBuffer, buffer); + ret = screenRegion_->SetAlignedHeight(); + EXPECT_EQ(ret, DH_SUCCESS); + EXPECT_EQ(screenRegion_->alignedHeight_, 32); + + height = 32; + screenRegion_->videoParam_->SetVideoHeight(height); + ret = screenRegion_->SetAlignedHeight(); + EXPECT_EQ(ret, DH_SUCCESS); + EXPECT_EQ(screenRegion_->alignedHeight_, 32); +} +/** + * @tc.name: OnEngineDataDone_001 + * @tc.desc: Verify the OnEngineDataDone function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionTestV2, OnEngineDataDone_001, TestSize.Level1) +{ + std::shared_ptr buffer = nullptr; + size_t frameNumber = screenRegion_->frameNumber_; + screenRegion_->OnEngineDataDone(buffer); + EXPECT_TRUE(screenRegion_->frameNumber_ > frameNumber); + + buffer = std::make_shared(); + screenRegion_->videoParam_ = nullptr; + screenRegion_->windowSurface_ = nullptr; + frameNumber = screenRegion_->frameNumber_; + screenRegion_->OnEngineDataDone(buffer); + EXPECT_TRUE(screenRegion_->frameNumber_ > frameNumber); + + screenRegion_->windowSurface_ = IConsumerSurface::Create(); + frameNumber = screenRegion_->frameNumber_; + screenRegion_->OnEngineDataDone(buffer); + EXPECT_TRUE(screenRegion_->frameNumber_ > frameNumber); + + screenRegion_->videoParam_ = std::make_shared(); + frameNumber = screenRegion_->frameNumber_; + screenRegion_->OnEngineDataDone(buffer); + EXPECT_TRUE(screenRegion_->frameNumber_ > frameNumber); +} + /** * @tc.name: CheckContentJson_001 * @tc.desc: Verify the CheckContentJson function failed. diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregionmgr_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregionmgr_test.cpp index f18233062bba854b2f38b253e6cc86e4013fe056..3194376494853e88b4aff382b076982e227227fd 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregionmgr_test.cpp +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregionmgr_test.cpp @@ -97,17 +97,26 @@ HWTEST_F(ScreenRegionManagerTestV2, GetScreenDumpInfo_002, TestSize.Level1) } /** - * @tc.name: OnProviderEvent_002 + * @tc.name: OnProviderEvent_001 * @tc.desc: Verify the OnProviderEvent function failed. * @tc.type: FUNC * @tc.require: Issue Number */ -HWTEST_F(ScreenRegionManagerTestV2, OnProviderEvent_002, TestSize.Level1) +HWTEST_F(ScreenRegionManagerTestV2, OnProviderEvent_001, TestSize.Level1) { AVTransEvent event; EngineProviderListener engineProviderListener; + event.type = EventType::EVENT_CHANNEL_OPENED; int32_t ret = engineProviderListener.OnProviderEvent(event); EXPECT_EQ(DH_SUCCESS, ret); + + event.type = EventType::EVENT_CHANNEL_CLOSED; + ret = engineProviderListener.OnProviderEvent(event); + EXPECT_EQ(DH_SUCCESS, ret); + + event.type = EventType::EVENT_ENGINE_ERROR; + ret = engineProviderListener.OnProviderEvent(event); + EXPECT_EQ(DH_SUCCESS, ret); } } // namespace V2_0 } // namespace DistributedHardware diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn b/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn index 8ea8bd5733b630880c5948168f79d6d7bcc08114..f95607353dba774636d373d1e684e8cc28357cdb 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn @@ -67,8 +67,6 @@ ohos_unittest("DscreenRegionMgrTest") { "${services_path}/screenservice/sinkservice:distributed_screen_sink", "${services_path}/screenservice/sourceservice:distributed_screen_source", "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", ] external_deps = [ @@ -78,6 +76,8 @@ ohos_unittest("DscreenRegionMgrTest") { "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:distributedhardwareutils", "distributed_hardware_fwk:libdhfwk_sdk", + "googletest:gmock", + "googletest:gtest_main", "graphic_2d:libcomposer", "graphic_2d:libgraphic_utils", "graphic_2d:librender_service_client", diff --git a/services/screenservice/test/unittest/sourceservice/dscreenmgr/BUILD.gn b/services/screenservice/test/unittest/sourceservice/dscreenmgr/BUILD.gn index 3d20b361d39938ca2736a18ad7f55aee84e3aaf6..a9dcd9bf6d622227e805b38faba6ec6df6e2ea43 100644 --- a/services/screenservice/test/unittest/sourceservice/dscreenmgr/BUILD.gn +++ b/services/screenservice/test/unittest/sourceservice/dscreenmgr/BUILD.gn @@ -68,8 +68,6 @@ ohos_unittest("DscreenMgrTest") { "${distributedscreen_path}/common:distributed_screen_utils", "${services_path}/screenservice/sourceservice:distributed_screen_source", "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", ] external_deps = [ @@ -83,6 +81,8 @@ ohos_unittest("DscreenMgrTest") { "distributed_hardware_fwk:distributedhardwareutils", "distributed_hardware_fwk:libdhfwk_sdk", "dsoftbus:softbus_client", + "googletest:gmock", + "googletest:gtest_main", "graphic_2d:libcomposer", "graphic_2d:librender_service_client", "graphic_surface:surface", diff --git a/services/screenservice/test/unittest/sourceservice/dscreenservice/BUILD.gn b/services/screenservice/test/unittest/sourceservice/dscreenservice/BUILD.gn index fffb46fbe76aa0bc0fc56fc541fbf7b7655523a8..6c79e0f3339cdd1ff633824af3b5349aea22ad56 100644 --- a/services/screenservice/test/unittest/sourceservice/dscreenservice/BUILD.gn +++ b/services/screenservice/test/unittest/sourceservice/dscreenservice/BUILD.gn @@ -52,13 +52,13 @@ ohos_unittest("DScreenSourceStubTest") { deps = [ "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", "${services_path}/screenservice/sourceservice:distributed_screen_source", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", ] external_deps = [ "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", + "googletest:gmock", + "googletest:gtest_main", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/services/screentransport/screendatachannel/include/screen_data_channel_impl.h b/services/screentransport/screendatachannel/include/screen_data_channel_impl.h index 23a3bc10aa335dcce84f8310425d3993a6e91738..46a1d95c80b70b12ff02b9585adb70310e70b902 100644 --- a/services/screentransport/screendatachannel/include/screen_data_channel_impl.h +++ b/services/screentransport/screendatachannel/include/screen_data_channel_impl.h @@ -34,7 +34,7 @@ public: ~ScreenDataChannelImpl() override = default; int32_t CreateSession(const std::shared_ptr &listener) override; int32_t ReleaseSession() override; - int32_t OpenSession(const std::shared_ptr &listener) override; + int32_t OpenSession(const std::shared_ptr listener) override; int32_t CloseSession() override; int32_t SendData(const std::shared_ptr &screenData) override; void SetJpegSessionFlag(bool flag) override; diff --git a/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp b/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp index 535eb8df25ec9ec9d5b7dedfe2faa00e21f4ab55..e452b829aba2243e9dae1f691d6c1f5c86612c27 100644 --- a/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp +++ b/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp @@ -100,7 +100,7 @@ int32_t ScreenDataChannelImpl::ReleaseSession() return DH_SUCCESS; } -int32_t ScreenDataChannelImpl::OpenSession(const std::shared_ptr &listener) +int32_t ScreenDataChannelImpl::OpenSession(const std::shared_ptr listener) { DHLOGI("%{public}s: OpenSession, peerDevId(%{public}s)", DSCREEN_LOG_TAG, GetAnonyString(peerDevId_).c_str()); if (listener == nullptr) { diff --git a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp index 88213a5e0643e9387f1df63c7a2c80db86512d76..25015aa9ad801390e79f26136bd040731072e07f 100644 --- a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp +++ b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp @@ -479,11 +479,15 @@ void ImageSinkDecoder::DecodeScreenData() int32_t bufferIndex = 0; { std::unique_lock lock(dataMutex_); - decodeCond_.wait_for(lock, std::chrono::milliseconds(DECODE_WAIT_MILLISECONDS), [this]() { + auto status = decodeCond_.wait_for(lock, std::chrono::milliseconds(DECODE_WAIT_MILLISECONDS), [this]() { return (!videoDataQueue_.empty() && !availableInputIndexsQueue_.empty() && !availableInputBufferQueue_.empty()); }); - + if (!status) { + DHLOGD("%{public}s: Data queue wait timeout after %{public}d ms.", DSCREEN_LOG_TAG, + DECODE_WAIT_MILLISECONDS); + continue; + } if (videoDataQueue_.empty() || availableInputIndexsQueue_.empty() || availableInputBufferQueue_.empty()) { DHLOGD("%{public}s: Index queue or data queue or buffer queue is empty.", DSCREEN_LOG_TAG); continue; diff --git a/services/screentransport/screensinktrans/BUILD.gn b/services/screentransport/screensinktrans/BUILD.gn index 4bb63ebcce1310d2c4bf886a4aa7c4b48e8d181a..f073e1aa117311d0f71fac3f7d805e9765f46f93 100644 --- a/services/screentransport/screensinktrans/BUILD.gn +++ b/services/screentransport/screensinktrans/BUILD.gn @@ -80,8 +80,6 @@ ohos_shared_library("distributed_screen_sinktrans") { "media_foundation:media_foundation", ] - public_external_deps = [ "json:nlohmann_json_static" ] - subsystem_name = "distributedhardware" part_name = "distributed_screen" diff --git a/services/screentransport/screensinktrans/src/screen_sink_trans.cpp b/services/screentransport/screensinktrans/src/screen_sink_trans.cpp index e25957386231e696f4a6241929ddc1338ecaebaf..9f53f9efc70cdd10b161e96a65eb3ded5afea676 100644 --- a/services/screentransport/screensinktrans/src/screen_sink_trans.cpp +++ b/services/screentransport/screensinktrans/src/screen_sink_trans.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -48,24 +48,29 @@ int32_t ScreenSinkTrans::SetUp(const VideoParam &localParam, const VideoParam &r int32_t ScreenSinkTrans::Release() { DHLOGI("%{public}s: Release.", DSCREEN_LOG_TAG); - if (imageProcessor_ == nullptr || screenChannel_ == nullptr) { - DHLOGE("%{public}s: Processor or channel is null, Setup first.", DSCREEN_LOG_TAG); - return ERR_DH_SCREEN_TRANS_NULL_VALUE; - } - int32_t ret = imageProcessor_->ReleaseImageProcessor(); - if (ret != DH_SUCCESS) { - DHLOGD("%{public}s: Release image processor failed ret: %{public}" PRId32, DSCREEN_LOG_TAG, ret); + int32_t ret = 0; + if (imageProcessor_ != nullptr) { + ret = imageProcessor_->ReleaseImageProcessor(); + if (ret != DH_SUCCESS) { + DHLOGW("%{public}s: Release image processor failed ret: %{public}" PRId32, DSCREEN_LOG_TAG, ret); + } + imageProcessor_ = nullptr; + } else { + DHLOGI("%{public}s: Processor is null, Setup first.", DSCREEN_LOG_TAG); } - imageProcessor_ = nullptr; - StartTrace(DSCREEN_HITRACE_LABEL, DSCREEN_SINK_RELEASE_SESSION_START); - ret = screenChannel_->ReleaseSession(); - FinishTrace(DSCREEN_HITRACE_LABEL); - if (ret != DH_SUCCESS) { - DHLOGD("%{public}s: Release channel session failed ret: %{public}" PRId32, DSCREEN_LOG_TAG, ret); + if (screenChannel_ != nullptr) { + StartTrace(DSCREEN_HITRACE_LABEL, DSCREEN_SINK_RELEASE_SESSION_START); + ret = screenChannel_->ReleaseSession(); + FinishTrace(DSCREEN_HITRACE_LABEL); + if (ret != DH_SUCCESS) { + DHLOGW("%{public}s: Release channel session failed ret: %{public}" PRId32, DSCREEN_LOG_TAG, ret); + } + screenChannel_ = nullptr; + } else { + DHLOGI("%{public}s: Channel is null, Setup first.", DSCREEN_LOG_TAG); } - screenChannel_ = nullptr; DHLOGI("%{public}s: Release success.", DSCREEN_LOG_TAG); return DH_SUCCESS; @@ -92,29 +97,26 @@ int32_t ScreenSinkTrans::Start() int32_t ScreenSinkTrans::Stop() { DHLOGI("%{public}s: Stop.", DSCREEN_LOG_TAG); - if (imageProcessor_ == nullptr || screenChannel_ == nullptr) { - DHLOGE("%{public}s: Processor or channel is null, Setup first.", DSCREEN_LOG_TAG); - return ERR_DH_SCREEN_TRANS_NULL_VALUE; - } - bool stopStatus = true; - int32_t ret = imageProcessor_->StopImageProcessor(); - if (ret != DH_SUCCESS) { - DHLOGD("%{public}s: Stop image processor failed ret: %{public}" PRId32, DSCREEN_LOG_TAG, ret); - stopStatus = false; - } - - StartTrace(DSCREEN_HITRACE_LABEL, DSCREEN_SINK_CLOSE_SESSION_START); - ret = screenChannel_->CloseSession(); - FinishTrace(DSCREEN_HITRACE_LABEL); - if (ret != DH_SUCCESS && ret != ERR_DH_SCREEN_TRANS_SESSION_NOT_OPEN) { - DHLOGD("%{public}s: Close Session failed ret: %{public}" PRId32, DSCREEN_LOG_TAG, ret); - stopStatus = false; + int32_t ret = 0; + if (imageProcessor_ != nullptr) { + ret = imageProcessor_->StopImageProcessor(); + if (ret != DH_SUCCESS) { + DHLOGW("%{public}s: Stop image processor failed ret: %{public}" PRId32, DSCREEN_LOG_TAG, ret); + } + } else { + DHLOGI("%{public}s: Processor is null, Setup first.", DSCREEN_LOG_TAG); } - if (!stopStatus) { - DHLOGE("%{public}s: Stop sink trans failed.", DSCREEN_LOG_TAG); - return ERR_DH_SCREEN_TRANS_ERROR; + if (screenChannel_ != nullptr) { + StartTrace(DSCREEN_HITRACE_LABEL, DSCREEN_SINK_CLOSE_SESSION_START); + ret = screenChannel_->CloseSession(); + FinishTrace(DSCREEN_HITRACE_LABEL); + if (ret != DH_SUCCESS) { + DHLOGW("%{public}s: Close Session failed ret: %{public}" PRId32, DSCREEN_LOG_TAG, ret); + } + } else { + DHLOGI("%{public}s: Channel is null, Setup first.", DSCREEN_LOG_TAG); } DHLOGI("%{public}s: Stop success.", DSCREEN_LOG_TAG); diff --git a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp index c2b3b08f6a3f289c0c1a740330b0d15d7f006358..07ee23fa8adf48d5919626ad06c9569e2412a248 100644 --- a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp +++ b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp @@ -43,10 +43,6 @@ void ConsumerBufferListener::OnBufferAvailable() void ImageSourceEncoder::InitDscreenDBG() { - if ((DBG_SO_NAME.length() == 0) || (DBG_SO_NAME.length() > PATH_MAX)) { - DHLOGE("File canonicalization failed, so name: %{public}s.", DBG_SO_NAME.c_str()); - return; - } pHandler_ = dlopen(DBG_SO_NAME.c_str(), RTLD_LAZY | RTLD_NODELETE | RTLD_GLOBAL); if (pHandler_ == nullptr) { DHLOGE("so: %{public}s load failed, fail reason: %{public}s.", DBG_SO_NAME.c_str(), dlerror()); @@ -442,4 +438,4 @@ void ImageSourceEncoder::OnOutputFormatChanged(const Media::Format &format) (void) format; } } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/screentransport/screensourcetrans/BUILD.gn b/services/screentransport/screensourcetrans/BUILD.gn index 0960cebcd41451f1c70504da3b06fcd97d976f2f..d75d798ea84f4cee99bfd16bb22b292ff6d5db6e 100644 --- a/services/screentransport/screensourcetrans/BUILD.gn +++ b/services/screentransport/screensourcetrans/BUILD.gn @@ -81,8 +81,6 @@ ohos_shared_library("distributed_screen_sourcetrans") { "media_foundation:media_foundation", ] - public_external_deps = [ "json:nlohmann_json_static" ] - subsystem_name = "distributedhardware" part_name = "distributed_screen" diff --git a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp index 5fe9e2a5a8065438504fddfc0d369bddc6e0a888..60d8e3900b82574a9eef8567585f1ab8ff5cb1fc 100644 --- a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp +++ b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp @@ -415,7 +415,13 @@ void ScreenSourceTrans::FeedChannelData() std::shared_ptr screenData; { std::unique_lock lock(dataQueueMtx_); - dataCond_.wait_for(lock, std::chrono::seconds(DATA_WAIT_SECONDS), [this]() { return !dataQueue_.empty(); }); + auto status = dataCond_.wait_for( + lock, std::chrono::seconds(DATA_WAIT_SECONDS), [this]() { return !dataQueue_.empty(); }); + if (!status) { + DHLOGD("%{public}s: Data queue wait timeout after %{public}d seconds.", DSCREEN_LOG_TAG, + DATA_WAIT_SECONDS); + continue; + } if (dataQueue_.empty()) { DHLOGD("%{public}s:Data queue is empty.", DSCREEN_LOG_TAG); continue; diff --git a/services/screentransport/test/unittest/screendatachannel/BUILD.gn b/services/screentransport/test/unittest/screendatachannel/BUILD.gn index 2d1f4b3bc21faab456d307219c7e0ab6d357da44..05329a4d8262879cdd394ad261b5b5b5cd7be5c0 100644 --- a/services/screentransport/test/unittest/screendatachannel/BUILD.gn +++ b/services/screentransport/test/unittest/screendatachannel/BUILD.gn @@ -52,11 +52,7 @@ ohos_unittest("DataChannelTest") { "${common_path}/test/unittest/resource:dscreen_unittest_public_config", ] - deps = [ - "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] + deps = [ "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans" ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -65,6 +61,8 @@ ohos_unittest("DataChannelTest") { "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", "dsoftbus:softbus_client", + "googletest:gmock", + "googletest:gtest_main", "hilog:libhilog", ] diff --git a/services/screentransport/test/unittest/screensinkprocessor/BUILD.gn b/services/screentransport/test/unittest/screensinkprocessor/BUILD.gn index a46b88b25f1453c56f976dffcc84b27e22deb095..5b85c35e4e09a7ac74649b9be436ab43b8a82272 100644 --- a/services/screentransport/test/unittest/screensinkprocessor/BUILD.gn +++ b/services/screentransport/test/unittest/screensinkprocessor/BUILD.gn @@ -58,16 +58,14 @@ ohos_unittest("SinkProcessorTest") { "${common_path}/test/unittest/resource:dscreen_unittest_public_config", ] - deps = [ - "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] + deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] external_deps = [ "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", + "googletest:gmock", + "googletest:gtest_main", "graphic_surface:surface", "hilog:libhilog", "media_foundation:media_foundation", diff --git a/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_decoder_test.cpp b/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_decoder_test.cpp index 6f9a503f18311db33a296f63b9eef93ed3f16ced..62dfa99dedf8e19c0625a84048c9dd4a724afc2d 100644 --- a/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_decoder_test.cpp +++ b/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_decoder_test.cpp @@ -286,6 +286,37 @@ HWTEST_F(ImageSinkDecoderTest, set_output_surface_test_001, TestSize.Level1) EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, imageDecoder_->SetOutputSurface(pSurface)); } +/** + * @tc.name: set_output_surface_test_002 + * @tc.desc: Verify the SetOutputSurface function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ImageSinkDecoderTest, set_output_surface_test_002, TestSize.Level1) +{ + MediaAVCodec::AVCodecErrorType errorType = MediaAVCodec::AVCODEC_ERROR_EXTEND_START; + imageDecoder_->OnError(errorType, DH_SUCCESS); + sptr surface = IConsumerSurface::Create("test"); + sptr bp = surface->GetProducer(); + sptr pSurface = nullptr; + EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, imageDecoder_->SetOutputSurface(pSurface)); + + pSurface = Surface::CreateSurfaceAsProducer(bp); + imageDecoder_->consumerSurface_ = nullptr; + EXPECT_NE(ERR_DH_SCREEN_TRANS_NULL_VALUE, imageDecoder_->SetOutputSurface(pSurface)); + + imageDecoder_->consumerSurface_ = IConsumerSurface::Create(); + imageDecoder_->producerSurface_ = nullptr; + EXPECT_NE(ERR_DH_SCREEN_TRANS_NULL_VALUE, imageDecoder_->SetOutputSurface(pSurface)); + + imageDecoder_->producerSurface_ = IConsumerSurface::Create(); + imageDecoder_->configParam_.SetPartialRefreshFlag(false); + EXPECT_NE(ERR_DH_SCREEN_TRANS_NULL_VALUE, imageDecoder_->SetOutputSurface(pSurface)); + + imageDecoder_->configParam_.SetPartialRefreshFlag(true); + EXPECT_NE(ERR_DH_SCREEN_TRANS_NULL_VALUE, imageDecoder_->SetOutputSurface(pSurface)); +} + /** * @tc.name: InputScreenData_test_001 * @tc.desc: Verify the InputScreenData function. @@ -383,7 +414,7 @@ HWTEST_F(ImageSinkDecoderTest, on_output_format_changed_test_001, TestSize.Level /** * @tc.name: ProcessData_001 - * @tc.desc: Verify the DecodeScreenData function. + * @tc.desc: Verify the ProcessData function. * @tc.type: FUNC * @tc.require: Issue Number */ @@ -396,7 +427,7 @@ HWTEST_F(ImageSinkDecoderTest, ProcessData_001, TestSize.Level1) /** * @tc.name: ProcessData_002 - * @tc.desc: Verify the DecodeScreenData function. + * @tc.desc: Verify the ProcessData function. * @tc.type: FUNC * @tc.require: Issue Number */ @@ -410,7 +441,7 @@ HWTEST_F(ImageSinkDecoderTest, ProcessData_002, TestSize.Level1) /** * @tc.name: ProcessData_003 - * @tc.desc: Verify the DecodeScreenData function. + * @tc.desc: Verify the ProcessData function. * @tc.type: FUNC * @tc.require: Issue Number */ @@ -423,7 +454,7 @@ HWTEST_F(ImageSinkDecoderTest, ProcessData_003, TestSize.Level1) /** * @tc.name: ProcessData_004 - * @tc.desc: Verify the DecodeScreenData function. + * @tc.desc: Verify the ProcessData function. * @tc.type: FUNC * @tc.require: Issue Number */ @@ -438,7 +469,7 @@ HWTEST_F(ImageSinkDecoderTest, ProcessData_004, TestSize.Level1) /** * @tc.name: ProcessData_005 - * @tc.desc: Verify the DecodeScreenData function. + * @tc.desc: Verify the ProcessData function. * @tc.type: FUNC * @tc.require: Issue Number */ @@ -454,7 +485,7 @@ HWTEST_F(ImageSinkDecoderTest, ProcessData_005, TestSize.Level1) /** * @tc.name: ProcessData_006 - * @tc.desc: Verify the DecodeScreenData function. + * @tc.desc: Verify the ProcessData function. * @tc.type: FUNC * @tc.require: Issue Number */ diff --git a/services/screentransport/test/unittest/screensinktrans/BUILD.gn b/services/screentransport/test/unittest/screensinktrans/BUILD.gn index 6b4550dc9881ac60857f0ccaa3c4d569d3166d40..cf17a523432906940f4c0370e628d95164c02880 100644 --- a/services/screentransport/test/unittest/screensinktrans/BUILD.gn +++ b/services/screentransport/test/unittest/screensinktrans/BUILD.gn @@ -55,17 +55,15 @@ ohos_unittest("SinkTransTest") { "${common_path}/test/unittest/resource:dscreen_unittest_public_config", ] - deps = [ - "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] + deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] external_deps = [ "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", "dsoftbus:softbus_client", + "googletest:gmock", + "googletest:gtest_main", "graphic_surface:surface", "hilog:libhilog", "media_foundation:media_foundation", diff --git a/services/screentransport/test/unittest/screensinktrans/src/screen_sink_trans_test.cpp b/services/screentransport/test/unittest/screensinktrans/src/screen_sink_trans_test.cpp index 241850622661b337486ed2c826378d0ce12c3679..51b6a590d7e1cf98efa813339433b62f2c158088 100644 --- a/services/screentransport/test/unittest/screensinktrans/src/screen_sink_trans_test.cpp +++ b/services/screentransport/test/unittest/screensinktrans/src/screen_sink_trans_test.cpp @@ -120,7 +120,7 @@ HWTEST_F(ScreenSinkTransTest, release_test_001, TestSize.Level1) HWTEST_F(ScreenSinkTransTest, release_test_002, TestSize.Level1) { trans_->imageProcessor_ = nullptr; - EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, trans_->Release()); + EXPECT_EQ(DH_SUCCESS, trans_->Release()); } /** @@ -143,7 +143,7 @@ HWTEST_F(ScreenSinkTransTest, start_test_002, TestSize.Level1) */ HWTEST_F(ScreenSinkTransTest, stop_test_002, TestSize.Level1) { - EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, trans_->Stop()); + EXPECT_EQ(DH_SUCCESS, trans_->Stop()); } /** diff --git a/services/screentransport/test/unittest/screensourceprocessor/BUILD.gn b/services/screentransport/test/unittest/screensourceprocessor/BUILD.gn index d10b49cdebe8e75a17a0fb232e465c78aa772481..f54d1338b5681a7c71c4d2fd02f51da9a4be5f06 100644 --- a/services/screentransport/test/unittest/screensourceprocessor/BUILD.gn +++ b/services/screentransport/test/unittest/screensourceprocessor/BUILD.gn @@ -55,16 +55,14 @@ ohos_unittest("SourceProcessorTest") { "${common_path}/test/unittest/resource:dscreen_unittest_public_config", ] - deps = [ - "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] + deps = [ "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans" ] external_deps = [ "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", + "googletest:gmock", + "googletest:gtest_main", "graphic_surface:surface", "graphic_surface:sync_fence", "ipc:ipc_core", diff --git a/services/screentransport/test/unittest/screensourcetrans/BUILD.gn b/services/screentransport/test/unittest/screensourcetrans/BUILD.gn index cf33b5ea69acc15df19dec63cf69d3cfa77b9f85..5899769797d0e672a687fa566295cfe0d3f20080 100644 --- a/services/screentransport/test/unittest/screensourcetrans/BUILD.gn +++ b/services/screentransport/test/unittest/screensourcetrans/BUILD.gn @@ -55,11 +55,7 @@ ohos_unittest("SourceTransTest") { "${common_path}/test/unittest/resource:dscreen_unittest_public_config", ] - deps = [ - "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] + deps = [ "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans" ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -69,6 +65,8 @@ ohos_unittest("SourceTransTest") { "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", "dsoftbus:softbus_client", + "googletest:gmock", + "googletest:gtest_main", "graphic_2d:libgraphic_utils", "graphic_surface:surface", "graphic_surface:sync_fence", diff --git a/services/screentransport/test/unittest/screentranstestutils/BUILD.gn b/services/screentransport/test/unittest/screentranstestutils/BUILD.gn index 36c8da8933ad50824dc4f1067e61c639cde8f14d..6226113765e7c28c3c7fdc595b704def7e5135f4 100644 --- a/services/screentransport/test/unittest/screentranstestutils/BUILD.gn +++ b/services/screentransport/test/unittest/screentranstestutils/BUILD.gn @@ -59,14 +59,14 @@ ohos_unittest("ScreenCallbackTest") { deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans", "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", ] external_deps = [ "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", + "googletest:gmock", + "googletest:gtest_main", "graphic_2d:libgraphic_utils", "graphic_surface:surface", "graphic_surface:sync_fence", diff --git a/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h b/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h index a0a36c99fc850f8882cbbfd998f57ce499d53e93..eb7937564776a085e481c912d709ea5fd5a66a14 100644 --- a/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h +++ b/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h @@ -90,7 +90,7 @@ public: { return DH_SUCCESS; } - int32_t OpenSession(const std::shared_ptr &listener) override + int32_t OpenSession(const std::shared_ptr listener) override { return DH_SUCCESS; } diff --git a/services/softbusadapter/test/fuzztest/BUILD.gn b/services/softbusadapter/test/fuzztest/BUILD.gn index 5798ca82b03ba17d05090a81c76a70ebfd0e07c3..d04b76d9a4b022994ec3e4339836c8acec6faa4f 100644 --- a/services/softbusadapter/test/fuzztest/BUILD.gn +++ b/services/softbusadapter/test/fuzztest/BUILD.gn @@ -14,12 +14,5 @@ group("fuzztest") { testonly = true - deps = [ - "softbusadapter_fuzzer:fuzztest", - "softbusonbytesreceived_fuzzer:fuzztest", - "softbusonmessagereceived_fuzzer:fuzztest", - "softbusonsessionclosed_fuzzer:fuzztest", - "softbusonsessionopened_fuzzer:fuzztest", - "softbusonstreamreceived_fuzzer:fuzztest", - ] + deps = [ "softbusadapter_fuzzer:fuzztest" ] } diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/BUILD.gn index e2bf14e4cc1d894860f39f3887f5936660654db3..1f4510b7f10dfa850c6106fa63aa66a4c031d948 100644 --- a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/BUILD.gn +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/BUILD.gn @@ -29,13 +29,14 @@ ohos_fuzztest("SoftbusAdapterFuzzTest") { include_dirs = [ "${common_path}/include", + "${interfaces_path}/innerkits/native_cpp/test/include", "${services_path}/common/databuffer/include", "${services_path}/common/screen_channel/include", "${services_path}/common/utils/include", - "${services_path}/screentransport/screensourcetrans/include", "${services_path}/screentransport/screendatachannel/include", - "${services_path}/screentransport/screensourceprocessor/include", "${services_path}/screentransport/screensourceprocessor/encoder/include", + "${services_path}/screentransport/screensourceprocessor/include", + "${services_path}/screentransport/screensourcetrans/include", "${services_path}/softbusadapter/include", ] diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp index 50223e1c7141f9a7df79be546a1d6ba11ee9d80c..8b9983117c61faccc0d5df04af1178b93bddf57e 100644 --- a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp @@ -19,9 +19,10 @@ #include "dscreen_errcode.h" #include "dscreen_util.h" #include "isoftbus_listener.h" +#include "socket.h" +#include "softbus_adapter.h" #include "softbus_bus_center.h" #include "softbus_common.h" -#include "softbus_adapter.h" namespace OHOS { namespace DistributedHardware { @@ -62,6 +63,138 @@ void SoftbusAdapterFuzzTest(const uint8_t* data, size_t size) adapter->SendSoftbusBytes(sessionId, adapterData, dataLen1); adapter->CloseSoftbusSession(sessionId); } + +void SoftbusOnBytesReceivedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + void *adapterData = nullptr; + uint32_t dataLen = *(reinterpret_cast(data)); + std::shared_ptr adapter = std::make_shared(); + adapter->OnBytesReceived(sessionId, adapterData, dataLen); +} + +void SoftbusOnMessageReceivedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + void *adapterData = nullptr; + unsigned int dataLen = *(reinterpret_cast(data)); + std::shared_ptr adapter = std::make_shared(); + adapter->OnMessageReceived(sessionId, adapterData, dataLen); +} + +void SoftbusOnSessionClosedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + std::shared_ptr adapter = std::make_shared(); + ShutdownReason reason = SHUTDOWN_REASON_UNKNOWN; + adapter->OnSoftbusSessionClosed(sessionId, reason); +} + +void SoftbusOnSessionOpenedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + PeerSocketInfo peerSocketInfo = { + .name = const_cast(PEER_SESSION_NAME.c_str()), + .networkId = const_cast(REMOTE_DEV_ID.c_str()), + .pkgName = const_cast(DSCREEN_PKG_NAME_TEST.c_str()), + .dataType = DATA_TYPE_BYTES + }; + std::shared_ptr adapter = std::make_shared(); + adapter->OnSoftbusSessionOpened(sessionId, peerSocketInfo); +} + +void SoftbusOnStreamReceivedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + StreamData *stream = nullptr; + StreamData *ext = nullptr; + StreamFrameInfo *info = nullptr; + std::shared_ptr adapter = std::make_shared(); + adapter->OnStreamReceived(sessionId, stream, ext, info); +} + +void SoftbusRegisterSoftbusListenerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::shared_ptr listener = std::make_shared(); + std::string sessionName(reinterpret_cast(data), size); + std::string peerDevId(reinterpret_cast(data), size); + + std::shared_ptr softbusAdapter = std::make_shared(); + (void)softbusAdapter->RegisterSoftbusListener(listener, sessionName, peerDevId); + (void)softbusAdapter->UnRegisterSoftbusListener(sessionName, peerDevId); +} + +void SoftbusUnRegisterSoftbusListenerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string sessionName(reinterpret_cast(data), size); + std::string peerDevId(reinterpret_cast(data), size); + + std::shared_ptr softbusAdapter = std::make_shared(); + (void)softbusAdapter->UnRegisterSoftbusListener(sessionName, peerDevId); +} + +void SoftbusCreateSoftbusSessionServerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string pkgName(reinterpret_cast(data), size); + std::string sessionName(reinterpret_cast(data), size); + std::string peerDevId(reinterpret_cast(data), size); + + std::shared_ptr softbusAdapter = std::make_shared(); + (void)softbusAdapter->CreateSoftbusSessionServer(pkgName, sessionName, peerDevId); + (void)softbusAdapter->RemoveSoftbusSessionServer(pkgName, sessionName, peerDevId); +} + +void SoftbusRemoveSoftbusSessionServerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string pkgName(reinterpret_cast(data), size); + std::string sessionName(reinterpret_cast(data), size); + std::string peerDevId(reinterpret_cast(data), size); + + std::shared_ptr softbusAdapter = std::make_shared(); + (void)softbusAdapter->RemoveSoftbusSessionServer(pkgName, sessionName, peerDevId); +} + +void SoftbusOpenSoftbusSessionFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string mySessionName(reinterpret_cast(data), size); + std::string peerSessionName(reinterpret_cast(data), size); + std::string peerDevId(reinterpret_cast(data), size); + + std::shared_ptr softbusAdapter = std::make_shared(); + int32_t socketId = softbusAdapter->OpenSoftbusSession(mySessionName, peerSessionName, peerDevId); + (void)softbusAdapter->CloseSoftbusSession(socketId); +} + } // namespace DistributedHardware } // namespace OHOS @@ -70,5 +203,45 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::SoftbusAdapterFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusOnBytesReceivedFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusOnMessageReceivedFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusOnSessionClosedFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusOnSessionOpenedFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusOnStreamReceivedFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusRegisterSoftbusListenerFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusUnRegisterSoftbusListenerFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusCreateSoftbusSessionServerFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusRemoveSoftbusSessionServerFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusOpenSoftbusSessionFuzzTest(data, size); + return 0; +} + +extern "C" __attribute__((constructor)) int Socket(SocketInfo info) +{ + return 0; +} + +extern "C" __attribute__((constructor)) int Listen(int32_t socket, const QosTV qos[], uint32_t qosCount, + const ISocketListener *listener) +{ + return 0; +} + +extern "C" __attribute__((constructor)) int Bind(int32_t socket, const QosTV qos[], uint32_t qosCount, + const ISocketListener *listener) +{ + return 0; +} + +extern "C" __attribute__((constructor)) void Shutdown(int32_t socket) {} + +extern "C" __attribute__((constructor)) int SendBytes(int32_t socket, const void *data, uint32_t len) +{ + return 0; +} + +extern "C" __attribute__((constructor)) int SendStream(int32_t socket, const StreamData *data, const StreamData *ext, + const StreamFrameInfo *param) +{ return 0; } diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h index d6ae1c1ca4ea879142db94f9ce7ef73a9ad2496d..4e1bde8c11ee43d46bd04ece77ec882a0070b982 100644 --- a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h @@ -18,4 +18,20 @@ #define FUZZ_PROJECT_NAME "softbusadapter_fuzzer" +#include "isoftbus_listener.h" + +namespace OHOS { +namespace DistributedHardware { +class MockSoftbusListener : public ISoftbusListener { +public: + MockSoftbusListener() = default; + ~MockSoftbusListener() = default; + void OnSessionOpened(int32_t sessionId, PeerSocketInfo info) override {} + void OnSessionClosed(int32_t sessionId, ShutdownReason reason) override {} + void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) override {} + void OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, + const StreamFrameInfo *param) override {} +}; +} // namespace DistributedHardware +} // namespace OHOS #endif diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn deleted file mode 100644 index 36b525b0f2adc730045a6f62d7da9345139f1e5f..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2023-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################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedscreen.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnBytesReceivedFuzzTest") { - module_out_path = "${fuzz_test_path}/softbusadapter" - fuzz_config_file = "${services_path}/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer" - - configs = - [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - - sources = [ "softbusonbytesreceived_fuzzer.cpp" ] - - include_dirs = [ - "${common_path}/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/common/utils/include", - "${services_path}/screentransport/screensourcetrans/include", - "${services_path}/screentransport/screendatachannel/include", - "${services_path}/screentransport/screensourceprocessor/include", - "${services_path}/screentransport/screensourceprocessor/encoder/include", - "${services_path}/softbusadapter/include", - ] - - deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributed_av_receiver", - "distributed_hardware_fwk:libdhfwk_sdk", - "dsoftbus:softbus_client", - "hilog:libhilog", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnBytesReceivedFuzzTest\"", - "LOG_DOMAIN=0xD004140", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnBytesReceivedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init deleted file mode 100644 index 2b595da0c26af63ffb2d5f4132c086b2e5986fce..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp deleted file mode 100644 index 5dde7dd20ce74e98371b7f3a9a0245eff26a4877..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2023-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 "softbusonbytesreceived_fuzzer.h" - -#include - -#include "dscreen_constants.h" -#include "dscreen_errcode.h" -#include "dscreen_util.h" -#include "isoftbus_listener.h" -#include "softbus_bus_center.h" -#include "softbus_common.h" -#include "softbus_adapter.h" - -namespace OHOS { -namespace DistributedHardware { -void SoftbusOnBytesReceivedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - int32_t sessionId = *(reinterpret_cast(data)); - void *adapterData = nullptr; - uint32_t dataLen = *(reinterpret_cast(data)); - std::shared_ptr adapter = std::make_shared(); - adapter->OnBytesReceived(sessionId, adapterData, dataLen); -} -} // 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::SoftbusOnBytesReceivedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h deleted file mode 100644 index 245aaab342df157b4e1deb9aaa2f1e26bfaf5d92..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 SOFTBUSONBYTESRECEIVED_FUZZER_H -#define SOFTBUSONBYTESRECEIVED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonbytesreceived_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/BUILD.gn deleted file mode 100644 index f6dbb0ba84a34adb93253cc521e561f2868a5d4c..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/BUILD.gn +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2023-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################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedscreen.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnMessageReceivedFuzzTest") { - module_out_path = "${fuzz_test_path}/softbusadapter" - fuzz_config_file = "${services_path}/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer" - - configs = - [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - - sources = [ "softbusonmessagereceived_fuzzer.cpp" ] - - include_dirs = [ - "${common_path}/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/common/utils/include", - "${services_path}/screentransport/screensourcetrans/include", - "${services_path}/screentransport/screendatachannel/include", - "${services_path}/screentransport/screensourceprocessor/include", - "${services_path}/screentransport/screensourceprocessor/encoder/include", - "${services_path}/softbusadapter/include", - ] - - deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributed_av_receiver", - "distributed_hardware_fwk:libdhfwk_sdk", - "dsoftbus:softbus_client", - "hilog:libhilog", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnMessageReceivedFuzzTest\"", - "LOG_DOMAIN=0xD004140", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnMessageReceivedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/corpus/init deleted file mode 100644 index 2b595da0c26af63ffb2d5f4132c086b2e5986fce..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.cpp deleted file mode 100644 index ed35470116e59c8f5759820130cbe2666f882eaf..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2023-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 "softbusonmessagereceived_fuzzer.h" - -#include - -#include "dscreen_constants.h" -#include "dscreen_errcode.h" -#include "dscreen_util.h" -#include "isoftbus_listener.h" -#include "softbus_bus_center.h" -#include "softbus_common.h" -#include "softbus_adapter.h" - -namespace OHOS { -namespace DistributedHardware { -void SoftbusOnMessageReceivedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - int32_t sessionId = *(reinterpret_cast(data)); - void *adapterData = nullptr; - unsigned int dataLen = *(reinterpret_cast(data)); - std::shared_ptr adapter = std::make_shared(); - adapter->OnMessageReceived(sessionId, adapterData, dataLen); -} -} // 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::SoftbusOnMessageReceivedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.h deleted file mode 100644 index 1fe5ddd594c86ce69f833954352d9a2297f0c8fb..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 SOFTBUSONMESSAGESECEIVED_FUZZER_H -#define SOFTBUSONMESSAGESECEIVED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonmessagereceived_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn deleted file mode 100644 index bb63ac686e428823e409caca3bd2e059de3a1036..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2023-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################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedscreen.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnSessionClosedFuzzTest") { - module_out_path = "${fuzz_test_path}/softbusadapter" - fuzz_config_file = "${services_path}/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer" - - configs = - [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - - sources = [ "softbusonsessionclosed_fuzzer.cpp" ] - - include_dirs = [ - "${common_path}/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/common/utils/include", - "${services_path}/screentransport/screensourcetrans/include", - "${services_path}/screentransport/screendatachannel/include", - "${services_path}/screentransport/screensourceprocessor/include", - "${services_path}/screentransport/screensourceprocessor/encoder/include", - "${services_path}/softbusadapter/include", - ] - - deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributed_av_receiver", - "distributed_hardware_fwk:libdhfwk_sdk", - "dsoftbus:softbus_client", - "hilog:libhilog", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnSessionClosedFuzzTest\"", - "LOG_DOMAIN=0xD004140", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnSessionClosedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init deleted file mode 100644 index 2b595da0c26af63ffb2d5f4132c086b2e5986fce..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp deleted file mode 100644 index ede42c686bfa8c8061598fc924eea5cb99efa595..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2023-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 "softbusonsessionclosed_fuzzer.h" - -#include - -#include "dscreen_constants.h" -#include "dscreen_errcode.h" -#include "dscreen_util.h" -#include "isoftbus_listener.h" -#include "softbus_bus_center.h" -#include "softbus_common.h" -#include "softbus_adapter.h" - -namespace OHOS { -namespace DistributedHardware { -void SoftbusOnSessionClosedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - int32_t sessionId = *(reinterpret_cast(data)); - std::shared_ptr adapter = std::make_shared(); - ShutdownReason reason = SHUTDOWN_REASON_UNKNOWN; - adapter->OnSoftbusSessionClosed(sessionId, reason); -} -} // 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::SoftbusOnSessionClosedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h deleted file mode 100644 index 8641aaaa2db177f4f941c12d679a9252c29ddea9..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 SOFTBUSONSESSIONCLOSED_FUZZER_H -#define SOFTBUSONSESSIONCLOSED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonsessionclosed_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn deleted file mode 100644 index 78ab9843e02cea48145988220ed1d30fd0ec2d76..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2023-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################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedscreen.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnSessionOpenedFuzzTest") { - module_out_path = "${fuzz_test_path}/softbusadapter" - fuzz_config_file = "${services_path}/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer" - - configs = - [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - - sources = [ "softbusonsessionopened_fuzzer.cpp" ] - - include_dirs = [ - "${common_path}/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/common/utils/include", - "${services_path}/screentransport/screensourcetrans/include", - "${services_path}/screentransport/screendatachannel/include", - "${services_path}/screentransport/screensourceprocessor/include", - "${services_path}/screentransport/screensourceprocessor/encoder/include", - "${services_path}/softbusadapter/include", - ] - - deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributed_av_receiver", - "distributed_hardware_fwk:libdhfwk_sdk", - "dsoftbus:softbus_client", - "hilog:libhilog", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnSessionOpenedFuzzTest\"", - "LOG_DOMAIN=0xD004140", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnSessionOpenedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init deleted file mode 100644 index 2b595da0c26af63ffb2d5f4132c086b2e5986fce..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp deleted file mode 100644 index a77c325180e427af84f2be7a74c78f284d04cb1b..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2023-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 "softbusonsessionopened_fuzzer.h" - -#include - -#include "dscreen_constants.h" -#include "dscreen_errcode.h" -#include "dscreen_util.h" -#include "isoftbus_listener.h" -#include "softbus_bus_center.h" -#include "softbus_common.h" -#include "softbus_adapter.h" - -namespace OHOS { -namespace DistributedHardware { - namespace { - const std::string PEER_SESSION_NAME = "ohos.dhardware.dscreen.session8647073e02e7a78f09473aa124"; - const std::string REMOTE_DEV_ID = "f6d4c0864707aefte7a78f09473aa122ff57fc81c00981fcf5be989e7d112124"; - const std::string DSCREEN_PKG_NAME_TEST = "ohos.dhardware.dscreen"; -} -void SoftbusOnSessionOpenedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - int32_t sessionId = *(reinterpret_cast(data)); - PeerSocketInfo peerSocketInfo = { - .name = const_cast(PEER_SESSION_NAME.c_str()), - .networkId = const_cast(REMOTE_DEV_ID.c_str()), - .pkgName = const_cast(DSCREEN_PKG_NAME_TEST.c_str()), - .dataType = DATA_TYPE_BYTES - }; - std::shared_ptr adapter = std::make_shared(); - adapter->OnSoftbusSessionOpened(sessionId, peerSocketInfo); -} -} // 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::SoftbusOnSessionOpenedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h deleted file mode 100644 index 8dbb5a98a3755b96e7bca50afc896e9b225c701b..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 SOFTBUSONSESSIONOPENED_FUZZER_H -#define SOFTBUSONSESSIONOPENED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonsessionopened_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn deleted file mode 100644 index 7d6f71077fd266185a88a4a47ad5c398ac2eb858..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2023-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################### -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../../../distributedscreen.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnStreamReceivedFuzzTest") { - module_out_path = "${fuzz_test_path}/softbusadapter" - fuzz_config_file = "${services_path}/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer" - - configs = - [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - - sources = [ "softbusonstreamreceived_fuzzer.cpp" ] - - include_dirs = [ - "${common_path}/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/common/utils/include", - "${services_path}/screentransport/screensourcetrans/include", - "${services_path}/screentransport/screendatachannel/include", - "${services_path}/screentransport/screensourceprocessor/include", - "${services_path}/screentransport/screensourceprocessor/encoder/include", - "${services_path}/softbusadapter/include", - ] - - deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributed_av_receiver", - "distributed_hardware_fwk:libdhfwk_sdk", - "dsoftbus:softbus_client", - "hilog:libhilog", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnStreamReceivedFuzzTest\"", - "LOG_DOMAIN=0xD004140", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnStreamReceivedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init deleted file mode 100644 index 2b595da0c26af63ffb2d5f4132c086b2e5986fce..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp deleted file mode 100644 index ea1869721265b4e1ad61d017fa3c63111ab469a1..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2023-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 "softbusonstreamreceived_fuzzer.h" - -#include "dscreen_constants.h" -#include "dscreen_errcode.h" -#include "dscreen_util.h" -#include "isoftbus_listener.h" -#include "softbus_bus_center.h" -#include "softbus_common.h" -#include "softbus_adapter.h" - -namespace OHOS { -namespace DistributedHardware { -void SoftbusOnStreamReceivedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - int32_t sessionId = *(reinterpret_cast(data)); - StreamData *stream = nullptr; - StreamData *ext = nullptr; - StreamFrameInfo *info = nullptr; - std::shared_ptr adapter = std::make_shared(); - adapter->OnStreamReceived(sessionId, stream, ext, info); -} -} // 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::SoftbusOnStreamReceivedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h deleted file mode 100644 index 245aaab342df157b4e1deb9aaa2f1e26bfaf5d92..0000000000000000000000000000000000000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 SOFTBUSONBYTESRECEIVED_FUZZER_H -#define SOFTBUSONBYTESRECEIVED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonbytesreceived_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/unittest/BUILD.gn b/services/softbusadapter/test/unittest/BUILD.gn index 02a5fdc292d0830c5958ae0c8c5051b7734229d6..32aa4c749a8c5634178c514f3b4e7176f17bb640 100644 --- a/services/softbusadapter/test/unittest/BUILD.gn +++ b/services/softbusadapter/test/unittest/BUILD.gn @@ -50,11 +50,7 @@ ohos_unittest("SoftBusAdapterTest") { "${common_path}/test/unittest/resource:dscreen_unittest_public_config", ] - deps = [ - "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] + deps = [ "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans" ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -63,6 +59,8 @@ ohos_unittest("SoftBusAdapterTest") { "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", "dsoftbus:softbus_client", + "googletest:gmock", + "googletest:gtest_main", ] } diff --git a/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp b/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp index f299396b98c1b91e298992df681728cd3c2853de..d7be3eec02148b1655436675f1fa99b829b9d1e4 100644 --- a/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp +++ b/services/softbusadapter/test/unittest/src/softbus_adapter_test.cpp @@ -106,6 +106,10 @@ HWTEST_F(SoftbusAdapterTest, CreateSoftbusSessionServer_001, TestSize.Level1) streamData = &sData; softbusAdapter.OnBytesReceived(sessionId, data, dataLen); softbusAdapter.OnStreamReceived(sessionId, streamData, ext, frameInfo); + dataLen = DSCREEN_MAX_RECV_DATA_LEN + 1; + sData.bufLen = DSCREEN_MAX_RECV_DATA_LEN + 1; + softbusAdapter.OnBytesReceived(sessionId, data, dataLen); + softbusAdapter.OnStreamReceived(sessionId, streamData, ext, frameInfo); dataLen = 100; sData.bufLen = 100; softbusAdapter.OnBytesReceived(sessionId, data, dataLen);