diff --git a/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp b/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp index c545680f5bc3da897c5d484e2aa6629aeca24bc7..4d97fac06ae42d91e6f4ffba49bf9de77be4e8e5 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/ability_manager_service_thirteenth_test.cpp @@ -19,6 +19,7 @@ #include "hilog_tag_wrapper.h" #include "sub_managers_helper.h" #include "mission_list_manager.h" +#include "global_constant.h" using namespace testing; using namespace testing::ext; @@ -33,6 +34,7 @@ constexpr int32_t ONE = 1; constexpr int32_t TWO = 2; constexpr int32_t FOUNDATION_UID = 5523; constexpr int32_t DMS_UID = 5522; +constexpr int32_t LOW_MEMORY_KILL_WHILE_STARTING = 1111; namespace OHOS { namespace AAFwk { @@ -1193,6 +1195,39 @@ HWTEST_F(AbilityManagerServiceThirteenthTest, GetMissionIdByAbilityTokenInner_00 TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest GetMissionIdByAbilityTokenInner_004 end"); } +/* + * Feature: AbilityManagerService + * Name: KillProcessWithReason_002 + * Function: KillProcessWithReason + * SubFunction: NA + * FunctionPoints: AbilityManagerService KillProcessWithReason + */ +HWTEST_F(AbilityManagerServiceThirteenthTest, KillProcessWithReason_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest KillProcessWithReason_002 start"); + + auto abilityMs_ = std::make_shared(); + EXPECT_NE(abilityMs_, nullptr); + + auto mockSubManagersHelper = std::make_shared(nullptr, nullptr); + EXPECT_NE(mockSubManagersHelper, nullptr); + auto mockCurrentUIAbilityManager = std::make_shared(0); + EXPECT_NE(mockCurrentUIAbilityManager, nullptr); + abilityMs_->subManagersHelper_ = mockSubManagersHelper; + abilityMs_->subManagersHelper_->currentUIAbilityManager_ = mockCurrentUIAbilityManager; + + int32_t pid = LOW_MEMORY_KILL_WHILE_STARTING; + MyStatus::GetInstance().permPermission_ = 1; + ExitReason reason; + reason.exitMsg = AbilityRuntime::GlobalConstant::LOW_MEMORY_KILL; + reason.reason = Reason::REASON_RESOURCE_CONTROL; + MyStatus::GetInstance().smhGetUIAbilityManagerByUid_ = true; + + EXPECT_EQ(abilityMs_->KillProcessWithReason(pid, reason), ERR_KILL_APP_WHILE_STARTING); + + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirteenthTest KillProcessWithReason_002 end"); +} + /* * Feature: AbilityManagerService * Name: DelegatorDoAbilityForeground_001 diff --git a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp index 9e8db637edba162aaa3cfe7e0d0fbc8f2aba59c9..3c6f59aaaf950c5af6225f82a4b55d2191a8a0af 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp +++ b/test/unittest/ability_manager_service_thirteenth_test/mock/src/mock_ui_ability_lifecycle_manager.cpp @@ -16,7 +16,7 @@ #include "mock_ui_ability_lifecycle_manager.h" #include "mock_my_status.h" - +constexpr int32_t LOW_MEMORY_KILL_WHILE_STARTING = 1111; namespace OHOS { namespace AAFwk { @@ -30,6 +30,9 @@ bool UIAbilityLifecycleManager::ProcessColdStartBranch(AbilityRequest &abilityRe bool UIAbilityLifecycleManager::IsBundleStarting(pid_t pid) { + if (pid == LOW_MEMORY_KILL_WHILE_STARTING) { + return true; + } return false; }