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 destroy 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 void *a_thread_func() 28 { 29 30 pthread_exit(0); 31 return NULL; 32 } 33 34 int main(void) 35 { 36 pthread_t new_th; 37 pthread_attr_t new_attr; 38 int ret; 39 40 /* Initialize attribute */ 41 if (pthread_attr_init(&new_attr) != 0) { 42 perror("Cannot initialize attribute object\n"); 43 return PTS_UNRESOLVED; 44 } 45 46 /* Destroy attribute */ 47 if (pthread_attr_destroy(&new_attr) != 0) { 48 perror("Cannot destroy the attribute object\n"); 49 return PTS_UNRESOLVED; 50 } 51 52 /* Creating a thread, passing to it the destroyed attribute, should 53 * result in an error value of EINVAL (invalid 'attr' value). */ 54 ret = pthread_create(&new_th, &new_attr, a_thread_func, NULL); 55 56 if (ret == EINVAL) { 57 printf("Test PASSED\n"); 58 return PTS_PASS; 59 } else if ((ret != 0) && ((ret == EPERM) || (ret == EAGAIN))) { 60 perror("Error created a new thread\n"); 61 return PTS_UNRESOLVED; 62 } else if (ret == 0) { 63 printf 64 ("Test PASSED: NOTE*: Though returned 0 when creating a thread with a destroyed attribute, this behavior is compliant with garbage-in-garbage-out. \n"); 65 return PTS_PASS; 66 } else { 67 printf 68 ("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", 69 ret); 70 return PTS_FAIL; 71 } 72 73 } 74