1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cinttypes>
17 #include <sys/resource.h>
18 #include <sched.h>
19 #include <linux/sched.h>
20 #include "gtest/gtest.h"
21 #include "parameters.h"
22 #define private public
23 #include "concurrent_task_controller.h"
24 #include "rtg_interface.h"
25 #include "ipc_skeleton.h"
26 #include "concurrent_task_log.h"
27 #undef private
28
29 namespace OHOS {
30 namespace FFRT_TEST {
31 using namespace testing;
32 using namespace testing::ext;
33 using namespace OHOS::ConcurrentTask;
34 using namespace std;
35
36
37 class ConcurrentTaskControllerTest : public testing::Test {
38 public:
39 static void SetUpTestCase();
40 static void TearDownTestCase();
41 void SetUp();
42 void TearDown();
43 };
44
SetUpTestCase()45 void ConcurrentTaskControllerTest::SetUpTestCase()
46 {
47 }
48
TearDownTestCase()49 void ConcurrentTaskControllerTest::TearDownTestCase()
50 {
51 }
52
SetUp()53 void ConcurrentTaskControllerTest::SetUp()
54 {
55 }
56
TearDown()57 void ConcurrentTaskControllerTest::TearDown()
58 {
59 }
60
61 /**
62 * @tc.name: ReportDataTest
63 * @tc.desc: Test whether the ReportDataTest interface are normal.
64 * @tc.type: FUNC
65 */
66 HWTEST_F(ConcurrentTaskControllerTest, ReportDataTest, TestSize.Level1)
67 {
68 uint32_t resType = 0;
69 int64_t value = 0;
70 const Json::Value payload;
71 TaskController repData;
72 repData.ReportData(resType, value, payload);
73 }
74
75 /**
76 * @tc.name: PushTaskTest
77 * @tc.desc: Test whether the PushTask interface are normal.
78 * @tc.type: FUNC
79 */
80 HWTEST_F(ConcurrentTaskControllerTest, QueryIntervalTest, TestSize.Level1)
81 {
82 TaskController queInt;
83 int queryItem = QUERY_UI;
84 IntervalReply queryRs = {87, 657, 357, 214};
85 queInt.QueryInterval(queryItem, queryRs);
86 queryItem = QUERY_RENDER;
87 queInt.QueryInterval(queryItem, queryRs);
88 queryItem = QUERY_RENDER_SERVICE;
89 queInt.QueryInterval(queryItem, queryRs);
90 queryItem = QUERY_COMPOSER;
91 queInt.QueryInterval(queryItem, queryRs);
92 queryItem = QURRY_TYPE_MAX;
93 queInt.QueryInterval(queryItem, queryRs);
94 }
95
96 /**
97 * @tc.name: PushTaskTest
98 * @tc.desc: Test whether the PushTask interface are normal.
99 * @tc.type: FUNC
100 */
101 HWTEST_F(ConcurrentTaskControllerTest, InitTest, TestSize.Level1)
102 {
103 TaskController::GetInstance().Init();
104 }
105
106 /**
107 * @tc.name: PushTaskTest
108 * @tc.desc: Test whether the PushTask interface are normal.
109 * @tc.type: FUNC
110 */
111 HWTEST_F(ConcurrentTaskControllerTest, TypeMapInitTest, TestSize.Level1)
112 {
113 TaskController::GetInstance().TypeMapInit();
114 }
115
116 /**
117 * @tc.name: PushTaskTest
118 * @tc.desc: Test whether the PushTask interface are normal.
119 * @tc.type: FUNC
120 */
121 HWTEST_F(ConcurrentTaskControllerTest, TryCreateRsGroupTest, TestSize.Level1)
122 {
123 TaskController::GetInstance().rtgEnabled_ = false;
124 TaskController::GetInstance().TryCreateRsGroup();
125 TaskController::GetInstance().rtgEnabled_ = true;
126 TaskController::GetInstance().TryCreateRsGroup();
127 }
128
129 /**
130 * @tc.name: PushTaskTest
131 * @tc.desc: Test whether the PushTask interface are normal.
132 * @tc.type: FUNC
133 */
134 HWTEST_F(ConcurrentTaskControllerTest, TryCreateRSMainGrpTest, TestSize.Level1)
135 {
136 TaskController::GetInstance().rtgEnabled_ = false;
137 TaskController::GetInstance().TryCreateRSMainGrp();
138 TaskController::GetInstance().rtgEnabled_ = true;
139 TaskController::GetInstance().TryCreateRSMainGrp();
140 }
141
142 /**
143 * @tc.name: PushTaskTest
144 * @tc.desc: Test whether the PushTask interface are normal.
145 * @tc.type: FUNC
146 */
147 HWTEST_F(ConcurrentTaskControllerTest, TryCreateRSRenderGrpTest, TestSize.Level1)
148 {
149 TaskController::GetInstance().rtgEnabled_ = false;
150 TaskController::GetInstance().TryCreateRSRenderGrp();
151 TaskController::GetInstance().rtgEnabled_ = true;
152 TaskController::GetInstance().TryCreateRSRenderGrp();
153 }
154
155 /**
156 * @tc.name:QueryRenderServiceTest
157 * @tc.desc: Test whether the QueryRenderService interface is normal
158 * @tc.type: FUNC
159 */
160 HWTEST_F(ConcurrentTaskControllerTest, QueryRenderServiceTest, TestSize.Level1)
161 {
162 int uid = SYSTEM_UID;
163 IntervalReply queryRs = {87, 657, 357, 214};
164 TaskController::GetInstance().QueryRenderService(uid, queryRs);
165 int grpId = TaskController::GetInstance().renderServiceMainGrpId_;
166 EXPECT_TRUE(grpId > 0);
167 }
168
169 /**
170 * @tc.name: PushTaskTest
171 * @tc.desc: Test whether the PushTask interface are normal.
172 * @tc.type: FUNC
173 */
174 HWTEST_F(ConcurrentTaskControllerTest, QueryRenderServiceMainTest, TestSize.Level1)
175 {
176 int uid = SYSTEM_UID;
177 int pid = getpid();
178 IntervalReply queryRs = {87, 657, 357, 214};
179 TaskController::GetInstance().QueryRenderServiceMain(uid, pid, queryRs);
180 int flag = TaskController::GetInstance().renderServiceMainGrpId_;
181 TaskController::GetInstance().renderServiceMainGrpId_ = 1;
182 TaskController::GetInstance().QueryRenderServiceMain(uid, pid, queryRs);
183 TaskController::GetInstance().renderServiceMainGrpId_ = -1;
184 TaskController::GetInstance().QueryRenderServiceMain(uid, pid, queryRs);
185 TaskController::GetInstance().renderServiceMainGrpId_ = flag;
186 TaskController::GetInstance().QueryRenderServiceMain(uid, pid, queryRs);
187 }
188
189 /**
190 * @tc.name: PushTaskTest
191 * @tc.desc: Test whether the PushTask interface are normal.
192 * @tc.type: FUNC
193 */
194 HWTEST_F(ConcurrentTaskControllerTest, QueryRenderServiceRenderTest, TestSize.Level1)
195 {
196 int uid = SYSTEM_UID;
197 int pid = getpid();
198 IntervalReply queryRs = {87, 657, 357, 214};
199 TaskController::GetInstance().QueryRenderServiceRender(uid, pid, queryRs);
200 int flag = TaskController::GetInstance().renderServiceRenderGrpId_;
201 TaskController::GetInstance().renderServiceRenderGrpId_ = 1;
202 TaskController::GetInstance().QueryRenderServiceRender(uid, pid, queryRs);
203 TaskController::GetInstance().renderServiceRenderGrpId_ = -1;
204 TaskController::GetInstance().QueryRenderServiceRender(uid, pid, queryRs);
205 TaskController::GetInstance().renderServiceRenderGrpId_ = flag;
206 TaskController::GetInstance().QueryRenderServiceRender(uid, pid, queryRs);
207 }
208
209 /**
210 * @tc.name: PushTaskTest
211 * @tc.desc: Test whether the PushTask interface are normal.
212 * @tc.type: FUNC
213 */
214 HWTEST_F(ConcurrentTaskControllerTest, GetRequestTypeTest, TestSize.Level1)
215 {
216 std::string strRequstType = "test";
217 int ret = TaskController::GetInstance().GetRequestType(strRequstType);
218 EXPECT_EQ(ret, MSG_TYPE_MAX);
219 TaskController::GetInstance().msgType_["test"] = 8;
220 ret = TaskController::GetInstance().GetRequestType(strRequstType);
221 EXPECT_EQ(ret, 8);
222 TaskController::GetInstance().msgType_.erase("test");
223 ret = TaskController::GetInstance().GetRequestType(strRequstType);
224 EXPECT_EQ(ret, MSG_TYPE_MAX);
225 }
226
227 /**
228 * @tc.name: PushTaskTest
229 * @tc.desc: Test whether the PushTask interface are normal.
230 * @tc.type: FUNC
231 */
232 HWTEST_F(ConcurrentTaskControllerTest, NewForegroundTest, TestSize.Level1)
233 {
234 TaskController fore;
235 int uid = getuid();
236 int tid = gettid();
237 fore.NewForeground(uid, tid);
238 fore.NewBackground(uid, tid);
239 fore.NewAppStart(uid, tid, "", -1);
240 fore.NewForeground(uid, tid);
241 fore.NewBackground(uid, tid);
242 fore.ContinuousTaskProcess(uid, tid, static_cast<int>(MSG_CONTINUOUS_TASK_START));
243 fore.FocusStatusProcess(uid, tid, static_cast<int>(MSG_GET_FOCUS));
244 fore.FocusStatusProcess(uid, tid, static_cast<int>(MSG_LOSE_FOCUS));
245 fore.AppKilled(uid, tid);
246 tid = 574;
247 fore.foregroundApp_.push_back(ForegroundAppRecord(tid, 0));
248 fore.foregroundApp_.push_back(ForegroundAppRecord(1, 0));
249 fore.foregroundApp_.push_back(ForegroundAppRecord(3, 0));
250 auto iter = fore.foregroundApp_.begin();
251 EXPECT_EQ(iter->GetPid(), tid);
252 fore.NewForeground(uid, tid);
253 fore.NewBackground(uid, tid);
254 fore.NewAppStart(uid, tid, "", -1);
255 fore.NewForeground(uid, tid);
256 fore.NewBackground(uid, tid);
257 fore.ContinuousTaskProcess(uid, tid, static_cast<int>(MSG_CONTINUOUS_TASK_END));
258 fore.AppKilled(uid, tid);
259 }
260
261 /**
262 * @tc.name: PushTaskTest
263 * @tc.desc: Test whether the PushTask interface are normal.
264 * @tc.type: FUNC
265 */
266 HWTEST_F(ConcurrentTaskControllerTest, PrintInfoTest, TestSize.Level1)
267 {
268 TaskController print;
269 print.foregroundApp_.push_back(ForegroundAppRecord(1, 0));
270 print.foregroundApp_.push_back(ForegroundAppRecord(3, 0));
271 print.foregroundApp_.push_back(ForegroundAppRecord(5, 0));
272 auto iter = print.foregroundApp_.begin();
273 EXPECT_NE(iter, print.foregroundApp_.end());
274 print.PrintInfo();
275 }
276
277 /**
278 * @tc.name: PushTaskTest
279 * @tc.desc: Test whether the PushTask interface are normal.
280 * @tc.type: FUNC
281 */
282 HWTEST_F(ConcurrentTaskControllerTest, AddKeyThreadTest, TestSize.Level1)
283 {
284 int uid = 758;
285 int tid = 45;
286 int tid2 = 46;
287 int tid3 = 47;
288 int tid4 = 48;
289 int tid5 = 49;
290 int prio = PRIO_NORMAL;
291 ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(tid, 0);
292 foregroundapprecord.AddKeyThread(tid, prio);
293 foregroundapprecord.keyThreads_.insert(tid);
294 foregroundapprecord.AddKeyThread(tid, prio);
295 foregroundapprecord.grpId_ = -1;
296 foregroundapprecord.AddKeyThread(tid, prio);
297 foregroundapprecord.grpId_ = 1;
298 foregroundapprecord.AddKeyThread(tid, prio);
299 foregroundapprecord.keyThreads_.insert(tid2);
300 foregroundapprecord.keyThreads_.insert(tid3);
301 foregroundapprecord.keyThreads_.insert(tid4);
302 foregroundapprecord.keyThreads_.insert(tid5);
303 foregroundapprecord.keyThreads_.insert(tid5);
304 foregroundapprecord.AddKeyThread(tid, prio);
305 prio = RPIO_IN;
306 foregroundapprecord.keyThreads_.insert(tid);
307 prio = PRIO_RT;
308 foregroundapprecord.keyThreads_.insert(tid);
309 foregroundapprecord.AddKeyThread(tid, prio);
310 foregroundapprecord.keyThreads_.clear();
311 }
312
313 /**
314 * @tc.name: PushTaskTest
315 * @tc.desc: Test whether the PushTask interface are normal.
316 * @tc.type: FUNC
317 */
318 HWTEST_F(ConcurrentTaskControllerTest, BeginSceneTest, TestSize.Level1)
319 {
320 int pid = 758;
321 ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(pid, 0);
322 foregroundapprecord.BeginScene();
323 foregroundapprecord.EndScene();
324 foregroundapprecord.grpId_ = -1;
325 foregroundapprecord.BeginScene();
326 foregroundapprecord.EndScene();
327 foregroundapprecord.grpId_ = 1;
328 foregroundapprecord.BeginScene();
329 foregroundapprecord.EndScene();
330 }
331
332 /**
333 * @tc.name: PushTaskTest
334 * @tc.desc: Test whether the PushTask interface are normal.
335 * @tc.type: FUNC
336 */
337 HWTEST_F(ConcurrentTaskControllerTest, IsValidTest, TestSize.Level1)
338 {
339 int pid = 758;
340 ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(pid, 0);
341 EXPECT_EQ(foregroundapprecord.GetPid(), foregroundapprecord.pid_);
342 EXPECT_EQ(foregroundapprecord.GetGrpId(), foregroundapprecord.grpId_);
343 foregroundapprecord.pid_ = -1;
344 foregroundapprecord.grpId_ = 1;
345 EXPECT_EQ(foregroundapprecord.IsValid(), false);
346 foregroundapprecord.pid_ = -1;
347 foregroundapprecord.grpId_ = -1;
348 EXPECT_EQ(foregroundapprecord.IsValid(), false);
349 foregroundapprecord.pid_ = 1;
350 foregroundapprecord.grpId_ = -1;
351 EXPECT_EQ(foregroundapprecord.IsValid(), true);
352 foregroundapprecord.pid_ = 1;
353 foregroundapprecord.grpId_ = 1;
354 EXPECT_EQ(foregroundapprecord.IsValid(), true);
355 }
356
357 /**
358 * @tc.name: PushTaskTest
359 * @tc.desc: Test whether the PushTask interface are normal.
360 * @tc.type: FUNC
361 */
362 HWTEST_F(ConcurrentTaskControllerTest, PrintKeyThreadsTest, TestSize.Level1)
363 {
364 int pid = 758;
365 ForegroundAppRecord foregroundapprecord = ForegroundAppRecord(pid, 0);
366 foregroundapprecord.keyThreads_.insert(1);
367 foregroundapprecord.keyThreads_.insert(3);
368 foregroundapprecord.keyThreads_.insert(5);
369 foregroundapprecord.keyThreads_.insert(7);
370 foregroundapprecord.keyThreads_.insert(9);
371 auto iter = foregroundapprecord.keyThreads_.begin();
372 EXPECT_NE(iter, foregroundapprecord.keyThreads_.end());
373 foregroundapprecord.PrintKeyThreads();
374 }
375
376
377 /**
378 * @tc.name: QueryDeadlineTest
379 * @tc.desc: Test whether the QueryDeadlineTest interface are normal.
380 * @tc.type: FUNC
381 */
382 HWTEST_F(ConcurrentTaskControllerTest, QueryDeadlineTest, TestSize.Level1)
383 {
384 int queryItem = DDL_RATE;
385 DeadlineReply ddlReply = { false };
386 const Json::Value payload;
387 TaskController::GetInstance().QueryDeadline(queryItem, ddlReply, payload);
388 }
389
390 /**
391 * @tc.name: ModifySystemRateTest
392 * @tc.desc: Test whether the ModifySystemRate interface are normal.
393 * @tc.type: FUNC
394 */
395 HWTEST_F(ConcurrentTaskControllerTest, ModifySystemRateTest, TestSize.Level1)
396 {
397 Json::Value payload;
398 TaskController::GetInstance().ModifySystemRate(payload);
399 payload["1111"] = "60";
400 TaskController::GetInstance().ModifySystemRate(payload);
401 }
402
403 /**
404 * @tc.name: SetAppRate
405 * @tc.desc: Test whether the SetAppRate interface are normal.
406 * @tc.type: FUNC
407 */
408 HWTEST_F(ConcurrentTaskControllerTest, SetAppRateTest, TestSize.Level1)
409 {
410 Json::Value payload;
411 ForegroundAppRecord foreApp1 = ForegroundAppRecord(758, 758);
412 foreApp1.SetRate(60);
413 TaskController::GetInstance().foregroundApp_.push_back(foreApp1);
414 TaskController::GetInstance().foregroundApp_.begin()->grpId_ = 1;
415 payload["758"] = "120";
416 TaskController::GetInstance().SetAppRate(payload);
417 int curAppRate = TaskController::GetInstance().foregroundApp_.begin()->GetRate();
418 EXPECT_EQ(curAppRate, 120);
419 payload["-1"] = "120";
420 TaskController::GetInstance().SetAppRate(payload);
421 EXPECT_EQ(OHOS::system::GetIntParameter("persist.ffrt.interval.appRate", 0), 120);
422 }
423
424 /**
425 * @tc.name: FindRateFromInfo
426 * @tc.desc: Test whether the FindRateFromInfo interface are normal.
427 * @tc.type: FUNC
428 */
429 HWTEST_F(ConcurrentTaskControllerTest, FindRateFromInfoTest, TestSize.Level1)
430 {
431 Json::Value payload;
432 payload["758"] = "120";
433 payload["759"] = "120XXY";
434 int ret = TaskController::GetInstance().FindRateFromInfo(754, payload);
435 EXPECT_EQ(ret, 0);
436 ret = TaskController::GetInstance().FindRateFromInfo(758, payload);
437 EXPECT_EQ(ret, 120);
438 TaskController::GetInstance().FindRateFromInfo(759, payload);
439 }
440
441 /**
442 * @tc.name: SetRenderServiceRate
443 * @tc.desc: Test whether the SetRenderServiceRate interface are normal.
444 * @tc.type: FUNC
445 */
446 HWTEST_F(ConcurrentTaskControllerTest, SetRenderServiceRateTest, TestSize.Level1)
447 {
448 Json::Value payload;
449 payload["758"] = "120";
450 TaskController::GetInstance().renderServiceMainTid_ = 758;
451 TaskController::GetInstance().systemRate_ = 0;
452 TaskController::GetInstance().renderServiceMainGrpId_ = 1;
453 TaskController::GetInstance().SetRenderServiceRate(payload);
454 EXPECT_EQ(TaskController::GetInstance().systemRate_, 120);
455 EXPECT_EQ(OHOS::system::GetIntParameter("persist.ffrt.interval.rsRate", 0), 120);
456 }
457
458 /**
459 * @tc.name: SetFrameRate
460 * @tc.desc: Test whether the SetFrameRate interface are normal.
461 * @tc.type: FUNC
462 */
463 HWTEST_F(ConcurrentTaskControllerTest, SetFrameRateTest, TestSize.Level1)
464 {
465 TaskController::GetInstance().SetFrameRate(758, 120);
466 TaskController::GetInstance().SetFrameRate(0, 120);
467 }
468
469 /**
470 * @tc.name: GetPid
471 * @tc.desc: Test whether the GetPid interface are normal.
472 * @tc.type: FUNC
473 */
474 HWTEST_F(ConcurrentTaskControllerTest, GetPidTest, TestSize.Level1)
475 {
476 ForegroundAppRecord foreApp = ForegroundAppRecord(758, 0);
477 EXPECT_EQ(foreApp.GetPid(), 758);
478 }
479
480 /**
481 * @tc.name: GetUiTid
482 * @tc.desc: Test whether the GetUiTid interface are normal.
483 * @tc.type: FUNC
484 */
485 HWTEST_F(ConcurrentTaskControllerTest, GetUiTidTest, TestSize.Level1)
486 {
487 ForegroundAppRecord foreApp = ForegroundAppRecord(758, 758);
488 EXPECT_EQ(foreApp.GetUiTid(), 758);
489 }
490
491 /**
492 * @tc.name: SetRate
493 * @tc.desc: Test whether the SetRate interface are normal.
494 * @tc.type: FUNC
495 */
496 HWTEST_F(ConcurrentTaskControllerTest, SetRateTest, TestSize.Level1)
497 {
498 ForegroundAppRecord foreApp = ForegroundAppRecord(758, 758);
499 foreApp.SetRate(120);
500 EXPECT_EQ(foreApp.GetRate(), 120);
501 }
502
503 /**
504 * @tc.name: SetUiTid
505 * @tc.desc: Test whether the SetUiTid interface are normal.
506 * @tc.type: FUNC
507 */
508 HWTEST_F(ConcurrentTaskControllerTest, SetUiTidTest, TestSize.Level1)
509 {
510 ForegroundAppRecord foreApp = ForegroundAppRecord(758, 758);
511 EXPECT_EQ(foreApp.GetUiTid(), 758);
512 foreApp.SetUiTid(755);
513 EXPECT_EQ(foreApp.GetUiTid(), 755);
514 }
515
516 /**
517 * @tc.name: SetGrpId
518 * @tc.desc: Test whether the SetGrpId interface are normal.
519 * @tc.type: FUNC
520 */
521 HWTEST_F(ConcurrentTaskControllerTest, SetGrpId, TestSize.Level1)
522 {
523 ForegroundAppRecord foreApp = ForegroundAppRecord(758, 758);
524 foreApp.SetGrpId(-1);
525 EXPECT_EQ(foreApp.GetGrpId(), -1);
526 }
527
528 /**
529 * @tc.name: GetGameScene
530 * @tc.desc: Test whether the GetGameScene interface are normal.
531 * @tc.type: FUNC
532 */
533 HWTEST_F(ConcurrentTaskControllerTest, GetGameScene, TestSize.Level1)
534 {
535 std::string testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\","
536 "\"gameScene\":\"1\",\"renderThread\":\"5579\"}";
537 GameStatus status = TaskController::GetInstance().GetGameScene(testMsg);
538 EXPECT_EQ(status, GAME_ENTRY_MSG);
539 testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\",\"gameScene\":\"0\"}";
540 status = TaskController::GetInstance().GetGameScene(testMsg);
541 EXPECT_EQ(status, GAME_EXIT_MSG);
542 testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\",\"gameScene\":\"2\"}";
543 status = TaskController::GetInstance().GetGameScene(testMsg);
544 EXPECT_EQ(status, STATUS_MSG_MAX);
545 testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\",\"cameraScene\":\"1\"}";
546 status = TaskController::GetInstance().GetGameScene(testMsg);
547 EXPECT_EQ(status, CAMERA_ENTRY_MSG);
548 testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\",\"cameraScene\":\"0\"}";
549 status = TaskController::GetInstance().GetGameScene(testMsg);
550 EXPECT_EQ(status, CAMERA_EXIT_MSG);
551 }
552
553 /**
554 * @tc.name: GetGamePid
555 * @tc.desc: Test whether the GetGamePid interface are normal.
556 * @tc.type: FUNC
557 */
558 HWTEST_F(ConcurrentTaskControllerTest, GetGamePid, TestSize.Level1)
559 {
560 std::string testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\","
561 "\"gameScene\":\"1\",\"renderThread\":\"5579\"}";
562 int gamePid = TaskController::GetInstance().GetGamePid(testMsg);
563 EXPECT_EQ(gamePid, 5578);
564 testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\",\"gameScene\":\"0\"}";
565 gamePid = TaskController::GetInstance().GetGamePid(testMsg);
566 EXPECT_EQ(gamePid, -1);
567 testMsg = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\",\"gameScene\":\"2\"}";
568 gamePid = TaskController::GetInstance().GetGamePid(testMsg);
569 EXPECT_EQ(gamePid, -1);
570 }
571
572 /**
573 * @tc.name: NewForegroundAppRecord
574 * @tc.desc: Test whether the NewForegroundAppRecord interface are normal.
575 * @tc.type: FUNC
576 */
577 HWTEST_F(ConcurrentTaskControllerTest, NewForegroundAppRecord, TestSize.Level1)
578 {
579 TaskController::GetInstance().curGamePid_ = 756;
580 TaskController::GetInstance().NewForegroundAppRecord(756, 756, true);
581 TaskController::GetInstance().NewForegroundAppRecord(757, 757, true);
582 TaskController::GetInstance().NewForegroundAppRecord(757, 757, false);
583 }
584
585 /**
586 * @tc.name: ModifyGameState
587 * @tc.desc: Test whether the ModifyGameState interface are normal.
588 * @tc.type: FUNC
589 */
590 HWTEST_F(ConcurrentTaskControllerTest, ModifyGameState, TestSize.Level1)
591 {
592 Json::Value payload;
593 payload["gameMsg"] = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\","
594 "\"gameScene\":\"1\",\"renderThread\":\"5579\"}";
595 TaskController::GetInstance().ModifyGameState(payload);
596 EXPECT_EQ(TaskController::GetInstance().curGamePid_, 5578);
597 payload["gameMsg"] = "{\"gamePid\":\"5578\",\"packageName\":\"com.happyelements.OhosAnimal\","
598 "\"gameScene\":\"0\"}";
599 TaskController::GetInstance().ModifyGameState(payload);
600 EXPECT_EQ(TaskController::GetInstance().curGamePid_, -1);
601 }
602 }
603 }
604