1-1.c revision 354ebb48db8e66a853a58379a4808d5dcd1ceac3
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_getstack() 9 * 10 * Steps: 11 * 1. Initialize pthread_attr_t object (attr) 12 * 2. set the stackaddr and stacksize to attr 13 * 3. get the stackaddr and 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_getstack" 28#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " 29 30int main() 31{ 32 pthread_attr_t attr; 33 void *stack_addr; 34 size_t stack_size; 35 size_t ssize; 36 void *saddr; 37 int rc; 38 39 /* Initialize attr */ 40 rc = pthread_attr_init(&attr); 41 if (rc != 0) { 42 perror(ERROR_PREFIX "pthread_attr_init"); 43 exit(PTS_UNRESOLVED); 44 } 45 46 /* Get the default stack_addr and stack_size value */ 47 rc = pthread_attr_getstack(&attr, &stack_addr, &stack_size); 48 if (rc != 0) { 49 perror(ERROR_PREFIX "pthread_attr_getstack"); 50 exit(PTS_UNRESOLVED); 51 } 52 printf("stack_addr = %p, stack_size = %zu\n", stack_addr, stack_size); 53 54 stack_size = PTHREAD_STACK_MIN; 55 56 if (posix_memalign(&stack_addr, sysconf(_SC_PAGE_SIZE), 57 stack_size) != 0) { 58 perror(ERROR_PREFIX "out of memory while " 59 "allocating the stack memory"); 60 exit(PTS_UNRESOLVED); 61 } 62 printf("stack_addr = %p, stack_size = %zu\n", stack_addr, stack_size); 63 64 rc = pthread_attr_setstack(&attr, stack_addr, stack_size); 65 if (rc != 0) { 66 perror(ERROR_PREFIX "pthread_attr_setstack"); 67 exit(PTS_UNRESOLVED); 68 } 69 70 rc = pthread_attr_getstack(&attr, &saddr, &ssize); 71 if (rc != 0) { 72 perror(ERROR_PREFIX "pthread_attr_getstack"); 73 exit(PTS_UNRESOLVED); 74 } 75 printf("saddr = %p, ssize = %zu\n", saddr, ssize); 76 77 rc = pthread_attr_destroy(&attr); 78 if (rc != 0) { 79 perror(ERROR_PREFIX "pthread_attr_destroy"); 80 exit(PTS_UNRESOLVED); 81 } 82 83 printf("Test PASSED\n"); 84 return PTS_PASS; 85} 86