1 /*
2 * Copyright (C) 2022 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 <pthread.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include "functionalext.h"
20
21 static pthread_mutex_t g_mutex;
22
23 /**
24 * @tc.name: pthread_mutex_init_0100
25 * @tc.desc: Verify pthread_mutex_init process success when second args is null.
26 * @tc.desc: level 0
27 */
pthread_mutex_init_0100(void)28 void pthread_mutex_init_0100(void)
29 {
30 int32_t ret = pthread_mutex_init(&g_mutex, NULL);
31 EXPECT_EQ("pthread_mutex_init_0100", ret, 0);
32 }
33
34 /**
35 * @tc.name: pthread_mutex_init_0200
36 * @tc.desc: Verify pthread_mutex_init process success when second args is PTHREAD_MUTEX_RECURSIVE.
37 * @tc.desc: level 1
38 */
pthread_mutex_init_0200(void)39 void pthread_mutex_init_0200(void)
40 {
41 int32_t type = PTHREAD_MUTEX_RECURSIVE;
42 int32_t ret = pthread_mutex_init(&g_mutex, (pthread_mutexattr_t *)(&type));
43 EXPECT_EQ("pthread_mutex_init_0200", ret, 0);
44 }
45
46 /**
47 * @tc.name: pthread_mutex_init_0300
48 * @tc.desc: Verify pthread_mutex_init process success when second args is PTHREAD_MUTEX_RECURSIVE.
49 * @tc.desc: level 1
50 */
pthread_mutex_init_0300(void)51 void pthread_mutex_init_0300(void)
52 {
53 int32_t type = PTHREAD_MUTEX_ERRORCHECK;
54 int32_t ret = pthread_mutex_init(&g_mutex, (pthread_mutexattr_t *)(&type));
55 EXPECT_EQ("pthread_mutex_init_0300", ret, 0);
56 }
57
main(void)58 int main(void)
59 {
60 pthread_mutex_init_0100();
61 pthread_mutex_init_0200();
62 pthread_mutex_init_0300();
63 return t_status;
64 }
65