• 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 <unistd.h>
19 #include "functionalext.h"
20 
21 const int32_t ERROR = 2U;
22 
23 /**
24  * @tc.name      : pthread_attr_setdetachstate_0100
25  * @tc.desc      : Verify pthread_attr_setdetachstate process success
26  * @tc.level     : Level 1
27  */
pthread_attr_setdetachstate_0100(void)28 void pthread_attr_setdetachstate_0100(void)
29 {
30     pthread_attr_t attr;
31     pthread_attr_init(&attr);
32     struct sched_param sched = {0, 1};
33     int32_t ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
34     EXPECT_EQ("pthread_attr_setdetachstate_0100", ret, 0);
35     ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
36     EXPECT_EQ("pthread_attr_setdetachstate_0100", ret, 0);
37     pthread_attr_destroy(&attr);
38 }
39 
40 /**
41  * @tc.name      : pthread_attr_setdetachstate_0200
42  * @tc.desc      : Verify pthread_attr_setdetachstate process fail.Because second param is error
43  * @tc.level     : Level 1
44  */
pthread_attr_setdetachstate_0200(void)45 void pthread_attr_setdetachstate_0200(void)
46 {
47     pthread_attr_t attr;
48     pthread_attr_init(&attr);
49     int32_t ret = pthread_attr_setdetachstate(&attr, ERROR);
50     EXPECT_EQ("pthread_attr_setdetachstate_0200", ret, EINVAL);
51     pthread_attr_destroy(&attr);
52 }
53 
main(int argc,char * argv[])54 int main(int argc, char *argv[])
55 {
56     pthread_attr_setdetachstate_0100();
57     pthread_attr_setdetachstate_0200();
58     return t_status;
59 }
60