1/* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * Created by: rolla.n.selbak 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 that pthread_attr_destroy() 9 * shall destory a thread attributes object. An implementation may cause 10 * pthread_attr_destroy() to set 'attr' to an implementation-defined invalid 11 * value. 12 * 13 * Steps: 14 * 1. Initialize a pthread_attr_t object using pthread_attr_init() 15 * 2. Destroy that initialized attribute using pthread_attr_destroy() 16 * 3. Using pthread_attr_create(), pass to it the destroyed attribute. It 17 * should return the error EINVAL, the value specified by 'attr' is 18 * is invalid. 19 * 20 */ 21 22#include <pthread.h> 23#include <stdio.h> 24#include <errno.h> 25#include "posixtest.h" 26 27 28void *a_thread_func() 29{ 30 31 pthread_exit(0); 32 return NULL; 33} 34 35int main() 36{ 37 pthread_t new_th; 38 pthread_attr_t new_attr; 39 int ret; 40 41 /* Initialize attribute */ 42 if(pthread_attr_init(&new_attr) != 0) 43 { 44 perror("Cannot initialize attribute object\n"); 45 return PTS_UNRESOLVED; 46 } 47 48 /* Destroy attribute */ 49 if(pthread_attr_destroy(&new_attr) != 0) 50 { 51 perror("Cannot destroy the attribute object\n"); 52 return PTS_UNRESOLVED; 53 } 54 55 /* Creating a thread, passing to it the destroyed attribute, should 56 * result in an error value of EINVAL (invalid 'attr' value). */ 57 ret=pthread_create(&new_th, &new_attr, a_thread_func, NULL); 58 59 if(ret==EINVAL) 60 { 61 printf("Test PASSED\n"); 62 return PTS_PASS; 63 } 64 else if((ret != 0) && ((ret == EPERM) || (ret == EAGAIN))) 65 { 66 perror("Error created a new thread\n"); 67 return PTS_UNRESOLVED; 68 } 69 else if(ret==0) 70 { 71 printf("Test PASSED: NOTE*: Though returned 0 when creating a thread with a destroyed attribute, this behavior is compliant with garbage-in-garbage-out. \n"); 72 return PTS_PASS; 73 } else 74 { 75 printf("Test FAILED: (1) Incorrect return code from pthread_create(); %d not EINVAL or (2) Error in pthread_create()'s behavior in returning error codes \n", ret); 76 return PTS_FAIL; 77 } 78 79} 80 81 82