From 55b8e0683aea745533e71800e4efe76a3af4deaf Mon Sep 17 00:00:00 2001 From: pwx1285814 Date: Mon, 7 Oct 2024 19:17:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=AE=E5=BC=82=E4=BB=A3=E7=A0=81=E5=90=8C?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: pwx1285814 --- bundle.json | 3 +- common/BUILD.gn | 2 - .../screen_sink/src/dscreen_sink_handler.cpp | 8 +- .../src/dscreen_source_handler.cpp | 6 + .../initsink_fuzzer.cpp | 5 + .../proxyinitsink_fuzzer/initsink_fuzzer.cpp | 1 + .../initsource_fuzzer.cpp | 1 + .../test/unittest/screensinktest/BUILD.gn | 8 +- .../src/dscreen_sink_handler_test.cpp | 15 ++ .../test/unittest/screensourcetest/BUILD.gn | 8 +- .../src/dscreen_source_handler_test.cpp | 15 ++ screenhandler/include/dscreen_handler.h | 3 +- screenhandler/src/dscreen_handler.cpp | 13 +- .../test/unittest/screenhandler/BUILD.gn | 9 +- .../common/databuffer/src/data_buffer.cpp | 4 +- .../screen_channel/include/iscreen_channel.h | 2 +- .../common/test/unittest/databuffer/BUILD.gn | 12 +- services/common/test/unittest/utils/BUILD.gn | 9 +- services/screenclient/test/unittest/BUILD.gn | 4 +- services/screenservice/sinkservice/BUILD.gn | 2 - .../screenregionmgr/1.0/src/screenregion.cpp | 22 +-- .../2.0/include/screenregion.h | 4 +- .../screenregionmgr/2.0/src/screenregion.cpp | 109 ++++++++--- .../2.0/src/screenregionmgr.cpp | 10 +- services/screenservice/sourceservice/BUILD.gn | 2 - .../dscreenmgr/1.0/src/dscreen.cpp | 6 +- .../dscreenmgr/2.0/src/dscreen.cpp | 6 +- .../dscreenmgr/2.0/src/dscreen_manager.cpp | 10 +- services/screenservice/test/fuzztest/BUILD.gn | 2 +- .../BUILD.gn | 10 +- .../corpus/init | 0 .../dscreenmanager_fuzzer.cpp | 151 +++++++++++++++ .../dscreenmanager_fuzzer.h} | 2 +- .../project.xml | 0 .../onchange_fuzzer/onchange_fuzzer.cpp | 49 ----- .../sinkservice/dscreenservice/BUILD.gn | 4 +- .../1.0/src/screenregion_test.cpp | 2 +- .../2.0/src/screenregion_test.cpp | 143 +++++++++++++- .../2.0/src/screenregionmgr_test.cpp | 13 +- .../sinkservice/screenregionmgr/BUILD.gn | 4 +- .../sourceservice/dscreenmgr/BUILD.gn | 4 +- .../sourceservice/dscreenservice/BUILD.gn | 4 +- .../include/screen_data_channel_impl.h | 2 +- .../src/screen_data_channel_impl.cpp | 2 +- .../decoder/src/image_sink_decoder.cpp | 8 +- .../screentransport/screensinktrans/BUILD.gn | 2 - .../screensinktrans/src/screen_sink_trans.cpp | 72 +++---- .../encoder/src/image_source_encoder.cpp | 6 +- .../screensourcetrans/BUILD.gn | 2 - .../src/screen_source_trans.cpp | 8 +- .../test/unittest/screendatachannel/BUILD.gn | 8 +- .../unittest/screensinkprocessor/BUILD.gn | 8 +- .../src/image_sink_decoder_test.cpp | 43 ++++- .../test/unittest/screensinktrans/BUILD.gn | 8 +- .../src/screen_sink_trans_test.cpp | 4 +- .../unittest/screensourceprocessor/BUILD.gn | 8 +- .../test/unittest/screensourcetrans/BUILD.gn | 8 +- .../unittest/screentranstestutils/BUILD.gn | 4 +- .../include/screentrans_test_utils.h | 2 +- .../softbusadapter/test/fuzztest/BUILD.gn | 9 +- .../fuzztest/softbusadapter_fuzzer/BUILD.gn | 5 +- .../softbusadapter_fuzzer.cpp | 175 +++++++++++++++++- .../softbusadapter_fuzzer.h | 16 ++ .../softbusonbytesreceived_fuzzer/BUILD.gn | 63 ------- .../softbusonbytesreceived_fuzzer/corpus/init | 16 -- .../softbusonbytesreceived_fuzzer/project.xml | 25 --- .../softbusonbytesreceived_fuzzer.cpp | 51 ----- .../softbusonbytesreceived_fuzzer.h | 21 --- .../softbusonmessagereceived_fuzzer/BUILD.gn | 63 ------- .../corpus/init | 16 -- .../project.xml | 25 --- .../softbusonmessagereceived_fuzzer.cpp | 51 ----- .../softbusonmessagereceived_fuzzer.h | 21 --- .../softbusonsessionclosed_fuzzer/BUILD.gn | 63 ------- .../softbusonsessionclosed_fuzzer/corpus/init | 16 -- .../softbusonsessionclosed_fuzzer/project.xml | 25 --- .../softbusonsessionclosed_fuzzer.cpp | 50 ----- .../softbusonsessionclosed_fuzzer.h | 21 --- .../softbusonsessionopened_fuzzer/BUILD.gn | 63 ------- .../softbusonsessionopened_fuzzer/corpus/init | 16 -- .../softbusonsessionopened_fuzzer/project.xml | 25 --- .../softbusonsessionopened_fuzzer.cpp | 60 ------ .../softbusonsessionopened_fuzzer.h | 21 --- .../softbusonstreamreceived_fuzzer/BUILD.gn | 63 ------- .../corpus/init | 16 -- .../project.xml | 25 --- .../softbusonstreamreceived_fuzzer.cpp | 50 ----- .../softbusonstreamreceived_fuzzer.h | 21 --- .../softbusadapter/test/unittest/BUILD.gn | 8 +- .../unittest/src/softbus_adapter_test.cpp | 4 + 90 files changed, 811 insertions(+), 1175 deletions(-) rename services/screenservice/test/fuzztest/sourceservice/dscreenmgr/{onchange_fuzzer => dscreenmanager_fuzzer}/BUILD.gn (91%) rename services/screenservice/test/fuzztest/sourceservice/dscreenmgr/{onchange_fuzzer => dscreenmanager_fuzzer}/corpus/init (100%) create mode 100644 services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp rename services/screenservice/test/fuzztest/sourceservice/dscreenmgr/{onchange_fuzzer/onchange_fuzzer.h => dscreenmanager_fuzzer/dscreenmanager_fuzzer.h} (93%) rename services/screenservice/test/fuzztest/sourceservice/dscreenmgr/{onchange_fuzzer => dscreenmanager_fuzzer}/project.xml (100%) delete mode 100644 services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h delete mode 100644 services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.h delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h diff --git a/bundle.json b/bundle.json index d60cc459..bf7c1623 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 96cc038b..74c7be17 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 9c09b2a3..dcdd9240 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 8468baed..8d6c7221 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 e6a5e6fc..ece8a40a 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 33937b93..819d9352 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 2d40347a..bfa212bf 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 56a525ca..4752e7e6 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 6cfc342b..d2bc2f2a 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 331104b7..582577ba 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 df780acf..ed8856f2 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 c53faf55..fb7b7e06 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 f400116f..36a29ecd 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 6fc2f86b..1d6d96d8 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 36a5ea41..0a48e140 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 24d5c493..b2e74395 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 63275332..6b962131 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 58f2bbfc..8ff1370f 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 0e19567d..057379e3 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 6db4bea6..350eeae3 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 3624f722..d6fe6b31 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 e21fcded..e06470bc 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 410fcb0b..78269dce 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 93da68f3..b81e5646 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 97da3dd8..4061c4fb 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 8e862c44..5c4951f7 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 e68a659d..458a8dcd 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 2ccb802a..91bd7ee2 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 4d55ed50..a4905fb7 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 be9d7eaa..885e1a59 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 00000000..221aeab3 --- /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 26a3775e..91d433d3 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 44c0b0d8..00000000 --- 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 f29179a5..16472d9f 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 29a01970..1d22cc31 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 b63b7f1c..e17ecea0 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 f1823306..31943764 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 8ea8bd57..f9560735 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 3d20b361..a9dcd9bf 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 fffb46fb..6c79e0f3 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 23a3bc10..46a1d95c 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 535eb8df..e452b829 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 88213a5e..25015aa9 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 4bb63ebc..f073e1aa 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 e2595738..9f53f9ef 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 c2b3b08f..07ee23fa 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 0960cebc..d75d798e 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 5fe9e2a5..60d8e390 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 2d1f4b3b..05329a4d 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 a46b88b2..5b85c35e 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 6f9a503f..62dfa99d 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 6b4550dc..cf17a523 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 24185062..51b6a590 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 d10b49cd..f54d1338 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 cf33b5ea..58997697 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 36c8da89..62261137 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 a0a36c99..eb793756 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 5798ca82..d04b76d9 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 e2bf14e4..1f4510b7 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 50223e1c..8b998311 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 d6ae1c1c..4e1bde8c 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 36b525b0..00000000 --- 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 2b595da0..00000000 --- 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 4fdbc407..00000000 --- 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 5dde7dd2..00000000 --- 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 245aaab3..00000000 --- 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 f6dbb0ba..00000000 --- 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 2b595da0..00000000 --- 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 4fdbc407..00000000 --- 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 ed354701..00000000 --- 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 1fe5ddd5..00000000 --- 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 bb63ac68..00000000 --- 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 2b595da0..00000000 --- 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 4fdbc407..00000000 --- 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 ede42c68..00000000 --- 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 8641aaaa..00000000 --- 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 78ab9843..00000000 --- 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 2b595da0..00000000 --- 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 4fdbc407..00000000 --- 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 a77c3251..00000000 --- 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 8dbb5a98..00000000 --- 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 7d6f7107..00000000 --- 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 2b595da0..00000000 --- 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 4fdbc407..00000000 --- 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 ea186972..00000000 --- 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 245aaab3..00000000 --- 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 02a5fdc2..32aa4c74 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 f299396b..d7be3eec 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); -- Gitee