• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gtest/gtest.h"
17 
18 #include "../include/qos_interface.h"
19 
20 namespace OHOS {
21 namespace FFRT_TEST {
22 using namespace testing;
23 using namespace testing::ext;
24 using namespace OHOS::FFRT_TEST;
25 using namespace std;
26 
27 
28 class QosInterfaceTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp();
33     void TearDown();
34 };
35 
SetUpTestCase()36 void QosInterfaceTest::SetUpTestCase()
37 {
38 }
39 
TearDownTestCase()40 void QosInterfaceTest::TearDownTestCase()
41 {
42 }
43 
SetUp()44 void QosInterfaceTest::SetUp()
45 {
46 }
47 
TearDown()48 void QosInterfaceTest::TearDown()
49 {
50 }
51 
52 extern "C" {
53 /**
54  * @tc.name: EnableRtgTest
55  * @tc.desc: Test whether the OnRemoteRequest interface are normal.
56  * @tc.type: FUNC
57  */
58 HWTEST_F(QosInterfaceTest, EnableRtgTest, TestSize.Level1)
59 {
60     bool flag = true;
61     int ret = EnableRtg(flag);
62     EXPECT_EQ(ret, 0);
63 }
64 
65 /**
66  * @tc.name: AuthEnableTest
67  * @tc.desc: Test whether the OnRemoteRequest interface are normal.
68  * @tc.type: FUNC
69  */
70 HWTEST_F(QosInterfaceTest, AuthEnableTest, TestSize.Level1)
71 {
72     unsigned int uid = 1;
73     unsigned int uaFlag = 1;
74     unsigned int status = 1;
75     int ret = AuthEnable(uid, uaFlag, status);
76     EXPECT_EQ(ret, 0);
77 }
78 
79 /**
80  * @tc.name: AuthSwitchTest
81  * @tc.desc: Test whether the AuthSwitch interface are normal.
82  * @tc.type: FUNC
83  */
84 HWTEST_F(QosInterfaceTest, AuthSwitchTest, TestSize.Level1)
85 {
86     unsigned int uid = 1;
87     unsigned int rtgFlag = 1;
88     unsigned int qosFlag = 1;
89     unsigned int status = 1;
90     int ret = AuthSwitch(uid, rtgFlag, qosFlag, status);
91     EXPECT_EQ(ret, 0);
92 }
93 
94 /**
95  * @tc.name: AuthDeleteTest
96  * @tc.desc: Test whether the AuthDelete interface are normal.
97  * @tc.type: FUNC
98  */
99 HWTEST_F(QosInterfaceTest, AuthDeleteTest, TestSize.Level1)
100 {
101     unsigned int uid = 1;
102     int ret = AuthDelete(uid);
103     EXPECT_EQ(ret, 0);
104 }
105 
106 /**
107  * @tc.name: AuthPauseTest
108  * @tc.desc: Test whether the AuthPause interface are normal.
109  * @tc.type: FUNC
110  */
111 HWTEST_F(QosInterfaceTest, AuthPauseTest, TestSize.Level1)
112 {
113     unsigned int uid = 1;
114     int ret = -1;
115     ret = AuthPause(uid);
116     EXPECT_EQ(ret, -1);
117 }
118 
119 /**
120  * @tc.name: QosApplyTest
121  * @tc.desc: Test whether the QosApply interface are normal.
122  * @tc.type: FUNC
123  */
124 HWTEST_F(QosInterfaceTest, QosApplyTest, TestSize.Level1)
125 {
126     unsigned int level = 1;
127     int ret = -1;
128     ret = QosApply(level);
129 #if defined(ARM64_TEST) && ARM64_TEST
130     EXPECT_EQ(ret, 0);
131 #else
132     (void)ret;
133 #endif
134 }
135 
136 /**
137  * @tc.name: AuthGetTest
138  * @tc.desc: Test whether the AuthGet interface are normal.
139  * @tc.type: FUNC
140  */
141 HWTEST_F(QosInterfaceTest, AuthGetTest, TestSize.Level1)
142 {
143     unsigned int uid = 1000;
144     unsigned int uaFlag1 = 0;
145     unsigned int *uaFlag = &uaFlag1;
146     unsigned int status1 = 0;
147     unsigned int *status = &status1;
148     int ret = AuthGet(uid, uaFlag, status);
149     EXPECT_GE(ret, 0);
150     uid = -1;
151     ret = AuthGet(uid, uaFlag, status);
152     EXPECT_EQ(ret, -1);
153 }
154 
155 /**
156  * @tc.name: QosApplyForOtherTest
157  * @tc.desc: Test whether the QosApplyForOther interface are normal.
158  * @tc.type: FUNC
159  */
160 HWTEST_F(QosInterfaceTest, QosApplyForOtherTest, TestSize.Level1)
161 {
162     unsigned int level = 1;
163     int tid = gettid();
164     int ret = -1;
165     ret = QosApplyForOther(level, tid);
166 #if defined(ARM64_TEST) && ARM64_TEST
167     EXPECT_EQ(ret, 0);
168 #else
169     (void)ret;
170 #endif
171 }
172 
173 /**
174  * @tc.name: QosLeaveTest
175  * @tc.desc: Test whether the QosLeave interface are normal.
176  * @tc.type: FUNC
177  */
178 HWTEST_F(QosInterfaceTest, QosLeaveTest, TestSize.Level1)
179 {
180     int ret = -1;
181     ret = QosLeave();
182 #if defined(ARM64_TEST) && ARM64_TEST
183     EXPECT_EQ(ret, 0);
184 #else
185     (void)ret;
186 #endif
187 }
188 
189 /**
190  * @tc.name: QosLeaveForOtherTest
191  * @tc.desc: Test whether the QosLeaveForOther interface are normal.
192  * @tc.type: FUNC
193  */
194 HWTEST_F(QosInterfaceTest, QosLeaveForOtherTest, TestSize.Level1)
195 {
196     int ret = -1;
197     int tid = gettid();
198     int level = 1;
199     ret = QosApplyForOther(level, tid);
200     ret = QosLeaveForOther(tid);
201 #if defined(ARM64_TEST) && ARM64_TEST
202     EXPECT_EQ(ret, 0);
203 #else
204     (void)ret;
205 #endif
206 }
207 
208 /**
209  * @tc.name: QosPolicyTest
210  * @tc.desc: Test whether the QosPolicy interface are normal.
211  * @tc.type: FUNC
212  */
213 
214 static struct QosPolicyDatas g_defaultQosPolicy = {
215     .policyType = static_cast<unsigned int>(QosPolicyType::QOS_POLICY_DEFAULT),
216     .policyFlag = QOS_FLAG_ALL,
217     .policys = {
218         {0, 0, 0, 1024, 0},
219         {0, 0, 0, 1024, 0},
220         {0, 0, 0, 1024, 0},
221         {0, 0, 0, 1024, 0},
222         {0, 0, 0, 1024, 0},
223         {0, 0, 0, 1024, 0},
224         {0, 0, 0, 1024, 0},
225     }
226 };
227 
228 HWTEST_F(QosInterfaceTest, QosPolicyTest, TestSize.Level1)
229 {
230     int ret = -1;
231     struct QosPolicyDatas *policyDatas = nullptr;
232     ret = QosPolicy(policyDatas);
233     EXPECT_EQ(ret, -1);
234 #if defined(ARM64_TEST) && ARM64_TEST
235     ret = QosPolicy(&g_defaultQosPolicy);
236     EXPECT_EQ(ret, 0);
237 #endif
238 }
239 }
240 }
241 }