• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <functional>
17 #include <gtest/gtest.h>
18 
19 #include "policy/thermal_policy.h"
20 #include "work_policy_manager.h"
21 #include "work_scheduler_service.h"
22 #include "thermal_mgr_client.h"
23 
24 using namespace testing::ext;
25 
26 namespace {
27 OHOS::PowerMgr::ThermalLevel thermalLevel_;
MockProcess(OHOS::PowerMgr::ThermalLevel thermlLevel)28 void MockProcess(OHOS::PowerMgr::ThermalLevel thermlLevel)
29 {
30     thermalLevel_ = thermlLevel;
31 }
32 }
33 
34 namespace OHOS {
35 namespace PowerMgr {
GetThermalLevel()36 ThermalLevel ThermalMgrClient::GetThermalLevel()
37 {
38     return thermalLevel_;
39 }
40 }
41 namespace WorkScheduler {
42 class ThermalPolicyTest : public testing::Test {
43 public:
44     static void SetUpTestCase();
TearDownTestCase()45     static void TearDownTestCase() {};
SetUp()46     void SetUp() {};
TearDown()47     void TearDown() {};
48     static std::shared_ptr<WorkPolicyManager> workPolicyManager_;
49     static std::shared_ptr<ThermalPolicy> thermalPolicy_;
50 };
51 
52 std::shared_ptr<ThermalPolicy> ThermalPolicyTest::thermalPolicy_ = nullptr;
53 std::shared_ptr<WorkPolicyManager> ThermalPolicyTest::workPolicyManager_ = nullptr;
54 
SetUpTestCase()55 void ThermalPolicyTest::SetUpTestCase()
56 {
57     std::shared_ptr<WorkSchedulerService> workSchedulerService_ = std::make_shared<WorkSchedulerService>();
58     workSchedulerService_->Start();
59     workPolicyManager_ = std::make_shared<WorkPolicyManager>(workSchedulerService_);
60     thermalPolicy_ = std::make_shared<ThermalPolicy>(workPolicyManager_);
61 }
62 
63 /**
64  * @tc.name: GetPolicyMaxRunning_001
65  * @tc.desc: Test ThermalPolicy GetPolicyMaxRunning.
66  * @tc.type: FUNC
67  * @tc.require: I974IQ
68  */
69 HWTEST_F(ThermalPolicyTest, GetPolicyMaxRunning_001, TestSize.Level1)
70 {
71     WorkSchedSystemPolicy systemPolicy;
72     MockProcess(PowerMgr::ThermalLevel::WARM);
73     int32_t ret = thermalPolicy_->GetPolicyMaxRunning(systemPolicy);
74     EXPECT_EQ(ret, 0);
75 }
76 
77 /**
78  * @tc.name: GetPolicyMaxRunning_002
79  * @tc.desc: Test ThermalPolicy GetPolicyMaxRunning.
80  * @tc.type: FUNC
81  * @tc.require: I974IQ
82  */
83 HWTEST_F(ThermalPolicyTest, GetPolicyMaxRunning_002, TestSize.Level1)
84 {
85     WorkSchedSystemPolicy systemPolicy;
86     MockProcess(PowerMgr::ThermalLevel::NORMAL);
87     int32_t ret = thermalPolicy_->GetPolicyMaxRunning(systemPolicy);
88     EXPECT_EQ(ret, 1);
89 }
90 
91 /**
92  * @tc.name: GetPolicyMaxRunning_003
93  * @tc.desc: Test ThermalPolicy GetPolicyMaxRunning.
94  * @tc.type: FUNC
95  * @tc.require: I974IQ
96  */
97 HWTEST_F(ThermalPolicyTest, GetPolicyMaxRunning_003, TestSize.Level1)
98 {
99     WorkSchedSystemPolicy systemPolicy;
100     MockProcess(PowerMgr::ThermalLevel::COOL);
101     int32_t ret = thermalPolicy_->GetPolicyMaxRunning(systemPolicy);
102     EXPECT_EQ(ret, 3);
103 }
104 }
105 }
106