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_getspecific()
90dc076565f772bb1953209fb69ea150b494aaa40robbiew *
100dc076565f772bb1953209fb69ea150b494aaa40robbiew * It shall return the thread-specific data value associated with the given 'key'.  If no
110dc076565f772bb1953209fb69ea150b494aaa40robbiew * thread-specific data value is associated with 'key, then the value NULL shall be returned.
120dc076565f772bb1953209fb69ea150b494aaa40robbiew * It does not return any errors.
130dc076565f772bb1953209fb69ea150b494aaa40robbiew *
140dc076565f772bb1953209fb69ea150b494aaa40robbiew * Steps:
150dc076565f772bb1953209fb69ea150b494aaa40robbiew * 1.  Create pthread_key_t object and do no specify a key accociated with this key
160dc076565f772bb1953209fb69ea150b494aaa40robbiew * 2.  Call pthread_getspecific() and check that the value returns 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
31354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	if (pthread_key_create(&key, NULL) != 0) {
320dc076565f772bb1953209fb69ea150b494aaa40robbiew		printf("Error: pthread_key_create() failed\n");
330dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_UNRESOLVED;
340dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
350dc076565f772bb1953209fb69ea150b494aaa40robbiew
360dc076565f772bb1953209fb69ea150b494aaa40robbiew	rc = pthread_getspecific(key);
37354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	if (rc != NULL) {
38354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		printf
39354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		    ("Test FAILED: Did not return correct value, expected NULL, but got %ld\n",
40354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao		     (long)rc);
410dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_FAIL;
420dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
432c28215423293e443469a07ae7011135d058b671Garrett Cooper
44354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	if (pthread_key_delete(key) != 0) {
450dc076565f772bb1953209fb69ea150b494aaa40robbiew		printf("Error: pthread_key_delete() failed\n");
460dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_UNRESOLVED;
470dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
482c28215423293e443469a07ae7011135d058b671Garrett Cooper
490dc076565f772bb1953209fb69ea150b494aaa40robbiew	printf("Test PASSED\n");
500dc076565f772bb1953209fb69ea150b494aaa40robbiew	return PTS_PASS;
51ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman}
52