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 <climits>
18 #include <cstring>
19 #include "eu/worker_manager.h"
20 #include "eu/scpuworker_manager.h"
21 #include "eu/cpu_monitor.h"
22 #ifdef FFRT_GITEE
23 #include "eu/cpu_manager_interface.h"
24 #else
25 #include "eu/cpu_manager_strategy.h"
26 #endif
27 #include "sched/scheduler.h"
28 #include "sched/workgroup_internal.h"
29 #include "common.h"
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 WorkerManagerTest : 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: JoinRtgTest
58 * @tc.desc: Test whether the JoinRtg interface are normal.
59 * @tc.type: FUNC
60 */
HWTEST_F(WorkerManagerTest, JoinRtgTest, TestSize.Level1)61 HWTEST_F(WorkerManagerTest, JoinRtgTest, TestSize.Level1)
62 {
63 CPUWorkerManager* cm = new SCPUWorkerManager();
64 QoS* qos = new QoS();
65 cm->JoinRtg(*qos);
66 }
67
68 /**
69 * @tc.name: JoinTGTest
70 * @tc.desc: Test whether the JoinTG interface are normal.
71 * @tc.type: FUNC
72 */
HWTEST_F(WorkerManagerTest, JoinTGTest, TestSize.Level1)73 HWTEST_F(WorkerManagerTest, JoinTGTest, TestSize.Level1)
74 {
75 CPUWorkerManager* cm = new SCPUWorkerManager();
76 QoS* qos = new QoS(ffrt_qos_deadline_request);
77 ThreadGroup* tg = cm->JoinTG(*qos);
78 EXPECT_NE(tg, nullptr);
79
80 QoS* qos1 = new QoS(ffrt_qos_user_interactive);
81 ThreadGroup* tg1 = cm->JoinTG(*qos1);
82 EXPECT_EQ(tg1, nullptr);
83 }
84
85 /**
86 * @tc.name: LeaveTGTest
87 * @tc.desc: Test whether the LeaveTG interface are normal.
88 * @tc.type: FUNC
89 */
HWTEST_F(WorkerManagerTest, LeaveTGTest, TestSize.Level1)90 HWTEST_F(WorkerManagerTest, LeaveTGTest, TestSize.Level1)
91 {
92 CPUWorkerManager* cm = new SCPUWorkerManager();
93 QoS* qos = new QoS();
94 cm->LeaveTG(*qos);
95 }
96