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 <stdlib.h>
17 #include <threads.h>
18 #include <unistd.h>
19 #include "functionalext.h"
20
21 static mtx_t g_mtx;
22
threadfuncA(void * arg)23 int threadfuncA(void *arg)
24 {
25 int ret= mtx_lock(&g_mtx);
26 EXPECT_EQ("mtx_unlock_0100", ret, 0);
27 ret = mtx_unlock(&g_mtx);
28 EXPECT_EQ("mtx_unlock_0100", ret, 0);
29 return 0;
30 }
31
32 /**
33 * @tc.name : mtx_unlock_0100.
34 * @tc.desc : Verify process mtx_unlock once success.
35 * @tc.level : Level 0.
36 */
mtx_unlock_0100(void)37 void mtx_unlock_0100(void)
38 {
39 int result = mtx_init(&g_mtx, mtx_plain);
40 if (result != thrd_success) {
41 t_error("%s mtx_init failed", __func__);
42 return;
43 }
44 thrd_t tid1;
45 result = thrd_create(&tid1, threadfuncA, NULL);
46 if (result != thrd_success) {
47 t_error("%s thrd_create failed", __func__);
48 return;
49 }
50 result = thrd_join(tid1, NULL);
51 if (result != thrd_success) {
52 t_error("%s thrd_join failed", __func__);
53 return;
54 }
55 }
56
main(void)57 int main(void)
58 {
59 mtx_unlock_0100();
60 return t_status;
61 }