3-1.c revision 2c28215423293e443469a07ae7011135d058b671
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_getspecific() 9 * 10 * It shall return the thread-specific data value associated with the given 'key'. If no 11 * thread-specific data value is associated with 'key, then the value NULL shall be returned. 12 * It does not return any errors. 13 * 14 * Steps: 15 * 1. Create pthread_key_t object and do no specify a key accociated with this key 16 * 2. Call pthread_getspecific() and check that the value returns 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 26int main() 27{ 28 pthread_key_t key; 29 void* rc; 30 31 if (pthread_key_create(&key, NULL) != 0) 32 { 33 printf("Error: pthread_key_create() failed\n"); 34 return PTS_UNRESOLVED; 35 } 36 37 rc = pthread_getspecific(key); 38 if (rc != NULL) 39 { 40 printf("Test FAILED: Did not return correct value, expected NULL, but got %ld\n", (long)rc); 41 return PTS_FAIL; 42 } 43 44 if (pthread_key_delete(key) != 0) 45 { 46 printf("Error: pthread_key_delete() failed\n"); 47 return PTS_UNRESOLVED; 48 } 49 50 printf("Test PASSED\n"); 51 return PTS_PASS; 52}