• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define private public
17 #define protected public
18 #include <gtest/gtest.h>
19 #include <thread>
20 #include "eu/cpu_worker.h"
21 #include "eu/cpuworker_manager.h"
22 #include "eu/cpu_monitor.h"
23 #include "eu/cpu_manager_interface.h"
24 #include "eu/worker_thread.h"
25 #include "sched/qos.h"
26 #undef private
27 #undef protected
28 
29 using namespace testing;
30 using namespace testing::ext;
31 using namespace ffrt;
32 using namespace std;
33 
34 
35 class CpuMonitorTest : public testing::Test {
36 protected:
SetUpTestCase()37     static void SetUpTestCase()
38     {
39     }
40 
TearDownTestCase()41     static void TearDownTestCase()
42     {
43     }
44 
SetUp()45     virtual void SetUp()
46     {
47     }
48 
TearDown()49     virtual void TearDown()
50     {
51     }
52 };
53 
54 /**
55  * @tc.name: GetMonitorTid
56  * @tc.desc: Test whether the GetMonitorTid interface are normal.
57  * @tc.type: FUNC
58  *
59  *
60  */
61 HWTEST_F(CpuMonitorTest, GetMonitorTid, TestSize.Level1)
62 {
63     CPUWorkerManager *it = new CPUWorkerManager();
64     CPUMonitor cpu({
65         std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1),
66         std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1),
67         std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)});
68 
69     uint32_t tid;
70     tid = cpu.GetMonitorTid();
71 }
72 
73 /**
74  * @tc.name: HandleBlocked
75  * @tc.desc: Test whether the HandleBlocked interface are normal.
76  * @tc.type: FUNC
77  *
78  *
79  */
80 HWTEST_F(CpuMonitorTest, HandleBlocked, TestSize.Level1)
81 {
82     CPUWorkerManager *it = new CPUWorkerManager();
83     CPUMonitor cpu({
84         std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1),
85         std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1),
86         std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)});
87 
88     cpu.HandleBlocked(5);
89 }
90 
91 /**
92  * @tc.name: DecExeNumRef
93  * @tc.desc: Test whether the DecExeNumRef interface are normal.
94  * @tc.type: FUNC
95  *
96  *
97  */
98 HWTEST_F(CpuMonitorTest, DecExeNumRef, TestSize.Level1)
99 {
100     CPUWorkerManager *it = new CPUWorkerManager();
101     CPUMonitor cpu({
102         std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1),
103         std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1),
104         std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)});
105 
106     cpu.DecExeNumRef(5);
107 }
108 
109 /**
110  * @tc.name: IncSleepingRef
111  * @tc.desc: Test whether the IncSleepingRef interface are normal.
112  * @tc.type: FUNC
113  *
114  *
115  */
116 HWTEST_F(CpuMonitorTest, IncSleepingRef, TestSize.Level1)
117 {
118     CPUWorkerManager *it = new CPUWorkerManager();
119     CPUMonitor cpu({
120         std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1),
121         std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1),
122         std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)});
123 
124     cpu.IncSleepingRef(5);
125 }
126 
127 /**
128  * @tc.name: DecSleepingRef
129  * @tc.desc: Test whether the DecSleepingRef interface are normal.
130  * @tc.type: FUNC
131  *
132  *
133  */
134 HWTEST_F(CpuMonitorTest, DecSleepingRef, TestSize.Level1)
135 {
136     CPUWorkerManager *it = new CPUWorkerManager();
137     CPUMonitor cpu({
138         std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1),
139         std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1),
140         std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)});
141 
142     cpu.DecSleepingRef(5);
143 }
144 
145 /**
146  * @tc.name: IntoSleep
147  * @tc.desc: Test whether the IntoSleep interface are normal.
148  * @tc.type: FUNC
149  *
150  *
151  */
152 HWTEST_F(CpuMonitorTest, IntoSleep, TestSize.Level1)
153 {
154     CPUWorkerManager *it = new CPUWorkerManager();
155     CPUMonitor cpu({
156         std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1),
157         std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1),
158         std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)});
159 
160     cpu.IntoSleep(5);
161 }
162 
163 /**
164  * @tc.name: WakeupCount
165  * @tc.desc: Test whether the WakeupCount interface are normal.
166  * @tc.type: FUNC
167  *
168  *
169  */
170 HWTEST_F(CpuMonitorTest, WakeupCount, TestSize.Level1)
171 {
172     CPUWorkerManager *it = new CPUWorkerManager();
173     CPUMonitor cpu({
174         std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1),
175         std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1),
176         std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)});
177 
178     cpu.WakeupCount(5);
179 }
180 
181 /**
182  * @tc.name: TimeoutCount
183  * @tc.desc: Test whether the TimeoutCount interface are normal.
184  * @tc.type: FUNC
185  *
186  *
187  */
188 HWTEST_F(CpuMonitorTest, TimeoutCount, TestSize.Level1)
189 {
190     CPUWorkerManager *it = new CPUWorkerManager();
191     CPUMonitor cpu({
192         std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1),
193         std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1),
194         std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)});
195 
196     cpu.TimeoutCount(5);
197 }
198 
199 /**
200  * @tc.name: RegWorker
201  * @tc.desc: Test whether the RegWorker interface are normal.
202  * @tc.type: FUNC
203  *
204  *
205  */
206 HWTEST_F(CpuMonitorTest, RegWorker, TestSize.Level1)
207 {
208     CPUWorkerManager *it = new CPUWorkerManager();
209     CPUMonitor cpu({
210         std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1),
211         std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1),
212         std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)});
213 
214     cpu.RegWorker(5);
215 }
216 
217 /**
218  * @tc.name: UnRegWorker
219  * @tc.desc: Test whether the UnRegWorker interface are normal.
220  * @tc.type: FUNC
221  *
222  *
223  */
224 HWTEST_F(CpuMonitorTest, UnRegWorker, TestSize.Level1)
225 {
226     CPUWorkerManager *it = new CPUWorkerManager();
227     CPUMonitor cpu({
228         std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1),
229         std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1),
230         std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)});
231 
232     cpu.UnRegWorker();
233 }
234 
235 /**
236  * @tc.name: Notify
237  * @tc.desc: Test whether the Notify interface are normal.
238  * @tc.type: FUNC
239  *
240  *
241  */
242 HWTEST_F(CpuMonitorTest, Notify, TestSize.Level1)
243 {
244     CPUWorkerManager *it = new CPUWorkerManager();
245     CPUMonitor cpu({
246         std::bind(&CPUWorkerManager::IncWorker, it, std::placeholders::_1),
247         std::bind(&CPUWorkerManager::WakeupWorkers, it, std::placeholders::_1),
248         std::bind(&CPUWorkerManager::GetTaskCount, it, std::placeholders::_1)});
249 
250     cpu.Notify(5, TaskNotifyType(1));
251 }
252