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 <stdio.h>
17 #include <pthread.h>
18 #include "test.h"
19 #include "functionalext.h"
20
21 pthread_t pid;
22 int flag = 0;
23
threadfunc(void *arg)24 void *threadfunc(void *arg)
25 {
26 sleep(2);
27 flag++;
28 return 0;
29 }
30
31 /**
32 * @tc.name : pthread_join_0100
33 * @tc.desc : The parameters are valid, verify that the main thread does not wait for other threads to end the
34 * scene
35 * @tc.level : Level 0
36 */
pthread_join_0100(void)37 void pthread_join_0100(void)
38 {
39 flag = 0;
40 pthread_create(&pid, NULL, threadfunc, NULL);
41 int result = pthread_join(pid, NULL);
42 if (result != 0) {
43 t_error("%s pthread_join error get result is %d are not want 0\n", __func__, result);
44 }
45 if (flag != 1) {
46 t_error("%s pthread_join error get flag is %d are not want 1\n", __func__, flag);
47 }
48 }
49
50 /**
51 * @tc.name : pthread_join_0200
52 * @tc.desc : The input parameter pthread_t is NULL, pthread_join() returns errno code ESRCH
53 * @tc.level : Level 0
54 */
pthread_join_0200(void)55 void pthread_join_0200(void)
56 {
57 pthread_t t = NULL;
58 int result = pthread_join(t, NULL);
59 if (result != ESRCH) {
60 t_error("%s pthread_join error get result is %d are not want ESRCH\n", __func__, result);
61 }
62 }
63
main(int argc, char *argv[])64 int main(int argc, char *argv[])
65 {
66 pthread_join_0100();
67 pthread_join_0200();
68 return t_status;
69 }