1 /* 2 * Copyright (c) 2004, Intel Corporation. All rights reserved. 3 * Created by: crystal.xiong REMOVE-THIS AT intel DOT com 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 8 * Test pthread_attr_getstacksize() 9 * 10 * Steps: 11 * 1. Initialize pthread_attr_t object (attr) 12 * 2. set the stacksize to attr 13 * 3. get the stacksize 14 */ 15 16 #include <pthread.h> 17 #include <limits.h> 18 #include <stdio.h> 19 #include <string.h> 20 #include <stdlib.h> 21 #include <sys/param.h> 22 #include <errno.h> 23 #include <unistd.h> 24 #include "posixtest.h" 25 26 #define TEST "1-1" 27 #define FUNCTION "pthread_attr_getstacksize" 28 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " 29 30 int main(void) 31 { 32 pthread_attr_t attr; 33 size_t stack_size; 34 size_t ssize; 35 void *saddr; 36 int rc; 37 38 /* Initialize attr */ 39 rc = pthread_attr_init(&attr); 40 if (rc != 0) { 41 perror(ERROR_PREFIX "pthread_attr_init"); 42 exit(PTS_UNRESOLVED); 43 } 44 45 /* Get the default stack_addr and stack_size value */ 46 rc = pthread_attr_getstacksize(&attr, &stack_size); 47 if (rc != 0) { 48 perror(ERROR_PREFIX "pthread_attr_getstacksize"); 49 exit(PTS_UNRESOLVED); 50 } 51 /* printf("stack_size = %lu\n", stack_size); */ 52 53 stack_size = PTHREAD_STACK_MIN; 54 55 if (posix_memalign(&saddr, sysconf(_SC_PAGE_SIZE), stack_size) != 0) { 56 perror(ERROR_PREFIX "out of memory while " 57 "allocating the stack memory"); 58 exit(PTS_UNRESOLVED); 59 } 60 /* printf("stack_size = %lu\n", stack_size); */ 61 62 rc = pthread_attr_setstacksize(&attr, stack_size); 63 if (rc != 0) { 64 perror(ERROR_PREFIX "pthread_attr_setstacksize"); 65 exit(PTS_UNRESOLVED); 66 } 67 68 rc = pthread_attr_getstacksize(&attr, &ssize); 69 if (rc != 0) { 70 perror(ERROR_PREFIX "pthread_attr_getstacksize"); 71 exit(PTS_UNRESOLVED); 72 } 73 /* printf("ssize = %lu\n", ssize); */ 74 75 rc = pthread_attr_destroy(&attr); 76 if (rc != 0) { 77 perror(ERROR_PREFIX "pthread_attr_destroy"); 78 exit(PTS_UNRESOLVED); 79 } 80 81 printf("Test PASSED\n"); 82 return PTS_PASS; 83 } 84