1 /* 2 * Copyright (c) 2023 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 #include <thread> 18 #include <cstdio> 19 #include <cstdlib> 20 #include <unistd.h> 21 #include <sys/ioctl.h> 22 #include <fcntl.h> 23 #include <unistd.h> 24 #include <sys/syscall.h> 25 #include <linux/types.h> 26 #include "eu/qos_interface.h" 27 #include "ffrt_inner.h" 28 #include "common.h" 29 30 #define GET_TID() syscall(SYS_gettid) 31 32 using namespace testing; 33 #ifdef HWTEST_TESTING_EXT_ENABLE 34 using namespace testing::ext; 35 #endif 36 using namespace ffrt; 37 38 class QosInterfaceTest : public testing::Test { 39 protected: SetUpTestCase()40 static void SetUpTestCase() 41 { 42 } 43 TearDownTestCase()44 static void TearDownTestCase() 45 { 46 } 47 SetUp()48 void SetUp() override 49 { 50 } 51 TearDown()52 void TearDown() override 53 { 54 } 55 }; 56 57 #if !defined(SCHED_RGT_CTRL_DNE) 58 /** 59 * @tc.name: FFRTEnableRtg_test 60 * @tc.desc: Test whether the FFRTEnableRtg interface are normal. 61 * @tc.type: FUNC 62 */ 63 HWTEST_F(QosInterfaceTest, FFRTEnableRtgTest, TestSize.Level0) 64 { 65 bool flag = false; 66 EXPECT_EQ(0, FFRTEnableRtg(flag)); 67 68 flag = true; 69 EXPECT_EQ(0, FFRTEnableRtg(flag)); 70 } 71 #endif 72 73 #if !defined(AUTH_CTRL_DNE) 74 /** 75 * @tc.name: FFRTAuthEnable_test 76 * @tc.desc: Test whether the FFRTAuthEnable interface are normal. 77 * @tc.type: FUNC 78 */ 79 HWTEST_F(QosInterfaceTest, FFRTAuthEnableTest, TestSize.Level0) 80 { 81 unsigned int uid = getpid(); 82 unsigned int uaFlag = 0x1fff; 83 unsigned int status = 3; 84 85 EXPECT_EQ(0, FFRTAuthEnable(uid, uaFlag, status)); 86 } 87 88 /** 89 * @tc.name: FFRTAuthSwitch_test 90 * @tc.desc: Test whether the FFRTAuthSwitch interface are normal. 91 * @tc.type: FUNC 92 */ 93 HWTEST_F(QosInterfaceTest, FFRTAuthSwitchTest, TestSize.Level0) 94 { 95 unsigned int uid = getpid(); 96 unsigned int rtgFlag = 0x1fff; 97 unsigned int qosFlag = 0x0003; 98 unsigned int status = 3; 99 100 EXPECT_EQ(0, FFRTAuthSwitch(uid, rtgFlag, qosFlag, status)); 101 } 102 103 /** 104 * @tc.name: FFRTAuthDelete_test 105 * @tc.desc: Test whether the FFRTAuthDelete interface are normal. 106 * @tc.type: FUNC 107 */ 108 HWTEST_F(QosInterfaceTest, FFRTAuthDeleteTest, TestSize.Level0) 109 { 110 unsigned int uid = getpid(); 111 112 EXPECT_EQ(0, FFRTAuthDelete(uid)); 113 } 114 115 /** 116 * @tc.name: FFRTAuthPause_test 117 * @tc.desc: Test whether the FFRTAuthPause interface are normal. 118 * @tc.type: FUNC 119 */ 120 HWTEST_F(QosInterfaceTest, FFRTAuthPauseTest, TestSize.Level0) 121 { 122 unsigned int uid = getpid(); 123 unsigned int uaFlag = 0x1fff; 124 unsigned int status = 3; 125 FFRTAuthEnable(uid, uaFlag, status); 126 127 EXPECT_EQ(0, FFRTAuthPause(uid)); 128 } 129 130 /** 131 * @tc.name: FFRTAuthGet_test 132 * @tc.desc: Test whether the FFRTAuthGet interface are normal. 133 * @tc.type: FUNC 134 */ 135 HWTEST_F(QosInterfaceTest, FFRTAuthGetTest, TestSize.Level0) 136 { 137 unsigned int uid = getpid(); 138 unsigned int uaFlag = 0x1fff; 139 unsigned int status = 3; 140 141 FFRTAuthEnable(uid, uaFlag, status); 142 EXPECT_EQ(0, FFRTAuthGet(uid, &uaFlag, &status)); 143 } 144 #endif 145 146 #if !defined(SCHED_QOS_CTRL_DNE) 147 /** 148 * @tc.name: FFRTQosApply_test 149 * @tc.desc: Test whether the FFRTQosApply interface are normal. 150 * @tc.type: FUNC 151 */ 152 HWTEST_F(QosInterfaceTest, FFRTQosApplyTest, TestSize.Level0) 153 { 154 unsigned int level = 1; 155 156 EXPECT_EQ(0, FFRTQosApply(level)); 157 } 158 159 /** 160 * @tc.name: FFRTQosApplyForOther_test 161 * @tc.desc: Test whether the FFRTQosApplyForOther interface are normal. 162 * @tc.type: FUNC 163 */ 164 HWTEST_F(QosInterfaceTest, FFRTQosApplyForOtherTest, TestSize.Level0) 165 { 166 unsigned int level = 1; 167 int tid = GET_TID(); 168 169 EXPECT_EQ(0, FFRTQosApplyForOther(level, tid)); 170 } 171 172 /** 173 * @tc.name: FFRTQosLeave_test 174 * @tc.desc: Test whether the FFRTQosLeave interface are normal. 175 * @tc.type: FUNC 176 */ 177 HWTEST_F(QosInterfaceTest, FFRTQosLeaveTest, TestSize.Level0) 178 { 179 EXPECT_EQ(0, FFRTQosLeave()); 180 } 181 182 /** 183 * @tc.name: FFRTQosLeaveForOther_test 184 * @tc.desc: Test whether the FFRTQosLeaveForOther interface are normal. 185 * @tc.type: FUNC 186 */ 187 HWTEST_F(QosInterfaceTest, FFRTQosLeaveForOtherTest, TestSize.Level0) 188 { 189 unsigned int level = 1; 190 int tid = GET_TID(); 191 FFRTQosApplyForOther(level, tid); 192 193 EXPECT_EQ(0, FFRTQosLeaveForOther(tid)); 194 } 195 196 /** 197 * @tc.name: QosPolicyTest 198 * @tc.desc: Test whether the QosPolicy interface are normal. 199 * @tc.type: FUNC 200 */ 201 HWTEST_F(QosInterfaceTest, QosPolicyTest, TestSize.Level0) 202 { 203 struct QosPolicyData qp = {0, 0, 0, 0, 0}; 204 struct QosPolicyDatas policyDatas = {0, 0, {qp}}; 205 206 EXPECT_EQ(-1, QosPolicy(&policyDatas)); 207 } 208 #endif 209