1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * SPDX-License-Identifier: GPL-2.0
4 *
5 * Unless required by applicable law or agreed to in writing, software
6 * distributed under the License is distributed on an "AS IS" BASIS,
7 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8 * See the License for the specific language governing permissions and
9 * limitations under the License.
10 */
11
12 #include "rtg_test.h"
13 #include <cstdio>
14 #include <cstdlib>
15 #include <fcntl.h>
16 #include <cerrno>
17 #include <unistd.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <sys/mman.h>
21 #include <sys/wait.h>
22 #include <sys/ioctl.h>
23 #include <ctime>
24 #include <climits>
25 #include <pthread.h>
26 #include <sys/syscall.h>
27 #include <securec.h>
28 #include <string>
29 #include <vector>
30
31 using namespace testing::ext;
32 using namespace std;
33
34 constexpr size_t MAX_LENGTH = 100;
35 constexpr size_t MAX_STR_LEN = 100;
36 const char RTG_SCHED_IPC_MAGIC = 0xAB;
37 const int RTG_ERR = -1;
38 const int RTG_SUCC = 0;
39 const int MAX_TID_NUM = 5;
40 const int MULTI_FRAME_NUM = 5;
41
42 #define CMD_ID_SET_ENABLE \
43 _IOWR(RTG_SCHED_IPC_MAGIC, SET_ENABLE, struct rtg_enable_data)
44 #define CMD_ID_SET_RTG \
45 _IOWR(RTG_SCHED_IPC_MAGIC, SET_RTG, struct rtg_str_data)
46 #define CMD_ID_BEGIN_FRAME_FREQ \
47 _IOWR(RTG_SCHED_IPC_MAGIC, BEGIN_FRAME_FREQ, struct proc_state_data)
48 #define CMD_ID_END_FRAME_FREQ \
49 _IOWR(RTG_SCHED_IPC_MAGIC, END_FRAME_FREQ, struct proc_state_data)
50 #define CMD_ID_END_SCENE \
51 _IOWR(RTG_SCHED_IPC_MAGIC, END_SCENE, struct proc_state_data)
52 #define CMD_ID_SET_MIN_UTIL \
53 _IOWR(RTG_SCHED_IPC_MAGIC, SET_MIN_UTIL, struct proc_state_data)
54 #define CMD_ID_SET_MARGIN \
55 _IOWR(RTG_SCHED_IPC_MAGIC, SET_MARGIN, struct proc_state_data)
56 #define CMD_ID_LIST_RTG_THREAD \
57 _IOWR(RTG_SCHED_IPC_MAGIC, LIST_RTG_THREAD, struct rtg_grp_data)
58 #define CMD_ID_LIST_RTG \
59 _IOWR(RTG_SCHED_IPC_MAGIC, LIST_RTG, struct rtg_info)
60 #define CMD_ID_SET_RTG_ATTR \
61 _IOWR(RTG_SCHED_IPC_MAGIC, SET_RTG_ATTR, struct rtg_str_data)
62 #define CMD_ID_SET_CONFIG \
63 _IOWR(RTG_SCHED_IPC_MAGIC, SET_CONFIG, struct rtg_str_data)
64
65 struct rtg_enable_data {
66 int enable;
67 int len;
68 char *data;
69 };
70
71 struct rtg_str_data {
72 int type;
73 int len;
74 char *data;
75 };
76
77 struct proc_state_data {
78 int grp_id;
79 int state_param;
80 };
81
82 enum grp_ctrl_cmd {
83 CMD_CREATE_RTG_GRP,
84 CMD_ADD_RTG_THREAD,
85 CMD_REMOVE_RTG_THREAD,
86 CMD_CLEAR_RTG_GRP,
87 CMD_DESTROY_RTG_GRP
88 };
89
90 struct rtg_grp_data {
91 int rtg_cmd;
92 int grp_id;
93 int prio_type;
94 int rt_cnt;
95 int tid_num;
96 int tids[MAX_TID_NUM];
97 };
98
99 struct rtg_info {
100 int rtg_num;
101 int rtgs[MULTI_FRAME_NUM];
102 };
103
104 enum rtg_sched_cmdid {
105 SET_ENABLE = 1,
106 SET_RTG,
107 SET_CONFIG,
108 SET_RTG_ATTR,
109 BEGIN_FRAME_FREQ = 5,
110 END_FRAME_FREQ,
111 END_SCENE,
112 SET_MIN_UTIL,
113 SET_MARGIN,
114 LIST_RTG = 10,
115 LIST_RTG_THREAD,
116 SEARCH_RTG,
117 GET_ENABLE,
118 RTG_CTRL_MAX_NR,
119 };
120
121 enum rtg_type : int {
122 VIP = 0,
123 TOP_TASK_KEY,
124 NORMAL_TASK,
125 RTG_TYPE_MAX,
126 };
127
BasicOpenRtgNode()128 static int BasicOpenRtgNode()
129 {
130 char fileName[] = "/proc/self/sched_rtg_ctrl";
131 int fd = open(fileName, O_RDWR);
132
133 if (fd < 0) {
134 cout << "open node err." << endl;
135 }
136
137 return fd;
138 }
139
EnableRtg(bool flag)140 static int EnableRtg(bool flag)
141 {
142 struct rtg_enable_data enableData;
143 char configStr[] = "load_freq_switch:1;sched_cycle:1";
144
145 enableData.enable = flag;
146 enableData.len = sizeof(configStr);
147 enableData.data = configStr;
148 int fd = BasicOpenRtgNode();
149 if (fd < 0) {
150 return RTG_ERR;
151 }
152 if (ioctl(fd, CMD_ID_SET_ENABLE, &enableData)) {
153 close(fd);
154 return RTG_ERR;
155 }
156
157 close(fd);
158 return 0;
159 }
160
CreateNewRtgGrp(int prioType,int rtNum)161 static int CreateNewRtgGrp(int prioType, int rtNum)
162 {
163 struct rtg_grp_data grp_data;
164 int ret;
165 int fd = BasicOpenRtgNode();
166 if (fd < 0) {
167 return RTG_ERR;
168 }
169 (void)memset_s(&grp_data, sizeof(struct rtg_grp_data), 0, sizeof(struct rtg_grp_data));
170 if ((prioType > 0) && (prioType < RTG_TYPE_MAX)) {
171 grp_data.prio_type = prioType;
172 }
173 if (rtNum > 0) {
174 grp_data.rt_cnt = rtNum;
175 }
176 grp_data.rtg_cmd = CMD_CREATE_RTG_GRP;
177 ret = ioctl(fd, CMD_ID_SET_RTG, &grp_data);
178
179 close(fd);
180 return ret;
181 }
182
DestroyRtgGrp(int GrpId)183 static int DestroyRtgGrp(int GrpId)
184 {
185 struct rtg_grp_data grp_data;
186 int ret;
187 int fd = BasicOpenRtgNode();
188 if (fd < 0) {
189 return fd;
190 }
191 (void)memset_s(&grp_data, sizeof(struct rtg_grp_data), 0, sizeof(struct rtg_grp_data));
192 grp_data.rtg_cmd = CMD_DESTROY_RTG_GRP;
193 grp_data.grp_id = GrpId;
194 ret = ioctl(fd, CMD_ID_SET_RTG, &grp_data);
195
196 close(fd);
197 return ret;
198 }
199
AddThreadToRtg(int tid,int grpId,int prioType)200 static int AddThreadToRtg(int tid, int grpId, int prioType)
201 {
202 struct rtg_grp_data grp_data;
203 int ret;
204 int fd = BasicOpenRtgNode();
205 if (fd < 0) {
206 return fd;
207 }
208 (void)memset_s(&grp_data, sizeof(struct rtg_grp_data), 0, sizeof(struct rtg_grp_data));
209 grp_data.tid_num = 1;
210 grp_data.tids[0] = tid;
211 grp_data.grp_id = grpId;
212 grp_data.rtg_cmd = CMD_ADD_RTG_THREAD;
213 grp_data.prio_type = prioType;
214 ret = ioctl(fd, CMD_ID_SET_RTG, &grp_data);
215
216 close(fd);
217 return ret;
218 }
219
ClearRtgGrp(int GrpId)220 static int ClearRtgGrp(int GrpId)
221 {
222 struct rtg_grp_data grp_data;
223 int ret;
224 int fd = BasicOpenRtgNode();
225 if (fd < 0) {
226 return fd;
227 }
228 (void)memset_s(&grp_data, sizeof(struct rtg_grp_data), 0, sizeof(struct rtg_grp_data));
229 grp_data.rtg_cmd = CMD_CLEAR_RTG_GRP;
230 grp_data.grp_id = GrpId;
231 ret = ioctl(fd, CMD_ID_SET_RTG, &grp_data);
232 if (ret < 0) {
233 return ret;
234 }
235
236 close(fd);
237 return ret;
238 };
239
BeginFrameFreq(int grpId,int stateParam)240 static int BeginFrameFreq(int grpId, int stateParam)
241 {
242 int ret = 0;
243 struct proc_state_data state_data;
244 state_data.grp_id = grpId;
245 state_data.state_param = stateParam;
246 int fd = BasicOpenRtgNode();
247 if (fd < 0) {
248 return fd;
249 }
250 ret = ioctl(fd, CMD_ID_BEGIN_FRAME_FREQ, &state_data);
251
252 close(fd);
253 return ret;
254 }
255
EndFrameFreq(int grpId)256 static int EndFrameFreq(int grpId)
257 {
258 int ret = 0;
259 struct proc_state_data state_data;
260 state_data.grp_id = grpId;
261 state_data.state_param = 0;
262 int fd = BasicOpenRtgNode();
263 if (fd < 0) {
264 return fd;
265 }
266 ret = ioctl(fd, CMD_ID_END_FRAME_FREQ, &state_data);
267
268 close(fd);
269 return ret;
270 }
271
EndScene(int grpId)272 static int EndScene(int grpId)
273 {
274 int ret = 0;
275 struct proc_state_data state_data;
276 state_data.grp_id = grpId;
277
278 int fd = BasicOpenRtgNode();
279 if (fd < 0) {
280 return fd;
281 }
282 ret = ioctl(fd, CMD_ID_END_SCENE, &state_data);
283
284 close(fd);
285 return ret;
286 }
287
SetStateParam(unsigned int cmd,int grpId,int stateParam)288 static int SetStateParam(unsigned int cmd, int grpId, int stateParam)
289 {
290 int ret = 0;
291 struct proc_state_data state_data;
292 state_data.grp_id = grpId;
293 state_data.state_param = stateParam;
294
295 int fd = BasicOpenRtgNode();
296 if (fd < 0) {
297 return fd;
298 }
299 ret = ioctl(fd, cmd, &state_data);
300
301 close(fd);
302 return ret;
303 }
304
305
ListRtgThread(int grpId,vector<int> * rs)306 static int ListRtgThread(int grpId, vector<int> *rs)
307 {
308 int ret = 0;
309 struct rtg_grp_data grp_data;
310 int fd = BasicOpenRtgNode();
311 if (fd < 0) {
312 return fd;
313 }
314 if (!rs) {
315 return RTG_ERR;
316 }
317 (void)memset_s(&grp_data, sizeof(struct rtg_grp_data), 0, sizeof(struct rtg_grp_data));
318 grp_data.grp_id = grpId;
319 ret = ioctl(fd, CMD_ID_LIST_RTG_THREAD, &grp_data);
320 if (ret < 0) {
321 return ret;
322 } else {
323 rs->clear();
324 for (int i = 0; i < grp_data.tid_num; i++) {
325 rs->push_back(grp_data.tids[i]);
326 }
327 }
328
329 close(fd);
330 return ret;
331 }
332
ListRtgGroup(vector<int> * rs)333 static int ListRtgGroup(vector<int> *rs)
334 {
335 int ret = 0;
336 struct rtg_info rtg_info;
337 int fd = BasicOpenRtgNode();
338 if (fd < 0) {
339 return fd;
340 }
341 if (!rs) {
342 return RTG_ERR;
343 }
344 (void)memset_s(&rtg_info, sizeof(struct rtg_info), 0, sizeof(struct rtg_info));
345 ret = ioctl(fd, CMD_ID_LIST_RTG, &rtg_info);
346 if (ret < 0) {
347 return ret;
348 } else {
349 rs->clear();
350 for (int i = 0; i < rtg_info.rtg_num; i++) {
351 rs->push_back(rtg_info.rtgs[i]);
352 }
353 }
354
355 close(fd);
356 return ret;
357 }
358
SetFrameRateAndPrioType(int rtgId,int rate,int rtgType)359 static int SetFrameRateAndPrioType(int rtgId, int rate, int rtgType)
360 {
361 int ret = 0;
362 char str_data[MAX_LENGTH] = {};
363 (void)sprintf_s(str_data, sizeof(str_data), "rtgId:%d;rate:%d;type:%d", rtgId, rate, rtgType);
364 struct rtg_str_data strData;
365 strData.len = strlen(str_data);
366 strData.data = str_data;
367
368 int fd = BasicOpenRtgNode();
369 if (fd < 0) {
370 return fd;
371 }
372 ret = ioctl(fd, CMD_ID_SET_RTG_ATTR, &strData);
373
374 close(fd);
375 return ret;
376 }
377
SetMaxVipRtgs(int rtframe)378 static int SetMaxVipRtgs(int rtframe)
379 {
380 int ret = 0;
381 char str_data[MAX_STR_LEN] = {};
382 (void)sprintf_s(str_data, sizeof(str_data), "rtframe:%d", rtframe);
383 struct rtg_str_data strData;
384 strData.len = strlen(str_data);
385 strData.data = str_data;
386
387 int fd = BasicOpenRtgNode();
388 if (fd < 0) {
389 return fd;
390 }
391 ret = ioctl(fd, CMD_ID_SET_CONFIG, &strData);
392
393 close(fd);
394 return ret;
395 }
396
AddThreadsToRtg(vector<int> tids,int grpId,int prioType)397 static int AddThreadsToRtg(vector<int> tids, int grpId, int prioType)
398 {
399 struct rtg_grp_data grp_data;
400 int ret;
401 int fd = BasicOpenRtgNode();
402
403 if (fd < 0) {
404 return fd;
405 }
406 (void)memset_s(&grp_data, sizeof(struct rtg_grp_data), 0, sizeof(struct rtg_grp_data));
407 int num = static_cast<int>(tids.size());
408 if (num > MAX_TID_NUM) {
409 return -1;
410 }
411 grp_data.tid_num = num;
412 grp_data.grp_id = grpId;
413 grp_data.rtg_cmd = CMD_ADD_RTG_THREAD;
414 grp_data.prio_type = prioType;
415 for (int i = 0; i < num; i++) {
416 if (tids[i] < 0) {
417 return -1;
418 }
419 grp_data.tids[i] = tids[i];
420 }
421 ret = ioctl(fd, CMD_ID_SET_RTG, &grp_data);
422
423 close(fd);
424 return ret;
425 }
426
SetUp()427 void RtgTest::SetUp() {
428 // must enable rtg before use the interface
429 int ret = EnableRtg(true);
430 ASSERT_EQ(RTG_SUCC, ret);
431 }
432
TearDown()433 void RtgTest::TearDown() {
434 // disable rtg after use the interface
435 int ret = EnableRtg(false);
436 ASSERT_EQ(RTG_SUCC, ret);
437 }
438
SetUpTestCase()439 void RtgTest::SetUpTestCase() {}
440
TearDownTestCase()441 void RtgTest::TearDownTestCase() {}
442
443 /**
444 * @tc.name: setEnableSucc
445 * @tc.desc: Verify the enable rtg function.
446 * @tc.type: FUNC
447 */
448 HWTEST_F(RtgTest, setEnableSucc, Function | MediumTest | Level1)
449 {
450 int ret;
451
452 // test set enable again
453 ret = EnableRtg(true);
454 ASSERT_EQ(RTG_SUCC, ret);
455
456 // test set disable again
457 ret = EnableRtg(false);
458 ASSERT_EQ(RTG_SUCC, ret);
459 }
460
461 /**
462 * @tc.name: createAndDestroyRtgSucc
463 * @tc.desc: Verify the create and destroy rtggrp function.
464 * @tc.type: FUNC
465 */
466 HWTEST_F(RtgTest, createAndDestroyRtgSucc, Function | MediumTest | Level1)
467 {
468 int ret;
469 int grpId;
470
471 grpId = CreateNewRtgGrp(NORMAL_TASK, 0);
472 ASSERT_GT(grpId, 0);
473 ret = DestroyRtgGrp(grpId);
474 ASSERT_EQ(ret, 0);
475 }
476
477 /**
478 * @tc.name: destoryErrorRtgGrp
479 * @tc.desc: Verify Destroy function with error param.
480 * @tc.type: FUNC
481 */
482 HWTEST_F(RtgTest, destoryErrorRtgGrp, Function | MediumTest | Level1)
483 {
484 int ret;
485 ret = DestroyRtgGrp(-1);
486 ASSERT_NE(RTG_SUCC, ret);
487 }
488
489 /**
490 * @tc.name: addRtgGrpSucc
491 * @tc.desc: Verify add rtg function.
492 * @tc.type: FUNC
493 */
494 HWTEST_F(RtgTest, addRtgGrpSucc, Function | MediumTest | Level1)
495 {
496 int ret;
497 int grpId;
498 int pid = getpid();
499
500 grpId = CreateNewRtgGrp(VIP, 0);
501 ASSERT_GT(grpId, 0);
502 ret = AddThreadToRtg(pid, grpId, VIP);
503 ASSERT_EQ(ret, 0);
504 ret = DestroyRtgGrp(grpId);
505 ASSERT_EQ(ret, 0);
506 }
507
508 /**
509 * @tc.name: addRtgGrpFail
510 * @tc.desc: Verify add rtg function with error param.
511 * @tc.type: FUNC
512 */
513 HWTEST_F(RtgTest, addRtgGrpFail, Function | MediumTest | Level1)
514 {
515 int ret;
516 int grpId;
517 int pid = getpid();
518
519 grpId = CreateNewRtgGrp(VIP, 0);
520 ASSERT_GT(grpId, 0);
521
522 // error tid
523 ret = AddThreadToRtg(-1, grpId, VIP);
524 ASSERT_NE(ret, 0);
525
526 // error grpid
527 ret=AddThreadToRtg(pid, -1, VIP);
528 ASSERT_NE(ret, RTG_SUCC);
529 ret = DestroyRtgGrp(grpId);
530 ASSERT_EQ(ret, 0);
531 }
532
533 /**
534 * @tc.name: clearRtgSucc
535 * @tc.desc: Verify clear rtg function.
536 * @tc.type: FUNC
537 */
538 HWTEST_F(RtgTest, clearRtgSucc, Function | MediumTest | Level1)
539 {
540 int ret;
541 int grpId;
542 int pid = getpid();
543
544 grpId = CreateNewRtgGrp(VIP, 0);
545 ASSERT_GT(grpId, 0);
546 ret = AddThreadToRtg(pid, grpId, VIP);
547 ASSERT_EQ(ret, RTG_SUCC);
548 ret = ClearRtgGrp(grpId);
549 ASSERT_EQ(ret, RTG_SUCC);
550 ret = DestroyRtgGrp(grpId);
551 ASSERT_EQ(ret, RTG_SUCC);
552 }
553
554 /**
555 * @tc.name: clearRtgFail
556 * @tc.desc: Verify clear rtg function with error param.
557 * @tc.type: FUNC
558 */
559 HWTEST_F(RtgTest, clearRtgFail, Function | MediumTest | Level1)
560 {
561 int ret;
562
563 ret = ClearRtgGrp(-1);
564 ASSERT_NE(ret, RTG_SUCC);
565 }
566
567 /**
568 * @tc.name: begainFrameFreqSucc
569 * @tc.desc: Verify rtg frame start function.
570 * @tc.type: FUNC
571 */
572 HWTEST_F(RtgTest, begainFrameFreqSucc, Function | MediumTest | Level1)
573 {
574 int ret;
575 int grpId;
576
577 grpId = CreateNewRtgGrp(VIP, 0);
578 ASSERT_GT(grpId, 0);
579 ret = BeginFrameFreq(grpId, 0);
580 ASSERT_EQ(ret, RTG_SUCC);
581 ret = DestroyRtgGrp(grpId);
582 ASSERT_EQ(ret, RTG_SUCC);
583 }
584
585 /**
586 * @tc.name: begainFrameFreqFail
587 * @tc.desc: Verify rtg frame start function with error param.
588 * @tc.type: FUNC
589 */
590 HWTEST_F(RtgTest, begainFrameFreqFail, Function | MediumTest | Level1)
591 {
592 int ret;
593 ret = BeginFrameFreq(-1, 0);
594 ASSERT_NE(ret, RTG_SUCC);
595 }
596
597 /**
598 * @tc.name: endFrameFreqSucc
599 * @tc.desc: Verify rtg frame end function.
600 * @tc.type: FUNC
601 */
602 HWTEST_F(RtgTest, endFrameFreqSucc, Function | MediumTest | Level1)
603 {
604 int ret;
605 int grpId;
606
607 grpId = CreateNewRtgGrp(VIP, 0);
608 ASSERT_GT(grpId, 0);
609 ret = EndFrameFreq(grpId);
610 ASSERT_EQ(ret, RTG_SUCC);
611 ret = DestroyRtgGrp(grpId);
612 ASSERT_EQ(ret, RTG_SUCC);
613 }
614
615 /**
616 * @tc.name: endFrameFreqFail
617 * @tc.desc: Verify rtg frame end function with error param.
618 * @tc.type: FUNC
619 */
620 HWTEST_F(RtgTest, endFrameFreqFail, Function | MediumTest | Level1)
621 {
622 int ret;
623 ret = EndFrameFreq(-1);
624 ASSERT_NE(ret, RTG_SUCC);
625 }
626
627 /**
628 * @tc.name: endSceneSucc
629 * @tc.desc: Verify scene end function.
630 * @tc.type: FUNC
631 */
632 HWTEST_F(RtgTest, endSceneSucc, Function | MediumTest | Level1)
633 {
634 int ret;
635 int grpId;
636
637 grpId = CreateNewRtgGrp(VIP, 0);
638 ASSERT_GT(grpId, 0);
639 ret = EndScene(grpId);
640 ASSERT_EQ(ret, RTG_SUCC);
641 ret = DestroyRtgGrp(grpId);
642 ASSERT_EQ(ret, RTG_SUCC);
643 }
644
645 /**
646 * @tc.name: endSceneFail
647 * @tc.desc: Verify scene end function.
648 * @tc.type: FUNC
649 */
650 HWTEST_F(RtgTest, endSceneFail, Function | MediumTest | Level1)
651 {
652 int ret;
653
654 ret = EndScene(-1);
655 ASSERT_NE(ret, RTG_SUCC);
656 }
657
658 /**
659 * @tc.name: setMinUtilSucc
660 * @tc.desc: Verify set min util function.
661 * @tc.type: FUNC
662 */
663 HWTEST_F(RtgTest, setMinUtilSucc, Function | MediumTest | Level1)
664 {
665 int ret;
666 int grpId;
667
668 grpId = CreateNewRtgGrp(VIP, 0);
669 ASSERT_GT(grpId, 0);
670 ret = SetStateParam(CMD_ID_SET_MIN_UTIL, grpId, 0);
671 ASSERT_EQ(ret, RTG_SUCC);
672 ret = DestroyRtgGrp(grpId);
673 ASSERT_EQ(ret, RTG_SUCC);
674 }
675
676 /**
677 * @tc.name: setMinUtilFail
678 * @tc.desc: Verify set min util function with Error Param.
679 * @tc.type: FUNC
680 */
681 HWTEST_F(RtgTest, setMinUtilFail, Function | MediumTest | Level1)
682 {
683 int ret;
684
685 ret = SetStateParam(CMD_ID_SET_MIN_UTIL, -1, 0);
686 ASSERT_NE(ret, RTG_SUCC);
687 }
688
689 /**
690 * @tc.name: setMarginSucc
691 * @tc.desc: Verify set min margin function.
692 * @tc.type: FUNC
693 */
694 HWTEST_F(RtgTest, setMarginSucc, Function | MediumTest | Level1)
695 {
696 int ret;
697 int grpId;
698
699 grpId = CreateNewRtgGrp(VIP, 0);
700 ASSERT_GT(grpId, 0);
701 ret = SetStateParam(CMD_ID_SET_MARGIN, grpId, 0);
702 ASSERT_EQ(ret, RTG_SUCC);
703 ret = DestroyRtgGrp(grpId);
704 ASSERT_EQ(ret, RTG_SUCC);
705 }
706
707 /**
708 * @tc.name: setMarginFail
709 * @tc.desc: Verify set min margin function with error param.
710 * @tc.type: FUNC
711 */
712 HWTEST_F(RtgTest, setMarginFail, Function | MediumTest | Level1)
713 {
714 int ret;
715
716 ret = SetStateParam(CMD_ID_SET_MARGIN, -1, 0);
717 ASSERT_NE(ret, RTG_SUCC);
718 }
719
720 /**
721 * @tc.name: listRtgThreadSucc
722 * @tc.desc: Verify list rtg thread function.
723 * @tc.type: FUNC
724 */
725 HWTEST_F(RtgTest, ListRtgThreadSucc, Function | MediumTest | Level1)
726 {
727 int ret;
728 int grpId;
729 vector<int> rs;
730
731 grpId = CreateNewRtgGrp(VIP, 0);
732 ASSERT_GT(grpId, 0);
733 ret = ListRtgThread(grpId, &rs);
734 ASSERT_EQ(ret, 0);
735 ret = DestroyRtgGrp(grpId);
736 ASSERT_EQ(ret, 0);
737 }
738
739 /**
740 * @tc.name: listRtgThreadFail
741 * @tc.desc: Verify list rtg thread function with null vector input.
742 * @tc.type: FUNC
743 */
744 HWTEST_F(RtgTest, ListRtgThreadFail, Function | MediumTest | Level1)
745 {
746 int ret;
747 int grpId;
748 vector<int> rs;
749
750 grpId = CreateNewRtgGrp(VIP, 0);
751 ASSERT_GT(grpId, 0);
752 ret = ListRtgThread(grpId, nullptr);
753 ASSERT_NE(ret, RTG_SUCC);
754 ret = ListRtgThread(-1, &rs);
755 ASSERT_NE(ret, RTG_SUCC);
756 ret = DestroyRtgGrp(grpId);
757 ASSERT_EQ(ret, RTG_SUCC);
758 }
759
760 /**
761 * @tc.name: listRtgSucc
762 * @tc.desc: Verify list rtg function.
763 * @tc.type: FUNC
764 */
765 HWTEST_F(RtgTest, ListRtgSucc, Function | MediumTest | Level1)
766 {
767 int ret;
768 vector<int> rs;
769
770 ret = ListRtgGroup(&rs);
771 ASSERT_EQ(ret, RTG_SUCC);
772 }
773
774 /**
775 * @tc.name: listRtgFail
776 * @tc.desc: Verify list rtg function with error param.
777 * @tc.type: FUNC
778 */
779 HWTEST_F(RtgTest, ListRtgFail, Function | MediumTest | Level1)
780 {
781 int ret;
782
783 ret = ListRtgGroup(nullptr);
784 ASSERT_NE(ret, RTG_SUCC);
785 }
786
787 /**
788 * @tc.name: SetRtgAttrSucc
789 * @tc.desc: Verify rtg attr set function.
790 * @tc.type: FUNC
791 */
792 HWTEST_F(RtgTest, SetRtgAttrSucc, Function | MediumTest | Level1)
793 {
794 int ret;
795 int grpId;
796
797 grpId = CreateNewRtgGrp(VIP, 0);
798 ASSERT_GT(grpId, 0);
799 ret = SetFrameRateAndPrioType(grpId, 60, VIP);
800 ASSERT_EQ(ret, RTG_SUCC);
801 ret = DestroyRtgGrp(grpId);
802 ASSERT_EQ(ret, RTG_SUCC);
803 }
804
805 /**
806 * @tc.name: SetRtgAttrFail
807 * @tc.desc: Verify rtg attr set function with error param.
808 * @tc.type: FUNC
809 */
810 HWTEST_F(RtgTest, SetRtgAttrFail, Function | MediumTest | Level1)
811 {
812 int ret;
813 int grpId;
814 grpId = CreateNewRtgGrp(VIP, 0);
815 ASSERT_GT(grpId, 0);
816 ret = SetFrameRateAndPrioType(grpId, 90, -1);
817 ASSERT_NE(ret, RTG_SUCC);
818 ret = DestroyRtgGrp(grpId);
819 ASSERT_EQ(ret, RTG_SUCC);
820 }
821
822 /**
823 * @tc.name: SetMaxVipRtgSucc
824 * @tc.desc: Verify rtg max vip num set function.
825 * @tc.type: FUNC
826 */
827 HWTEST_F(RtgTest, SetMaxVipRtgSucc, Function | MediumTest | Level1)
828 {
829 int ret;
830
831 ret = SetMaxVipRtgs(2);
832 ASSERT_EQ(ret, RTG_SUCC);
833 }
834
835 /**
836 * @tc.name: SetMaxVipRtgFail
837 * @tc.desc: Verify rtg max vip num set function with error param.
838 * @tc.type: FUNC
839 */
840 HWTEST_F(RtgTest, SetMaxVipRtgFail, Function | MediumTest | Level1)
841 {
842 int ret;
843
844 // set 0 vip num
845 ret = SetMaxVipRtgs(0);
846 ASSERT_NE(ret, RTG_SUCC);
847
848 // set large vip num
849 ret = SetMaxVipRtgs(50000);
850 ASSERT_NE(ret, RTG_SUCC);
851 }
852
853 /**
854 * @tc.name: RtgAddMutipleThreadsSucc
855 * @tc.desc: Verify rtg multiple add function.
856 * @tc.type: FUNC
857 */
858 HWTEST_F(RtgTest, RtgAddMutipleThreadsSucc, Function | MediumTest | Level1)
859 {
860 int ret;
861 int pid[3];
862 vector<int> threads;
863 int grpId;
864
865 for (int i = 0; i < 3; i++) {
866 pid[i] = fork();
867 ASSERT_TRUE(pid[i] >= 0) << "> parent: fork errno = " << errno;
868 if (pid[i] == 0) {
869 usleep(50000);
870 _Exit(0);
871 }
872 threads.push_back(pid[i]);
873 }
874 grpId = CreateNewRtgGrp(NORMAL_TASK, 0);
875 ASSERT_GT(grpId, 0);
876 ret = AddThreadsToRtg(threads, grpId, NORMAL_TASK);
877 ASSERT_EQ(ret, RTG_SUCC);
878 ret = DestroyRtgGrp(grpId);
879 ASSERT_EQ(ret, RTG_SUCC);
880 }
881
882 /**
883 * @tc.name: RtgAddMutipleThreadsOutOfLimit
884 * @tc.desc: Verify rtg multiple add function with out of limit threads.
885 * @tc.type: FUNC
886 */
887 HWTEST_F(RtgTest, RtgAddMutipleThreadsOutOfLimit, Function | MediumTest | Level1)
888 {
889 int ret;
890 int pid[8];
891 vector<int> threads;
892 int grpId;
893
894 for (int i = 0; i < 8; i++) {
895 pid[i] = fork();
896 ASSERT_TRUE(pid[i] >= 0) << "> parent: fork errno = " << errno;
897 if (pid[i] == 0) {
898 usleep(50000);
899 _Exit(0);
900 }
901 threads.push_back(pid[i]);
902 }
903 grpId = CreateNewRtgGrp(NORMAL_TASK, 0);
904 ASSERT_GT(grpId, 0);
905 ret = AddThreadsToRtg(threads, grpId, NORMAL_TASK);
906 ASSERT_NE(ret, RTG_SUCC);
907 ret = DestroyRtgGrp(grpId);
908 ASSERT_EQ(ret, RTG_SUCC);
909 }
910