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 /** 58 * @tc.name: FFRTEnableRtg_test 59 * @tc.desc: Test whether the FFRTEnableRtg interface are normal. 60 * @tc.type: FUNC 61 */ 62 HWTEST_F(QosInterfaceTest, FFRTEnableRtgTest, TestSize.Level1) 63 { 64 bool flag = false; 65 EXPECT_EQ(0, FFRTEnableRtg(flag)); 66 67 flag = true; 68 EXPECT_EQ(0, FFRTEnableRtg(flag)); 69 } 70 71 /** 72 * @tc.name: FFRTAuthEnable_test 73 * @tc.desc: Test whether the FFRTAuthEnable interface are normal. 74 * @tc.type: FUNC 75 */ 76 HWTEST_F(QosInterfaceTest, FFRTAuthEnableTest, TestSize.Level1) 77 { 78 unsigned int uid = getpid(); 79 unsigned int uaFlag = 0x1fff; 80 unsigned int status = 3; 81 82 EXPECT_EQ(0, FFRTAuthEnable(uid, uaFlag, status)); 83 } 84 85 /** 86 * @tc.name: FFRTAuthSwitch_test 87 * @tc.desc: Test whether the FFRTAuthSwitch interface are normal. 88 * @tc.type: FUNC 89 */ 90 HWTEST_F(QosInterfaceTest, FFRTAuthSwitchTest, TestSize.Level1) 91 { 92 unsigned int uid = getpid(); 93 unsigned int rtgFlag = 0x1fff; 94 unsigned int qosFlag = 0x0003; 95 unsigned int status = 3; 96 97 EXPECT_EQ(0, FFRTAuthSwitch(uid, rtgFlag, qosFlag, status)); 98 } 99 100 /** 101 * @tc.name: FFRTAuthDelete_test 102 * @tc.desc: Test whether the FFRTAuthDelete interface are normal. 103 * @tc.type: FUNC 104 */ 105 HWTEST_F(QosInterfaceTest, FFRTAuthDeleteTest, TestSize.Level1) 106 { 107 unsigned int uid = getpid(); 108 109 EXPECT_EQ(0, FFRTAuthDelete(uid)); 110 } 111 112 /** 113 * @tc.name: FFRTAuthPause_test 114 * @tc.desc: Test whether the FFRTAuthPause interface are normal. 115 * @tc.type: FUNC 116 */ 117 HWTEST_F(QosInterfaceTest, FFRTAuthPauseTest, TestSize.Level1) 118 { 119 unsigned int uid = getpid(); 120 unsigned int uaFlag = 0x1fff; 121 unsigned int status = 3; 122 FFRTAuthEnable(uid, uaFlag, status); 123 124 EXPECT_EQ(0, FFRTAuthPause(uid)); 125 } 126 127 /** 128 * @tc.name: FFRTAuthGet_test 129 * @tc.desc: Test whether the FFRTAuthGet interface are normal. 130 * @tc.type: FUNC 131 */ 132 HWTEST_F(QosInterfaceTest, FFRTAuthGetTest, TestSize.Level1) 133 { 134 unsigned int uid = getpid(); 135 unsigned int uaFlag = 0x1fff; 136 unsigned int status = 3; 137 138 FFRTAuthEnable(uid, uaFlag, status); 139 EXPECT_EQ(0, FFRTAuthGet(uid, &uaFlag, &status)); 140 } 141 142 /** 143 * @tc.name: FFRTQosApply_test 144 * @tc.desc: Test whether the FFRTQosApply interface are normal. 145 * @tc.type: FUNC 146 */ 147 HWTEST_F(QosInterfaceTest, FFRTQosApplyTest, TestSize.Level1) 148 { 149 unsigned int level = 1; 150 151 EXPECT_EQ(0, FFRTQosApply(level)); 152 } 153 154 /** 155 * @tc.name: FFRTQosApplyForOther_test 156 * @tc.desc: Test whether the FFRTQosApplyForOther interface are normal. 157 * @tc.type: FUNC 158 */ 159 HWTEST_F(QosInterfaceTest, FFRTQosApplyForOtherTest, TestSize.Level1) 160 { 161 unsigned int level = 1; 162 int tid = GET_TID(); 163 164 EXPECT_EQ(0, FFRTQosApplyForOther(level, tid)); 165 } 166 167 /** 168 * @tc.name: FFRTQosLeave_test 169 * @tc.desc: Test whether the FFRTQosLeave interface are normal. 170 * @tc.type: FUNC 171 */ 172 HWTEST_F(QosInterfaceTest, FFRTQosLeaveTest, TestSize.Level1) 173 { 174 EXPECT_EQ(0, FFRTQosLeave()); 175 } 176 177 /** 178 * @tc.name: FFRTQosLeaveForOther_test 179 * @tc.desc: Test whether the FFRTQosLeaveForOther interface are normal. 180 * @tc.type: FUNC 181 */ 182 HWTEST_F(QosInterfaceTest, FFRTQosLeaveForOtherTest, TestSize.Level1) 183 { 184 unsigned int level = 1; 185 int tid = GET_TID(); 186 FFRTQosApplyForOther(level, tid); 187 188 EXPECT_EQ(0, FFRTQosLeaveForOther(tid)); 189 } 190 191 /** 192 * @tc.name: QosPolicyTest 193 * @tc.desc: Test whether the QosPolicy interface are normal. 194 * @tc.type: FUNC 195 */ 196 HWTEST_F(QosInterfaceTest, QosPolicyTest, TestSize.Level1) 197 { 198 struct QosPolicyData qp = {0, 0, 0, 0, 0}; 199 struct QosPolicyDatas policyDatas = {0, 0, {qp}}; 200 201 EXPECT_EQ(-1, QosPolicy(&policyDatas)); 202 } 203