Home | History | Annotate | Download | only in pthread_attr_init
      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_init()
      9  *  shall initialize a thread attributes object 'attr' with the default value
     10  *  for all the individual attributes used by a given implementation.
     11 
     12  *  NOTE: Since most default values are implementation specific, only the
     13  *  attribute of the detachstate will be tested since the default value
     14  *  is defined in the spec. (default value:  PTHREAD_CREATE_JOINABLE)
     15  *
     16  * Steps:
     17  * 1.  Initialize a pthread_attr_t object using pthread_attr_init()
     18  * 2.  Using pthread_attr_getdetachstate(), test that the default value
     19  *     of the detachstate is PTHREAD_CREATE_JOINABLE (the default).
     20  *
     21  */
     22 
     23 #include <pthread.h>
     24 #include <stdio.h>
     25 #include "posixtest.h"
     26 
     27 int main(void)
     28 {
     29 	pthread_attr_t new_attr;
     30 	int detach_state;
     31 
     32 	/* Initialize attribute */
     33 	if (pthread_attr_init(&new_attr) != 0) {
     34 		perror("Cannot initialize attribute object\n");
     35 		return PTS_UNRESOLVED;
     36 	}
     37 
     38 	/* The test passes if the attribute object has a detachstate of
     39 	 * PTHREAD_CREATE_JOINABLE, which is the default value for this
     40 	 * attribute. */
     41 	if (pthread_attr_getdetachstate(&new_attr, &detach_state) != 0) {
     42 		perror("Error obtaining the detachstate of the attribute\n");
     43 		return PTS_UNRESOLVED;
     44 	}
     45 
     46 	if (detach_state == PTHREAD_CREATE_JOINABLE) {
     47 		printf("Test PASSED\n");
     48 		return PTS_PASS;
     49 	} else {
     50 		printf("Test FAILED\n");
     51 		return PTS_FAIL;
     52 	}
     53 }
     54