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
17 #include "thermal_mgr_system_test.h"
18
19 #include <algorithm>
20 #include <cstdio>
21 #include <cstdlib>
22 #include <mutex>
23 #include <fcntl.h>
24 #include <libxml/tree.h>
25 #include <mutex>
26 #include <unistd.h>
27 #include "securec.h"
28
29 #include "constants.h"
30 #include "mock_thermal_mgr_client.h"
31 #include "string_operation.h"
32 #include "thermal_common.h"
33 #include "thermal_config_file_parser.h"
34 #include "thermal_log.h"
35 #include "thermal_mgr_client.h"
36 #include "thermal_service.h"
37 #include "thermal_srv_config_parser.h"
38
39 using namespace OHOS::HiviewDFX;
40 using namespace OHOS::PowerMgr;
41 using namespace OHOS;
42 using namespace std;
43 using namespace testing::ext;
44
45 namespace {
46 static sptr<ThermalService> g_service;
47 static std::map<std::string, SensorInfoMap> g_sensorInfoMap;
48 static int32_t g_temp = 0;
49 std::unique_ptr<ThermalConfigFileParser> g_parser;
50 const std::string SYSTEM_CONFIG = "/vendor/etc/thermal_config/thermal_service_config.xml";
51 } // namespace
52
WriteFile(std::string path,std::string buf,size_t size)53 int32_t ThermalMgrSystemTest::WriteFile(std::string path, std::string buf, size_t size)
54 {
55 FILE* stream = fopen(path.c_str(), "w+");
56 if (stream == nullptr) {
57 return ERR_INVALID_VALUE;
58 }
59 size_t ret = fwrite(buf.c_str(), strlen(buf.c_str()), 1, stream);
60 if (ret == ERR_OK) {
61 THERMAL_HILOGE(COMP_SVC, "ret=%{public}zu", ret);
62 }
63 int32_t state = fseek(stream, 0, SEEK_SET);
64 if (state != ERR_OK) {
65 fclose(stream);
66 return state;
67 }
68 state = fclose(stream);
69 if (state != ERR_OK) {
70 return state;
71 }
72 return ERR_OK;
73 }
74
ReadFile(const char * path,char * buf,size_t size)75 int32_t ThermalMgrSystemTest::ReadFile(const char* path, char* buf, size_t size)
76 {
77 int32_t ret;
78
79 int32_t fd = open(path, O_RDONLY, S_IRUSR | S_IRGRP | S_IROTH);
80 if (fd < ERR_OK) {
81 THERMAL_HILOGD(LABEL_TEST, "WriteFile: failed to open file fd: %{public}d", fd);
82 return ERR_INVALID_VALUE;
83 }
84
85 ret = read(fd, buf, size);
86 if (ret < ERR_OK) {
87 THERMAL_HILOGD(LABEL_TEST, "WriteFile: failed to read file ret: %{public}d", ret);
88 close(fd);
89 return ERR_INVALID_VALUE;
90 }
91
92 close(fd);
93 buf[size - 1] = '\0';
94 return ERR_OK;
95 }
96
InitNode()97 int32_t ThermalMgrSystemTest::InitNode()
98 {
99 char bufTemp[MAX_PATH] = {0};
100 int32_t ret = -1;
101 std::map<std::string, int32_t> sensor;
102 sensor["battery"] = 0;
103 sensor["charger"] = 0;
104 sensor["pa"] = 0;
105 sensor["ap"] = 0;
106 sensor["ambient"] = 0;
107 sensor["cpu"] = 0;
108 sensor["soc"] = 0;
109 sensor["shell"] = 0;
110 for (auto iter : sensor) {
111 ret = snprintf_s(bufTemp, MAX_PATH, sizeof(bufTemp) - 1, SIMULATION_TEMP_DIR.c_str(), iter.first.c_str());
112 if (ret < EOK) {
113 return ret;
114 }
115 std::string temp = std::to_string(iter.second) + "\n";
116 WriteFile(bufTemp, temp, temp.length());
117 }
118 return ERR_OK;
119 }
120
ConvertInt(const std::string & value)121 int32_t ThermalMgrSystemTest::ConvertInt(const std::string& value)
122 {
123 return std::stoi(value);
124 }
125
SetUpTestCase()126 void ThermalMgrSystemTest::SetUpTestCase()
127 {
128 system("setenforce 0");
129 system("mount -o rw,remount /vendor");
130 g_service = DelayedSpSingleton<ThermalService>::GetInstance();
131 g_service->InitSystemTestModules();
132 g_parser = std::make_unique<ThermalConfigFileParser>();
133 g_parser->ParseXmlFile(SYSTEM_CONFIG);
134 }
135
TearDownTestCase()136 void ThermalMgrSystemTest::TearDownTestCase()
137 {
138 system("setenforce 1");
139 }
140
SetUp()141 void ThermalMgrSystemTest::SetUp()
142 {
143 InitNode();
144 }
145
TearDown()146 void ThermalMgrSystemTest::TearDown()
147 {
148 }
149
GetSystemTestTemp(std::vector<LevelItem> & iter,const int32_t & needLevel)150 static void GetSystemTestTemp(std::vector<LevelItem>& iter, const int32_t& needLevel)
151 {
152 THERMAL_HILOGD(LABEL_TEST, "GetSystemTestTemp: start.");
153 for (auto info : iter) {
154 THERMAL_HILOGD(LABEL_TEST, "info.level = %{public}d", info.level);
155 if (info.level == static_cast<uint32_t>(needLevel)) {
156 g_temp = info.threshold;
157 }
158 }
159 }
160
GetSensorName(SensorInfoMap & info,const std::string & sensorName,const int32_t & needLevel)161 static void GetSensorName(SensorInfoMap& info, const std::string& sensorName, const int32_t& needLevel)
162 {
163 THERMAL_HILOGD(LABEL_TEST, "GetSensorName: start.");
164 for (auto iter = info.begin(); iter != info.end(); ++iter) {
165 THERMAL_HILOGD(COMP_SVC, "SENSOR name = %{public}s", iter->first.c_str());
166 if (iter->first == sensorName) {
167 GetSystemTestTemp(iter->second, needLevel);
168 }
169 }
170 }
171
GetSensorClusterName(const std::string & sensorClusterName,const std::string & sensorName,const int32_t & needLevel)172 static void GetSensorClusterName(const std::string& sensorClusterName, const std::string& sensorName,
173 const int32_t& needLevel)
174 {
175 THERMAL_HILOGD(LABEL_TEST, "GetSensorClusterName: start.");
176 if (g_parser == nullptr) {
177 THERMAL_HILOGD(LABEL_TEST, "g_parser: is nullptr.");
178 return;
179 }
180
181 std::map<std::string, SensorInfoMap> sensorInfoMap = g_parser->GetSensorInfoMap();
182 for (auto info = sensorInfoMap.begin(); info != sensorInfoMap.end(); ++info) {
183 THERMAL_HILOGD(COMP_SVC, "sensor_cluster name = %{public}s", info->first.c_str());
184 if (info->first == sensorClusterName) {
185 GetSensorName(info->second, sensorName, needLevel);
186 }
187 }
188 }
189
190
191 namespace {
192 /**
193 * @tc.name: ThermalMgrSystemTest001
194 * @tc.desc: test get current configured level by setting temp
195 * @tc.type: FEATURE
196 * @tc.cond: Set Battery temp, High Temp
197 * @tc.result level 1
198 */
199 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest001, Function|MediumTest|Level2)
200 {
201 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest001: start.");
202 char batteryTempBuf[MAX_PATH] = {0};
203 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
204 EXPECT_EQ(true, ret >= EOK);
205 GetSensorClusterName("base_safe", "battery", 1);
206 int32_t batteryTemp = g_temp + 100;
207 std::string sTemp = to_string(batteryTemp) + "\n";
208 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
209 EXPECT_EQ(true, ret == ERR_OK);
210
211 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
212 THERMAL_HILOGD(LABEL_TEST, "SIMUL PATH has been in ");
213 return;
214 }
215
216 MockThermalMgrClient::GetInstance().GetThermalInfo();
217
218 char levelBuf[MAX_PATH] = {0};
219 char levelValue[MAX_PATH] = {0};
220 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
221 EXPECT_EQ(true, ret >= EOK);
222 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
223 EXPECT_EQ(true, ret == ERR_OK);
224 std::string level = levelValue;
225 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
226 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
227 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest001 failed";
228 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest001: end.");
229 }
230
231 /**
232 * @tc.name: ThermalMgrSystemTest002
233 * @tc.desc: test get current configured level by setting temp
234 * @tc.type: FEATURE
235 * @tc.cond: Set Battery temp, High Temp
236 * @tc.result level 2
237 */
238 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest002, Function|MediumTest|Level2)
239 {
240 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest002: start.");
241 char batteryTempBuf[MAX_PATH] = {0};
242 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
243 EXPECT_EQ(true, ret >= EOK);
244 GetSensorClusterName("base_safe", "battery", 2);
245 int32_t batteryTemp = g_temp +100;
246 std::string sTemp = to_string(batteryTemp) + "\n";
247 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
248 EXPECT_EQ(true, ret == ERR_OK);
249
250 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
251 THERMAL_HILOGD(LABEL_TEST, "SIMUL PATH has been in ");
252 return;
253 }
254
255 MockThermalMgrClient::GetInstance().GetThermalInfo();
256
257 char levelBuf[MAX_PATH] = {0};
258 char levelValue[MAX_PATH] = {0};
259 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
260 EXPECT_EQ(true, ret >= EOK);
261 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
262 EXPECT_EQ(true, ret == ERR_OK);
263 std::string level = levelValue;
264 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
265 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
266 EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest002 failed";
267 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest002: end.");
268 }
269
270 /**
271 * @tc.name: ThermalMgrSystemTest003
272 * @tc.desc: test get current configured level by setting temp
273 * @tc.type: FEATURE
274 * @tc.cond: Set Battery temp, High Temp
275 * @tc.result level 3
276 */
277 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest003, Function|MediumTest|Level2)
278 {
279 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest003: start.");
280 char batteryTempBuf[MAX_PATH] = {0};
281 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
282 EXPECT_EQ(true, ret >= EOK);
283 GetSensorClusterName("base_safe", "battery", 3);
284 int32_t batteryTemp = g_temp + 100;
285 std::string sTemp = to_string(batteryTemp) + "\n";
286 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
287 EXPECT_EQ(true, ret == ERR_OK);
288
289 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
290 THERMAL_HILOGD(LABEL_TEST, "SIMUL PATH has been in ");
291 return;
292 }
293
294 MockThermalMgrClient::GetInstance().GetThermalInfo();
295
296 char levelBuf[MAX_PATH] = {0};
297 char levelValue[MAX_PATH] = {0};
298 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
299 EXPECT_EQ(true, ret >= EOK);
300 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
301 EXPECT_EQ(true, ret == ERR_OK);
302 std::string level = levelValue;
303 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
304 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
305 EXPECT_EQ(true, value == 3) << "ThermalMgrSystemTest003 failed";
306 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest003: end.");
307 }
308
309 /**
310 * @tc.name: ThermalMgrSystemTest004
311 * @tc.desc: test get current configured level by setting temp
312 * @tc.type: FEATURE
313 * @tc.cond: Set Battery temp, High Temp
314 * @tc.result level 4
315 */
316 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest004, Function|MediumTest|Level2)
317 {
318 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest003: start.");
319 char batteryTempBuf[MAX_PATH] = {0};
320 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
321 EXPECT_EQ(true, ret >= EOK);
322 GetSensorClusterName("base_safe", "battery", 4);
323 int32_t batteryTemp = g_temp + 100;
324 std::string sTemp = to_string(batteryTemp) + "\n";
325 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
326 EXPECT_EQ(true, ret == ERR_OK);
327
328 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
329 THERMAL_HILOGD(LABEL_TEST, "SIMUL PATH has been in ");
330 return;
331 }
332
333 MockThermalMgrClient::GetInstance().GetThermalInfo();
334
335 char levelBuf[MAX_PATH] = {0};
336 char levelValue[MAX_PATH] = {0};
337 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
338 EXPECT_EQ(true, ret >= EOK);
339 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
340 EXPECT_EQ(true, ret == ERR_OK);
341 std::string level = levelValue;
342 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
343 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest005 failed";
344 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest004: end.");
345 }
346
347 /**
348 * @tc.name: ThermalMgrSystemTest005
349 * @tc.desc: test level asc logic by setting temp
350 * @tc.type: FEATURE
351 * @tc.cond: Set Battery temp, High Temp
352 * @tc.result level 1 ==> level 4
353 */
354 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest005, Function|MediumTest|Level2)
355 {
356 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest005: start.");
357 char batteryTempBuf[MAX_PATH] = {0};
358 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
359 EXPECT_EQ(true, ret >= EOK);
360 GetSensorClusterName("base_safe", "battery", 1);
361 int32_t batteryTemp = g_temp + 100;
362 std::string sTemp = to_string(batteryTemp) + "\n";
363 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
364 EXPECT_EQ(true, ret == ERR_OK);
365 char levelBuf[MAX_PATH] = {0};
366 char levelValue[MAX_PATH] = {0};
367 std::string level;
368 int32_t value;
369 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
370 THERMAL_HILOGD(LABEL_TEST, "SIMUL PATH has been in ");
371 return;
372 }
373
374 MockThermalMgrClient::GetInstance().GetThermalInfo();
375 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
376 EXPECT_EQ(true, ret >= EOK);
377 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
378 EXPECT_EQ(true, ret == ERR_OK);
379 level = levelValue;
380 value = ThermalMgrSystemTest::ConvertInt(level);
381 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest005 failed";
382
383 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
384 EXPECT_EQ(true, ret >= EOK);
385 GetSensorClusterName("base_safe", "battery", 4);
386 batteryTemp = g_temp + 100;
387 sTemp = to_string(batteryTemp) + "\n";
388 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
389 EXPECT_EQ(true, ret == ERR_OK);
390 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
391 return;
392 }
393
394 MockThermalMgrClient::GetInstance().GetThermalInfo();
395 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
396 EXPECT_EQ(true, ret >= EOK);
397 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
398 EXPECT_EQ(true, ret == ERR_OK);
399 level = levelValue;
400 value = ThermalMgrSystemTest::ConvertInt(level);
401 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
402 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest005 failed";
403 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest005: end.");
404 }
405
406 /**
407 * @tc.name: ThermalMgrSystemTest006
408 * @tc.desc: test level asc logic by setting temp
409 * @tc.type: FEATURE
410 * @tc.cond: Set Battery temp, High Temp
411 * @tc.result level 2 ==> level 4
412 */
413 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest006, Function|MediumTest|Level2)
414 {
415 char batteryTempBuf[MAX_PATH] = {0};
416 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
417 EXPECT_EQ(true, ret >= EOK);
418 GetSensorClusterName("base_safe", "battery", 2);
419 int32_t batteryTemp = g_temp + 100;
420 std::string sTemp = to_string(batteryTemp) + "\n";
421 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
422 EXPECT_EQ(true, ret == ERR_OK);
423
424 char levelBuf[MAX_PATH] = {0};
425 char levelValue[MAX_PATH] = {0};
426 std::string level;
427 int32_t value;
428 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
429 return;
430 }
431
432 MockThermalMgrClient::GetInstance().GetThermalInfo();
433 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
434 EXPECT_EQ(true, ret >= EOK);
435 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
436 EXPECT_EQ(true, ret == ERR_OK);
437 level = levelValue;
438 value = ThermalMgrSystemTest::ConvertInt(level);
439 EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest006 failed";
440
441 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
442 EXPECT_EQ(true, ret >= EOK);
443 GetSensorClusterName("base_safe", "battery", 4);
444 batteryTemp = g_temp + 100;
445 sTemp = to_string(batteryTemp) + "\n";
446 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
447 EXPECT_EQ(true, ret == ERR_OK);
448 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
449 return;
450 }
451
452 MockThermalMgrClient::GetInstance().GetThermalInfo();
453 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
454 EXPECT_EQ(true, ret >= EOK);
455 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
456 EXPECT_EQ(true, ret == ERR_OK);
457 level = levelValue;
458 value = ThermalMgrSystemTest::ConvertInt(level);
459 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest006 failed";
460 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest006: end.");
461 }
462
463 /**
464 * @tc.name: ThermalMgrSystemTest007
465 * @tc.desc: test level desc logic by setting temp
466 * @tc.type: FEATURE
467 * @tc.cond: Set Battery temp, High Temp
468 * @tc.result level 4 ===> level 1
469 */
470 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest007, Function|MediumTest|Level2)
471 {
472 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest007: start.");
473 char batteryTempBuf[MAX_PATH] = {0};
474 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
475 EXPECT_EQ(true, ret >= EOK);
476 GetSensorClusterName("base_safe", "battery", 4);
477 int32_t batteryTemp = g_temp + 100;
478 std::string sTemp = to_string(batteryTemp) + "\n";
479 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
480 EXPECT_EQ(true, ret == ERR_OK);
481
482 char levelBuf[MAX_PATH] = {0};
483 char levelValue[MAX_PATH] = {0};
484 std::string level;
485 int32_t value;
486 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
487 return;
488 }
489
490 MockThermalMgrClient::GetInstance().GetThermalInfo();
491 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
492 EXPECT_EQ(true, ret >= EOK);
493 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
494 EXPECT_EQ(true, ret == ERR_OK);
495 level = levelValue;
496 value = ThermalMgrSystemTest::ConvertInt(level);
497 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest007 failed";
498
499 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
500 EXPECT_EQ(true, ret >= EOK);
501 GetSensorClusterName("base_safe", "battery", 1);
502 batteryTemp = g_temp + 100;
503
504 sTemp = to_string(batteryTemp) + "\n";
505 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
506 EXPECT_EQ(true, ret == ERR_OK);
507 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
508 return;
509 }
510
511 MockThermalMgrClient::GetInstance().GetThermalInfo();
512 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
513 EXPECT_EQ(true, ret >= EOK);
514 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
515 EXPECT_EQ(true, ret == ERR_OK);
516 level = levelValue;
517 value = ThermalMgrSystemTest::ConvertInt(level);
518 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest007 failed";
519 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest007: end.");
520 }
521
522 /**
523 * @tc.name: ThermalMgrSystemTest008
524 * @tc.desc: test level desc logic by setting temp
525 * @tc.type: FEATURE
526 * @tc.cond: Set Battery temp, High Temp
527 * @tc.result level 3 ===> level 0
528 */
529 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest008, Function|MediumTest|Level2)
530 {
531 char batteryTempBuf[MAX_PATH] = {0};
532 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
533 EXPECT_EQ(true, ret >= EOK);
534 GetSensorClusterName("base_safe", "battery", 3);
535 int32_t batteryTemp = g_temp + 100;
536 std::string sTemp = to_string(batteryTemp) + "\n";
537 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
538 EXPECT_EQ(true, ret == ERR_OK);
539
540 char levelBuf[MAX_PATH] = {0};
541 char levelValue[MAX_PATH] = {0};
542 std::string level;
543 int32_t value;
544 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
545 return;
546 }
547
548 MockThermalMgrClient::GetInstance().GetThermalInfo();
549 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) -1, CONFIG_LEVEL_PATH.c_str());
550 EXPECT_EQ(true, ret >= EOK);
551 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
552 EXPECT_EQ(true, ret == ERR_OK);
553 level = levelValue;
554 value = ThermalMgrSystemTest::ConvertInt(level);
555 EXPECT_EQ(true, value == 3) << "ThermalMgrSystemTest008 failed";
556
557 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
558 EXPECT_EQ(true, ret >= EOK);
559 GetSensorClusterName("base_safe", "battery", 1);
560 batteryTemp = g_temp - 3000;
561 sTemp = to_string(batteryTemp) + "\n";
562 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
563 EXPECT_EQ(true, ret == ERR_OK);
564 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
565 return;
566 }
567
568 MockThermalMgrClient::GetInstance().GetThermalInfo();
569 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
570 EXPECT_EQ(true, ret >= EOK);
571 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
572 EXPECT_EQ(true, ret == ERR_OK);
573 level = levelValue;
574 value = ThermalMgrSystemTest::ConvertInt(level);
575 EXPECT_EQ(true, value == 0) << "ThermalMgrSystemTest008 failed";
576 }
577
578 /**
579 * @tc.name: ThermalMgrSystemTest009
580 * @tc.desc: test get current configured level by setting temp
581 * @tc.type: FEATURE
582 * @tc.cond: Set Battery temp, Lower Temp
583 * @tc.result level 1
584 */
585 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest009, Function|MediumTest|Level2)
586 {
587 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest009: start.");
588
589 char batteryTempBuf[MAX_PATH] = {0};
590 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
591 EXPECT_EQ(true, ret >= EOK);
592 GetSensorClusterName("cold_safe", "battery", 1);
593 int32_t batteryTemp = g_temp - 2000;
594 THERMAL_HILOGD(LABEL_TEST, "TEMP: %{public}d", batteryTemp);
595 std::string sTemp = to_string(batteryTemp) + "\n";
596 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
597 EXPECT_EQ(true, ret == ERR_OK);
598
599 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
600 THERMAL_HILOGD(LABEL_TEST, "SIMUL PATH has been in ");
601 return;
602 }
603
604 MockThermalMgrClient::GetInstance().GetThermalInfo();
605
606 char levelBuf[MAX_PATH] = {0};
607 char levelValue[MAX_PATH] = {0};
608 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
609 EXPECT_EQ(true, ret >= EOK);
610 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
611 EXPECT_EQ(true, ret == ERR_OK);
612 std::string level = levelValue;
613 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
614 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest009 failed";
615 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest009: end.");
616 }
617
618 /**
619 * @tc.name: ThermalMgrSystemTest010
620 * @tc.desc: test get current configured level by setting temp
621 * @tc.type: FEATURE
622 * @tc.cond: Set Battery temp, Lower Temp
623 * @tc.result level 2
624 */
625 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest010, Function|MediumTest|Level2)
626 {
627 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest010: start.");
628
629 char batteryTempBuf[MAX_PATH] = {0};
630 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
631 EXPECT_EQ(true, ret >= EOK);
632 GetSensorClusterName("cold_safe", "battery", 2);
633 int32_t batteryTemp = g_temp - 2000;
634 THERMAL_HILOGD(LABEL_TEST, "TEMP: %{public}d", batteryTemp);
635 std::string sTemp = to_string(batteryTemp) + "\n";
636 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
637 EXPECT_EQ(true, ret == ERR_OK);
638
639 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
640 THERMAL_HILOGD(LABEL_TEST, "SIMUL PATH has been in ");
641 return;
642 }
643
644 MockThermalMgrClient::GetInstance().GetThermalInfo();
645
646 char levelBuf[MAX_PATH] = {0};
647 char levelValue[MAX_PATH] = {0};
648 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
649 EXPECT_EQ(true, ret >= EOK);
650 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
651 EXPECT_EQ(true, ret == ERR_OK);
652 std::string level = levelValue;
653 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
654 EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest010 failed";
655 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest010: end.");
656 }
657
658 /**
659 * @tc.name: ThermalMgrSystemTest011
660 * @tc.desc: test get current configured level by setting temp
661 * @tc.type: FEATURE
662 * @tc.cond: Set Battery temp, Lower Temp
663 * @tc.result level 3
664 */
665 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest011, Function|MediumTest|Level2)
666 {
667 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest011: start.");
668
669 char batteryTempBuf[MAX_PATH] = {0};
670 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
671 EXPECT_EQ(true, ret >= EOK);
672 GetSensorClusterName("cold_safe", "battery", 3);
673 int32_t batteryTemp = g_temp - 1000;
674 std::string sTemp = to_string(batteryTemp) + "\n";
675 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
676 EXPECT_EQ(true, ret == ERR_OK);
677
678 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
679 THERMAL_HILOGD(LABEL_TEST, "SIMUL PATH has been in ");
680 return;
681 }
682
683 MockThermalMgrClient::GetInstance().GetThermalInfo();
684
685 char levelBuf[MAX_PATH] = {0};
686 char levelValue[MAX_PATH] = {0};
687 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
688 EXPECT_EQ(true, ret >= EOK);
689 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
690 EXPECT_EQ(true, ret == ERR_OK);
691 std::string level = levelValue;
692 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
693 EXPECT_EQ(true, value == 3) << "ThermalMgrSystemTest011 failed";
694 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest011: end.");
695 }
696
697 /**
698 * @tc.name: ThermalMgrSystemTest012
699 * @tc.desc: test get current configured level by setting temp
700 * @tc.type: FEATURE
701 * @tc.cond: Set Battery temp, Lower Temp
702 * @tc.result level 4
703 */
704 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest012, Function|MediumTest|Level2)
705 {
706 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest012: start.");
707
708 char batteryTempBuf[MAX_PATH] = {0};
709 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
710 EXPECT_EQ(true, ret >= EOK);
711 GetSensorClusterName("cold_safe", "battery", 4);
712 int32_t batteryTemp = g_temp - 2000;
713 THERMAL_HILOGD(LABEL_TEST, "TEMP: %{public}d", batteryTemp);
714 std::string sTemp = to_string(batteryTemp) + "\n";
715 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
716 EXPECT_EQ(true, ret == ERR_OK);
717
718 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
719 THERMAL_HILOGD(LABEL_TEST, "SIMUL PATH has been in ");
720 return;
721 }
722
723 MockThermalMgrClient::GetInstance().GetThermalInfo();
724
725 char levelBuf[MAX_PATH] = {0};
726 char levelValue[MAX_PATH] = {0};
727 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
728 EXPECT_EQ(true, ret >= EOK);
729 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
730 EXPECT_EQ(true, ret == ERR_OK);
731 std::string level = levelValue;
732 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
733 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest012 failed";
734 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest012: end.");
735 }
736
737 /**
738 * @tc.name: ThermalMgrSystemTest013
739 * @tc.desc: test level asc logic by setting temp
740 * @tc.type: FEATURE
741 * @tc.cond: Set Battery temp, Lower Temp
742 * @tc.result level 1 ==> level 4
743 */
744 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest013, Function|MediumTest|Level2)
745 {
746 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest013: start.");
747
748 char batteryTempBuf[MAX_PATH] = {0};
749 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
750 EXPECT_EQ(true, ret >= EOK);
751 GetSensorClusterName("cold_safe", "battery", 1);
752 int32_t batteryTemp = g_temp - 2000;
753 std::string sTemp = to_string(batteryTemp) + "\n";
754 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
755 EXPECT_EQ(true, ret == ERR_OK);
756
757 char levelBuf[MAX_PATH] = {0};
758 char levelValue[MAX_PATH] = {0};
759 std::string level;
760 int32_t value;
761 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
762 return;
763 }
764
765 MockThermalMgrClient::GetInstance().GetThermalInfo();
766 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
767 EXPECT_EQ(true, ret >= EOK);
768 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
769 EXPECT_EQ(true, ret == ERR_OK);
770 level = levelValue;
771 value = ThermalMgrSystemTest::ConvertInt(level);
772 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest013 failed";
773
774 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
775 EXPECT_EQ(true, ret >= EOK);
776 GetSensorClusterName("cold_safe", "battery", 4);
777 batteryTemp = g_temp - 2000;
778 sTemp = to_string(batteryTemp) + "\n";
779 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
780 EXPECT_EQ(true, ret == ERR_OK);
781 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
782 return;
783 }
784
785 MockThermalMgrClient::GetInstance().GetThermalInfo();
786 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
787 EXPECT_EQ(true, ret >= EOK);
788 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
789 EXPECT_EQ(true, ret == ERR_OK);
790 level = levelValue;
791 value = ThermalMgrSystemTest::ConvertInt(level);
792 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest013 failed";
793 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest013: end.");
794 }
795
796 /**
797 * @tc.name: ThermalMgrSystemTest014
798 * @tc.desc: test level asc logic by setting temp
799 * @tc.type: FEATURE
800 * @tc.cond: Set Battery temp, High Temp
801 * @tc.result level 2 ==> level 4
802 */
803 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest014, Function|MediumTest|Level2)
804 {
805 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest014: start.");
806
807 char batteryTempBuf[MAX_PATH] = {0};
808 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
809 EXPECT_EQ(true, ret >= EOK);
810 GetSensorClusterName("cold_safe", "battery", 2);
811 int32_t batteryTemp = g_temp - 2000;
812 std::string sTemp = to_string(batteryTemp) + "\n";
813 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
814 EXPECT_EQ(true, ret == ERR_OK);
815
816 char levelBuf[MAX_PATH] = {0};
817 char levelValue[MAX_PATH] = {0};
818 std::string level;
819 int32_t value;
820 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
821 return;
822 }
823
824 MockThermalMgrClient::GetInstance().GetThermalInfo();
825 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
826 EXPECT_EQ(true, ret >= EOK);
827 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
828 EXPECT_EQ(true, ret == ERR_OK);
829 level = levelValue;
830 value = ThermalMgrSystemTest::ConvertInt(level);
831 EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest014 failed";
832
833 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
834 EXPECT_EQ(true, ret >= EOK);
835 GetSensorClusterName("cold_safe", "battery", 4);
836 batteryTemp = g_temp - 2000;
837 sTemp = to_string(batteryTemp) + "\n";
838 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
839 EXPECT_EQ(true, ret == ERR_OK);
840 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
841 return;
842 }
843
844 MockThermalMgrClient::GetInstance().GetThermalInfo();
845 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
846 EXPECT_EQ(true, ret >= EOK);
847 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
848 EXPECT_EQ(true, ret == ERR_OK);
849 level = levelValue;
850 value = ThermalMgrSystemTest::ConvertInt(level);
851 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest014 failed";
852 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest014: end.");
853 }
854
855 /**
856 * @tc.name: ThermalMgrSystemTest015
857 * @tc.desc: test level desc logic by setting temp
858 * @tc.type: FEATURE
859 * @tc.cond: Set Battery temp, High Temp
860 * @tc.result level 4 ===> level 1
861 */
862 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest015, Function|MediumTest|Level2)
863 {
864 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest015: start.");
865
866 char batteryTempBuf[MAX_PATH] = {0};
867 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
868 EXPECT_EQ(true, ret >= EOK);
869 GetSensorClusterName("cold_safe", "battery", 4);
870 int32_t batteryTemp = g_temp - 2000;
871 std::string sTemp = to_string(batteryTemp) + "\n";
872 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
873 EXPECT_EQ(true, ret == ERR_OK);
874
875 char levelBuf[MAX_PATH] = {0};
876 char levelValue[MAX_PATH] = {0};
877 std::string level;
878 int32_t value;
879 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
880 return;
881 }
882
883 MockThermalMgrClient::GetInstance().GetThermalInfo();
884 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
885 EXPECT_EQ(true, ret >= EOK);
886 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
887 EXPECT_EQ(true, ret == ERR_OK);
888 level = levelValue;
889 value = ThermalMgrSystemTest::ConvertInt(level);
890 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest015 failed";
891
892 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
893 EXPECT_EQ(true, ret >= EOK);
894 GetSensorClusterName("cold_safe", "battery", 1);
895 batteryTemp = g_temp - 2000;
896 sTemp = to_string(batteryTemp) + "\n";
897 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
898 EXPECT_EQ(true, ret == ERR_OK);
899 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
900 return;
901 }
902
903 MockThermalMgrClient::GetInstance().GetThermalInfo();
904 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
905 EXPECT_EQ(true, ret >= EOK);
906 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
907 EXPECT_EQ(true, ret == ERR_OK);
908 level = levelValue;
909 value = ThermalMgrSystemTest::ConvertInt(level);
910 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest015 failed";
911 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest015: end.");
912 }
913
914 /**
915 * @tc.name: ThermalMgrSystemTest016
916 * @tc.desc: test level desc logic by setting temp
917 * @tc.type: FEATURE
918 * @tc.cond: Set Battery temp, High Temp
919 * @tc.result level 3 ===> level 0
920 */
921 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest016, Function|MediumTest|Level2)
922 {
923 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest016: start.");
924
925 char batteryTempBuf[MAX_PATH] = {0};
926 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
927 EXPECT_EQ(true, ret >= EOK);
928 GetSensorClusterName("cold_safe", "battery", 3);
929 int32_t batteryTemp = g_temp - 1000;
930 std::string sTemp = to_string(batteryTemp) + "\n";
931 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
932 EXPECT_EQ(true, ret == ERR_OK);
933
934 char levelBuf[MAX_PATH] = {0};
935 char levelValue[MAX_PATH] = {0};
936 std::string level;
937 int32_t value;
938 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
939 return;
940 }
941
942 MockThermalMgrClient::GetInstance().GetThermalInfo();
943 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
944 EXPECT_EQ(true, ret >= EOK);
945 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
946 EXPECT_EQ(true, ret == ERR_OK);
947 level = levelValue;
948 value = ThermalMgrSystemTest::ConvertInt(level);
949 EXPECT_EQ(true, value == 3) << "ThermalMgrSystemTest016 failed";
950
951 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
952 EXPECT_EQ(true, ret >= EOK);
953 GetSensorClusterName("cold_safe", "battery", 1);
954 batteryTemp = g_temp + 10000;
955 sTemp = to_string(batteryTemp) + "\n";
956 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
957 EXPECT_EQ(true, ret == ERR_OK);
958 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
959 return;
960 }
961
962 MockThermalMgrClient::GetInstance().GetThermalInfo();
963 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, CONFIG_LEVEL_PATH.c_str());
964 EXPECT_EQ(true, ret >= EOK);
965 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
966 EXPECT_EQ(true, ret == ERR_OK);
967 level = levelValue;
968 value = ThermalMgrSystemTest::ConvertInt(level);
969 EXPECT_EQ(true, value == 0) << "ThermalMgrSystemTest016 failed";
970 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest016: end.");
971 }
972
973 /**
974 * @tc.name: ThermalMgrSystemTest017
975 * @tc.desc: test get process value by setting temp
976 * @tc.type: FEATURE
977 * @tc.cond: Set Battery temp, Lower Temp
978 * @tc.result level 1 procss 3
979 */
980 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest017, Function|MediumTest|Level2)
981 {
982 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest017: start.");
983 char batteryTempBuf[MAX_PATH] = {0};
984 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
985 EXPECT_EQ(true, ret >= EOK);
986
987 GetSensorClusterName("base_safe", "battery", 1);
988 int32_t batteryTemp = g_temp + 1000;
989 THERMAL_HILOGD(LABEL_TEST, "TEMP: %{public}d", batteryTemp);
990 std::string sTemp = to_string(batteryTemp);
991 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
992 EXPECT_EQ(true, ret == ERR_OK);
993
994 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
995 THERMAL_HILOGD(LABEL_TEST, "SIMUL PATH has been in ");
996 return;
997 }
998
999 MockThermalMgrClient::GetInstance().GetThermalInfo();
1000
1001 char procsessBuf[MAX_PATH] = {0};
1002 char procsesValue[MAX_PATH] = {0};
1003 ret = snprintf_s(procsessBuf, MAX_PATH, sizeof(procsessBuf) - 1, PROCESS_PATH.c_str());
1004 EXPECT_EQ(true, ret >= EOK);
1005
1006 ret = ThermalMgrSystemTest::ReadFile(procsessBuf, procsesValue, sizeof(procsesValue));
1007 EXPECT_EQ(true, ret == ERR_OK);
1008
1009 std::string process = procsesValue;
1010 int32_t value = ThermalMgrSystemTest::ConvertInt(process);
1011 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
1012 EXPECT_EQ(true, value == 3) << "ThermalMgrSystemTest017 failed";
1013
1014 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest017: end.");
1015 }
1016
1017 /**
1018 * @tc.name: ThermalMgrSystemTest018
1019 * @tc.desc: test get process value by setting temp
1020 * @tc.type: FEATURE
1021 * @tc.cond: Set Battery temp, Lower Temp
1022 * @tc.result level 2 procss 1
1023 */
1024 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest018, Function|MediumTest|Level2)
1025 {
1026 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest018: start.");
1027 char batteryTempBuf[MAX_PATH] = {0};
1028 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
1029 EXPECT_EQ(true, ret >= EOK);
1030
1031 GetSensorClusterName("base_safe", "battery", 2);
1032 int32_t batteryTemp = g_temp + 1000;
1033 THERMAL_HILOGD(LABEL_TEST, "TEMP: %{public}d", batteryTemp);
1034 std::string sTemp = to_string(batteryTemp);
1035 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
1036 EXPECT_EQ(true, ret == ERR_OK);
1037 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
1038 THERMAL_HILOGD(LABEL_TEST, "SIMUL PATH has been in ");
1039 return;
1040 }
1041
1042 MockThermalMgrClient::GetInstance().GetThermalInfo();
1043
1044 char procsessBuf[MAX_PATH] = {0};
1045 char procsesValue[MAX_PATH] = {0};
1046 ret = snprintf_s(procsessBuf, MAX_PATH, sizeof(procsessBuf) - 1, PROCESS_PATH.c_str());
1047 EXPECT_EQ(true, ret >= EOK);
1048 ret = ThermalMgrSystemTest::ReadFile(procsessBuf, procsesValue, sizeof(procsesValue));
1049 EXPECT_EQ(true, ret == ERR_OK);
1050 std::string process = procsesValue;
1051 int32_t value = ThermalMgrSystemTest::ConvertInt(process);
1052 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
1053 EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest018 failed";
1054 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest018: end.");
1055 }
1056
1057 /**
1058 * @tc.name: ThermalMgrSystemTest019
1059 * @tc.desc: test get process value by setting temp
1060 * @tc.type: FEATURE
1061 * @tc.cond: Set Battery temp, Lower Temp
1062 * @tc.result level 3 procss 1
1063 */
1064 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest019, Function|MediumTest|Level2)
1065 {
1066 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest019: start.");
1067
1068 char batteryTempBuf[MAX_PATH] = {0};
1069 int32_t ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str());
1070 EXPECT_EQ(true, ret >= EOK);
1071 GetSensorClusterName("base_safe", "battery", 3);
1072 int32_t batteryTemp = g_temp + 1000;
1073 THERMAL_HILOGD(LABEL_TEST, "TEMP: %{public}d", batteryTemp);
1074 std::string sTemp = to_string(batteryTemp);
1075 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
1076 EXPECT_EQ(true, ret == ERR_OK);
1077
1078 if (access(VENDOR_CONFIG.c_str(), 0) != 0) {
1079 THERMAL_HILOGD(LABEL_TEST, "SIMUL PATH has been in ");
1080 return;
1081 }
1082
1083 MockThermalMgrClient::GetInstance().GetThermalInfo();
1084 char procsessBuf[MAX_PATH] = {0};
1085 char procsesValue[MAX_PATH] = {0};
1086 ret = snprintf_s(procsessBuf, MAX_PATH, sizeof(procsessBuf) - 1, PROCESS_PATH.c_str());
1087 EXPECT_EQ(true, ret >= EOK);
1088 ret = ThermalMgrSystemTest::ReadFile(procsessBuf, procsesValue, sizeof(procsesValue));
1089 EXPECT_EQ(true, ret == ERR_OK);
1090 std::string process = procsesValue;
1091 int32_t value = ThermalMgrSystemTest::ConvertInt(process);
1092 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
1093 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest019 failed";
1094 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest019: end.");
1095 }
1096 }
1097
1098