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_delete()
9 *
10 * Shall delete a thread-specific data key previously returned by pthread_key_create.  The
11 * thread-specific data values specified data values associated with 'key' need not be NULL at
12 * the time pthread_key_delete is called.  It is the responsibility of the application to free
13 * any application storage or perform any cleanup actions for data structures related to the
14 * deleted key or associated thread-specific data in any threads; this cleanup can be done
15 * either before or after pthread_key_delete is called.  Any attempt to use 'key' following
16 * the call to pthread_key_delete results in undefined behavior.
17 *
18 * Steps:
19 * 1. Create many keys, and specify and value to them
20 * 2. Delete the keys with pthread_key_delete
21 * 3. Verify that this will not result in an error
22 *
23 */
24
25#include <pthread.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <unistd.h>
29#include "posixtest.h"
30
31#define NUM_OF_KEYS 10
32#define KEY_VALUE 100
33
34int main()
35{
36	pthread_key_t keys[NUM_OF_KEYS];
37	int i;
38
39	for(i = 0;i<NUM_OF_KEYS;i++)
40	{
41		if(pthread_key_create(&keys[i], NULL) != 0)
42		{
43			printf("Error: pthread_key_create() failed\n");
44			return PTS_UNRESOLVED;
45		}
46
47		if(pthread_setspecific(keys[i], (void*)(long)(KEY_VALUE + i)) != 0)
48		{
49			printf("Error: pthread_setspecific failed\n");
50			return PTS_UNRESOLVED;
51		}
52
53		if(pthread_key_delete(keys[i]) != 0)
54		{
55			printf("Test FAILED\n");
56			return PTS_FAIL;
57		}
58	}
59
60	printf("Test PASSED\n");
61	return PTS_PASS;
62}
63