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#ifndef WITH_NO_MOCKER 18#include <mockcpp/mockcpp.hpp> 19#endif 20#include <fcntl.h> 21#include "eu/osattr_manager.h" 22#ifndef WITH_NO_MOCKER 23#include "eu/qos_config.h" 24#endif 25#include "eu/qos_interface.h" 26#include "../common.h" 27 28using namespace testing; 29#ifdef HWTEST_TESTING_EXT_ENABLE 30using namespace testing::ext; 31#endif 32using namespace ffrt; 33 34class CgroupQosTest : public testing::Test { 35protected: 36 static void SetUpTestCase() 37 { 38#ifndef WITH_NO_MOCKER 39 MOCKER(write).stubs().will(returnValue(0)); 40 MOCKER(read).stubs().will(returnValue(0)); 41#endif 42 } 43 44 static void TearDownTestCase() 45 { 46#ifndef WITH_NO_MOCKER 47 GlobalMockObject::verify(); 48#endif 49 } 50 51 virtual void SetUp() 52 { 53 } 54 55 virtual void TearDown() 56 { 57 } 58}; 59 60#ifndef FFRT_GITEE 61HWTEST_F(CgroupQosTest, UpdateSchedAttr_test, TestSize.Level1) 62{ 63 ffrt_os_sched_attr attr = {100, 10, 99, 99, 9, "2-3"}; 64 int ret = 0; 65#ifndef WITH_NO_MOCKER 66 ret = OSAttrManager::Instance()->UpdateSchedAttr(QoS(static_cast<int>(qos_defined_ive)), &attr); 67 EXPECT_EQ(ret, 0); 68#endif 69 ret = OSAttrManager::Instance()->UpdateSchedAttr(QoS(static_cast<int>(qos_user_interactive)), &attr); 70 EXPECT_EQ(ret, -1); 71} 72#endif 73 74HWTEST_F(CgroupQosTest, SetTidToCGroup_test, TestSize.Level1) 75{ 76 OSAttrManager::Instance()->SetTidToCGroup(100); 77 OSAttrManager::Instance()->SetTidToCGroup(-1); 78} 79 80HWTEST_F(CgroupQosTest, SetCGroupCtlPara_test, TestSize.Level1) 81{ 82 OSAttrManager::Instance()->SetCGroupCtlPara("", 1); 83 OSAttrManager::Instance()->SetCGroupCtlPara("test", 1); 84} 85 86HWTEST_F(CgroupQosTest, SetCGroupSetPara_test, TestSize.Level1) 87{ 88 OSAttrManager::Instance()->SetCGroupSetPara("", "1"); 89 OSAttrManager::Instance()->SetCGroupSetPara("test", "1"); 90} 91 92HWTEST_F(CgroupQosTest, SetTidToCGroupPrivate_test, TestSize.Level1) 93{ 94 OSAttrManager::Instance()->SetTidToCGroupPrivate("test", 100); 95 OSAttrManager::Instance()->SetTidToCGroupPrivate("test", -1); 96} 97 98HWTEST_F(CgroupQosTest, SetCGroupPara_test, TestSize.Level1) 99{ 100 int a = 100; 101 OSAttrManager::Instance()->SetCGroupPara("/proc/cpuinfo", a); 102} 103 104HWTEST_F(CgroupQosTest, SetCGroupPara_err_test, TestSize.Level1) 105{ 106#ifndef WITH_NO_MOCKER 107 MOCKER(write).stubs().will(returnValue(0)); 108 MOCKER(read).stubs().will(returnValue(0)); 109#endif 110 int a = 3; 111 OSAttrManager::Instance()->SetCGroupPara("/proc/cpuinfo", a); 112#ifndef WITH_NO_MOCKER 113 MOCKER(write).stubs().will(returnValue(-1)); 114 MOCKER(read).stubs().will(returnValue(0)); 115#endif 116 OSAttrManager::Instance()->SetCGroupPara("/proc/cpuinfo", a); 117#ifndef WITH_NO_MOCKER 118 MOCKER(write).stubs().will(returnValue(0)); 119 MOCKER(read).stubs().will(returnValue(33)); 120#endif 121 OSAttrManager::Instance()->SetCGroupPara("/proc/cpuinfo", a); 122} 123 124class QosTest : public testing::Test { 125protected: 126 static void SetUpTestCase() 127 { 128 } 129 130 static void TearDownTestCase() 131 { 132 } 133 134 virtual void SetUp() 135 { 136 } 137 138 virtual void TearDown() 139 { 140 } 141}; 142 143HWTEST_F(QosTest, QosConfig_test, TestSize.Level1) 144{ 145#ifndef WITH_NO_MOCKER 146 QosConfig::Instance().setPolicySystem(); 147#endif 148} 149 150class QosInterfaceTest : public testing::Test { 151protected: 152 static void SetUpTestCase() 153 { 154 } 155 156 static void TearDownTestCase() 157 { 158 } 159 160 virtual void SetUp() 161 { 162 } 163 164 virtual void TearDown() 165 { 166 } 167}; 168 169HWTEST_F(QosInterfaceTest, QosPolicyTest, TestSize.Level1) 170{ 171 struct QosPolicyData qp = {0, 0, 0, 0, 0}; 172 struct QosPolicyDatas policyDatas = {0, 0, {qp}}; 173 174 QosPolicy(&policyDatas); 175} 176 177HWTEST_F(QosInterfaceTest, FFRTEnableRtgTest, TestSize.Level1) 178{ 179 bool flag = false; 180 FFRTEnableRtg(flag); 181} 182 183HWTEST_F(QosInterfaceTest, FFRTAuthEnableTest, TestSize.Level1) 184{ 185 unsigned int uid = 3039; 186 unsigned int uaFlag = 0x1fff; 187 unsigned int status = 3; 188 FFRTAuthEnable(uid, uaFlag, status); 189} 190 191HWTEST_F(QosInterfaceTest, FFRTAuthSwitchTest, TestSize.Level1) 192{ 193 unsigned int uid = 3039; 194 unsigned int rtgFlag = 0x1fff; 195 unsigned int qosFlag = 0x0003; 196 unsigned int status = 3; 197 FFRTAuthSwitch(uid, rtgFlag, qosFlag, status); 198} 199 200HWTEST_F(QosInterfaceTest, FFRTAuthDeleteTest, TestSize.Level1) 201{ 202 unsigned int uid = 3039; 203 FFRTAuthDelete(uid); 204} 205 206HWTEST_F(QosInterfaceTest, FFRTAuthPauseTest, TestSize.Level1) 207{ 208 unsigned int uid = 3039; 209 unsigned int uaFlag = 0x1fff; 210 unsigned int status = 3; 211 FFRTAuthEnable(uid, uaFlag, status); 212 FFRTAuthPause(uid); 213} 214 215HWTEST_F(QosInterfaceTest, FFRTAuthGetTest, TestSize.Level1) 216{ 217 unsigned int uid = 3039; 218 unsigned int uaFlag = 0x1fff; 219 unsigned int status = 3; 220 221 FFRTAuthEnable(uid, uaFlag, status); 222 FFRTAuthGet(uid, &uaFlag, &status); 223} 224 225HWTEST_F(QosInterfaceTest, FFRTQosApplyTest, TestSize.Level1) 226{ 227 unsigned int level = 1; 228 229 FFRTQosApply(level); 230} 231 232HWTEST_F(QosInterfaceTest, FFRTQosApplyForOtherTest, TestSize.Level1) 233{ 234 unsigned int level = 1; 235 int tid = 0; 236 237 FFRTQosApplyForOther(level, tid); 238} 239 240HWTEST_F(QosInterfaceTest, FFRTQosLeaveTest, TestSize.Level1) 241{ 242 FFRTQosLeave(); 243} 244 245HWTEST_F(QosInterfaceTest, FFRTQosLeaveForOtherTest, TestSize.Level1) 246{ 247 unsigned int level = 1; 248 int tid = 0; 249 FFRTQosApplyForOther(level, tid); 250 251 FFRTQosLeaveForOther(tid); 252} 253 254HWTEST_F(QosInterfaceTest, FFRTQosConvertInt, TestSize.Level1) 255{ 256 QoS qos1 = 1; 257 QoS qos2 = 2; 258 QoS qos3 = qos1 + qos2; 259 printf("qos3=%d", qos3()); 260}