• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  * conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  * of conditions and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  * to endorse or promote products derived from this software without specific prior written
16  * permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #ifndef _IT_PROCESS_PLIMITS_H
31 #define _IT_PROCESS_PLIMITS_H
32 
33 #include <string>
34 #include <vector>
35 #include <iostream>
36 #include <sstream>
37 #include <regex>
38 #include <fcntl.h>
39 #include <iostream>
40 #include <cstring>
41 #include <fstream>
42 #include <regex>
43 #include <sstream>
44 #include <numeric>
45 #include "osTest.h"
46 
47 #define MEM_PAGE_SIZE 4096
48 #define MEM_SLEEP_TIME 5
49 #define MEM_RESERVED_PAGE 2
50 #define CHILD_FUNC_ARG           (0x2088)
51 #define STACK_SIZE               (1024 * 1024)
52 #define PROCESS_LIMIT_AMOUNT     (64)
53 #define TEST_BUFFER_SIZE         (512)
54 #define CPUP10S_INDEX            (11)
55 #define CPUP1S_INDEX             (12)
56 #define WAIT_CPUP_STABLE         (7)
57 #define WAIT_CPUP_STABLE_FOR_100 (17)
58 #define STATISTIC_TIMES          (11)
59 #define PERIOD_10_SEC_IN_US      (10 * 1000 * 1000)
60 #define QUOTA_2_SEC_IN_US        (2 * 1000 * 1000)
61 #define QUOTA_5_SEC_IN_US        (5 * 1000 * 1000)
62 #define QUOTA_6_SEC_IN_US        (6 * 1000 * 1000)
63 #define QUOTA_7_SEC_IN_US        (7 * 1000 * 1000)
64 #define QUOTA_10_SEC_IN_US       (10 * 1000 * 1000)
65 #define QUOTA_PERCENT_20         (20)
66 #define QUOTA_PERCENT_50         (50)
67 #define QUOTA_PERCENT_60         (60)
68 #define QUOTA_PERCENT_70         (70)
69 #define QUOTA_PERCENT_100        (100)
70 #define HARDWARE_CORE_AMOUNT     (2)
71 #define TOLERANCE_ERROR          (5)
72 
73 int WriteFile(const char *filepath, const char *buf);
74 int RmdirLimiterFile(std::string path);
75 int RmdirControlFile(std::string path);
76 int ReadFile(const char *filepath, char *buf);
77 int GetLine(char *buf, int count, int maxLen, char **array);
78 int RmdirTest (std::string path);
79 extern UINT32 LosCurTaskIDGet();
80 
81 int ForkChilds(int num, int *pidArray);
82 int CreatePlimitGroup(const char* groupName, char *childPidFiles,
83                       unsigned long long periodUs, unsigned long long quotaUs);
84 int AddPidIntoSchedLimiters(int num, int *pidArray, const char *procspath);
85 int WaitForCpupStable(int expectedCpupPercent);
86 double CalcCpupUsage(int childAmount, int *childPidArray, int expectedCpupPercent);
87 double CheckCpupUsage(double sumAllChildsCpup, int expectedCpupPercent);
88 int TerminateChildProcess(int *childPidArray, int childAmount, int sig);
89 double TestCpupInPlimit(int childAmount, const char* groupName,
90                         unsigned long long periodUs, unsigned long long quotaUs, int expectedCpupPercent);
91 double TestCpupWithoutLimit(int childAmount, const char* groupName, int expectedCpupPercent);
92 
93 #if defined(LOSCFG_USER_TEST_SMOKE)
94 void ItProcessPlimits001(void);
95 void ItProcessPlimits002(void);
96 void ItProcessPlimits003(void);
97 void ItProcessPlimits004(void);
98 void ItProcessPlimits005(void);
99 void ItProcessPlimits006(void);
100 void ItProcessPlimits007(void);
101 void ItProcessPlimits008(void);
102 void ItProcessPlimitsMemory001(void);
103 void ItProcessPlimitsMemory002(void);
104 void ItProcessPlimitsPid001(void);
105 void ItProcessPlimitsPid002(void);
106 void ItProcessPlimitsPid003(void);
107 void ItProcessPlimitsPid004(void);
108 void ItProcessPlimitsPid005(void);
109 void ItProcessPlimitsPid006(void);
110 void ItProcessPlimitsSched001(VOID);
111 void ItProcessPlimitsSched002(VOID);
112 void ItProcessPlimitsSched003(VOID);
113 void ItProcessPlimitsSched004(VOID);
114 void ItProcessPlimitsDevices001(void);
115 void ItProcessPlimitsDevices002(void);
116 void ItProcessPlimitsDevices003(void);
117 void ItProcessPlimitsDevices004(void);
118 void ItProcessPlimitsDevices005(void);
119 void ItProcessPlimitsDevices006(void);
120 void ItProcessPlimitsDevices007(void);
121 void ItProcessPlimitsDevices008(void);
122 void ItProcessPlimitsDevices009(void);
123 void ItProcessPlimitsIpc002(void);
124 void ItProcessPlimitsIpc003(void);
125 void ItProcessPlimitsIpc004(void);
126 void ItProcessPlimitsIpc005(void);
127 void ItProcessPlimitsIpc006(void);
128 void ItProcessPlimitsIpc007(void);
129 void ItProcessPlimitsIpc008(void);
130 void ItProcessPlimitsIpc009(void);
131 void ItProcessPlimitsIpc010(void);
132 void ItProcessPlimitsIpc011(void);
133 void ItProcessPlimitsIpc012(void);
134 void ItProcessPlimitsIpc013(void);
135 #endif
136 #endif /* _IT_PROCESS_PLIMITS_H */
137