From 40290685f8fe6fb430648991dc090eb64bf11c6e Mon Sep 17 00:00:00 2001 From: h60047265 Date: Thu, 12 Jun 2025 10:11:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85TDD=E7=94=A8=E4=BE=8B&?= =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: h60047265 --- .../native/include/collect/icollect_plugin.h | 2 +- .../system_ability_state_scheduler.cpp | 2 +- .../source/system_ability_manager_stub.cpp | 2 +- .../src/device_param_collect_test.cpp | 1 + .../device_status_collect_manager_test.cpp | 21 +++++++++ .../src/system_ability_mgr_proxy_test.cpp | 29 ++++++++++++ .../system_ability_mgr_stub_unload_test.cpp | 47 +++++++++++++++++++ .../unittest/src/system_ability_mgr_test.cpp | 21 +++++++++ .../system_ability_state_scheduler_test.cpp | 8 ++-- 9 files changed, 126 insertions(+), 7 deletions(-) diff --git a/services/samgr/native/include/collect/icollect_plugin.h b/services/samgr/native/include/collect/icollect_plugin.h index 240059a0..2641a72e 100644 --- a/services/samgr/native/include/collect/icollect_plugin.h +++ b/services/samgr/native/include/collect/icollect_plugin.h @@ -77,7 +77,7 @@ public: } virtual const std::vector& GetLowMemPrepareList() { - std::vector res; + static std::vector res; return res; } void ReportEvent(const OnDemandEvent& event); diff --git a/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp b/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp index d7bdd978..eb77d83f 100644 --- a/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp +++ b/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp @@ -768,7 +768,7 @@ int32_t SystemAbilityStateScheduler::UnloadProcess(const std::vector readLock(processMapLock_); - for (auto it : processList) { + for (const auto& it : processList) { if (processContextMap_.count(it) != 0) { auto& processContext = processContextMap_[it]; if (processContext == nullptr) { diff --git a/services/samgr/native/source/system_ability_manager_stub.cpp b/services/samgr/native/source/system_ability_manager_stub.cpp index f10c2ca9..1680b6cf 100644 --- a/services/samgr/native/source/system_ability_manager_stub.cpp +++ b/services/samgr/native/source/system_ability_manager_stub.cpp @@ -814,7 +814,7 @@ int32_t SystemAbilityManagerStub::GetLruIdleSystemAbilityProcInner(MessageParcel } if (result != ERR_OK) { HILOGE("GetLruIdleSystemAbilityProc result is %{public}d", result); - return ERR_OK; + return result; } size_t size = infos.size(); ret = reply.WriteInt32(size); diff --git a/services/samgr/native/test/unittest/src/device_param_collect_test.cpp b/services/samgr/native/test/unittest/src/device_param_collect_test.cpp index a281776a..05c3cfc2 100644 --- a/services/samgr/native/test/unittest/src/device_param_collect_test.cpp +++ b/services/samgr/native/test/unittest/src/device_param_collect_test.cpp @@ -287,6 +287,7 @@ HWTEST_F(DeviceParamCollectTest, AddCollectEvent002, TestSize.Level3) events.emplace_back(event); events.emplace_back(event2); int32_t ret = deviceParamCollect->AddCollectEvent(events); + deviceParamCollect->GetLowMemPrepareList(); EXPECT_EQ(ret, ERR_OK); } } // namespace OHOS \ No newline at end of file diff --git a/services/samgr/native/test/unittest/src/device_status_collect_manager_test.cpp b/services/samgr/native/test/unittest/src/device_status_collect_manager_test.cpp index 206af003..629587a4 100644 --- a/services/samgr/native/test/unittest/src/device_status_collect_manager_test.cpp +++ b/services/samgr/native/test/unittest/src/device_status_collect_manager_test.cpp @@ -22,6 +22,7 @@ #define private public #include "common_event_collect.h" #include "device_status_collect_manager.h" +#include "device_param_collect.h" #ifdef SUPPORT_COMMON_EVENT #include "common_event_collect.h" #include "common_event_manager.h" @@ -48,6 +49,8 @@ constexpr int64_t EXTRA_ID = 1; const std::string SA_TAG_DEVICE_ON_LINE = "deviceonline"; const std::string WIFI_NAME = "wifi_status"; constexpr int32_t MOCK_PLUGIN = 20; +constexpr uint32_t SAID = 1494; +constexpr uint32_t INVALID_SAID = -1; sptr collect; } @@ -733,6 +736,24 @@ HWTEST_F(DeviceStatusCollectManagerTest, UpdateOnDemandEvents003, TestSize.Level DTEST_LOG << "UpdateOnDemandEvents003 end" << std::endl; } +/** + * @tc.name: GetLowMemPrepareList001 + * @tc.desc: Test GetLowMemPrepareList + * @tc.type: FUNC + * @tc.require: I76X9Q + */ +HWTEST_F(DeviceStatusCollectManagerTest, GetLowMemPrepareList001, TestSize.Level3) +{ + DTEST_LOG << "GetLowMemPrepareList001 begin"< deviceParamCollect = new DeviceParamCollect(collect); + deviceParamCollect->lowMemPrepareList_.push_back(INVALID_SAID); + deviceParamCollect->lowMemPrepareList_.push_back(SAID); + collect->collectPluginMap_[PARAM] = deviceParamCollect; + std::vector saIds = collect->GetLowMemPrepareList(); + EXPECT_FALSE(saIds.empty()); + DTEST_LOG << "GetLowMemPrepareList001 end"< sm = new SystemAbilityManagerProxy(nullptr); + std::vector procInfos; + MessageParcel reply; + + int32_t size = 1; + reply.WriteInt32(size); + + int32_t pid = 12345; + reply.WriteInt32(pid); + + std::u16string procName = u"testProcName"; + reply.WriteString16(procName); + + int64_t lastTime = 1749631716; + reply.WriteInt64(lastTime); + + int32_t res = sm->ReadIdleProcessInfoFromParcel(reply, procInfos); + EXPECT_EQ(res, ERR_OK); + DTEST_LOG << " ReadIdleProcessInfoFromParcel001 end " << std::endl; +} } \ No newline at end of file diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_stub_unload_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_stub_unload_test.cpp index bd3e7572..e025700e 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_stub_unload_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_stub_unload_test.cpp @@ -28,6 +28,7 @@ #define private public #include "sa_status_change_mock.h" #include "system_ability_manager.h" +#include "device_param_collect.h" using namespace std; using namespace testing; @@ -514,4 +515,50 @@ HWTEST_F(SystemAbilityMgrStubUnLoadTest, UnloadSystemAbilityInner003, TestSize.L int32_t result = saMgr->UnloadSystemAbilityInner(data, reply); EXPECT_EQ(result, GET_SA_CONTEXT_FAIL); } + +/** + * @tc.name: UnloadProcessInner001 + * @tc.desc: Test UnloadProcess + * @tc.type: FUNC + * @tc.require: I6H10P + */ +HWTEST_F(SystemAbilityMgrStubUnLoadTest, UnloadProcessInner001, TestSize.Level3) +{ + DTEST_LOG << "UnloadProcessInner001 begin" << std::endl; + sptr saMgr = SystemAbilityManager::GetInstance(); + SamMockPermission::MockProcess("memmgrservice"); + EXPECT_TRUE(saMgr != nullptr); + MessageParcel data; + MessageParcel reply; + int32_t result = saMgr->UnloadProcessInner(data, reply); + EXPECT_EQ(result, ERR_OK); + string deviceId = "memmgrservice"; + data.WriteString(deviceId); + result = saMgr->UnloadProcessInner(data, reply); + EXPECT_EQ(result, ERR_OK); + DTEST_LOG << "UnloadProcessInner001 end" << std::endl; +} + +/** + * @tc.name: GetLruIdleSystemAbilityProcInner001 + * @tc.desc: Test GetLruIdleSystemAbilityProcInner + * @tc.type: FUNC + * @tc.require: I6H10P + */ +HWTEST_F(SystemAbilityMgrStubUnLoadTest, GetLruIdleSystemAbilityProcInner001, TestSize.Level3) +{ + DTEST_LOG << "GetLruIdleSystemAbilityProcInner001 begin" << std::endl; + sptr saMgr = SystemAbilityManager::GetInstance(); + sptr pCollect = new DeviceStatusCollectManager(); + saMgr->collectManager_ = pCollect; + sptr deviceParamCollect = new DeviceParamCollect(pCollect); + deviceParamCollect->lowMemPrepareList_.push_back(INVALID_SAID); + deviceParamCollect->lowMemPrepareList_.push_back(SAID); + saMgr->collectManager_->collectPluginMap_[PARAM] = deviceParamCollect; + MessageParcel data; + MessageParcel reply; + int32_t result = saMgr->GetLruIdleSystemAbilityProcInner(data, reply); + EXPECT_EQ(result, ERR_OK); + DTEST_LOG << "GetLruIdleSystemAbilityProcInner001 end" << std::endl; +} } \ No newline at end of file diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp index f8fa4909..e16ea845 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp @@ -1666,4 +1666,25 @@ HWTEST_F(SystemAbilityMgrTest, GetLocalAbilityManagerProxy002, TestSize.Level3) DTEST_LOG << "GetLocalAbilityManagerProxy002 END" << std::endl; } + +/** + * @tc.name: UnloadProcess001 + * @tc.desc: Test UnloadProcess + * @tc.type: FUNC + * @tc.require: I7VQQG + */ +HWTEST_F(SystemAbilityMgrTest, UnloadProcess001, TestSize.Level3) +{ + DTEST_LOG << "UnloadProcess001 BEGIN" << std::endl; + sptr saMgr = new SystemAbilityManager; + EXPECT_TRUE(saMgr != nullptr); + std::vector processList; + int32_t ret = saMgr->UnloadProcess(processList); + EXPECT_EQ(ret, ERR_INVALID_VALUE); + saMgr->abilityStateScheduler_ = std::make_shared(); + ret = saMgr->UnloadProcess(processList); + EXPECT_NE(ret, ERR_INVALID_VALUE); + DTEST_LOG << "UnloadProcess001 END" << std::endl; +} + } // namespace OHOS \ No newline at end of file diff --git a/services/samgr/native/test/unittest/src/system_ability_state_scheduler_test.cpp b/services/samgr/native/test/unittest/src/system_ability_state_scheduler_test.cpp index 3796038f..27064710 100644 --- a/services/samgr/native/test/unittest/src/system_ability_state_scheduler_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_state_scheduler_test.cpp @@ -1977,12 +1977,12 @@ HWTEST_F(SystemAbilityStateSchedulerTest, UnloadProcess001, TestSize.Level3) std::make_shared(); std::list saProfiles; systemAbilityStateScheduler->Init(saProfiles); - systemAbilityStateScheduler->processContextMap_.clear(); + systemAbilityStateScheduler->processContextMap_[u"satest"] = + std::make_shared(); std::vector processList; - processList.push_back(u"test"); + processList.push_back(u"satest"); int32_t ret = systemAbilityStateScheduler->UnloadProcess(processList); EXPECT_NE(ret, TRANSIT_PROC_STATE_FAIL); DTEST_LOG<<"UnloadProcess001 END"<