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 #include "eu/cpu_manager_strategy.h"
23 #include "sched/scheduler.h"
24 #include "sched/workgroup_internal.h"
25 #include "common.h"
26 
27 using namespace testing;
28 #ifdef HWTEST_TESTING_EXT_ENABLE
29 using namespace testing::ext;
30 #endif
31 using namespace ffrt;
32 
33 class WorkerManagerTest : public testing::Test {
34 protected:
SetUpTestCase()35     static void SetUpTestCase()
36     {
37     }
38 
TearDownTestCase()39     static void TearDownTestCase()
40     {
41     }
42 
SetUp()43     virtual void SetUp()
44     {
45     }
46 
TearDown()47     virtual void TearDown()
48     {
49     }
50 };
51 
52 /**
53  * @tc.name: JoinRtgTest
54  * @tc.desc: Test whether the JoinRtg interface are normal.
55  * @tc.type: FUNC
56  */
57 HWTEST_F(WorkerManagerTest, JoinRtgTest, TestSize.Level1)
58 {
59     CPUWorkerManager* cm = new SCPUWorkerManager();
60     QoS* qos = new QoS();
61     cm->JoinRtg(*qos);
62 }
63 
64 /**
65  * @tc.name: JoinTGTest
66  * @tc.desc: Test whether the JoinTG interface are normal.
67  * @tc.type: FUNC
68  */
69 HWTEST_F(WorkerManagerTest, JoinTGTest, TestSize.Level1)
70 {
71     CPUWorkerManager* cm = new SCPUWorkerManager();
72     QoS* qos = new QoS(ffrt_qos_deadline_request);
73     ThreadGroup* tg = cm->JoinTG(*qos);
74     EXPECT_NE(tg, nullptr);
75 
76     QoS* qos1 = new QoS(ffrt_qos_user_interactive);
77     ThreadGroup* tg1 = cm->JoinTG(*qos1);
78     EXPECT_EQ(tg1, nullptr);
79 }
80 
81 /**
82  * @tc.name: LeaveTGTest
83  * @tc.desc: Test whether the LeaveTG interface are normal.
84  * @tc.type: FUNC
85  */
86 HWTEST_F(WorkerManagerTest, LeaveTGTest, TestSize.Level1)
87 {
88     CPUWorkerManager* cm = new SCPUWorkerManager();
89     QoS* qos = new QoS();
90     cm->LeaveTG(*qos);
91 }
92