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 #include <thread>
18 #include <cstring>
19 #include <algorithm>
20 #include <sched.h>
21 #include <unistd.h>
22 #include <sys/syscall.h>
23 #include <sys/resource.h>
24 #include "common.h"
25 
26 #define private public
27 #include "eu/worker_thread.h"
28 #undef private
29 
30 using namespace testing;
31 #ifdef HWTEST_TESTING_EXT_ENABLE
32 using namespace testing::ext;
33 #endif
34 using namespace ffrt;
35 
36 class WorkerThreadTest : public testing::Test {
37 protected:
SetUpTestCase()38     static void SetUpTestCase()
39     {
40     }
41 
TearDownTestCase()42     static void TearDownTestCase()
43     {
44     }
45 
SetUp()46     virtual void SetUp()
47     {
48     }
49 
TearDown()50     virtual void TearDown()
51     {
52     }
53 };
54 
55 /**
56  * @tc.name: IdleTest
57  * @tc.desc: Test whether the Idle interface are normal.
58  * @tc.type: FUNC
59  */
60 HWTEST_F(WorkerThreadTest, IdleTest, TestSize.Level1)
61 {
62     WorkerThread* wt = new WorkerThread(QoS(6));
63     bool ret = wt->Idle();
64     EXPECT_FALSE(ret);
65 }
66 
67 /**
68  * @tc.name: SetIdleTest
69  * @tc.desc: Test whether the SetIdle interface are normal.
70  * @tc.type: FUNC
71  */
72 HWTEST_F(WorkerThreadTest, SetIdleTest, TestSize.Level1)
73 {
74     WorkerThread* wt = new WorkerThread(QoS(6));
75     bool var = false;
76     wt->SetIdle(var);
77     EXPECT_FALSE(wt->idle);
78 }
79 
80 /**
81  * @tc.name: ExitedTest
82  * @tc.desc: Test whether the Exited interface are normal.
83  * @tc.type: FUNC
84  */
85 HWTEST_F(WorkerThreadTest, ExitedTest, TestSize.Level1)
86 {
87     WorkerThread* wt = new WorkerThread(QoS(6));
88     bool ret = wt->Exited();
89     EXPECT_FALSE(ret);
90 }
91 
92 /**
93  * @tc.name: SetExitedTest
94  * @tc.desc: Test whether the SetExited interface are normal.
95  * @tc.type: FUNC
96  */
97 HWTEST_F(WorkerThreadTest, SetExitedTest, TestSize.Level1)
98 {
99     WorkerThread* wt = new WorkerThread(QoS(6));
100     bool var = false;
101     wt->SetExited(var);
102     EXPECT_FALSE(wt->exited);
103 }
104 
105 /**
106  * @tc.name: GetQosTest
107  * @tc.desc: Test whether the GetQos interface are normal.
108  * @tc.type: FUNC
109  */
110 HWTEST_F(WorkerThreadTest, GetQosTest, TestSize.Level1)
111 {
112     WorkerThread* wt = new WorkerThread(QoS(6));
113     QoS ret = wt->GetQos();
114 }
115 
116 /**
117  * @tc.name: JoinTest
118  * @tc.desc: Test whether the Join interface are normal.
119  * @tc.type: FUNC
120  */
121 HWTEST_F(WorkerThreadTest, JoinTest, TestSize.Level1)
122 {
123     WorkerThread* wt = new WorkerThread(QoS(6));
124     wt->Join();
125 }
126 
127 /**
128  * @tc.name: DetachTest
129  * @tc.desc: Test whether the Detach interface are normal.
130  * @tc.type: FUNC
131  */
132 HWTEST_F(WorkerThreadTest, DetachTest, TestSize.Level1)
133 {
134     WorkerThread* wt = new WorkerThread(QoS(6));
135     wt->Detach();
136 }
137