• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "functionalext.h"
19 
20 static pthread_mutex_t g_mutex;
21 
22 /**
23  * @tc.name:      pthread_mutex_trylock_0100
24  * @tc.desc:      Verify process pthread_mutex_try_lock success
25  * @tc.level:     level 0
26  */
pthread_mutex_trylock_0100(void)27 void pthread_mutex_trylock_0100(void)
28 {
29     pthread_mutex_init(&g_mutex, NULL);
30     int ret = pthread_mutex_trylock(&g_mutex);
31     EXPECT_EQ("pthread_mutex_lock_0100", ret, 0);
32     pthread_mutex_unlock(&g_mutex);
33 }
34 
35 /**
36  * @tc.name:      pthread_mutex_trylock_0200
37  * @tc.desc:      Verify process pthread_mutex_try_lock fail
38  * @tc.level:     level 2
39  */
pthread_mutex_trylock_0200(void)40 void pthread_mutex_trylock_0200(void)
41 {
42     pthread_mutex_init(&g_mutex, NULL);
43     pthread_mutex_lock(&g_mutex);
44     int ret = pthread_mutex_trylock(&g_mutex);
45     EXPECT_NE("pthread_mutex_lock_0200", ret, 0);
46     pthread_mutex_unlock(&g_mutex);
47 }
48 
main(void)49 int main(void)
50 {
51     pthread_mutex_trylock_0100();
52     pthread_mutex_trylock_0200();
53     return t_status;
54 }