• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 "thermal_action_test.h"
17 
18 #ifdef THERMAL_GTEST
19 #define private   public
20 #endif
21 
22 #include <memory>
23 #include <singleton.h>
24 #include "action_application_process.h"
25 #include "action_charger.h"
26 #include "action_cpu_big.h"
27 #include "action_cpu_med.h"
28 #include "action_cpu_lit.h"
29 #include "action_cpu_isolate.h"
30 #include "action_display.h"
31 #include "action_gpu.h"
32 #include "action_node.h"
33 #include "action_shutdown.h"
34 #include "action_thermal_level.h"
35 #include "action_popup.h"
36 #include "action_volume.h"
37 #include "action_voltage.h"
38 #include "file_operation.h"
39 #include "iremote_object.h"
40 #include "mock_thermal_remote_object.h"
41 #include "thermal_service.h"
42 
43 using namespace testing::ext;
44 using namespace OHOS::PowerMgr;
45 using namespace OHOS;
46 using namespace std;
47 
48 namespace {
49 constexpr int32_t BUF_LEN = 32;
50 static sptr<ThermalService> g_service = nullptr;
51 std::shared_ptr<ActionApplicationProcess> g_actionApplicationProcess =
52     std::make_shared<ActionApplicationProcess>("process_ctrl");
53 std::shared_ptr<ActionCharger> g_actionCharger = std::make_shared<ActionCharger>("current_sc");
54 std::shared_ptr<ActionCpuBig> g_actionCpuBig = std::make_shared<ActionCpuBig>("cpu_big");
55 std::shared_ptr<ActionCpuMed> g_actionCpuMed = std::make_shared<ActionCpuMed>("cpu_med");
56 std::shared_ptr<ActionCpuLit> g_actionCpuLit = std::make_shared<ActionCpuLit>("cpu_lit");
57 std::shared_ptr<ActionCpuIsolate> g_actionCpuIsolate = std::make_shared<ActionCpuIsolate>("isolate");
58 std::shared_ptr<ActionDisplay> g_actionDisplay = std::make_shared<ActionDisplay>("lcd");
59 std::shared_ptr<ActionGpu> g_actionGpu = std::make_shared<ActionGpu>("gpu");
60 std::shared_ptr<ActionPopup> g_actionPopup = std::make_shared<ActionPopup>("popup");
61 std::shared_ptr<ActionShutdown> g_actionShutdown = std::make_shared<ActionShutdown>("shut_down");
62 std::shared_ptr<ActionThermalLevel> g_actionThermalLevel = std::make_shared<ActionThermalLevel>("thermallevel");
63 std::shared_ptr<ActionVolume> g_actionVolume = std::make_shared<ActionVolume>("volume");
64 std::shared_ptr<ActionVoltage> g_actionVoltage = std::make_shared<ActionVoltage>("voltage");
65 std::shared_ptr<ActionNode> g_actionNode = std::make_shared<ActionNode>("action_node");
66 }
67 
SetUpTestCase()68 void ThermalActionTest::SetUpTestCase()
69 {
70     g_service = ThermalService::GetInstance();
71     g_service->InitSystemTestModules();
72     g_service->OnStart();
73 }
74 
TearDownTestCase()75 void ThermalActionTest::TearDownTestCase()
76 {
77     g_service->OnStop();
78 }
79 
SetUp()80 void ThermalActionTest::SetUp() {}
81 
TearDown()82 void ThermalActionTest::TearDown() {}
83 
84 namespace {
85 /**
86  * @tc.name: ThermalActionTest001
87  * @tc.desc: Action Volume Function Test
88  * @tc.type: FUNC
89  */
90 HWTEST_F(ThermalActionTest, ThermalActionTest001, TestSize.Level0)
91 {
92     g_actionVolume->InitParams("volume");
93     g_actionVolume->SetEnableEvent(false);
94     g_actionVolume->AddActionValue("");
95     g_actionVolume->AddActionValue("1.0");
96     g_actionVolume->Execute();
97     g_actionVolume->VolumeRequest(1.0);
98     int32_t ret = g_actionVolume->VolumeExecution(1.0);
99     EXPECT_TRUE(ret == ERR_OK);
100 }
101 
102 /**
103  * @tc.name: ThermalActionTest002
104  * @tc.desc: Action Voltage Function Test
105  * @tc.type: FUNC
106  */
107 HWTEST_F(ThermalActionTest, ThermalActionTest002, TestSize.Level0)
108 {
109     g_actionVoltage->AddActionValue("");
110     g_actionVoltage->AddActionValue("1.0");
111     g_actionVoltage->Execute();
112     g_actionVoltage->SetVoltage(123456);
113     g_actionVoltage->ExecuteVoltageLimit();
114     int32_t ret = g_actionVoltage->WriteMockNode(123456);
115     EXPECT_FALSE(ret == ERR_OK);
116 }
117 
118 /**
119  * @tc.name: ThermalActionTest003
120  * @tc.desc: Action Thermal Level Function Test
121  * @tc.type: FUNC
122  */
123 HWTEST_F(ThermalActionTest, ThermalActionTest003, TestSize.Level0)
124 {
125     g_actionThermalLevel->AddActionValue("");
126     g_actionThermalLevel->AddActionValue("1.0");
127     g_actionThermalLevel->Execute();
128     g_actionThermalLevel->GetThermalLevel();
129     g_actionThermalLevel->LevelRequest(1);
130     g_actionThermalLevel->SubscribeThermalLevelCallback(nullptr);
131     g_actionThermalLevel->UnSubscribeThermalLevelCallback(nullptr);
132     std::shared_ptr<IRemoteObject::DeathRecipient> deathRecipient =
133         std::make_shared<ActionThermalLevel::ThermalLevelCallbackDeathRecipient>();
134     wptr<IRemoteObject> remoteObj = nullptr;
135     EXPECT_NE(deathRecipient, nullptr);
136     deathRecipient->OnRemoteDied(remoteObj);
137 
138     sptr<IRemoteObject> sptrRemoteObj = new MockThermalRemoteObject();
139     EXPECT_FALSE(sptrRemoteObj == nullptr);
140     deathRecipient->OnRemoteDied(sptrRemoteObj);
141 
142     g_actionThermalLevel->NotifyThermalLevelChanged(1);
143     bool ret = g_actionThermalLevel->
144         PublishLevelChangedEvents(ThermalCommonEventCode::CODE_THERMAL_LEVEL_CHANGED, 1);
145     EXPECT_TRUE(ret);
146 }
147 
148 /**
149  * @tc.name: ThermalActionTest004
150  * @tc.desc: Action Shutdown Function Test
151  * @tc.type: FUNC
152  */
153 HWTEST_F(ThermalActionTest, ThermalActionTest004, TestSize.Level0)
154 {
155     g_actionShutdown->AddActionValue("1.0");
156     g_actionShutdown->Execute();
157     int32_t ret = g_actionShutdown->ShutdownRequest(false);
158     EXPECT_TRUE(ret == ERR_OK);
159     g_actionShutdown->ShutdownExecution(false);
160     g_actionShutdown->ShutdownExecution(false);
161     ret = g_actionShutdown->DelayShutdown(false, 0, 0);
162     EXPECT_TRUE(ret == ERR_OK);
163 }
164 
165 /**
166  * @tc.name: ThermalActionTest005
167  * @tc.desc: Action Display Function Test
168  * @tc.type: FUNC
169  * @tc.require: issueI6KRS8
170  */
171 HWTEST_F(ThermalActionTest, ThermalActionTest005, TestSize.Level0)
172 {
173     g_actionDisplay->AddActionValue("");
174     g_actionDisplay->AddActionValue("1.0");
175     g_actionDisplay->Execute();
176     EXPECT_TRUE(g_actionDisplay->valueList_.empty());
177 }
178 
179 /**
180  * @tc.name: ThermalActionTest006
181  * @tc.desc: Action Charger Function Test
182  * @tc.type: FUNC
183  */
184 HWTEST_F(ThermalActionTest, ThermalActionTest006, TestSize.Level0)
185 {
186     g_actionCharger->AddActionValue("");
187     g_actionCharger->AddActionValue("1.0");
188     g_actionCharger->Execute();
189     g_actionCharger->ChargerRequest(0);
190     g_actionCharger->ExecuteCurrentLimit();
191     int32_t ret = g_actionCharger->WriteSimValue(0);
192     EXPECT_TRUE(ret);
193 }
194 
195 /**
196  * @tc.name: ThermalActionTest007
197  * @tc.desc: Action Application Process Test
198  * @tc.type: FUNC
199  */
200 HWTEST_F(ThermalActionTest, ThermalActionTest007, TestSize.Level0)
201 {
202     g_actionApplicationProcess->InitParams("");
203     g_actionApplicationProcess->AddActionValue("1");
204     g_actionApplicationProcess->Execute();
205     g_actionApplicationProcess->KillApplicationAction("");
206     g_actionApplicationProcess->KillProcess(0);
207     g_actionApplicationProcess->GetAppProcessInfoByName("");
208     g_actionApplicationProcess->GetAllRunnningAppProcess();
209     g_actionApplicationProcess->KillBgAppProcess();
210     g_actionApplicationProcess->KillAllAppProcess();
211     g_actionApplicationProcess->ProcessAppActionRequest(0);
212     g_actionApplicationProcess->ProcessAppActionExecution(0);
213     EXPECT_TRUE(g_actionApplicationProcess->valueList_.empty());
214 }
215 
216 /**
217  * @tc.name: ThermalActionTest008
218  * @tc.desc: Action CPU Big Test
219  * @tc.type: FUNC
220  * @tc.require: issueI6KRS8
221  */
222 HWTEST_F(ThermalActionTest, ThermalActionTest008, TestSize.Level0)
223 {
224     g_actionCpuBig->AddActionValue("");
225     g_actionCpuBig->AddActionValue("1.0");
226     g_actionCpuBig->Execute();
227     EXPECT_TRUE(g_actionCpuBig->valueList_.empty());
228 }
229 
230 /**
231  * @tc.name: ThermalActionTest009
232  * @tc.desc: Action CPU Med Test
233  * @tc.type: FUNC
234  * @tc.require: issueI6KRS8
235  */
236 HWTEST_F(ThermalActionTest, ThermalActionTest009, TestSize.Level0)
237 {
238     g_actionCpuMed->AddActionValue("");
239     g_actionCpuMed->AddActionValue("1.0");
240     g_actionCpuMed->Execute();
241     EXPECT_TRUE(g_actionCpuMed->valueList_.empty());
242 }
243 
244 /**
245  * @tc.name: ThermalActionTest010
246  * @tc.desc: Action CPU Lit Test
247  * @tc.type: FUNC
248  * @tc.require: issueI6KRS8
249  */
250 HWTEST_F(ThermalActionTest, ThermalActionTest010, TestSize.Level0)
251 {
252     g_actionCpuLit->AddActionValue("");
253     g_actionCpuLit->AddActionValue("1.0");
254     g_actionCpuLit->Execute();
255     EXPECT_TRUE(g_actionCpuLit->valueList_.empty());
256 }
257 
258 /**
259  * @tc.name: ThermalActionTest011
260  * @tc.desc: Action GPU Test
261  * @tc.type: FUNC
262  * @tc.require: issueI6KRS8
263  */
264 HWTEST_F(ThermalActionTest, ThermalActionTest011, TestSize.Level0)
265 {
266     g_actionGpu->AddActionValue("");
267     g_actionGpu->AddActionValue("1.0");
268     g_actionGpu->Execute();
269     EXPECT_TRUE(g_actionGpu->valueList_.empty());
270 }
271 
272 /**
273  * @tc.name: ThermalActionTest012
274  * @tc.desc: Action Isolate CPU Test
275  * @tc.type: FUNC
276   */
277 HWTEST_F(ThermalActionTest, ThermalActionTest012, TestSize.Level0)
278 {
279     g_actionCpuIsolate->AddActionValue("");
280     g_actionCpuIsolate->AddActionValue("1.0");
281     g_actionCpuIsolate->Execute();
282     EXPECT_TRUE(g_actionCpuIsolate->valueList_.empty());
283 }
284 
285 /**
286  * @tc.name: ThermalActionTest013
287  * @tc.desc: Action node Test
288  * @tc.type: FUNC
289   */
290 HWTEST_F(ThermalActionTest, ThermalActionTest013, TestSize.Level0)
291 {
292     std::string input = "1.0";
293     g_actionNode->InitParams("/data/service/el0/thermal/config/lcd");
294     g_actionNode->AddActionValue(input);
295     g_actionNode->Execute();
296     char buf[BUF_LEN];
297     FileOperation::ReadFile("/data/service/el0/thermal/config/lcd", buf, BUF_LEN);
298     std::string ret = buf;
299     EXPECT_EQ(input, ret);
300 }
301 } // namespace
302