From f356ef208455c36aa3e090447bda76593e5c8ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E8=8F=B2=E5=A2=A8?= Date: Sat, 21 Jun 2025 19:46:05 +0800 Subject: [PATCH] addTdd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 朱菲墨 --- ...bility_manager_service_thirteenth_test.cpp | 33 +++++++++++++++++++ .../src/mock_ui_ability_lifecycle_manager.cpp | 5 ++- 2 files changed, 37 insertions(+), 1 deletion(-) 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 c545680f5bc..af04e552492 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,37 @@ 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; + ExitReason reason; + reason.exitMsg = AbilityRuntime::GlobalConstant::LOW_MEMORY_KILL; + 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 9e8db637edb..d690f22d4e0 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; } -- Gitee