12c28215423293e443469a07ae7011135d058b671Garrett Cooper/*
20dc076565f772bb1953209fb69ea150b494aaa40robbiew * Copyright (c) 2002, Intel Corporation. All rights reserved.
30dc076565f772bb1953209fb69ea150b494aaa40robbiew * Created by:  bing.wei.liu REMOVE-THIS AT intel DOT com
40dc076565f772bb1953209fb69ea150b494aaa40robbiew * This file is licensed under the GPL license.  For the full content
52c28215423293e443469a07ae7011135d058b671Garrett Cooper * of this license, see the COPYING file at the top level of this
60dc076565f772bb1953209fb69ea150b494aaa40robbiew * source tree.
70dc076565f772bb1953209fb69ea150b494aaa40robbiew
80dc076565f772bb1953209fb69ea150b494aaa40robbiew * Test that pthread_key_create()
90dc076565f772bb1953209fb69ea150b494aaa40robbiew *
100dc076565f772bb1953209fb69ea150b494aaa40robbiew * Upon key creation, the value NULL shall be associated with the new key in all active threads.
110dc076565f772bb1953209fb69ea150b494aaa40robbiew * Upon thread creation, the value NULL shall be associated with all defined keys in the new
120dc076565f772bb1953209fb69ea150b494aaa40robbiew * thread.
130dc076565f772bb1953209fb69ea150b494aaa40robbiew *
140dc076565f772bb1953209fb69ea150b494aaa40robbiew * Steps:
150dc076565f772bb1953209fb69ea150b494aaa40robbiew * 1. Create a key
160dc076565f772bb1953209fb69ea150b494aaa40robbiew * 2. Verify that the default value is NULL
172c28215423293e443469a07ae7011135d058b671Garrett Cooper *
180dc076565f772bb1953209fb69ea150b494aaa40robbiew */
190dc076565f772bb1953209fb69ea150b494aaa40robbiew
200dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <pthread.h>
210dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h>
220dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdlib.h>
230dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <unistd.h>
240dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h"
250dc076565f772bb1953209fb69ea150b494aaa40robbiew
264ca2bbdcd3003f3c8df4e6129e9c7b2bd1514f87Cyril Hrubisint main(void)
270dc076565f772bb1953209fb69ea150b494aaa40robbiew{
280dc076565f772bb1953209fb69ea150b494aaa40robbiew	pthread_key_t key;
29354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	void *rc;
300dc076565f772bb1953209fb69ea150b494aaa40robbiew
310dc076565f772bb1953209fb69ea150b494aaa40robbiew	/* Verify that the value associated with "key" in a new thread is NULL */
320dc076565f772bb1953209fb69ea150b494aaa40robbiew	rc = pthread_getspecific(key);
33354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	if (rc != NULL) {
340dc076565f772bb1953209fb69ea150b494aaa40robbiew		printf("Test FAILED\n");
350dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_FAIL;
360dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
370dc076565f772bb1953209fb69ea150b494aaa40robbiew
38354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	if (pthread_key_create(&key, NULL) != 0) {
390dc076565f772bb1953209fb69ea150b494aaa40robbiew		printf("Error: pthread_key_create() failed\n");
400dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_UNRESOLVED;
41354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	} else {
420dc076565f772bb1953209fb69ea150b494aaa40robbiew		/* Verify that the value associated with "key" after it is newly created is
430dc076565f772bb1953209fb69ea150b494aaa40robbiew		 * NULL */
440dc076565f772bb1953209fb69ea150b494aaa40robbiew		rc = pthread_getspecific(key);
45354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		if (rc != NULL) {
460dc076565f772bb1953209fb69ea150b494aaa40robbiew			printf("Test FAILED\n");
470dc076565f772bb1953209fb69ea150b494aaa40robbiew			return PTS_FAIL;
480dc076565f772bb1953209fb69ea150b494aaa40robbiew		}
492c28215423293e443469a07ae7011135d058b671Garrett Cooper
500dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
510dc076565f772bb1953209fb69ea150b494aaa40robbiew
520dc076565f772bb1953209fb69ea150b494aaa40robbiew	printf("Test PASSED\n");
530dc076565f772bb1953209fb69ea150b494aaa40robbiew	return PTS_PASS;
54ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman}
55