diff --git a/services/samgr/native/include/collect/icollect_plugin.h b/services/samgr/native/include/collect/icollect_plugin.h index 240059a086c7a6723ca5aec18cd4b2a472f16385..2641a72ef11929a389c505b3ed92d04653545d5c 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 d7bdd978029286096099abc9fd207c96157b315a..eb77d83f9383c751e0ced094cf47f8ce1f2ca744 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 f10c2ca9f621af8e3cb514e680abc5db85fc6e52..1680b6cf948e22366a4398208380ed0bf140bfa9 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 a281776af0344c488f3bfeaff85d3925b9bcc6c2..05c3cfc269a226a24f78422d80cc9657044edec8 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 206af003d94dcfb9dbebaa728edc3f8dfbda5a5c..6799bb92b8949b1cd41e873ffd6d04a39d7a476f 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,18 @@ HWTEST_F(DeviceStatusCollectManagerTest, UpdateOnDemandEvents003, TestSize.Level DTEST_LOG << "UpdateOnDemandEvents003 end" << std::endl; } +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 bd3e7572b4b248dedee1e368f78b51f0cfcf3b2b..9ad3796c815dbc074c561943afd5129ea924a47e 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,38 @@ HWTEST_F(SystemAbilityMgrStubUnLoadTest, UnloadSystemAbilityInner003, TestSize.L int32_t result = saMgr->UnloadSystemAbilityInner(data, reply); EXPECT_EQ(result, GET_SA_CONTEXT_FAIL); } + +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; +} + +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 f8fa49094839f5d71561167cb62cbec8ece7c12e..0005d51d6852c4aaddcd765bce97f4c1ad9524d0 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,19 @@ HWTEST_F(SystemAbilityMgrTest, GetLocalAbilityManagerProxy002, TestSize.Level3) DTEST_LOG << "GetLocalAbilityManagerProxy002 END" << std::endl; } + +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 3796038f7e46202ddb8a6f1912fc0cd9aeb8cc4e..4cc2c438ac79ed0f8fec1e95fd5becdb4dfcff4f 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 @@ -1886,12 +1886,6 @@ HWTEST_F(SystemAbilityStateSchedulerTest, SetFfrt001, TestSize.Level3) DTEST_LOG<<"SetFfrt001 END"<(); 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"<