• 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 STACK_SIZE = 4 * 1024;
22 
23 /**
24  * @tc.name      : pthread_attr_getstack_0100
25  * @tc.desc      : Verify pthread_attr_getstack process fail. By default, get the thread stack address and size fail
26  * @tc.level     : Level 2
27  */
pthread_attr_getstack_0100(void)28 void pthread_attr_getstack_0100(void)
29 {
30     pthread_attr_t attr;
31     pthread_attr_init(&attr);
32     void *stack = NULL;
33     size_t stacksize;
34     int32_t ret = pthread_attr_getstack(&attr, &stack, &stacksize);
35     EXPECT_EQ("pthread_attr_getstack_0100", ret, EINVAL);
36     pthread_attr_destroy(&attr);
37 }
38 
39 /**
40  * @tc.name      : pthread_attr_getstack_0200
41  * @tc.desc      : Verify pthread_asuccessttr_getstack process success.Customize the thread stack,get the thread stack
42  *                 address and size success
43  * @tc.level     : Level 1
44  */
pthread_attr_getstack_0200(void)45 void pthread_attr_getstack_0200(void)
46 {
47     pthread_attr_t attr;
48     pthread_attr_init(&attr);
49     void *stack = malloc(STACK_SIZE);
50     EXPECT_PTRNE("pthread_attr_getstack_0200", stack, NULL);
51     void *retstack = NULL;
52     size_t stacksize;
53     pthread_attr_setstack(&attr, stack, STACK_SIZE);
54     int32_t ret = pthread_attr_getstack(&attr, &retstack, &stacksize);
55     EXPECT_EQ("pthread_attr_getstack_0200", ret, 0);
56     EXPECT_PTREQ("pthread_attr_getstack_0200", stack, retstack);
57     EXPECT_EQ("pthread_attr_getstack_0200", stacksize, STACK_SIZE);
58     pthread_attr_destroy(&attr);
59 }
60 
main(void)61 int main(void)
62 {
63     pthread_attr_getstack_0100();
64     pthread_attr_getstack_0200();
65     return t_status;
66 }
67