Home | History | Annotate | Download | only in pthread_key_create
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * Created by:  bing.wei.liu 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_key_create()
      9  *
     10  * Upon key creation, the value NULL shall be associated with the new key in all active threads.
     11  * Upon thread creation, the value NULL shall be associated with all defined keys in the new
     12  * thread.
     13  *
     14  * Steps:
     15  * 1. Create a key
     16  * 2. Verify that the default value is NULL
     17  *
     18  */
     19 
     20 #include <pthread.h>
     21 #include <stdio.h>
     22 #include <stdlib.h>
     23 #include <unistd.h>
     24 #include "posixtest.h"
     25 
     26 int main(void)
     27 {
     28 	pthread_key_t key;
     29 	void *rc;
     30 
     31 	/* Verify that the value associated with "key" in a new thread is NULL */
     32 	rc = pthread_getspecific(key);
     33 	if (rc != NULL) {
     34 		printf("Test FAILED\n");
     35 		return PTS_FAIL;
     36 	}
     37 
     38 	if (pthread_key_create(&key, NULL) != 0) {
     39 		printf("Error: pthread_key_create() failed\n");
     40 		return PTS_UNRESOLVED;
     41 	} else {
     42 		/* Verify that the value associated with "key" after it is newly created is
     43 		 * NULL */
     44 		rc = pthread_getspecific(key);
     45 		if (rc != NULL) {
     46 			printf("Test FAILED\n");
     47 			return PTS_FAIL;
     48 		}
     49 
     50 	}
     51 
     52 	printf("Test PASSED\n");
     53 	return PTS_PASS;
     54 }
     55