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