From 430014f47beda70ccd70d784ec02cbb64fa9727c Mon Sep 17 00:00:00 2001 From: superhanxin Date: Sat, 23 Nov 2024 17:55:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=88=86=E7=BB=84ut=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: superhanxin --- .../cgroupsched_fuzzer/cgroupsched_fuzzer.cpp | 24 +++++++++++++++++++ .../test/unittest/cgroup_sched_test.cpp | 22 +++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/ressched/plugins/cgroup_sched_plugin/test/fuzztest/cgroupsched_fuzzer/cgroupsched_fuzzer.cpp b/ressched/plugins/cgroup_sched_plugin/test/fuzztest/cgroupsched_fuzzer/cgroupsched_fuzzer.cpp index 0dee9cd0..1c60b7eb 100644 --- a/ressched/plugins/cgroup_sched_plugin/test/fuzztest/cgroupsched_fuzzer/cgroupsched_fuzzer.cpp +++ b/ressched/plugins/cgroup_sched_plugin/test/fuzztest/cgroupsched_fuzzer/cgroupsched_fuzzer.cpp @@ -1231,6 +1231,29 @@ namespace ResourceSchedule { return true; } + bool HandleOnAppStoppedFuzzTest(const uint8_t* data, size_t size) + { + if (data == nullptr) { + return false; + } + + // initialize + G_DATA = data; + g_size = size; + g_pos = 0; + + // getdata + uint32_t resType = GetData(); + int64_t value = GetData(); + nlohmann::json payload; + auto cgroupEventHandler = + std::make_shared("CgroupEventHandler_fuzz"); + + cgroupEventHandler->HandleOnAppStopped(resType, value, payload); + + return true; + } + bool AdjustForkProcessGroupFuzzTest(const uint8_t* data, size_t size) { if (data == nullptr) { @@ -1764,6 +1787,7 @@ namespace ResourceSchedule { OHOS::ResourceSchedule::HandleWebviewScreenCaptureFuzzTest(data, size); OHOS::ResourceSchedule::HandleReportWebviewVideoStateFuzzTest(data, size); OHOS::ResourceSchedule::HandleReportCosmicCubeStateFuzzTest(data, size); + OHOS::ResourceSchedule::HandleOnAppStoppedFuzzTest(data, size); } void CgroupAdjusterFuzzExecute(const uint8_t* data, size_t size) diff --git a/ressched/plugins/cgroup_sched_plugin/test/unittest/cgroup_sched_test.cpp b/ressched/plugins/cgroup_sched_plugin/test/unittest/cgroup_sched_test.cpp index dec4128c..ff6700d1 100644 --- a/ressched/plugins/cgroup_sched_plugin/test/unittest/cgroup_sched_test.cpp +++ b/ressched/plugins/cgroup_sched_plugin/test/unittest/cgroup_sched_test.cpp @@ -644,6 +644,28 @@ HWTEST_F(CGroupSchedTest, CGroupSchedTest_CgroupEventHandler_008, Function | Med EXPECT_FALSE(app1001->isCosmicCubeStateHide_); EXPECT_FALSE(app1002->isCosmicCubeStateHide_); } + +/** + * @tc.name: CGroupSchedTest_CgroupEventHandler_009 + * @tc.desc: cgroup event handler Test + * @tc.type: FUNC + * @tc.require: issuesIB0CYC + * @tc.desc: + */ +HWTEST_F(CGroupSchedTest, CGroupSchedTest_CgroupEventHandler_009, Function | MediumTest | Level1) +{ + auto cgroupEventHandler = std::make_shared("CgroupEventHandler_unittest"); + cgroupEventHandler->SetSupervisor(supervisor_); + EXPECT_NE(cgroupEventHandler->supervisor_, nullptr); + uint32_t resType = 0; + int64_t value = ResType::WebVideoState::WEB_VIDEO_PLAYING_START; + nlohmann::json payload; + payload["uid"] = 1000; + payload["bundleName"] = "test_009"; + auto app = supervisor_->GetAppRecordNonNull(1000); + cgroupEventHandler->HandleOnAppStopped(resType, value, payload); + EXPECT_FALSE(app); +} } // namespace CgroupSetting } // namespace ResourceSchedule } // namespace OHOS -- Gitee