• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <fcntl.h>
18 #include "eu/qos_interface.h"
19 #include "cpp/qos_convert.h"
20 #include "eu/osattr_manager.h"
21 #include "sync/delayed_worker.h"
22 #include "util/ffrt_facade.h"
23 #include "../common.h"
24 
25 using namespace testing;
26 #ifdef HWTEST_TESTING_EXT_ENABLE
27 using namespace testing::ext;
28 #endif
29 using namespace ffrt;
30 
31 
32 class QosConvertTest : public testing::Test {
33 protected:
SetUpTestCase()34     static void SetUpTestCase()
35     {
36     }
37 
TearDownTestCase()38     static void TearDownTestCase()
39     {
40     }
41 
SetUp()42     void SetUp() override
43     {
44     }
45 
TearDown()46     void TearDown() override
47     {
48     }
49 };
50 
51 HWTEST_F(QosConvertTest, GetDynamicQosTest, TestSize.Level1)
52 {
53     qos tmpQos = qos_default;
54     int ret = GetDynamicQos(tmpQos);
55     EXPECT_EQ(ret, -1);
56 }
57 
58 HWTEST_F(QosConvertTest, GetStaticQosTest, TestSize.Level1)
59 {
60     qos tmpQos = qos_default;
61     int ret = GetStaticQos(tmpQos);
62     EXPECT_EQ(ret, -1);
63 }
64 
65 HWTEST_F(QosConvertTest, IsDelayerWorkerThreadTest, TestSize.Level1)
66 {
67     DelayedWorker::ThreadEnvCreate();
68     sleep(1);
69     bool ret = DelayedWorker::IsDelayerWorkerThread();
70     EXPECT_EQ(ret, false);
71 }
72 
73 class CgroupQosTest : public testing::Test {
74 protected:
SetUpTestCase()75     static void SetUpTestCase()
76     {
77     }
78 
TearDownTestCase()79     static void TearDownTestCase()
80     {
81     }
82 
SetUp()83     void SetUp() override
84     {
85     }
86 
TearDown()87     void TearDown() override
88     {
89     }
90 };
91 
tmpFun()92 int tmpFun()
93 {
94     return 6;
95 }
96 
97 HWTEST_F(CgroupQosTest, SchedAttrTest, TestSize.Level1)
98 {
99     ffrt_os_sched_attr attr = {100, 10, 99, 99, 9, "2-3"};
100     static FuncQosMax funcQosMax = tmpFun;
101     OSAttrManager::Instance()->CheckSchedAttrPara("test", 5, 10, 8);
102     OSAttrManager::Instance()->CheckSchedAttrPara("test", 5, 10, 1);
103     OSAttrManager::Instance()->CheckSchedAttrPara("test", 5, 10, 15);
104     int ret = 0;
105 #ifndef FFRT_GITEE
106     ret = OSAttrManager::Instance()->UpdateSchedAttr(QoS(static_cast<int>(qos_defined_ive)), &attr);
107     EXPECT_EQ(ret, 0);
108 #endif
109 }
110 
111 HWTEST_F(CgroupQosTest, SetTidToCGroupPrivateTest, TestSize.Level1)
112 {
113     ffrt_os_sched_attr attr = {100, 10, 99, 99, 9, "2-3"};
114     std::string value = "1";
115     int num = 0xfffff;
116     int ret = 0;
117 #ifndef FFRT_GITEE
118     ret = OSAttrManager::Instance()->UpdateSchedAttr(QoS(static_cast<int>(qos_defined_ive)), &attr);
119     OSAttrManager::Instance()->SetTidToCGroupPrivate(value, num);
120     EXPECT_EQ(ret, 0);
121 #endif
122 }
123