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