/* * Copyright (c) 2023 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. */ #define private public #define protected public #include #include #include "eu/cpu_worker.h" #include "eu/scpuworker_manager.h" #include "eu/scpu_monitor.h" #include "eu/cpu_manager_strategy.h" #include "eu/worker_thread.h" #include "qos.h" #undef private #undef protected namespace OHOS { namespace FFRT_TEST { constexpr int QOS_DEFAULT = 5; constexpr int TASK_NOTIFY_TYPE_DEFAULT = 1; using namespace testing; using namespace testing::ext; using namespace OHOS::FFRT_TEST; using namespace ffrt; using namespace std; class CpuMonitorTest : public testing::Test { protected: static void SetUpTestCase() { } static void TearDownTestCase() { } virtual void SetUp() { } virtual void TearDown() { } }; /** * @tc.name: IntoSleep * @tc.desc: Test whether the IntoSleep interface are normal. * @tc.type: FUNC * * */ TEST_F(CpuMonitorTest, IntoSleep) { CPUWorkerManager *it = new SCPUWorkerManager(); SCPUMonitor cpu({ std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1), std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1), std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)}); cpu.IntoSleep(QoS(QOS_DEFAULT)); } /** * @tc.name: WakeupSleep * @tc.desc: Test whether the WakeupCount interface are normal. * @tc.type: FUNC * * */ TEST_F(CpuMonitorTest, WakeupSleep) { CPUWorkerManager *it = new SCPUWorkerManager(); SCPUMonitor cpu({ std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1), std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1), std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)}); cpu.WakeupSleep(QoS(QOS_DEFAULT)); } /** * @tc.name: TimeoutCount * @tc.desc: Test whether the TimeoutCount interface are normal. * @tc.type: FUNC * * */ TEST_F(CpuMonitorTest, TimeoutCount) { CPUWorkerManager *it = new SCPUWorkerManager(); SCPUMonitor cpu({ std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1), std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1), std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)}); cpu.TimeoutCount(QoS(QOS_DEFAULT)); } /** * @tc.name: Notify * @tc.desc: Test whether the Notify interface are normal. * @tc.type: FUNC * * */ TEST_F(CpuMonitorTest, Notify) { CPUWorkerManager *it = new SCPUWorkerManager(); SCPUMonitor cpu({ std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1), std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1), std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1), std::bind(&CPUWorkerManager::GetWorkerCount, it, std::placeholders::_1), CPUMonitor::HandleTaskNotifyDefault}); cpu.Notify(QoS(QOS_DEFAULT), TaskNotifyType(TASK_NOTIFY_TYPE_DEFAULT)); } /** * @tc.name: IntoDeepSleep * @tc.desc: Test whether the IntoDeepSleep interface are normal. * @tc.type: FUNC * * */ TEST_F(CpuMonitorTest, IntoDeepSleep) { CPUWorkerManager *it = new SCPUWorkerManager(); SCPUMonitor cpu({ std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1), std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1), std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)}); cpu.IntoDeepSleep(QoS(QOS_DEFAULT)); } /** * @tc.name: WakeupDeepSleep * @tc.desc: Test whether the OutOfDeepSleep interface are normal. * @tc.type: FUNC * * */ TEST_F(CpuMonitorTest, WakeupDeepSleep) { CPUWorkerManager *it = new SCPUWorkerManager(); SCPUMonitor cpu({ std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1), std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1), std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)}); cpu.WakeupDeepSleep(QoS(QOS_DEFAULT)); } /** * @tc.name: IsExceedDeepSleepThreshold * @tc.desc: Test whether the IsExceedDeepSleepThreshold interface are normal. * @tc.type: FUNC * * */ TEST_F(CpuMonitorTest, IsExceedDeepSleepThreshold) { CPUWorkerManager *it = new SCPUWorkerManager(); SCPUMonitor cpu({ std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1), std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1), std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)}); bool ret = cpu.IsExceedDeepSleepThreshold(); } } }