1060ff233Sopenharmony_ci/*
2060ff233Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3060ff233Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4060ff233Sopenharmony_ci * you may not use this file except in compliance with the License.
5060ff233Sopenharmony_ci * You may obtain a copy of the License at
6060ff233Sopenharmony_ci *
7060ff233Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8060ff233Sopenharmony_ci *
9060ff233Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10060ff233Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11060ff233Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12060ff233Sopenharmony_ci * See the License for the specific language governing permissions and
13060ff233Sopenharmony_ci * limitations under the License.
14060ff233Sopenharmony_ci */
15060ff233Sopenharmony_ci
16060ff233Sopenharmony_ci#include <securec.h>
17060ff233Sopenharmony_ci#include "gtest/gtest.h"
18060ff233Sopenharmony_ci#include "softbus_adapter_thread.h"
19060ff233Sopenharmony_ci#include "softbus_errcode.h"
20060ff233Sopenharmony_ci
21060ff233Sopenharmony_ciusing namespace std;
22060ff233Sopenharmony_ciusing namespace testing::ext;
23060ff233Sopenharmony_ci
24060ff233Sopenharmony_cinamespace OHOS {
25060ff233Sopenharmony_cistatic SoftBusCond g_cond;
26060ff233Sopenharmony_cistatic SoftBusMutex g_mutex;
27060ff233Sopenharmony_ciconst int32_t DELAY_TIME = 1000;
28060ff233Sopenharmony_ci
29060ff233Sopenharmony_ciclass SoftbusThreadTest : public testing::Test {
30060ff233Sopenharmony_ciprotected:
31060ff233Sopenharmony_ci    static void SetUpTestCase(void);
32060ff233Sopenharmony_ci    static void TearDownTestCase(void);
33060ff233Sopenharmony_ci    void SetUp();
34060ff233Sopenharmony_ci    void TearDown();
35060ff233Sopenharmony_ci};
36060ff233Sopenharmony_ci
37060ff233Sopenharmony_civoid SoftbusThreadTest::SetUpTestCase(void)
38060ff233Sopenharmony_ci{
39060ff233Sopenharmony_ci}
40060ff233Sopenharmony_ci
41060ff233Sopenharmony_civoid SoftbusThreadTest::TearDownTestCase(void)
42060ff233Sopenharmony_ci{
43060ff233Sopenharmony_ci}
44060ff233Sopenharmony_ci
45060ff233Sopenharmony_civoid SoftbusThreadTest::SetUp()
46060ff233Sopenharmony_ci{
47060ff233Sopenharmony_ci}
48060ff233Sopenharmony_ci
49060ff233Sopenharmony_civoid SoftbusThreadTest::TearDown()
50060ff233Sopenharmony_ci{
51060ff233Sopenharmony_ci}
52060ff233Sopenharmony_ci
53060ff233Sopenharmony_cistatic void *SoftBusThreadTask(void *arg)
54060ff233Sopenharmony_ci{
55060ff233Sopenharmony_ci    printf("----------%s--------\n", __FUNCTION__);
56060ff233Sopenharmony_ci    SoftBusSleepMs(DELAY_TIME);
57060ff233Sopenharmony_ci    return static_cast<void *>(const_cast<char *>("SoftBusThreadTask"));
58060ff233Sopenharmony_ci}
59060ff233Sopenharmony_ci
60060ff233Sopenharmony_cistatic void *ThreadSelfTest(void *arg)
61060ff233Sopenharmony_ci{
62060ff233Sopenharmony_ci    printf("----------%s--------\n", __FUNCTION__);
63060ff233Sopenharmony_ci    SoftBusThread thread = SoftBusThreadGetSelf();
64060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
65060ff233Sopenharmony_ci    SoftBusSleepMs(DELAY_TIME);
66060ff233Sopenharmony_ci    return nullptr;
67060ff233Sopenharmony_ci}
68060ff233Sopenharmony_ci
69060ff233Sopenharmony_cistatic void *ThreadWaitTest(void *arg)
70060ff233Sopenharmony_ci{
71060ff233Sopenharmony_ci    printf("----------%s--------\n", __FUNCTION__);
72060ff233Sopenharmony_ci    int32_t ret = SoftBusCondWait(&g_cond, &g_mutex, NULL);
73060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
74060ff233Sopenharmony_ci    SoftBusSleepMs(DELAY_TIME);
75060ff233Sopenharmony_ci    return nullptr;
76060ff233Sopenharmony_ci}
77060ff233Sopenharmony_ci
78060ff233Sopenharmony_cistatic void *ThreadSignalTest(void *arg)
79060ff233Sopenharmony_ci{
80060ff233Sopenharmony_ci    printf("----------%s--------\n", __FUNCTION__);
81060ff233Sopenharmony_ci    SoftBusSleepMs(DELAY_TIME);
82060ff233Sopenharmony_ci    int32_t ret = SoftBusCondSignal(&g_cond);
83060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
84060ff233Sopenharmony_ci    return nullptr;
85060ff233Sopenharmony_ci}
86060ff233Sopenharmony_ci
87060ff233Sopenharmony_ci/*
88060ff233Sopenharmony_ci* @tc.name: SoftbusMutexAttrInitTest001
89060ff233Sopenharmony_ci* @tc.desc: mutexAttr is nullptr
90060ff233Sopenharmony_ci* @tc.type: FUNC
91060ff233Sopenharmony_ci* @tc.require: 1
92060ff233Sopenharmony_ci*/
93060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftbusMutexAttrInitTest001, TestSize.Level0)
94060ff233Sopenharmony_ci{
95060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexAttrInit(nullptr);
96060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
97060ff233Sopenharmony_ci}
98060ff233Sopenharmony_ci
99060ff233Sopenharmony_ci/*
100060ff233Sopenharmony_ci* @tc.name: SoftbusMutexAttrInitTest002
101060ff233Sopenharmony_ci* @tc.desc: mutexAttr is valid
102060ff233Sopenharmony_ci* @tc.type: FUNC
103060ff233Sopenharmony_ci* @tc.require: 1
104060ff233Sopenharmony_ci*/
105060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftbusMutexAttrInitTest002, TestSize.Level0)
106060ff233Sopenharmony_ci{
107060ff233Sopenharmony_ci    SoftBusMutexAttr mutexAttr;
108060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexAttrInit(&mutexAttr);
109060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
110060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_MUTEX_NORMAL, mutexAttr.type);
111060ff233Sopenharmony_ci}
112060ff233Sopenharmony_ci
113060ff233Sopenharmony_ci/*
114060ff233Sopenharmony_ci* @tc.name: SoftBusMutexInitTest001
115060ff233Sopenharmony_ci* @tc.desc: mutexAttr is nullptr
116060ff233Sopenharmony_ci* @tc.type: FUNC
117060ff233Sopenharmony_ci* @tc.require: 1
118060ff233Sopenharmony_ci*/
119060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexInitTest001, TestSize.Level0)
120060ff233Sopenharmony_ci{
121060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
122060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, nullptr);
123060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
124060ff233Sopenharmony_ci}
125060ff233Sopenharmony_ci
126060ff233Sopenharmony_ci/*
127060ff233Sopenharmony_ci* @tc.name: SoftBusMutexInitTest002
128060ff233Sopenharmony_ci* @tc.desc: mutexAttr type is SOFTBUS_MUTEX_NORMAL
129060ff233Sopenharmony_ci* @tc.type: FUNC
130060ff233Sopenharmony_ci* @tc.require: 1
131060ff233Sopenharmony_ci*/
132060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexInitTest002, TestSize.Level0)
133060ff233Sopenharmony_ci{
134060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
135060ff233Sopenharmony_ci    SoftBusMutexAttr mutexAttr = {
136060ff233Sopenharmony_ci        .type = SOFTBUS_MUTEX_NORMAL,
137060ff233Sopenharmony_ci    };
138060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, &mutexAttr);
139060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
140060ff233Sopenharmony_ci}
141060ff233Sopenharmony_ci
142060ff233Sopenharmony_ci/*
143060ff233Sopenharmony_ci* @tc.name: SoftBusMutexInitTest003
144060ff233Sopenharmony_ci* @tc.desc: mutexAttr type is SOFTBUS_MUTEX_RECURSIVE
145060ff233Sopenharmony_ci* @tc.type: FUNC
146060ff233Sopenharmony_ci* @tc.require: 1
147060ff233Sopenharmony_ci*/
148060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexInitTest003, TestSize.Level0)
149060ff233Sopenharmony_ci{
150060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
151060ff233Sopenharmony_ci    SoftBusMutexAttr mutexAttr = {
152060ff233Sopenharmony_ci        .type = SOFTBUS_MUTEX_RECURSIVE,
153060ff233Sopenharmony_ci    };
154060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, &mutexAttr);
155060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
156060ff233Sopenharmony_ci}
157060ff233Sopenharmony_ci
158060ff233Sopenharmony_ci/*
159060ff233Sopenharmony_ci* @tc.name: SoftBusMutexLockTest001
160060ff233Sopenharmony_ci* @tc.desc: mutex is nullptr
161060ff233Sopenharmony_ci* @tc.type: FUNC
162060ff233Sopenharmony_ci* @tc.require: 1
163060ff233Sopenharmony_ci*/
164060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexLockTest001, TestSize.Level0)
165060ff233Sopenharmony_ci{
166060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexLock(nullptr);
167060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
168060ff233Sopenharmony_ci}
169060ff233Sopenharmony_ci
170060ff233Sopenharmony_ci/*
171060ff233Sopenharmony_ci* @tc.name: SoftBusMutexLockTest002
172060ff233Sopenharmony_ci* @tc.desc: mutexAttr type is SOFTBUS_MUTEX_NORMAL
173060ff233Sopenharmony_ci* @tc.type: FUNC
174060ff233Sopenharmony_ci* @tc.require: 1
175060ff233Sopenharmony_ci*/
176060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexLockTest002, TestSize.Level0)
177060ff233Sopenharmony_ci{
178060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
179060ff233Sopenharmony_ci    SoftBusMutexAttr mutexAttr = {
180060ff233Sopenharmony_ci        .type = SOFTBUS_MUTEX_NORMAL,
181060ff233Sopenharmony_ci    };
182060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, &mutexAttr);
183060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
184060ff233Sopenharmony_ci    ret = SoftBusMutexLock(&mutex);
185060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
186060ff233Sopenharmony_ci}
187060ff233Sopenharmony_ci
188060ff233Sopenharmony_ci/*
189060ff233Sopenharmony_ci* @tc.name: SoftBusMutexLockTest003
190060ff233Sopenharmony_ci* @tc.desc: mutexAttr type is SOFTBUS_MUTEX_RECURSIVE
191060ff233Sopenharmony_ci* @tc.type: FUNC
192060ff233Sopenharmony_ci* @tc.require: 1
193060ff233Sopenharmony_ci*/
194060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexLockTest003, TestSize.Level0)
195060ff233Sopenharmony_ci{
196060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
197060ff233Sopenharmony_ci    SoftBusMutexAttr mutexAttr = {
198060ff233Sopenharmony_ci        .type = SOFTBUS_MUTEX_RECURSIVE,
199060ff233Sopenharmony_ci    };
200060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, &mutexAttr);
201060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
202060ff233Sopenharmony_ci    ret = SoftBusMutexLock(&mutex);
203060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
204060ff233Sopenharmony_ci}
205060ff233Sopenharmony_ci
206060ff233Sopenharmony_ci/*
207060ff233Sopenharmony_ci* @tc.name: SoftBusMutexLockTest004
208060ff233Sopenharmony_ci* @tc.desc: mutex is default
209060ff233Sopenharmony_ci* @tc.type: FUNC
210060ff233Sopenharmony_ci* @tc.require: 1
211060ff233Sopenharmony_ci*/
212060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexLockTest004, TestSize.Level0)
213060ff233Sopenharmony_ci{
214060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
215060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, nullptr);
216060ff233Sopenharmony_ci    ret = SoftBusMutexLock(&mutex);
217060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
218060ff233Sopenharmony_ci}
219060ff233Sopenharmony_ci
220060ff233Sopenharmony_ci/*
221060ff233Sopenharmony_ci* @tc.name: SoftBusMutexLockTest005
222060ff233Sopenharmony_ci* @tc.desc: mutex value is 0
223060ff233Sopenharmony_ci* @tc.type: FUNC
224060ff233Sopenharmony_ci* @tc.require: 1
225060ff233Sopenharmony_ci*/
226060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexLockTest005, TestSize.Level0)
227060ff233Sopenharmony_ci{
228060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
229060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexLock(&mutex);
230060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
231060ff233Sopenharmony_ci}
232060ff233Sopenharmony_ci
233060ff233Sopenharmony_ci/*
234060ff233Sopenharmony_ci* @tc.name: SoftBusMutexUnlockTest001
235060ff233Sopenharmony_ci* @tc.desc: mutex is nullptr
236060ff233Sopenharmony_ci* @tc.type: FUNC
237060ff233Sopenharmony_ci* @tc.require: 1
238060ff233Sopenharmony_ci*/
239060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexUnlockTest001, TestSize.Level0)
240060ff233Sopenharmony_ci{
241060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexUnlock(nullptr);
242060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
243060ff233Sopenharmony_ci}
244060ff233Sopenharmony_ci
245060ff233Sopenharmony_ci/*
246060ff233Sopenharmony_ci* @tc.name: SoftBusMutexUnlockTest002
247060ff233Sopenharmony_ci* @tc.desc: mutex value is 0
248060ff233Sopenharmony_ci* @tc.type: FUNC
249060ff233Sopenharmony_ci* @tc.require: 1
250060ff233Sopenharmony_ci*/
251060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexUnlockTest002, TestSize.Level0)
252060ff233Sopenharmony_ci{
253060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
254060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexUnlock(&mutex);
255060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
256060ff233Sopenharmony_ci}
257060ff233Sopenharmony_ci
258060ff233Sopenharmony_ci/*
259060ff233Sopenharmony_ci* @tc.name: SoftBusMutexUnlockTest003
260060ff233Sopenharmony_ci* @tc.desc: mutexAttr type is SOFTBUS_MUTEX_NORMAL
261060ff233Sopenharmony_ci* @tc.type: FUNC
262060ff233Sopenharmony_ci* @tc.require: 1
263060ff233Sopenharmony_ci*/
264060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexUnlockTest003, TestSize.Level0)
265060ff233Sopenharmony_ci{
266060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
267060ff233Sopenharmony_ci    SoftBusMutexAttr mutexAttr = {
268060ff233Sopenharmony_ci        .type = SOFTBUS_MUTEX_NORMAL,
269060ff233Sopenharmony_ci    };
270060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, &mutexAttr);
271060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
272060ff233Sopenharmony_ci    ret = SoftBusMutexLock(&mutex);
273060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
274060ff233Sopenharmony_ci    ret = SoftBusMutexUnlock(&mutex);
275060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
276060ff233Sopenharmony_ci}
277060ff233Sopenharmony_ci
278060ff233Sopenharmony_ci/*
279060ff233Sopenharmony_ci* @tc.name: SoftBusMutexUnlockTest004
280060ff233Sopenharmony_ci* @tc.desc: mutexAttr type is SOFTBUS_MUTEX_NORMAL
281060ff233Sopenharmony_ci* @tc.type: FUNC
282060ff233Sopenharmony_ci* @tc.require: 1
283060ff233Sopenharmony_ci*/
284060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexUnlockTest004, TestSize.Level0)
285060ff233Sopenharmony_ci{
286060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
287060ff233Sopenharmony_ci    SoftBusMutexAttr mutexAttr = {
288060ff233Sopenharmony_ci        .type = SOFTBUS_MUTEX_RECURSIVE,
289060ff233Sopenharmony_ci    };
290060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, &mutexAttr);
291060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
292060ff233Sopenharmony_ci    ret = SoftBusMutexLock(&mutex);
293060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
294060ff233Sopenharmony_ci    ret = SoftBusMutexUnlock(&mutex);
295060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
296060ff233Sopenharmony_ci}
297060ff233Sopenharmony_ci
298060ff233Sopenharmony_ci/*
299060ff233Sopenharmony_ci* @tc.name: SoftBusMutexUnlockTest005
300060ff233Sopenharmony_ci* @tc.desc: mutex value is default
301060ff233Sopenharmony_ci* @tc.type: FUNC
302060ff233Sopenharmony_ci* @tc.require: 1
303060ff233Sopenharmony_ci*/
304060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexUnlockTest005, TestSize.Level0)
305060ff233Sopenharmony_ci{
306060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
307060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, nullptr);
308060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
309060ff233Sopenharmony_ci    ret = SoftBusMutexLock(&mutex);
310060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
311060ff233Sopenharmony_ci    ret = SoftBusMutexUnlock(&mutex);
312060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
313060ff233Sopenharmony_ci}
314060ff233Sopenharmony_ci
315060ff233Sopenharmony_ci/*
316060ff233Sopenharmony_ci* @tc.name: SoftBusMutexDestroyTest001
317060ff233Sopenharmony_ci* @tc.desc: mutex is nullptr
318060ff233Sopenharmony_ci* @tc.type: FUNC
319060ff233Sopenharmony_ci* @tc.require: 1
320060ff233Sopenharmony_ci*/
321060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexDestroyTest001, TestSize.Level0)
322060ff233Sopenharmony_ci{
323060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexDestroy(nullptr);
324060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
325060ff233Sopenharmony_ci}
326060ff233Sopenharmony_ci
327060ff233Sopenharmony_ci/*
328060ff233Sopenharmony_ci* @tc.name: SoftBusMutexDestroyTest002
329060ff233Sopenharmony_ci* @tc.desc: mutex value is 0
330060ff233Sopenharmony_ci* @tc.type: FUNC
331060ff233Sopenharmony_ci* @tc.require: 1
332060ff233Sopenharmony_ci*/
333060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexDestroyTest002, TestSize.Level0)
334060ff233Sopenharmony_ci{
335060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
336060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexDestroy(&mutex);
337060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
338060ff233Sopenharmony_ci}
339060ff233Sopenharmony_ci
340060ff233Sopenharmony_ci/*
341060ff233Sopenharmony_ci* @tc.name: SoftBusMutexDestroyTest003
342060ff233Sopenharmony_ci* @tc.desc: mutexAttr is nullptr
343060ff233Sopenharmony_ci* @tc.type: FUNC
344060ff233Sopenharmony_ci* @tc.require: 1
345060ff233Sopenharmony_ci*/
346060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexDestroyTest003, TestSize.Level0)
347060ff233Sopenharmony_ci{
348060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
349060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, nullptr);
350060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
351060ff233Sopenharmony_ci
352060ff233Sopenharmony_ci    ret = SoftBusMutexDestroy(&mutex);
353060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
354060ff233Sopenharmony_ci}
355060ff233Sopenharmony_ci
356060ff233Sopenharmony_ci/*
357060ff233Sopenharmony_ci* @tc.name: SoftBusMutexDestroyTest004
358060ff233Sopenharmony_ci* @tc.desc: mutexAttr is SOFTBUS_MUTEX_NORMAL
359060ff233Sopenharmony_ci* @tc.type: FUNC
360060ff233Sopenharmony_ci* @tc.require: 1
361060ff233Sopenharmony_ci*/
362060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexDestroyTest004, TestSize.Level0)
363060ff233Sopenharmony_ci{
364060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
365060ff233Sopenharmony_ci    SoftBusMutexAttr mutexAttr = {
366060ff233Sopenharmony_ci        .type = SOFTBUS_MUTEX_NORMAL,
367060ff233Sopenharmony_ci    };
368060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, &mutexAttr);
369060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
370060ff233Sopenharmony_ci
371060ff233Sopenharmony_ci    ret = SoftBusMutexDestroy(&mutex);
372060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
373060ff233Sopenharmony_ci}
374060ff233Sopenharmony_ci
375060ff233Sopenharmony_ci/*
376060ff233Sopenharmony_ci* @tc.name: SoftBusMutexDestroyTest005
377060ff233Sopenharmony_ci* @tc.desc: mutexAttr is SOFTBUS_MUTEX_RECURSIVE
378060ff233Sopenharmony_ci* @tc.type: FUNC
379060ff233Sopenharmony_ci* @tc.require: 1
380060ff233Sopenharmony_ci*/
381060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexDestroyTest005, TestSize.Level0)
382060ff233Sopenharmony_ci{
383060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
384060ff233Sopenharmony_ci    SoftBusMutexAttr mutexAttr = {
385060ff233Sopenharmony_ci        .type = SOFTBUS_MUTEX_RECURSIVE,
386060ff233Sopenharmony_ci    };
387060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, &mutexAttr);
388060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
389060ff233Sopenharmony_ci
390060ff233Sopenharmony_ci    ret = SoftBusMutexDestroy(&mutex);
391060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
392060ff233Sopenharmony_ci}
393060ff233Sopenharmony_ci
394060ff233Sopenharmony_ci/*
395060ff233Sopenharmony_ci * @tc.name: SoftBusMutexLockGuardTest001
396060ff233Sopenharmony_ci * @tc.desc: should call SoftBusMutexUnlock automatically when leave bracket scope
397060ff233Sopenharmony_ci * @tc.type: FUNC
398060ff233Sopenharmony_ci * @tc.require:
399060ff233Sopenharmony_ci */
400060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusMutexLockGuardTest001, TestSize.Level0)
401060ff233Sopenharmony_ci{
402060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
403060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, nullptr);
404060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
405060ff233Sopenharmony_ci    {
406060ff233Sopenharmony_ci        ret = SoftBusMutexLock(&mutex);
407060ff233Sopenharmony_ci        EXPECT_EQ(SOFTBUS_OK, ret);
408060ff233Sopenharmony_ci        SOFTBUS_LOCK_GUARD(mutex);
409060ff233Sopenharmony_ci    }
410060ff233Sopenharmony_ci    {
411060ff233Sopenharmony_ci        ret = SoftBusMutexLock(&mutex);
412060ff233Sopenharmony_ci        EXPECT_EQ(SOFTBUS_OK, ret);
413060ff233Sopenharmony_ci        SOFTBUS_LOCK_GUARD(mutex);
414060ff233Sopenharmony_ci    }
415060ff233Sopenharmony_ci    ret = SoftBusMutexDestroy(&mutex);
416060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
417060ff233Sopenharmony_ci}
418060ff233Sopenharmony_ci
419060ff233Sopenharmony_ci/*
420060ff233Sopenharmony_ci* @tc.name: SoftBusThreadAttrInitTest001
421060ff233Sopenharmony_ci* @tc.desc: threadAttr is nullptr
422060ff233Sopenharmony_ci* @tc.type: FUNC
423060ff233Sopenharmony_ci* @tc.require: 1
424060ff233Sopenharmony_ci*/
425060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadAttrInitTest001, TestSize.Level0)
426060ff233Sopenharmony_ci{
427060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(nullptr);
428060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
429060ff233Sopenharmony_ci}
430060ff233Sopenharmony_ci
431060ff233Sopenharmony_ci/*
432060ff233Sopenharmony_ci* @tc.name: SoftBusThreadAttrInitTest002
433060ff233Sopenharmony_ci* @tc.desc: threadAttr is valid
434060ff233Sopenharmony_ci* @tc.type: FUNC
435060ff233Sopenharmony_ci* @tc.require: 1
436060ff233Sopenharmony_ci*/
437060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadAttrInitTest002, TestSize.Level0)
438060ff233Sopenharmony_ci{
439060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
440060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
441060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
442060ff233Sopenharmony_ci}
443060ff233Sopenharmony_ci
444060ff233Sopenharmony_ci/*
445060ff233Sopenharmony_ci* @tc.name: SoftBusThreadCreateTest001
446060ff233Sopenharmony_ci* @tc.desc: thread is nullptr
447060ff233Sopenharmony_ci* @tc.type: FUNC
448060ff233Sopenharmony_ci* @tc.require: 1
449060ff233Sopenharmony_ci*/
450060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadCreateTest001, TestSize.Level0)
451060ff233Sopenharmony_ci{
452060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
453060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
454060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
455060ff233Sopenharmony_ci
456060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(nullptr, &threadAttr, SoftBusThreadTask, nullptr);
457060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
458060ff233Sopenharmony_ci}
459060ff233Sopenharmony_ci
460060ff233Sopenharmony_ci/*
461060ff233Sopenharmony_ci* @tc.name: SoftBusThreadCreateTest002
462060ff233Sopenharmony_ci* @tc.desc: threadAttr is nullptr
463060ff233Sopenharmony_ci* @tc.type: FUNC
464060ff233Sopenharmony_ci* @tc.require: 1
465060ff233Sopenharmony_ci*/
466060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadCreateTest002, TestSize.Level0)
467060ff233Sopenharmony_ci{
468060ff233Sopenharmony_ci    SoftBusThread thread = 0;
469060ff233Sopenharmony_ci
470060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadCreate(&thread, nullptr, SoftBusThreadTask, nullptr);
471060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
472060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
473060ff233Sopenharmony_ci}
474060ff233Sopenharmony_ci
475060ff233Sopenharmony_ci/*
476060ff233Sopenharmony_ci* @tc.name: SoftBusThreadCreateTest003
477060ff233Sopenharmony_ci* @tc.desc: threadAttr is valid
478060ff233Sopenharmony_ci* @tc.type: FUNC
479060ff233Sopenharmony_ci* @tc.require: 1
480060ff233Sopenharmony_ci*/
481060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadCreateTest003, TestSize.Level0)
482060ff233Sopenharmony_ci{
483060ff233Sopenharmony_ci    SoftBusThread thread = 0;
484060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
485060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
486060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
487060ff233Sopenharmony_ci
488060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
489060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
490060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
491060ff233Sopenharmony_ci}
492060ff233Sopenharmony_ci
493060ff233Sopenharmony_ci#if HAVE_PRO
494060ff233Sopenharmony_ci/*
495060ff233Sopenharmony_ci* @tc.name: SoftBusThreadCreateTest004
496060ff233Sopenharmony_ci* @tc.desc: threadAttr add taskName
497060ff233Sopenharmony_ci* @tc.type: FUNC
498060ff233Sopenharmony_ci* @tc.require: 1
499060ff233Sopenharmony_ci*/
500060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadCreateTest004, TestSize.Level0)
501060ff233Sopenharmony_ci{
502060ff233Sopenharmony_ci    SoftBusThread thread = 0;
503060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
504060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
505060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
506060ff233Sopenharmony_ci
507060ff233Sopenharmony_ci    threadAttr.taskName = "ThreadTask";
508060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
509060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ERR, ret);
510060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
511060ff233Sopenharmony_ci}
512060ff233Sopenharmony_ci#endif
513060ff233Sopenharmony_ci
514060ff233Sopenharmony_ci/*
515060ff233Sopenharmony_ci* @tc.name: SoftBusThreadCreateTest005
516060ff233Sopenharmony_ci* @tc.desc: threadAttr modify prior
517060ff233Sopenharmony_ci* @tc.type: FUNC
518060ff233Sopenharmony_ci* @tc.require: 1
519060ff233Sopenharmony_ci*/
520060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadCreateTest005, TestSize.Level0)
521060ff233Sopenharmony_ci{
522060ff233Sopenharmony_ci    SoftBusThread thread = 0;
523060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
524060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
525060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
526060ff233Sopenharmony_ci
527060ff233Sopenharmony_ci    threadAttr.prior = SOFTBUS_PRIORITY_HIGHEST;
528060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
529060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
530060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
531060ff233Sopenharmony_ci}
532060ff233Sopenharmony_ci
533060ff233Sopenharmony_ci/*
534060ff233Sopenharmony_ci* @tc.name: SoftBusThreadCreateTest006
535060ff233Sopenharmony_ci* @tc.desc: threadAttr modify prior
536060ff233Sopenharmony_ci* @tc.type: FUNC
537060ff233Sopenharmony_ci* @tc.require: 1
538060ff233Sopenharmony_ci*/
539060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadCreateTest006, TestSize.Level0)
540060ff233Sopenharmony_ci{
541060ff233Sopenharmony_ci    SoftBusThread thread = 0;
542060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
543060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
544060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
545060ff233Sopenharmony_ci
546060ff233Sopenharmony_ci    threadAttr.prior = SOFTBUS_PRIORITY_HIGH;
547060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
548060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
549060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
550060ff233Sopenharmony_ci}
551060ff233Sopenharmony_ci
552060ff233Sopenharmony_ci/*
553060ff233Sopenharmony_ci* @tc.name: SoftBusThreadCreateTest007
554060ff233Sopenharmony_ci* @tc.desc: threadAttr modify prior
555060ff233Sopenharmony_ci* @tc.type: FUNC
556060ff233Sopenharmony_ci* @tc.require: 1
557060ff233Sopenharmony_ci*/
558060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadCreateTest007, TestSize.Level0)
559060ff233Sopenharmony_ci{
560060ff233Sopenharmony_ci    SoftBusThread thread = 0;
561060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
562060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
563060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
564060ff233Sopenharmony_ci
565060ff233Sopenharmony_ci    threadAttr.prior = SOFTBUS_PRIORITY_DEFAULT;
566060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
567060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
568060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
569060ff233Sopenharmony_ci}
570060ff233Sopenharmony_ci
571060ff233Sopenharmony_ci/*
572060ff233Sopenharmony_ci* @tc.name: SoftBusThreadCreateTest008
573060ff233Sopenharmony_ci* @tc.desc: threadAttr modify prior
574060ff233Sopenharmony_ci* @tc.type: FUNC
575060ff233Sopenharmony_ci* @tc.require: 1
576060ff233Sopenharmony_ci*/
577060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadCreateTest008, TestSize.Level0)
578060ff233Sopenharmony_ci{
579060ff233Sopenharmony_ci    SoftBusThread thread = 0;
580060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
581060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
582060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
583060ff233Sopenharmony_ci
584060ff233Sopenharmony_ci    threadAttr.prior = SOFTBUS_PRIORITY_LOW;
585060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
586060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
587060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
588060ff233Sopenharmony_ci}
589060ff233Sopenharmony_ci
590060ff233Sopenharmony_ci/*
591060ff233Sopenharmony_ci* @tc.name: SoftBusThreadCreateTest009
592060ff233Sopenharmony_ci* @tc.desc: threadAttr modify prior
593060ff233Sopenharmony_ci* @tc.type: FUNC
594060ff233Sopenharmony_ci* @tc.require: 1
595060ff233Sopenharmony_ci*/
596060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadCreateTest009, TestSize.Level0)
597060ff233Sopenharmony_ci{
598060ff233Sopenharmony_ci    SoftBusThread thread = 0;
599060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
600060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
601060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
602060ff233Sopenharmony_ci
603060ff233Sopenharmony_ci    threadAttr.prior = SOFTBUS_PRIORITY_LOWEST;
604060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
605060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
606060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
607060ff233Sopenharmony_ci}
608060ff233Sopenharmony_ci
609060ff233Sopenharmony_ci#if HAVE_PRO
610060ff233Sopenharmony_ci/*
611060ff233Sopenharmony_ci* @tc.name: SoftBusThreadCreateTest010
612060ff233Sopenharmony_ci* @tc.desc: threadEntry is nullptr
613060ff233Sopenharmony_ci* @tc.type: FUNC
614060ff233Sopenharmony_ci* @tc.require: 1
615060ff233Sopenharmony_ci*/
616060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadCreateTest010, TestSize.Level0)
617060ff233Sopenharmony_ci{
618060ff233Sopenharmony_ci    SoftBusThread thread = 0;
619060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
620060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
621060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
622060ff233Sopenharmony_ci
623060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, nullptr, nullptr);
624060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ERR, ret);
625060ff233Sopenharmony_ci}
626060ff233Sopenharmony_ci
627060ff233Sopenharmony_ci/*
628060ff233Sopenharmony_ci* @tc.name: SoftBusThreadSetNameTest001
629060ff233Sopenharmony_ci* @tc.desc: name is nullptr
630060ff233Sopenharmony_ci* @tc.type: FUNC
631060ff233Sopenharmony_ci* @tc.require: 1
632060ff233Sopenharmony_ci*/
633060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadSetNameTest001, TestSize.Level0)
634060ff233Sopenharmony_ci{
635060ff233Sopenharmony_ci    SoftBusThread thread = 0;
636060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
637060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
638060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
639060ff233Sopenharmony_ci
640060ff233Sopenharmony_ci    threadAttr.prior = SOFTBUS_PRIORITY_HIGHEST;
641060ff233Sopenharmony_ci
642060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
643060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
644060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
645060ff233Sopenharmony_ci
646060ff233Sopenharmony_ci    ret = SoftBusThreadSetName(thread, nullptr);
647060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
648060ff233Sopenharmony_ci}
649060ff233Sopenharmony_ci
650060ff233Sopenharmony_ci/*
651060ff233Sopenharmony_ci* @tc.name: SoftBusThreadSetNameTest002
652060ff233Sopenharmony_ci* @tc.desc: name is large than TASK_NAME_MAX_LEN
653060ff233Sopenharmony_ci* @tc.type: FUNC
654060ff233Sopenharmony_ci* @tc.require: 1
655060ff233Sopenharmony_ci*/
656060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadSetNameTest002, TestSize.Level0)
657060ff233Sopenharmony_ci{
658060ff233Sopenharmony_ci    const char *name = "abcdefghijklmnopqrstuvwxyz";
659060ff233Sopenharmony_ci    SoftBusThread thread = 0;
660060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
661060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
662060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
663060ff233Sopenharmony_ci
664060ff233Sopenharmony_ci    threadAttr.prior = SOFTBUS_PRIORITY_HIGHEST;
665060ff233Sopenharmony_ci
666060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
667060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
668060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
669060ff233Sopenharmony_ci
670060ff233Sopenharmony_ci    ret = SoftBusThreadSetName(thread, name);
671060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
672060ff233Sopenharmony_ci}
673060ff233Sopenharmony_ci
674060ff233Sopenharmony_ci/*
675060ff233Sopenharmony_ci* @tc.name: SoftBusThreadSetNameTest003
676060ff233Sopenharmony_ci* @tc.desc: name is equal to TASK_NAME_MAX_LEN
677060ff233Sopenharmony_ci* @tc.type: FUNC
678060ff233Sopenharmony_ci* @tc.require: 1
679060ff233Sopenharmony_ci*/
680060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadSetNameTest003, TestSize.Level0)
681060ff233Sopenharmony_ci{
682060ff233Sopenharmony_ci    const char *name = "abcdefghijklmnop";
683060ff233Sopenharmony_ci    SoftBusThread thread = 0;
684060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
685060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
686060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
687060ff233Sopenharmony_ci
688060ff233Sopenharmony_ci    threadAttr.prior = SOFTBUS_PRIORITY_HIGHEST;
689060ff233Sopenharmony_ci
690060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
691060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
692060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
693060ff233Sopenharmony_ci
694060ff233Sopenharmony_ci    ret = SoftBusThreadSetName(thread, name);
695060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
696060ff233Sopenharmony_ci}
697060ff233Sopenharmony_ci
698060ff233Sopenharmony_ci/*
699060ff233Sopenharmony_ci* @tc.name: SoftBusThreadSetNameTest004
700060ff233Sopenharmony_ci* @tc.desc: name include chinese character
701060ff233Sopenharmony_ci* @tc.type: FUNC
702060ff233Sopenharmony_ci* @tc.require: 1
703060ff233Sopenharmony_ci*/
704060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadSetNameTest004, TestSize.Level0)
705060ff233Sopenharmony_ci{
706060ff233Sopenharmony_ci    const char *name = "a中文p";
707060ff233Sopenharmony_ci    SoftBusThread thread = 0;
708060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
709060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
710060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
711060ff233Sopenharmony_ci
712060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
713060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
714060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
715060ff233Sopenharmony_ci
716060ff233Sopenharmony_ci    ret = SoftBusThreadSetName(thread, name);
717060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ERR, ret);
718060ff233Sopenharmony_ci}
719060ff233Sopenharmony_ci
720060ff233Sopenharmony_ci/*
721060ff233Sopenharmony_ci* @tc.name: SoftBusThreadSetNameTest005
722060ff233Sopenharmony_ci* @tc.desc: name is valid
723060ff233Sopenharmony_ci* @tc.type: FUNC
724060ff233Sopenharmony_ci* @tc.require: 1
725060ff233Sopenharmony_ci*/
726060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadSetNameTest005, TestSize.Level0)
727060ff233Sopenharmony_ci{
728060ff233Sopenharmony_ci    const char *name = "testThread";
729060ff233Sopenharmony_ci    SoftBusThread thread = 0;
730060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
731060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
732060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
733060ff233Sopenharmony_ci
734060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
735060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
736060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
737060ff233Sopenharmony_ci
738060ff233Sopenharmony_ci    ret = SoftBusThreadSetName(thread, name);
739060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ERR, ret);
740060ff233Sopenharmony_ci}
741060ff233Sopenharmony_ci
742060ff233Sopenharmony_ci/*
743060ff233Sopenharmony_ci* @tc.name: SoftBusThreadSetNameTest006
744060ff233Sopenharmony_ci* @tc.desc: threadAttr is nullptr, name is valid
745060ff233Sopenharmony_ci* @tc.type: FUNC
746060ff233Sopenharmony_ci* @tc.require: 1
747060ff233Sopenharmony_ci*/
748060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadSetNameTest006, TestSize.Level0)
749060ff233Sopenharmony_ci{
750060ff233Sopenharmony_ci    const char *name = "testThread";
751060ff233Sopenharmony_ci    SoftBusThread thread = 0;
752060ff233Sopenharmony_ci
753060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadCreate(&thread, nullptr, SoftBusThreadTask, nullptr);
754060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
755060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
756060ff233Sopenharmony_ci
757060ff233Sopenharmony_ci    ret = SoftBusThreadSetName(thread, name);
758060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_ERR, ret);
759060ff233Sopenharmony_ci}
760060ff233Sopenharmony_ci#endif
761060ff233Sopenharmony_ci
762060ff233Sopenharmony_ci/*
763060ff233Sopenharmony_ci* @tc.name: SoftBusThreadGetSelfTest001
764060ff233Sopenharmony_ci* @tc.desc: threadAttr modify prior
765060ff233Sopenharmony_ci* @tc.type: FUNC
766060ff233Sopenharmony_ci* @tc.require: 1
767060ff233Sopenharmony_ci*/
768060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadGetSelfTest001, TestSize.Level0)
769060ff233Sopenharmony_ci{
770060ff233Sopenharmony_ci    SoftBusThread thread = 0;
771060ff233Sopenharmony_ci
772060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadCreate(&thread, NULL, ThreadSelfTest, nullptr);
773060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
774060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
775060ff233Sopenharmony_ci}
776060ff233Sopenharmony_ci
777060ff233Sopenharmony_ci/*
778060ff233Sopenharmony_ci* @tc.name: SoftBusCondInitTest001
779060ff233Sopenharmony_ci* @tc.desc: cond is nullptr
780060ff233Sopenharmony_ci* @tc.type: FUNC
781060ff233Sopenharmony_ci* @tc.require: 1
782060ff233Sopenharmony_ci*/
783060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondInitTest001, TestSize.Level0)
784060ff233Sopenharmony_ci{
785060ff233Sopenharmony_ci    int32_t ret = SoftBusCondInit(nullptr);
786060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
787060ff233Sopenharmony_ci}
788060ff233Sopenharmony_ci
789060ff233Sopenharmony_ci/*
790060ff233Sopenharmony_ci* @tc.name: SoftBusCondInitTest002
791060ff233Sopenharmony_ci* @tc.desc: cond is valid
792060ff233Sopenharmony_ci* @tc.type: FUNC
793060ff233Sopenharmony_ci* @tc.require: 1
794060ff233Sopenharmony_ci*/
795060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondInitTest002, TestSize.Level0)
796060ff233Sopenharmony_ci{
797060ff233Sopenharmony_ci    SoftBusCond cond = 0;
798060ff233Sopenharmony_ci    int32_t ret = SoftBusCondInit(&cond);
799060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
800060ff233Sopenharmony_ci    EXPECT_TRUE(cond != 0);
801060ff233Sopenharmony_ci}
802060ff233Sopenharmony_ci
803060ff233Sopenharmony_ci/*
804060ff233Sopenharmony_ci* @tc.name: SoftBusCondSignalTest001
805060ff233Sopenharmony_ci* @tc.desc: cond is nullptr
806060ff233Sopenharmony_ci* @tc.type: FUNC
807060ff233Sopenharmony_ci* @tc.require: 1
808060ff233Sopenharmony_ci*/
809060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondSignalTest001, TestSize.Level0)
810060ff233Sopenharmony_ci{
811060ff233Sopenharmony_ci    int32_t ret = SoftBusCondSignal(nullptr);
812060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
813060ff233Sopenharmony_ci}
814060ff233Sopenharmony_ci
815060ff233Sopenharmony_ci/*
816060ff233Sopenharmony_ci* @tc.name: SoftBusCondSignalTest002
817060ff233Sopenharmony_ci* @tc.desc: no wait thread
818060ff233Sopenharmony_ci* @tc.type: FUNC
819060ff233Sopenharmony_ci* @tc.require: 1
820060ff233Sopenharmony_ci*/
821060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondSignalTest002, TestSize.Level0)
822060ff233Sopenharmony_ci{
823060ff233Sopenharmony_ci    SoftBusCond cond = 0;
824060ff233Sopenharmony_ci    int32_t ret = SoftBusCondSignal(&cond);
825060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
826060ff233Sopenharmony_ci}
827060ff233Sopenharmony_ci
828060ff233Sopenharmony_ci/*
829060ff233Sopenharmony_ci* @tc.name: SoftBusCondSignalTest003
830060ff233Sopenharmony_ci* @tc.desc: no wait thread
831060ff233Sopenharmony_ci* @tc.type: FUNC
832060ff233Sopenharmony_ci* @tc.require: 1
833060ff233Sopenharmony_ci*/
834060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondSignalTest003, TestSize.Level0)
835060ff233Sopenharmony_ci{
836060ff233Sopenharmony_ci    SoftBusCond cond = 0;
837060ff233Sopenharmony_ci    int32_t ret = SoftBusCondInit(&cond);
838060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
839060ff233Sopenharmony_ci    EXPECT_TRUE(cond != 0);
840060ff233Sopenharmony_ci    ret = SoftBusCondSignal(&cond);
841060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
842060ff233Sopenharmony_ci}
843060ff233Sopenharmony_ci
844060ff233Sopenharmony_ci/*
845060ff233Sopenharmony_ci* @tc.name: SoftBusCondBroadcastTest001
846060ff233Sopenharmony_ci* @tc.desc: cond is nullptr
847060ff233Sopenharmony_ci* @tc.type: FUNC
848060ff233Sopenharmony_ci* @tc.require: 1
849060ff233Sopenharmony_ci*/
850060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondBroadcastTest001, TestSize.Level0)
851060ff233Sopenharmony_ci{
852060ff233Sopenharmony_ci    int32_t ret = SoftBusCondBroadcast(nullptr);
853060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
854060ff233Sopenharmony_ci}
855060ff233Sopenharmony_ci
856060ff233Sopenharmony_ci/*
857060ff233Sopenharmony_ci* @tc.name: SoftBusCondBroadcastTest002
858060ff233Sopenharmony_ci* @tc.desc: cond is not init
859060ff233Sopenharmony_ci* @tc.type: FUNC
860060ff233Sopenharmony_ci* @tc.require: 1
861060ff233Sopenharmony_ci*/
862060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondBroadcastTest002, TestSize.Level0)
863060ff233Sopenharmony_ci{
864060ff233Sopenharmony_ci    SoftBusCond cond = 0;
865060ff233Sopenharmony_ci
866060ff233Sopenharmony_ci    int32_t ret = SoftBusCondBroadcast(&cond);
867060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
868060ff233Sopenharmony_ci}
869060ff233Sopenharmony_ci
870060ff233Sopenharmony_ci/*
871060ff233Sopenharmony_ci* @tc.name: SoftBusCondBroadcastTest003
872060ff233Sopenharmony_ci* @tc.desc: cond is init value
873060ff233Sopenharmony_ci* @tc.type: FUNC
874060ff233Sopenharmony_ci* @tc.require: 1
875060ff233Sopenharmony_ci*/
876060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondBroadcastTest003, TestSize.Level0)
877060ff233Sopenharmony_ci{
878060ff233Sopenharmony_ci    SoftBusCond cond = 0;
879060ff233Sopenharmony_ci    int32_t ret = SoftBusCondInit(&cond);
880060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
881060ff233Sopenharmony_ci    EXPECT_TRUE(cond != 0);
882060ff233Sopenharmony_ci
883060ff233Sopenharmony_ci    ret = SoftBusCondBroadcast(&cond);
884060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
885060ff233Sopenharmony_ci}
886060ff233Sopenharmony_ci
887060ff233Sopenharmony_ci/*
888060ff233Sopenharmony_ci* @tc.name: SoftBusCondWaitTest001
889060ff233Sopenharmony_ci* @tc.desc: cond is nullptr
890060ff233Sopenharmony_ci* @tc.type: FUNC
891060ff233Sopenharmony_ci* @tc.require: 1
892060ff233Sopenharmony_ci*/
893060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondWaitTest001, TestSize.Level0)
894060ff233Sopenharmony_ci{
895060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
896060ff233Sopenharmony_ci    SoftBusMutexAttr mutexAttr = {
897060ff233Sopenharmony_ci        .type = SOFTBUS_MUTEX_NORMAL,
898060ff233Sopenharmony_ci    };
899060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, &mutexAttr);
900060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
901060ff233Sopenharmony_ci    ret = SoftBusCondWait(nullptr, &mutex, nullptr);
902060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
903060ff233Sopenharmony_ci}
904060ff233Sopenharmony_ci
905060ff233Sopenharmony_ci/*
906060ff233Sopenharmony_ci* @tc.name: SoftBusCondWaitTest002
907060ff233Sopenharmony_ci* @tc.desc: cond value is invalid
908060ff233Sopenharmony_ci* @tc.type: FUNC
909060ff233Sopenharmony_ci* @tc.require: 1
910060ff233Sopenharmony_ci*/
911060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondWaitTest002, TestSize.Level0)
912060ff233Sopenharmony_ci{
913060ff233Sopenharmony_ci    SoftBusCond cond = 0;
914060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
915060ff233Sopenharmony_ci    SoftBusMutexAttr mutexAttr = {
916060ff233Sopenharmony_ci        .type = SOFTBUS_MUTEX_NORMAL,
917060ff233Sopenharmony_ci    };
918060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&mutex, &mutexAttr);
919060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
920060ff233Sopenharmony_ci    ret = SoftBusCondWait(&cond, &mutex, nullptr);
921060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
922060ff233Sopenharmony_ci}
923060ff233Sopenharmony_ci
924060ff233Sopenharmony_ci/*
925060ff233Sopenharmony_ci* @tc.name: SoftBusCondWaitTest003
926060ff233Sopenharmony_ci* @tc.desc: mutex is nullptr
927060ff233Sopenharmony_ci* @tc.type: FUNC
928060ff233Sopenharmony_ci* @tc.require: 1
929060ff233Sopenharmony_ci*/
930060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondWaitTest003, TestSize.Level0)
931060ff233Sopenharmony_ci{
932060ff233Sopenharmony_ci    SoftBusCond cond = 0;
933060ff233Sopenharmony_ci    int32_t ret = SoftBusCondInit(&cond);
934060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
935060ff233Sopenharmony_ci    EXPECT_TRUE(cond != 0);
936060ff233Sopenharmony_ci    ret = SoftBusCondWait(&cond, nullptr, nullptr);
937060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
938060ff233Sopenharmony_ci}
939060ff233Sopenharmony_ci
940060ff233Sopenharmony_ci/*
941060ff233Sopenharmony_ci* @tc.name: SoftBusCondWaitTest004
942060ff233Sopenharmony_ci* @tc.desc: mutex value is invalid
943060ff233Sopenharmony_ci* @tc.type: FUNC
944060ff233Sopenharmony_ci* @tc.require: 1
945060ff233Sopenharmony_ci*/
946060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondWaitTest004, TestSize.Level0)
947060ff233Sopenharmony_ci{
948060ff233Sopenharmony_ci    SoftBusCond cond = 0;
949060ff233Sopenharmony_ci    SoftBusMutex mutex = 0;
950060ff233Sopenharmony_ci    int32_t ret = SoftBusCondInit(&cond);
951060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
952060ff233Sopenharmony_ci    EXPECT_TRUE(cond != 0);
953060ff233Sopenharmony_ci
954060ff233Sopenharmony_ci    ret = SoftBusCondWait(&cond, &mutex, nullptr);
955060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
956060ff233Sopenharmony_ci}
957060ff233Sopenharmony_ci
958060ff233Sopenharmony_ci/*
959060ff233Sopenharmony_ci* @tc.name: SoftBusCondDestroyTest001
960060ff233Sopenharmony_ci* @tc.desc: cond is null
961060ff233Sopenharmony_ci* @tc.type: FUNC
962060ff233Sopenharmony_ci* @tc.require: 1
963060ff233Sopenharmony_ci*/
964060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondDestroyTest001, TestSize.Level0)
965060ff233Sopenharmony_ci{
966060ff233Sopenharmony_ci    int32_t ret = SoftBusCondDestroy(nullptr);
967060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
968060ff233Sopenharmony_ci}
969060ff233Sopenharmony_ci
970060ff233Sopenharmony_ci/*
971060ff233Sopenharmony_ci* @tc.name: SoftBusCondDestroyTest002
972060ff233Sopenharmony_ci* @tc.desc: cond is valid
973060ff233Sopenharmony_ci* @tc.type: FUNC
974060ff233Sopenharmony_ci* @tc.require: 1
975060ff233Sopenharmony_ci*/
976060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondDestroyTest002, TestSize.Level0)
977060ff233Sopenharmony_ci{
978060ff233Sopenharmony_ci    SoftBusCond cond = 0;
979060ff233Sopenharmony_ci    int32_t ret = SoftBusCondInit(&cond);
980060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
981060ff233Sopenharmony_ci    EXPECT_TRUE(cond != 0);
982060ff233Sopenharmony_ci
983060ff233Sopenharmony_ci    ret = SoftBusCondDestroy(&cond);
984060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
985060ff233Sopenharmony_ci}
986060ff233Sopenharmony_ci
987060ff233Sopenharmony_ci/*
988060ff233Sopenharmony_ci* @tc.name: SoftBusCondDestroyTest003
989060ff233Sopenharmony_ci* @tc.desc: cond is valid
990060ff233Sopenharmony_ci* @tc.type: FUNC
991060ff233Sopenharmony_ci* @tc.require: 1
992060ff233Sopenharmony_ci*/
993060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusCondDestroyTest003, TestSize.Level0)
994060ff233Sopenharmony_ci{
995060ff233Sopenharmony_ci    SoftBusCond cond = 0;
996060ff233Sopenharmony_ci    int32_t ret = SoftBusCondDestroy(&cond);
997060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
998060ff233Sopenharmony_ci}
999060ff233Sopenharmony_ci
1000060ff233Sopenharmony_ci/*
1001060ff233Sopenharmony_ci* @tc.name: SoftBusThreadJoinTest001
1002060ff233Sopenharmony_ci* @tc.desc: value is nullptr
1003060ff233Sopenharmony_ci* @tc.type: FUNC
1004060ff233Sopenharmony_ci* @tc.require: 1
1005060ff233Sopenharmony_ci*/
1006060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadJoinTest001, TestSize.Level0)
1007060ff233Sopenharmony_ci{
1008060ff233Sopenharmony_ci    SoftBusThread thread = 0;
1009060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
1010060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
1011060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1012060ff233Sopenharmony_ci
1013060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
1014060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1015060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
1016060ff233Sopenharmony_ci    ret = SoftBusThreadJoin(thread, nullptr);
1017060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1018060ff233Sopenharmony_ci}
1019060ff233Sopenharmony_ci
1020060ff233Sopenharmony_ci/*
1021060ff233Sopenharmony_ci* @tc.name: SoftBusThreadJoinTest002
1022060ff233Sopenharmony_ci* @tc.desc: value is not nullptr
1023060ff233Sopenharmony_ci* @tc.type: FUNC
1024060ff233Sopenharmony_ci* @tc.require: 1
1025060ff233Sopenharmony_ci*/
1026060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadJoinTest002, TestSize.Level0)
1027060ff233Sopenharmony_ci{
1028060ff233Sopenharmony_ci    char *value = nullptr;
1029060ff233Sopenharmony_ci    SoftBusThread thread = 0;
1030060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
1031060ff233Sopenharmony_ci    int32_t ret = SoftBusThreadAttrInit(&threadAttr);
1032060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1033060ff233Sopenharmony_ci
1034060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&thread, &threadAttr, SoftBusThreadTask, nullptr);
1035060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1036060ff233Sopenharmony_ci    EXPECT_TRUE(thread != 0);
1037060ff233Sopenharmony_ci    ret = SoftBusThreadJoin(thread, (void **)&value);
1038060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1039060ff233Sopenharmony_ci    EXPECT_TRUE(value != nullptr);
1040060ff233Sopenharmony_ci}
1041060ff233Sopenharmony_ci
1042060ff233Sopenharmony_ci/*
1043060ff233Sopenharmony_ci* @tc.name: SoftBusThreadFullTest001
1044060ff233Sopenharmony_ci* @tc.desc: thread process test
1045060ff233Sopenharmony_ci* @tc.type: FUNC
1046060ff233Sopenharmony_ci* @tc.require: 1
1047060ff233Sopenharmony_ci*/
1048060ff233Sopenharmony_ciHWTEST_F(SoftbusThreadTest, SoftBusThreadFullTest001, TestSize.Level0)
1049060ff233Sopenharmony_ci{
1050060ff233Sopenharmony_ci    int32_t ret = SoftBusMutexInit(&g_mutex, NULL);
1051060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1052060ff233Sopenharmony_ci
1053060ff233Sopenharmony_ci    ret = SoftBusCondInit(&g_cond);
1054060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1055060ff233Sopenharmony_ci
1056060ff233Sopenharmony_ci    SoftBusThread threadWait = 0;
1057060ff233Sopenharmony_ci    SoftBusThread threadSignal = 0;
1058060ff233Sopenharmony_ci    SoftBusThreadAttr threadAttr = {0};
1059060ff233Sopenharmony_ci    ret = SoftBusThreadAttrInit(&threadAttr);
1060060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1061060ff233Sopenharmony_ci
1062060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&threadWait, &threadAttr, ThreadWaitTest, nullptr);
1063060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1064060ff233Sopenharmony_ci    EXPECT_TRUE(threadWait != 0);
1065060ff233Sopenharmony_ci
1066060ff233Sopenharmony_ci    ret = SoftBusThreadCreate(&threadSignal, &threadAttr, ThreadSignalTest, nullptr);
1067060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1068060ff233Sopenharmony_ci    EXPECT_TRUE(threadSignal != 0);
1069060ff233Sopenharmony_ci
1070060ff233Sopenharmony_ci    ret = SoftBusThreadJoin(threadWait, nullptr);
1071060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1072060ff233Sopenharmony_ci    ret = SoftBusThreadJoin(threadSignal, nullptr);
1073060ff233Sopenharmony_ci    EXPECT_EQ(SOFTBUS_OK, ret);
1074060ff233Sopenharmony_ci}
1075060ff233Sopenharmony_ci}
1076