1 /*
2 * Copyright (c) 2020 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 <cstdio>
20 #include <cstdlib>
21 #include <mutex>
22 #include <fcntl.h>
23 #include <unistd.h>
24 #include "securec.h"
25
26 #include "thermal_service.h"
27 #include "thermal_mgr_client.h"
28 #include "constants.h"
29 #include "thermal_common.h"
30 #include "thermal_log.h"
31
32 using namespace testing::ext;
33 using namespace OHOS::PowerMgr;
34 using namespace OHOS;
35 using namespace std;
36
37 namespace {
38 static sptr<ThermalService> service;
39 static std::mutex g_mtx;
40
41 using namespace OHOS::HiviewDFX;
42
43 static constexpr HiLogLabel LABEL = {LOG_CORE, 0, "ThermalMST"};
44
StartThermalProtector()45 static bool StartThermalProtector()
46 {
47 THERMAL_HILOGD(LABEL_TEST, "enter");
48 FILE *fp = nullptr;
49 fp = popen("/system/bin/thermal_protector&", "r");
50 if (fp == nullptr) {
51 HiLog::Error(LABEL, "popen function call failed.");
52 return false;
53 }
54
55 pclose(fp);
56
57 return true;
58 THERMAL_HILOGD(LABEL_TEST, "return");
59 }
60
StopThermalProtector()61 static bool StopThermalProtector()
62 {
63 THERMAL_HILOGD(LABEL_TEST, "enter");
64 FILE *fp = nullptr;
65 fp = popen("kill -9 $(pidof thermal_protector)", "r");
66 if (fp == nullptr) {
67 HiLog::Error(LABEL, " popen function call failed.");
68 return false;
69 }
70
71 pclose(fp);
72
73 return true;
74 THERMAL_HILOGD(LABEL_TEST, "return");
75 }
76
CheckThermalProtectorPID()77 static bool CheckThermalProtectorPID()
78 {
79 THERMAL_HILOGD(LABEL_TEST, "enter");
80 FILE *fp = nullptr;
81 fp = popen("pidof thermal_protector", "r");
82 if (fp == nullptr) {
83 HiLog::Error(LABEL, " popen function call failed.");
84 return false;
85 }
86 char pid[BUFFER_SIZE];
87 if (fgets(pid, sizeof(pid), fp) != nullptr) {
88 pclose(fp);
89 return true;
90 }
91
92 HiLog::Error(LABEL, "Getting Pid failed.");
93
94 pclose(fp);
95
96 return true;
97 THERMAL_HILOGD(LABEL_TEST, "return");
98 }
99 }
100
WriteFile(std::string path,std::string buf,size_t size)101 int32_t ThermalMgrSystemTest::WriteFile(std::string path, std::string buf, size_t size)
102 {
103 FILE *stream = fopen(path.c_str(), "w+");
104 if (stream == nullptr) {
105 return ERR_INVALID_VALUE;
106 }
107 size_t ret = fwrite(buf.c_str(), strlen(buf.c_str()), 1, stream);
108 if (ret == ERR_OK) {
109 THERMAL_HILOGE(COMP_SVC, "ret=%{public}zu", ret);
110 }
111 int32_t state = fseek(stream, 0, SEEK_SET);
112 if (state != ERR_OK) {
113 fclose(stream);
114 return state;
115 }
116 state = fclose(stream);
117 if (state != ERR_OK) {
118 return state;
119 }
120 return ERR_OK;
121 }
122
ReadFile(const char * path,char * buf,size_t size)123 int32_t ThermalMgrSystemTest::ReadFile(const char *path, char *buf, size_t size)
124 {
125 int32_t ret;
126
127 int32_t fd = open(path, O_RDONLY, S_IRUSR | S_IRGRP | S_IROTH);
128 if (fd < ERR_OK) {
129 THERMAL_HILOGD(LABEL_TEST, "WriteFile: failed to open file fd: %{public}d", fd);
130 return ERR_INVALID_VALUE;
131 }
132
133 ret = read(fd, buf, size);
134 if (ret < ERR_OK) {
135 THERMAL_HILOGD(LABEL_TEST, "WriteFile: failed to read file ret: %{public}d", ret);
136 close(fd);
137 return ERR_INVALID_VALUE;
138 }
139
140 close(fd);
141 buf[size - 1] = '\0';
142 return ERR_OK;
143 }
144
InitNode()145 int32_t ThermalMgrSystemTest::InitNode()
146 {
147 char bufTemp[MAX_PATH] = {0};
148 int32_t ret = -1;
149 std::map<std::string, int32_t> sensor;
150 sensor["battery"] = 0;
151 sensor["charger"] = 0;
152 sensor["pa"] = 0;
153 sensor["ap"] = 0;
154 sensor["ambient"] = 0;
155 sensor["cpu"] = 0;
156 sensor["soc"] = 0;
157 sensor["shell"] = 0;
158 for (auto iter : sensor) {
159 ret = snprintf_s(bufTemp, MAX_PATH, sizeof(bufTemp) - 1, SIMULATION_TEMP_DIR, iter.first.c_str());
160 if (ret < EOK) {
161 return ret;
162 }
163 std::string temp = std::to_string(iter.second) + "\n";
164 WriteFile(bufTemp, temp, temp.length());
165 }
166 return ERR_OK;
167 }
168
ConvertInt(const std::string & value)169 int32_t ThermalMgrSystemTest::ConvertInt(const std::string &value)
170 {
171 return std::stoi(value);
172 }
173
SetUpTestCase()174 void ThermalMgrSystemTest::SetUpTestCase()
175 {
176 }
177
TearDownTestCase()178 void ThermalMgrSystemTest::TearDownTestCase()
179 {
180 }
181
SetUp()182 void ThermalMgrSystemTest::SetUp()
183 {
184 InitNode();
185 }
186
TearDown()187 void ThermalMgrSystemTest::TearDown()
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 int32_t ret = -1;
203 char batteryTempBuf[MAX_PATH] = {0};
204 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
205 EXPECT_EQ(true, ret >= EOK);
206 int32_t batteryTemp = 40100;
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 sleep(SLEEP_INTERVAL_SEC);
212
213 char levelBuf[MAX_PATH] = {0};
214 char levelValue[MAX_PATH] = {0};
215 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
216 EXPECT_EQ(true, ret >= EOK);
217 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
218 EXPECT_EQ(true, ret == ERR_OK);
219 std::string level = levelValue;
220 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
221 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
222 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest001 failed";
223 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest001: end.");
224 }
225
226 /**
227 * @tc.name: ThermalMgrSystemTest002
228 * @tc.desc: test get current configured level by setting temp
229 * @tc.type: FEATURE
230 * @tc.cond: Set Battery temp, High Temp
231 * @tc.result level 2
232 */
233 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest002, Function|MediumTest|Level2)
234 {
235 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest002: start.");
236 int32_t ret = -1;
237 char batteryTempBuf[MAX_PATH] = {0};
238 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
239 EXPECT_EQ(true, ret >= EOK);
240 int32_t batteryTemp = 43100;
241 std::string sTemp = to_string(batteryTemp) + "\n";
242 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
243 EXPECT_EQ(true, ret == ERR_OK);
244
245 sleep(SLEEP_INTERVAL_SEC);
246
247 char levelBuf[MAX_PATH] = {0};
248 char levelValue[MAX_PATH] = {0};
249 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
250 EXPECT_EQ(true, ret >= EOK);
251 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
252 EXPECT_EQ(true, ret == ERR_OK);
253 std::string level = levelValue;
254 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
255 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
256 EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest002 failed";
257 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest002: end.");
258 }
259
260 /**
261 * @tc.name: ThermalMgrSystemTest003
262 * @tc.desc: test get current configured level by setting temp
263 * @tc.type: FEATURE
264 * @tc.cond: Set Battery temp, High Temp
265 * @tc.result level 3
266 */
267 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest003, Function|MediumTest|Level2)
268 {
269 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest003: start.");
270 int32_t ret = -1;
271 char batteryTempBuf[MAX_PATH] = {0};
272 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
273 EXPECT_EQ(true, ret >= EOK);
274 int32_t batteryTemp = 46100;
275 std::string sTemp = to_string(batteryTemp) + "\n";
276 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
277 EXPECT_EQ(true, ret == ERR_OK);
278
279 sleep(SLEEP_INTERVAL_SEC);
280
281 char levelBuf[MAX_PATH] = {0};
282 char levelValue[MAX_PATH] = {0};
283 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
284 EXPECT_EQ(true, ret >= EOK);
285 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
286 EXPECT_EQ(true, ret == ERR_OK);
287 std::string level = levelValue;
288 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
289 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
290 EXPECT_EQ(true, value == 3) << "ThermalMgrSystemTest003 failed";
291 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest003: end.");
292 }
293
294 /**
295 * @tc.name: ThermalMgrSystemTest004
296 * @tc.desc: test get current configured level by setting temp
297 * @tc.type: FEATURE
298 * @tc.cond: Set Battery temp, High Temp
299 * @tc.result level 4
300 */
301 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest004, Function|MediumTest|Level2)
302 {
303 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest003: start.");
304 int32_t ret = -1;
305 char batteryTempBuf[MAX_PATH] = {0};
306 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
307 EXPECT_EQ(true, ret >= EOK);
308 int32_t batteryTemp = 48100;
309 std::string sTemp = to_string(batteryTemp) + "\n";
310 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
311 EXPECT_EQ(true, ret == ERR_OK);
312
313 sleep(SLEEP_INTERVAL_SEC);
314
315 char levelBuf[MAX_PATH] = {0};
316 char levelValue[MAX_PATH] = {0};
317 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
318 EXPECT_EQ(true, ret >= EOK);
319 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
320 EXPECT_EQ(true, ret == ERR_OK);
321 std::string level = levelValue;
322 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
323 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest005 failed";
324 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest004: end.");
325 }
326
327 /**
328 * @tc.name: ThermalMgrSystemTest005
329 * @tc.desc: test level asc logic by setting temp
330 * @tc.type: FEATURE
331 * @tc.cond: Set Battery temp, High Temp
332 * @tc.result level 1 ==> level 4
333 */
334 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest005, Function|MediumTest|Level2)
335 {
336 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest005: start.");
337 int32_t ret = -1;
338 char batteryTempBuf[MAX_PATH] = {0};
339 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
340 EXPECT_EQ(true, ret >= EOK);
341 int32_t batteryTemp = 40100;
342 std::string sTemp = to_string(batteryTemp) + "\n";
343 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
344 EXPECT_EQ(true, ret == ERR_OK);
345
346 sleep(SLEEP_INTERVAL_SEC);
347
348 char levelBuf[MAX_PATH] = {0};
349 char levelValue[MAX_PATH] = {0};
350 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
351 EXPECT_EQ(true, ret >= EOK);
352 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
353 EXPECT_EQ(true, ret == ERR_OK);
354 std::string level = levelValue;
355 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
356 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest005 failed";
357
358 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
359 EXPECT_EQ(true, ret >= EOK);
360 batteryTemp = 48100;
361 sTemp = to_string(batteryTemp) + "\n";
362 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
363 EXPECT_EQ(true, ret == ERR_OK);
364 sleep(SLEEP_INTERVAL_SEC);
365
366 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
367 EXPECT_EQ(true, ret >= EOK);
368 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
369 EXPECT_EQ(true, ret == ERR_OK);
370 level = levelValue;
371 value = ThermalMgrSystemTest::ConvertInt(level);
372 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
373 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest005 failed";
374 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest005: end.");
375 }
376
377 /**
378 * @tc.name: ThermalMgrSystemTest006
379 * @tc.desc: test level asc logic by setting temp
380 * @tc.type: FEATURE
381 * @tc.cond: Set Battery temp, High Temp
382 * @tc.result level 2 ==> level 4
383 */
384 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest006, Function|MediumTest|Level2)
385 {
386 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest006: start.");
387 int32_t ret = -1;
388 char batteryTempBuf[MAX_PATH] = {0};
389 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
390 EXPECT_EQ(true, ret >= EOK);
391 int32_t batteryTemp = 43100;
392 std::string sTemp = to_string(batteryTemp) + "\n";
393 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
394 EXPECT_EQ(true, ret == ERR_OK);
395
396 sleep(SLEEP_INTERVAL_SEC);
397
398 char levelBuf[MAX_PATH] = {0};
399 char levelValue[MAX_PATH] = {0};
400 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
401 EXPECT_EQ(true, ret >= EOK);
402 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
403 EXPECT_EQ(true, ret == ERR_OK);
404 std::string level = levelValue;
405 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
406 EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest006 failed";
407
408 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
409 EXPECT_EQ(true, ret >= EOK);
410 batteryTemp = 48100;
411 sTemp = to_string(batteryTemp) + "\n";
412 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
413 EXPECT_EQ(true, ret == ERR_OK);
414 sleep(SLEEP_INTERVAL_SEC);
415
416 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
417 EXPECT_EQ(true, ret >= EOK);
418 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
419 EXPECT_EQ(true, ret == ERR_OK);
420 level = levelValue;
421 value = ThermalMgrSystemTest::ConvertInt(level);
422 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
423 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest006 failed";
424 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest006: end.");
425 }
426
427 /**
428 * @tc.name: ThermalMgrSystemTest007
429 * @tc.desc: test level desc logic by setting temp
430 * @tc.type: FEATURE
431 * @tc.cond: Set Battery temp, High Temp
432 * @tc.result level 4 ===> level 1
433 */
434 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest007, Function|MediumTest|Level2)
435 {
436 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest007: start.");
437 int32_t ret = -1;
438 char batteryTempBuf[MAX_PATH] = {0};
439 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
440 EXPECT_EQ(true, ret >= EOK);
441 int32_t batteryTemp = 48200;
442 std::string sTemp = to_string(batteryTemp) + "\n";
443 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
444 EXPECT_EQ(true, ret == ERR_OK);
445
446 sleep(SLEEP_INTERVAL_SEC);
447
448 char levelBuf[MAX_PATH] = {0};
449 char levelValue[MAX_PATH] = {0};
450 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
451 EXPECT_EQ(true, ret >= EOK);
452 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
453 EXPECT_EQ(true, ret == ERR_OK);
454 std::string level = levelValue;
455 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
456 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest007 failed";
457
458 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
459 EXPECT_EQ(true, ret >= EOK);
460 batteryTemp = 40900;
461 sTemp = to_string(batteryTemp) + "\n";
462 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
463 EXPECT_EQ(true, ret == ERR_OK);
464 sleep(SLEEP_INTERVAL_SEC);
465
466 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
467 EXPECT_EQ(true, ret >= EOK);
468 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
469 EXPECT_EQ(true, ret == ERR_OK);
470 level = levelValue;
471 value = ThermalMgrSystemTest::ConvertInt(level);
472 THERMAL_HILOGD(LABEL_TEST, "value is: %{public}d", value);
473 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest007 failed";
474 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest007: end.");
475 }
476
477 /**
478 * @tc.name: ThermalMgrSystemTest008
479 * @tc.desc: test level desc logic by setting temp
480 * @tc.type: FEATURE
481 * @tc.cond: Set Battery temp, High Temp
482 * @tc.result level 3 ===> level 0
483 */
484 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest008, Function|MediumTest|Level2)
485 {
486 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest008: start.");
487 int32_t ret = -1;
488 char batteryTempBuf[MAX_PATH] = {0};
489 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
490 EXPECT_EQ(true, ret >= EOK);
491 int32_t batteryTemp = 46100;
492 std::string sTemp = to_string(batteryTemp) + "\n";
493 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
494 EXPECT_EQ(true, ret == ERR_OK);
495
496 sleep(SLEEP_INTERVAL_SEC);
497
498 char levelBuf[MAX_PATH] = {0};
499 char levelValue[MAX_PATH] = {0};
500 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
501 EXPECT_EQ(true, ret >= EOK);
502 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
503 EXPECT_EQ(true, ret == ERR_OK);
504 std::string level = levelValue;
505 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
506 EXPECT_EQ(true, value == 3) << "ThermalMgrSystemTest008 failed";
507
508 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
509 EXPECT_EQ(true, ret >= EOK);
510 batteryTemp = 37000;
511 sTemp = to_string(batteryTemp) + "\n";
512 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
513 EXPECT_EQ(true, ret == ERR_OK);
514 sleep(SLEEP_INTERVAL_SEC);
515
516 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
517 EXPECT_EQ(true, ret >= EOK);
518 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
519 EXPECT_EQ(true, ret == ERR_OK);
520 level = levelValue;
521 value = ThermalMgrSystemTest::ConvertInt(level);
522 THERMAL_HILOGD(LABEL_TEST, "value is: %{public}d", value);
523 EXPECT_EQ(true, value == 0) << "ThermalMgrSystemTest008 failed";
524 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest008: end.");
525 }
526
527 /**
528 * @tc.name: ThermalMgrSystemTest009
529 * @tc.desc: test get current configured level by setting temp
530 * @tc.type: FEATURE
531 * @tc.cond: Set Battery temp, Lower Temp
532 * @tc.result level 1
533 */
534 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest009, Function|MediumTest|Level2)
535 {
536 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest009: start.");
537 int32_t ret = -1;
538 char batteryTempBuf[MAX_PATH] = {0};
539 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
540 EXPECT_EQ(true, ret >= EOK);
541 int32_t batteryTemp = -10000;
542 std::string sTemp = to_string(batteryTemp) + "\n";
543 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
544 EXPECT_EQ(true, ret == ERR_OK);
545
546 sleep(SLEEP_INTERVAL_SEC);
547
548 char levelBuf[MAX_PATH] = {0};
549 char levelValue[MAX_PATH] = {0};
550 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
551 EXPECT_EQ(true, ret >= EOK);
552 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
553 EXPECT_EQ(true, ret == ERR_OK);
554 std::string level = levelValue;
555 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
556 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest009 failed";
557 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest009: end.");
558 }
559
560 /**
561 * @tc.name: ThermalMgrSystemTest010
562 * @tc.desc: test get current configured level by setting temp
563 * @tc.type: FEATURE
564 * @tc.cond: Set Battery temp, Lower Temp
565 * @tc.result level 2
566 */
567 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest010, Function|MediumTest|Level2)
568 {
569 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest010: start.");
570 int32_t ret = -1;
571 char batteryTempBuf[MAX_PATH] = {0};
572 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
573 EXPECT_EQ(true, ret >= EOK);
574 int32_t batteryTemp = -15000;
575 std::string sTemp = to_string(batteryTemp) + "\n";
576 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
577 EXPECT_EQ(true, ret == ERR_OK);
578
579 sleep(SLEEP_INTERVAL_SEC);
580
581 char levelBuf[MAX_PATH] = {0};
582 char levelValue[MAX_PATH] = {0};
583 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
584 EXPECT_EQ(true, ret >= EOK);
585 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
586 EXPECT_EQ(true, ret == ERR_OK);
587 std::string level = levelValue;
588 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
589 EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest010 failed";
590 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest010: end.");
591 }
592
593 /**
594 * @tc.name: ThermalMgrSystemTest011
595 * @tc.desc: test get current configured level by setting temp
596 * @tc.type: FEATURE
597 * @tc.cond: Set Battery temp, Lower Temp
598 * @tc.result level 3
599 */
600 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest011, Function|MediumTest|Level2)
601 {
602 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest011: start.");
603 int32_t ret = -1;
604 char batteryTempBuf[MAX_PATH] = {0};
605 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
606 EXPECT_EQ(true, ret >= EOK);
607 int32_t batteryTemp = -20100;
608 std::string sTemp = to_string(batteryTemp) + "\n";
609 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
610 EXPECT_EQ(true, ret == ERR_OK);
611
612 sleep(SLEEP_INTERVAL_SEC);
613
614 char levelBuf[MAX_PATH] = {0};
615 char levelValue[MAX_PATH] = {0};
616 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
617 EXPECT_EQ(true, ret >= EOK);
618 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
619 EXPECT_EQ(true, ret == ERR_OK);
620 std::string level = levelValue;
621 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
622 EXPECT_EQ(true, value == 3) << "ThermalMgrSystemTest011 failed";
623 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest011: end.");
624 }
625
626 /**
627 * @tc.name: ThermalMgrSystemTest012
628 * @tc.desc: test get current configured level by setting temp
629 * @tc.type: FEATURE
630 * @tc.cond: Set Battery temp, Lower Temp
631 * @tc.result level 4
632 */
633 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest012, Function|MediumTest|Level2)
634 {
635 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest012: start.");
636 int32_t ret = -1;
637 char batteryTempBuf[MAX_PATH] = {0};
638 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
639 EXPECT_EQ(true, ret >= EOK);
640 int32_t batteryTemp = -22000;
641 std::string sTemp = to_string(batteryTemp) + "\n";
642 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
643 EXPECT_EQ(true, ret == ERR_OK);
644
645 sleep(SLEEP_INTERVAL_SEC);
646
647 char levelBuf[MAX_PATH] = {0};
648 char levelValue[MAX_PATH] = {0};
649 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
650 EXPECT_EQ(true, ret >= EOK);
651 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
652 EXPECT_EQ(true, ret == ERR_OK);
653 std::string level = levelValue;
654 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
655 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest012 failed";
656 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest012: end.");
657 }
658
659 /**
660 * @tc.name: ThermalMgrSystemTest013
661 * @tc.desc: test level asc logic by setting temp
662 * @tc.type: FEATURE
663 * @tc.cond: Set Battery temp, Lower Temp
664 * @tc.result level 1 ==> level 4
665 */
666 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest013, Function|MediumTest|Level2)
667 {
668 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest013: start.");
669 int32_t ret = -1;
670 char batteryTempBuf[MAX_PATH] = {0};
671 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
672 EXPECT_EQ(true, ret >= EOK);
673 int32_t batteryTemp = -10000;
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 sleep(SLEEP_INTERVAL_SEC);
679
680 char levelBuf[MAX_PATH] = {0};
681 char levelValue[MAX_PATH] = {0};
682 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
683 EXPECT_EQ(true, ret >= EOK);
684 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
685 EXPECT_EQ(true, ret == ERR_OK);
686 std::string level = levelValue;
687 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
688 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest013 failed";
689
690 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
691 EXPECT_EQ(true, ret >= EOK);
692 batteryTemp = -22000;
693 sTemp = to_string(batteryTemp) + "\n";
694 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
695 EXPECT_EQ(true, ret == ERR_OK);
696 sleep(SLEEP_INTERVAL_SEC);
697
698 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
699 EXPECT_EQ(true, ret >= EOK);
700 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
701 EXPECT_EQ(true, ret == ERR_OK);
702 level = levelValue;
703 value = ThermalMgrSystemTest::ConvertInt(level);
704 THERMAL_HILOGD(LABEL_TEST, "value is: %{public}d", value);
705 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest013 failed";
706 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest013: end.");
707 }
708
709 /**
710 * @tc.name: ThermalMgrSystemTest014
711 * @tc.desc: test level asc logic by setting temp
712 * @tc.type: FEATURE
713 * @tc.cond: Set Battery temp, High Temp
714 * @tc.result level 2 ==> level 4
715 */
716 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest014, Function|MediumTest|Level2)
717 {
718 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest014: start.");
719 int32_t ret = -1;
720 char batteryTempBuf[MAX_PATH] = {0};
721 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
722 EXPECT_EQ(true, ret >= EOK);
723 int32_t batteryTemp = -15000;
724 std::string sTemp = to_string(batteryTemp) + "\n";
725 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
726 EXPECT_EQ(true, ret == ERR_OK);
727
728 sleep(SLEEP_INTERVAL_SEC);
729
730 char levelBuf[MAX_PATH] = {0};
731 char levelValue[MAX_PATH] = {0};
732 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
733 EXPECT_EQ(true, ret >= EOK);
734 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
735 EXPECT_EQ(true, ret == ERR_OK);
736 std::string level = levelValue;
737 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
738 EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest014 failed";
739
740 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
741 EXPECT_EQ(true, ret >= EOK);
742 batteryTemp = -22000;
743 sTemp = to_string(batteryTemp) + "\n";
744 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
745 EXPECT_EQ(true, ret == ERR_OK);
746 sleep(SLEEP_INTERVAL_SEC);
747
748 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
749 EXPECT_EQ(true, ret >= EOK);
750 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
751 EXPECT_EQ(true, ret == ERR_OK);
752 level = levelValue;
753 value = ThermalMgrSystemTest::ConvertInt(level);
754 THERMAL_HILOGD(LABEL_TEST, "value is: %{public}d", value);
755 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest014 failed";
756 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest014: end.");
757 }
758
759 /**
760 * @tc.name: ThermalMgrSystemTest015
761 * @tc.desc: test level desc logic by setting temp
762 * @tc.type: FEATURE
763 * @tc.cond: Set Battery temp, High Temp
764 * @tc.result level 4 ===> level 1
765 */
766 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest015, Function|MediumTest|Level2)
767 {
768 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest015: start.");
769 int32_t ret = -1;
770 char batteryTempBuf[MAX_PATH] = {0};
771 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
772 EXPECT_EQ(true, ret >= EOK);
773 int32_t batteryTemp = -22000;
774 std::string sTemp = to_string(batteryTemp) + "\n";
775 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
776 EXPECT_EQ(true, ret == ERR_OK);
777
778 sleep(SLEEP_INTERVAL_SEC);
779
780 char levelBuf[MAX_PATH] = {0};
781 char levelValue[MAX_PATH] = {0};
782 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
783 EXPECT_EQ(true, ret >= EOK);
784 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
785 EXPECT_EQ(true, ret == ERR_OK);
786 std::string level = levelValue;
787 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
788 EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest015 failed";
789
790 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
791 EXPECT_EQ(true, ret >= EOK);
792 batteryTemp = -10000;
793 sTemp = to_string(batteryTemp) + "\n";
794 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
795 EXPECT_EQ(true, ret == ERR_OK);
796 sleep(SLEEP_INTERVAL_SEC);
797
798 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
799 EXPECT_EQ(true, ret >= EOK);
800 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
801 EXPECT_EQ(true, ret == ERR_OK);
802 level = levelValue;
803 value = ThermalMgrSystemTest::ConvertInt(level);
804 THERMAL_HILOGD(LABEL_TEST, "value is: %{public}d", value);
805 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest015 failed";
806 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest015: end.");
807 }
808
809 /**
810 * @tc.name: ThermalMgrSystemTest016
811 * @tc.desc: test level desc logic by setting temp
812 * @tc.type: FEATURE
813 * @tc.cond: Set Battery temp, High Temp
814 * @tc.result level 3 ===> level 0
815 */
816 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest016, Function|MediumTest|Level2)
817 {
818 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest016: start.");
819 int32_t ret = -1;
820 char batteryTempBuf[MAX_PATH] = {0};
821 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
822 EXPECT_EQ(true, ret >= EOK);
823 int32_t batteryTemp = -19100;
824 std::string sTemp = to_string(batteryTemp) + "\n";
825 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
826 EXPECT_EQ(true, ret == ERR_OK);
827
828 sleep(SLEEP_INTERVAL_SEC);
829
830 char levelBuf[MAX_PATH] = {0};
831 char levelValue[MAX_PATH] = {0};
832 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
833 EXPECT_EQ(true, ret >= EOK);
834 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
835 EXPECT_EQ(true, ret == ERR_OK);
836 std::string level = levelValue;
837 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
838 EXPECT_EQ(true, value == 3) << "ThermalMgrSystemTest016 failed";
839
840 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
841 EXPECT_EQ(true, ret >= EOK);
842 batteryTemp = -1000;
843 sTemp = to_string(batteryTemp) + "\n";
844 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
845 EXPECT_EQ(true, ret == ERR_OK);
846 sleep(SLEEP_INTERVAL_SEC);
847
848 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
849 EXPECT_EQ(true, ret >= EOK);
850 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
851 EXPECT_EQ(true, ret == ERR_OK);
852 level = levelValue;
853 value = ThermalMgrSystemTest::ConvertInt(level);
854 THERMAL_HILOGD(LABEL_TEST, "value is: %{public}d", value);
855 EXPECT_EQ(true, value == 0) << "ThermalMgrSystemTest016 failed";
856 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest016: end.");
857 }
858
859 /**
860 * @tc.name: ThermalMgrSystemTest017
861 * @tc.desc: test level asc logic by setting temp
862 * @tc.type: FEATURE
863 * @tc.cond: Set PA temp, High Temp With Aux sensor
864 * @tc.result level 1
865 */
866 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest017, Function|MediumTest|Level2)
867 {
868 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest017: start.");
869 int32_t ret = -1;
870 char paTempBuf[MAX_PATH] = {0};
871 char amTempBuf[MAX_PATH] = {0};
872 ret = snprintf_s(paTempBuf, MAX_PATH, sizeof(paTempBuf) - 1, paPath.c_str());
873 EXPECT_EQ(true, ret >= EOK);
874 ret = snprintf_s(amTempBuf, MAX_PATH, sizeof(amTempBuf) - 1, ambientPath.c_str());
875 EXPECT_EQ(true, ret >= EOK);
876
877 int32_t paTemp = 41000;
878 std::string sTemp = to_string(paTemp) + "\n";
879 ret = ThermalMgrSystemTest::WriteFile(paTempBuf, sTemp, sTemp.length());
880 EXPECT_EQ(true, ret == ERR_OK);
881
882 int32_t amTemp = 10000;
883 sTemp = to_string(amTemp) + "\n";
884 ret = ThermalMgrSystemTest::WriteFile(amTempBuf, sTemp, sTemp.length());
885 EXPECT_EQ(true, ret == ERR_OK);
886
887 sleep(SLEEP_INTERVAL_SEC);
888 char levelBuf[MAX_PATH] = {0};
889 char levelValue[MAX_PATH] = {0};
890 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
891 EXPECT_EQ(true, ret >= EOK);
892 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
893 EXPECT_EQ(true, ret == ERR_OK);
894 std::string level = levelValue;
895 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
896 THERMAL_HILOGD(LABEL_TEST, "value is: %{public}d", value);
897 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest017 failed";
898 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest017: end.");
899 }
900
901 /**
902 * @tc.name: ThermalMgrSystemTest018
903 * @tc.desc: test level asc logic by setting temp
904 * @tc.type: FEATURE
905 * @tc.cond: Set PA temp, High Temp With Aux sensor
906 * @tc.result level 1
907 */
908 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest018, Function|MediumTest|Level2)
909 {
910 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest018: start.");
911 int32_t ret = -1;
912 char paTempBuf[MAX_PATH] = {0};
913 char amTempBuf[MAX_PATH] = {0};
914 ret = snprintf_s(paTempBuf, MAX_PATH, sizeof(paTempBuf) - 1, paPath.c_str());
915 EXPECT_EQ(true, ret >= EOK);
916 ret = snprintf_s(amTempBuf, MAX_PATH, sizeof(amTempBuf) - 1, ambientPath.c_str());
917 EXPECT_EQ(true, ret >= EOK);
918
919 int32_t paTemp = 44000;
920 std::string sTemp = to_string(paTemp) + "\n";
921 ret = ThermalMgrSystemTest::WriteFile(paTempBuf, sTemp, sTemp.length());
922 EXPECT_EQ(true, ret == ERR_OK);
923
924 int32_t amTemp = 10000;
925 sTemp = to_string(amTemp) + "\n";
926 ret = ThermalMgrSystemTest::WriteFile(amTempBuf, sTemp, sTemp.length());
927 EXPECT_EQ(true, ret == ERR_OK);
928
929 sleep(SLEEP_INTERVAL_SEC);
930 char levelBuf[MAX_PATH] = {0};
931 char levelValue[MAX_PATH] = {0};
932 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
933 EXPECT_EQ(true, ret >= EOK);
934 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
935 EXPECT_EQ(true, ret == ERR_OK);
936 std::string level = levelValue;
937 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
938 THERMAL_HILOGD(LABEL_TEST, "value is: %{public}d", value);
939 EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest018 failed";
940 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest018: end.");
941 }
942
943 /**
944 * @tc.name: ThermalMgrSystemTest019
945 * @tc.desc: test level asc logic by setting temp
946 * @tc.type: FEATURE
947 * @tc.cond: Set PA temp, High Temp With Aux sensor
948 * @tc.result level 0
949 */
950 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest019, Function|MediumTest|Level2)
951 {
952 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest019: start.");
953 int32_t ret = -1;
954 char paTempBuf[MAX_PATH] = {0};
955 char amTempBuf[MAX_PATH] = {0};
956 ret = snprintf_s(paTempBuf, MAX_PATH, sizeof(paTempBuf) - 1, paPath.c_str());
957 EXPECT_EQ(true, ret >= EOK);
958 ret = snprintf_s(amTempBuf, MAX_PATH, sizeof(amTempBuf) - 1, ambientPath.c_str());
959 EXPECT_EQ(true, ret >= EOK);
960
961 int32_t paTemp = 44000;
962 std::string sTemp = to_string(paTemp) + "\n";
963 ret = ThermalMgrSystemTest::WriteFile(paTempBuf, sTemp, sTemp.length());
964 EXPECT_EQ(true, ret == ERR_OK);
965
966 int32_t amTemp = 1000;
967 sTemp = to_string(amTemp) + "\n";
968 ret = ThermalMgrSystemTest::WriteFile(amTempBuf, sTemp, sTemp.length());
969 EXPECT_EQ(true, ret == ERR_OK);
970
971 sleep(SLEEP_INTERVAL_SEC);
972 char levelBuf[MAX_PATH] = {0};
973 char levelValue[MAX_PATH] = {0};
974 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
975 EXPECT_EQ(true, ret >= EOK);
976 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
977 EXPECT_EQ(true, ret == ERR_OK);
978 std::string level = levelValue;
979 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
980 THERMAL_HILOGD(LABEL_TEST, "value is: %{public}d", value);
981 EXPECT_EQ(true, value == 0) << "ThermalMgrSystemTest019 failed";
982 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest019: end.");
983 }
984
985 /**
986 * @tc.name: ThermalMgrSystemTest020
987 * @tc.desc: test level asc logic by setting temp
988 * @tc.type: FEATURE
989 * @tc.cond: Set PA temp, High Temp With Aux sensor
990 * @tc.result level 1
991 */
992 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest020, Function|MediumTest|Level2)
993 {
994 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest020: start.");
995 int32_t ret = -1;
996 char apTempBuf[MAX_PATH] = {0};
997 char amTempBuf[MAX_PATH] = {0};
998 char shellTempBuf[MAX_PATH] = {0};
999 ret = snprintf_s(apTempBuf, MAX_PATH, sizeof(apTempBuf) - 1, apPath.c_str());
1000 EXPECT_EQ(true, ret >= EOK);
1001 ret = snprintf_s(amTempBuf, MAX_PATH, sizeof(amTempBuf) - 1, ambientPath.c_str());
1002 EXPECT_EQ(true, ret >= EOK);
1003 ret = snprintf_s(shellTempBuf, MAX_PATH, sizeof(shellTempBuf) - 1, shellPath.c_str());
1004 EXPECT_EQ(true, ret >= EOK);
1005
1006 int32_t apTemp = 78000;
1007 std::string sTemp = to_string(apTemp) + "\n";
1008 ret = ThermalMgrSystemTest::WriteFile(apTempBuf, sTemp, sTemp.length());
1009 EXPECT_EQ(true, ret == ERR_OK);
1010
1011 int32_t amTemp = 1000;
1012 sTemp = to_string(amTemp) + "\n";
1013 ret = ThermalMgrSystemTest::WriteFile(amTempBuf, sTemp, sTemp.length());
1014 EXPECT_EQ(true, ret == ERR_OK);
1015
1016 int32_t shellTemp = 2000;
1017 sTemp = to_string(shellTemp) + "\n";
1018 ret = ThermalMgrSystemTest::WriteFile(shellTempBuf, sTemp, sTemp.length());
1019 EXPECT_EQ(true, ret == ERR_OK);
1020
1021 sleep(SLEEP_INTERVAL_SEC);
1022 char levelBuf[MAX_PATH] = {0};
1023 char levelValue[MAX_PATH] = {0};
1024 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
1025 EXPECT_EQ(true, ret >= EOK);
1026 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
1027 EXPECT_EQ(true, ret == ERR_OK);
1028 std::string level = levelValue;
1029 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
1030 THERMAL_HILOGD(LABEL_TEST, "value is: %{public}d", value);
1031 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest020 failed";
1032 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest020: end.");
1033 }
1034
1035 /**
1036 * @tc.name: ThermalMgrSystemTest021
1037 * @tc.desc: test level asc logic by setting temp
1038 * @tc.type: FEATURE
1039 * @tc.cond: Set PA temp, High Temp With Aux sensor
1040 * @tc.result level 0
1041 */
1042 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest021, Function|MediumTest|Level2)
1043 {
1044 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest021: start.");
1045 int32_t ret = -1;
1046 char apTempBuf[MAX_PATH] = {0};
1047 char amTempBuf[MAX_PATH] = {0};
1048 char shellTempBuf[MAX_PATH] = {0};
1049 ret = snprintf_s(apTempBuf, MAX_PATH, sizeof(apTempBuf) - 1, apPath.c_str());
1050 EXPECT_EQ(true, ret >= EOK);
1051 ret = snprintf_s(amTempBuf, MAX_PATH, sizeof(amTempBuf) - 1, ambientPath.c_str());
1052 EXPECT_EQ(true, ret >= EOK);
1053 ret = snprintf_s(shellTempBuf, MAX_PATH, sizeof(shellTempBuf) - 1, shellPath.c_str());
1054 EXPECT_EQ(true, ret >= EOK);
1055
1056 int32_t apTemp = 78000;
1057 std::string sTemp = to_string(apTemp) + "\n";
1058 ret = ThermalMgrSystemTest::WriteFile(apTempBuf, sTemp, sTemp.length());
1059 EXPECT_EQ(true, ret == ERR_OK);
1060
1061 int32_t amTemp = 1000;
1062 sTemp = to_string(amTemp) + "\n";
1063 ret = ThermalMgrSystemTest::WriteFile(amTempBuf, sTemp, sTemp.length());
1064 EXPECT_EQ(true, ret == ERR_OK);
1065
1066 int32_t shellTemp = -100;
1067 sTemp = to_string(shellTemp) + "\n";
1068 ret = ThermalMgrSystemTest::WriteFile(shellTempBuf, sTemp, sTemp.length());
1069 EXPECT_EQ(true, ret == ERR_OK);
1070
1071 sleep(SLEEP_INTERVAL_SEC);
1072 char levelBuf[MAX_PATH] = {0};
1073 char levelValue[MAX_PATH] = {0};
1074 ret = snprintf_s(levelBuf, MAX_PATH, sizeof(levelBuf) - 1, configLevelPath.c_str());
1075 EXPECT_EQ(true, ret >= EOK);
1076 ret = ThermalMgrSystemTest::ReadFile(levelBuf, levelValue, sizeof(levelValue));
1077 EXPECT_EQ(true, ret == ERR_OK);
1078 std::string level = levelValue;
1079 int32_t value = ThermalMgrSystemTest::ConvertInt(level);
1080 THERMAL_HILOGD(LABEL_TEST, "value is: %{public}d", value);
1081 EXPECT_EQ(true, value == 0) << "ThermalMgrSystemTest021 failed";
1082 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest021: end.");
1083 }
1084
1085 /**
1086 * @tc.name: ThermalMgrSystemTest022
1087 * @tc.desc: test get cpu freq by setting temp
1088 * @tc.type: FEATURE
1089 * @tc.cond: Set BATTERY temp, state not satisfied
1090 * @tc.result level 1, freq 1992000
1091 */
1092 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest022, Function|MediumTest|Level2)
1093 {
1094 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest022: start.");
1095 int32_t ret = -1;
1096 char batteryTempBuf[MAX_PATH] = {0};
1097 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
1098 EXPECT_EQ(true, ret >= EOK);
1099 int32_t batteryTemp = 40100;
1100 std::string sTemp = to_string(batteryTemp) + "\n";
1101 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
1102 EXPECT_EQ(true, ret == ERR_OK);
1103
1104 sleep(SLEEP_INTERVAL_SEC);
1105
1106 char cpuBuf[MAX_PATH] = {0};
1107 char freqValue[MAX_PATH] = {0};
1108 ret = snprintf_s(cpuBuf, MAX_PATH, sizeof(cpuBuf) - 1, CPU_FREQ_PATH);
1109 EXPECT_EQ(true, ret >= EOK);
1110 ret = ThermalMgrSystemTest::ReadFile(cpuBuf, freqValue, sizeof(freqValue));
1111 EXPECT_EQ(true, ret == ERR_OK);
1112 std::string freq = freqValue;
1113 int32_t value = ThermalMgrSystemTest::ConvertInt(freq);
1114 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
1115 EXPECT_EQ(true, value == 1992000 || value == 1991500 || value == 1991200) << "ThermalMgrSystemTest022 failed";
1116 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest022: end.");
1117 }
1118
1119 /**
1120 * @tc.name: ThermalMgrSystemTest023
1121 * @tc.desc: test get cpu freq by setting temp
1122 * @tc.type: FEATURE
1123 * @tc.cond: Set BATTERY temp, state not satisfied
1124 * @tc.result level 2, freq 1992000
1125 */
1126
1127 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest023, Function|MediumTest|Level2)
1128 {
1129 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest023: start.");
1130 int32_t ret = -1;
1131 char batteryTempBuf[MAX_PATH] = {0};
1132 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
1133 EXPECT_EQ(true, ret >= EOK);
1134 int32_t batteryTemp = 43100;
1135 std::string sTemp = to_string(batteryTemp) + "\n";
1136 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
1137 EXPECT_EQ(true, ret == ERR_OK);
1138
1139 sleep(SLEEP_INTERVAL_SEC);
1140
1141 char cpuBuf[MAX_PATH] = {0};
1142 char freqValue[MAX_PATH] = {0};
1143 ret = snprintf_s(cpuBuf, MAX_PATH, sizeof(cpuBuf) - 1, CPU_FREQ_PATH);
1144 EXPECT_EQ(true, ret >= EOK);
1145 ret = ThermalMgrSystemTest::ReadFile(cpuBuf, freqValue, sizeof(freqValue));
1146 EXPECT_EQ(true, ret == ERR_OK);
1147 std::string freq = freqValue;
1148 int32_t value = ThermalMgrSystemTest::ConvertInt(freq);
1149 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
1150 EXPECT_EQ(true, value == 1991000 || value == 1990500 || value == 1990200) << "ThermalMgrSystemTest023 failed";
1151 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest023: end.");
1152 }
1153
1154 /**
1155 * @tc.name: ThermalMgrSystemTest024
1156 * @tc.desc: test get cpu freq by setting temp
1157 * @tc.type: FEATURE
1158 * @tc.cond: Set BATTERY temp, state not satisfied
1159 * @tc.result level 3, freq 1992000
1160 */
1161 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest024, Function|MediumTest|Level2)
1162 {
1163 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest024: start.");
1164 int32_t ret = -1;
1165 char batteryTempBuf[MAX_PATH] = {0};
1166 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
1167 EXPECT_EQ(true, ret >= EOK);
1168 int32_t batteryTemp = 46100;
1169 std::string sTemp = to_string(batteryTemp) + "\n";
1170 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
1171 EXPECT_EQ(true, ret == ERR_OK);
1172
1173 sleep(SLEEP_INTERVAL_SEC);
1174
1175 char cpuBuf[MAX_PATH] = {0};
1176 char freqValue[MAX_PATH] = {0};
1177 ret = snprintf_s(cpuBuf, MAX_PATH, sizeof(cpuBuf) - 1, CPU_FREQ_PATH);
1178 EXPECT_EQ(true, ret >= EOK);
1179 ret = ThermalMgrSystemTest::ReadFile(cpuBuf, freqValue, sizeof(freqValue));
1180 EXPECT_EQ(true, ret == ERR_OK);
1181 std::string freq = freqValue;
1182 int32_t value = ThermalMgrSystemTest::ConvertInt(freq);
1183 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
1184 EXPECT_EQ(true, value == 1990000 || value == 1989500 || value == 1989200) << "ThermalMgrSystemTest024 failed";
1185 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest024: end.");
1186 }
1187
1188 /**
1189 * @tc.name: ThermalMgrSystemTest025
1190 * @tc.desc: test get cpu freq by setting temp
1191 * @tc.type: FEATURE
1192 * @tc.cond: Set BATTERY temp, state not satisfied
1193 * @tc.result level 4, freq 1992000
1194 */
1195 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest025, Function|MediumTest|Level2)
1196 {
1197 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest025: start.");
1198 int32_t ret = -1;
1199 char batteryTempBuf[MAX_PATH] = {0};
1200 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
1201 EXPECT_EQ(true, ret >= EOK);
1202 int32_t batteryTemp = 48100;
1203 std::string sTemp = to_string(batteryTemp) + "\n";
1204 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
1205 EXPECT_EQ(true, ret == ERR_OK);
1206
1207 sleep(SLEEP_INTERVAL_SEC);
1208
1209 char cpuBuf[MAX_PATH] = {0};
1210 char freqValue[MAX_PATH] = {0};
1211 ret = snprintf_s(cpuBuf, MAX_PATH, sizeof(cpuBuf) - 1, CPU_FREQ_PATH);
1212 EXPECT_EQ(true, ret >= EOK);
1213 ret = ThermalMgrSystemTest::ReadFile(cpuBuf, freqValue, sizeof(freqValue));
1214 EXPECT_EQ(true, ret == ERR_OK);
1215 std::string freq = freqValue;
1216 int32_t value = ThermalMgrSystemTest::ConvertInt(freq);
1217 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
1218 EXPECT_EQ(true, value == 1990000 || value == 1989500 || value == 1989200) << "ThermalMgrSystemTest025 failed";
1219 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest025: end.");
1220 }
1221
1222 /**
1223 * @tc.name: ThermalMgrSystemTest050
1224 * @tc.desc: test get process value by setting temp
1225 * @tc.type: FEATURE
1226 * @tc.cond: Set Battery temp, Lower Temp
1227 * @tc.result level 1 procss 1
1228 */
1229 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest050, Function|MediumTest|Level2)
1230 {
1231 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest044: start.");
1232 int32_t ret = -1;
1233 char batteryTempBuf[MAX_PATH] = {0};
1234 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
1235 EXPECT_EQ(true, ret >= EOK);
1236 int32_t batteryTemp = 40100;
1237 std::string sTemp = to_string(batteryTemp);
1238 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
1239 EXPECT_EQ(true, ret == ERR_OK);
1240
1241 sleep(SLEEP_INTERVAL_SEC);
1242
1243 char procsessBuf[MAX_PATH] = {0};
1244 char procsesValue[MAX_PATH] = {0};
1245 ret = snprintf_s(procsessBuf, MAX_PATH, sizeof(procsessBuf) - 1, processPath.c_str());
1246 EXPECT_EQ(true, ret >= EOK);
1247 ret = ThermalMgrSystemTest::ReadFile(procsessBuf, procsesValue, sizeof(procsesValue));
1248 EXPECT_EQ(true, ret == ERR_OK);
1249 std::string process = procsesValue;
1250 int32_t value = ThermalMgrSystemTest::ConvertInt(process);
1251 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
1252 EXPECT_EQ(true, value == 3) << "ThermalMgrSystemTest050 failed";
1253 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest050: end.");
1254 }
1255
1256 /**
1257 * @tc.name: ThermalMgrSystemTest051
1258 * @tc.desc: test get process value by setting temp
1259 * @tc.type: FEATURE
1260 * @tc.cond: Set Battery temp, Lower Temp
1261 * @tc.result level 2 procss 1
1262 */
1263 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest051, Function|MediumTest|Level2)
1264 {
1265 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest051: start.");
1266 int32_t ret = -1;
1267 char batteryTempBuf[MAX_PATH] = {0};
1268 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
1269 EXPECT_EQ(true, ret >= EOK);
1270 int32_t batteryTemp = 43100;
1271 std::string sTemp = to_string(batteryTemp);
1272 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
1273 EXPECT_EQ(true, ret == ERR_OK);
1274
1275 sleep(SLEEP_INTERVAL_SEC);
1276
1277 char procsessBuf[MAX_PATH] = {0};
1278 char procsesValue[MAX_PATH] = {0};
1279 ret = snprintf_s(procsessBuf, MAX_PATH, sizeof(procsessBuf) - 1, processPath.c_str());
1280 EXPECT_EQ(true, ret >= EOK);
1281 ret = ThermalMgrSystemTest::ReadFile(procsessBuf, procsesValue, sizeof(procsesValue));
1282 EXPECT_EQ(true, ret == ERR_OK);
1283 std::string process = procsesValue;
1284 int32_t value = ThermalMgrSystemTest::ConvertInt(process);
1285 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
1286 EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest051 failed";
1287 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest051: end.");
1288 }
1289
1290 /**
1291 * @tc.name: ThermalMgrSystemTest052
1292 * @tc.desc: test get process value by setting temp
1293 * @tc.type: FEATURE
1294 * @tc.cond: Set Battery temp, Lower Temp
1295 * @tc.result level 3 procss 1
1296 */
1297 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest052, Function|MediumTest|Level2)
1298 {
1299 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest052: start.");
1300 int32_t ret = -1;
1301 char batteryTempBuf[MAX_PATH] = {0};
1302 ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, batteryPath.c_str());
1303 EXPECT_EQ(true, ret >= EOK);
1304 int32_t batteryTemp = 46100;
1305 std::string sTemp = to_string(batteryTemp);
1306 ret = ThermalMgrSystemTest::WriteFile(batteryTempBuf, sTemp, sTemp.length());
1307 EXPECT_EQ(true, ret == ERR_OK);
1308
1309 sleep(SLEEP_INTERVAL_SEC);
1310
1311 char procsessBuf[MAX_PATH] = {0};
1312 char procsesValue[MAX_PATH] = {0};
1313 ret = snprintf_s(procsessBuf, MAX_PATH, sizeof(procsessBuf) - 1, processPath.c_str());
1314 EXPECT_EQ(true, ret >= EOK);
1315 ret = ThermalMgrSystemTest::ReadFile(procsessBuf, procsesValue, sizeof(procsesValue));
1316 EXPECT_EQ(true, ret == ERR_OK);
1317 std::string process = procsesValue;
1318 int32_t value = ThermalMgrSystemTest::ConvertInt(process);
1319 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
1320 EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest052 failed";
1321 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest052: end.");
1322 }
1323
1324 /**
1325 * @tc.name: ThermalMgrSystemTest053
1326 * @tc.desc: test get process by setting temp
1327 * @tc.type: FEATURE
1328 * @tc.cond: Set PA temp, High Temp With Aux sensor
1329 * @tc.result level 1 process 2
1330 */
1331 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest053, Function|MediumTest|Level2)
1332 {
1333 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest053: start.");
1334 int32_t ret = -1;
1335 char paTempBuf[MAX_PATH] = {0};
1336 char amTempBuf[MAX_PATH] = {0};
1337 ret = snprintf_s(paTempBuf, MAX_PATH, sizeof(paTempBuf) - 1, paPath.c_str());
1338 EXPECT_EQ(true, ret >= EOK);
1339 ret = snprintf_s(amTempBuf, MAX_PATH, sizeof(amTempBuf) - 1, ambientPath.c_str());
1340 EXPECT_EQ(true, ret >= EOK);
1341
1342 int32_t paTemp = 41000;
1343 std::string sTemp = to_string(paTemp) + "\n";
1344 ret = ThermalMgrSystemTest::WriteFile(paTempBuf, sTemp, sTemp.length());
1345 EXPECT_EQ(true, ret == ERR_OK);
1346
1347 int32_t amTemp = 10000;
1348 sTemp = to_string(amTemp) + "\n";
1349 ret = ThermalMgrSystemTest::WriteFile(amTempBuf, sTemp, sTemp.length());
1350 EXPECT_EQ(true, ret == ERR_OK);
1351
1352 sleep(SLEEP_INTERVAL_SEC);
1353 char procsessBuf[MAX_PATH] = {0};
1354 char procsesValue[MAX_PATH] = {0};
1355 ret = snprintf_s(procsessBuf, MAX_PATH, sizeof(procsessBuf) - 1, processPath.c_str());
1356 EXPECT_EQ(true, ret >= EOK);
1357 ret = ThermalMgrSystemTest::ReadFile(procsessBuf, procsesValue, sizeof(procsesValue));
1358 EXPECT_EQ(true, ret == ERR_OK);
1359 std::string process = procsesValue;
1360 int32_t value = ThermalMgrSystemTest::ConvertInt(process);
1361 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
1362 EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest053 failed";
1363 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest053: end.");
1364 }
1365
1366 /**
1367 * @tc.name: ThermalMgrSystemTest054
1368 * @tc.desc: test get process by setting temp
1369 * @tc.type: FEATURE
1370 * @tc.cond: Set PA temp, High Temp With Aux sensor
1371 * @tc.result level 2 process 3
1372 */
1373 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest054, Function|MediumTest|Level2)
1374 {
1375 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest054: start.");
1376 int32_t ret = -1;
1377 char paTempBuf[MAX_PATH] = {0};
1378 char amTempBuf[MAX_PATH] = {0};
1379 ret = snprintf_s(paTempBuf, MAX_PATH, sizeof(paTempBuf) - 1, paPath.c_str());
1380 EXPECT_EQ(true, ret >= EOK);
1381 ret = snprintf_s(amTempBuf, MAX_PATH, sizeof(amTempBuf) - 1, ambientPath.c_str());
1382 EXPECT_EQ(true, ret >= EOK);
1383
1384 int32_t paTemp = 44000;
1385 std::string sTemp = to_string(paTemp) + "\n";
1386 ret = ThermalMgrSystemTest::WriteFile(paTempBuf, sTemp, sTemp.length());
1387 EXPECT_EQ(true, ret == ERR_OK);
1388
1389 int32_t amTemp = 10000;
1390 sTemp = to_string(amTemp) + "\n";
1391 ret = ThermalMgrSystemTest::WriteFile(amTempBuf, sTemp, sTemp.length());
1392 EXPECT_EQ(true, ret == ERR_OK);
1393
1394 sleep(SLEEP_INTERVAL_SEC);
1395 char procsessBuf[MAX_PATH] = {0};
1396 char procsesValue[MAX_PATH] = {0};
1397 ret = snprintf_s(procsessBuf, MAX_PATH, sizeof(procsessBuf) - 1, processPath.c_str());
1398 EXPECT_EQ(true, ret >= EOK);
1399 ret = ThermalMgrSystemTest::ReadFile(procsessBuf, procsesValue, sizeof(procsesValue));
1400 EXPECT_EQ(true, ret == ERR_OK);
1401 std::string process = procsesValue;
1402 int32_t value = ThermalMgrSystemTest::ConvertInt(process);
1403 THERMAL_HILOGD(LABEL_TEST, "value: %{public}d", value);
1404 EXPECT_EQ(true, value == 3) << "ThermalMgrSystemTest054 failed";
1405 THERMAL_HILOGD(LABEL_TEST, "ThermalMgrSystemTest054: end.");
1406 }
1407
1408 /*
1409 * Feature: Run thermal protect executable file.
1410 * Function: StartThermalProtector
1411 * CaseDescription:
1412 *
1413 */
1414 HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest055, TestSize.Level0)
1415 {
1416 HiLog::Info(LABEL, "ThermalModuleServiceTest006 start");
1417 if (!CheckThermalProtectorPID()) {
1418 EXPECT_EQ(true, StartThermalProtector());
1419 }
1420 sleep(SLEEP_INTERVAL_SEC);
1421 if (!CheckThermalProtectorPID()) {
1422 EXPECT_EQ(true, StopThermalProtector());
1423 }
1424 HiLog::Info(LABEL, "ThermalModuleServiceTest006 end");
1425 }
1426 }
1427