From 91c482b39b840c47168f8999bf332f6f74592f93 Mon Sep 17 00:00:00 2001 From: wonghiu45 Date: Tue, 15 Nov 2022 11:02:40 +0800 Subject: [PATCH] add low memory kill test category:bugfix issue:#I617CD Signed-off-by: wonghiu45 Change-Id: Id5101d3b4d6818d59797cf3b29b0a9df6f7b142e --- test/BUILD.gn | 17 +++ .../unittest/phone/low_memory_killer_test.cpp | 103 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 test/unittest/phone/low_memory_killer_test.cpp diff --git a/test/BUILD.gn b/test/BUILD.gn index 86ce10d..af64e87 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -294,6 +294,22 @@ ohos_unittest("memory_level_manager_test") { subsystem_name = "resourceschedule" } +ohos_unittest("low_memory_killer_test") { + module_out_path = module_output_path + configs = memmgr_service_configs + + sources = [ "unittest/phone/low_memory_killer_test.cpp" ] + + deps = memmgr_deps + if (is_standard_system) { + external_deps = memmgr_external_deps + public_deps = memmgr_public_deps + } + + part_name = "memmgr" + subsystem_name = "resourceschedule" +} + group("memmgr_unittest") { testonly = true deps = [ @@ -301,6 +317,7 @@ group("memmgr_unittest") { ":default_multi_account_strategy_test", ":innerkits_test", ":kernel_interface_test", + ":low_memory_killer_test", ":memcg_mgr_test", ":memcg_test", ":memmgr_config_manager_test", diff --git a/test/unittest/phone/low_memory_killer_test.cpp b/test/unittest/phone/low_memory_killer_test.cpp new file mode 100644 index 0000000..52cb4fc --- /dev/null +++ b/test/unittest/phone/low_memory_killer_test.cpp @@ -0,0 +1,103 @@ +/* + * 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 + * + * 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 "gtest/gtest.h" + +#include "utils.h" + +#define private public +#define protected public +#include "low_memory_killer.h" +#include "reclaim_strategy_manager.h" +#undef private +#undef protected + +namespace OHOS { +namespace Memory { +using namespace testing; +using namespace testing::ext; + +class LowMemoryKillerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void LowMemoryKillerTest::SetUpTestCase() +{ +} + +void LowMemoryKillerTest::TearDownTestCase() +{ +} + +void LowMemoryKillerTest::SetUp() +{ +} + +void LowMemoryKillerTest::TearDown() +{ +} + +HWTEST_F(LowMemoryKillerTest, PsiHandlerTest, TestSize.Level1) +{ + LowMemoryKiller::GetInstance().PsiHandler(); +} + +HWTEST_F(LowMemoryKillerTest, QueryKillMemoryPriorityPairTest, TestSize.Level1) +{ + unsigned int reta = 1; + int retb = 1; + std::pair ret = std::make_pair(reta, retb); + unsigned int currBufferKB = 54632; + unsigned int targetBufKB = 65231; + int killLevel = 0; + + ret = LowMemoryKiller::GetInstance().QueryKillMemoryPriorityPair(currBufferKB, targetBufKB, killLevel); + EXPECT_NE(ret.first, 1); + EXPECT_NE(ret.second, 1); +} + +HWTEST_F(LowMemoryKillerTest, PsiHandlerInnerTest, TestSize.Level1) +{ + LowMemoryKiller::GetInstance().PsiHandlerInner(); +} + +HWTEST_F(LowMemoryKillerTest, KillOneBundleByPrioTest, TestSize.Level1) +{ + int pid = 123; + int appId = 111; + std::string appName = "com.test"; + int userId = 234; + int score = 100; + std::shared_ptr para = std::make_shared(pid, appId, appName, userId, score, + AppAction::OTHERS); + ReclaimStrategyManager::GetInstance().NotifyAppStateChanged(para); + int minPrio = 10; + int ret = 1; + ret = LowMemoryKiller::GetInstance().KillOneBundleByPrio(minPrio); + EXPECT_NE(ret, 1); + MemcgMgr::GetInstance().RemoveUserMemcg(userId); +} + +HWTEST_F(LowMemoryKillerTest, GetEventHandlerTest, TestSize.Level1) +{ + bool ret = LowMemoryKiller::GetInstance().GetEventHandler(); + EXPECT_EQ(ret, true); +} +} +} \ No newline at end of file -- Gitee