lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* Copyright (C) 2002 Free Software Foundation, Inc. |
| 2 | This file is part of the GNU C Library. |
| 3 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, write to the Free |
| 17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 18 | 02111-1307 USA. */ |
| 19 | |
| 20 | #include <pthread.h> |
| 21 | #include <stdio.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | |
| 25 | static int |
| 26 | do_test (void) |
| 27 | { |
| 28 | pthread_key_t key1; |
| 29 | pthread_key_t key2; |
| 30 | void *value; |
| 31 | int result = 0; |
| 32 | int err; |
| 33 | |
| 34 | err = pthread_key_create (&key1, NULL); |
| 35 | if (err != 0) |
| 36 | { |
| 37 | printf ("1st key_create failed: %s\n", strerror (err)); |
| 38 | return 1; |
| 39 | } |
| 40 | |
| 41 | /* Initial value must be NULL. */ |
| 42 | value = pthread_getspecific (key1); |
| 43 | if (value != NULL) |
| 44 | { |
| 45 | puts ("1st getspecific != NULL"); |
| 46 | result = 1; |
| 47 | } |
| 48 | |
| 49 | err = pthread_setspecific (key1, (void *) -2l); |
| 50 | if (err != 0) |
| 51 | { |
| 52 | printf ("1st setspecific failed: %s\n", strerror (err)); |
| 53 | return 1; |
| 54 | } |
| 55 | |
| 56 | value = pthread_getspecific (key1); |
| 57 | if (value == NULL) |
| 58 | { |
| 59 | puts ("2nd getspecific == NULL\n"); |
| 60 | result = 1; |
| 61 | } |
| 62 | else if (value != (void *) -2l) |
| 63 | { |
| 64 | puts ("2nd getspecific != -2l\n"); |
| 65 | result = 1; |
| 66 | } |
| 67 | |
| 68 | err = pthread_setspecific (key1, (void *) -3l); |
| 69 | if (err != 0) |
| 70 | { |
| 71 | printf ("2nd setspecific failed: %s\n", strerror (err)); |
| 72 | return 1; |
| 73 | } |
| 74 | |
| 75 | value = pthread_getspecific (key1); |
| 76 | if (value == NULL) |
| 77 | { |
| 78 | puts ("3rd getspecific == NULL\n"); |
| 79 | result = 1; |
| 80 | } |
| 81 | else if (value != (void *) -3l) |
| 82 | { |
| 83 | puts ("3rd getspecific != -2l\n"); |
| 84 | result = 1; |
| 85 | } |
| 86 | |
| 87 | err = pthread_key_delete (key1); |
| 88 | if (err != 0) |
| 89 | { |
| 90 | printf ("key_delete failed: %s\n", strerror (err)); |
| 91 | result = 1; |
| 92 | } |
| 93 | |
| 94 | |
| 95 | err = pthread_key_create (&key2, NULL); |
| 96 | if (err != 0) |
| 97 | { |
| 98 | printf ("2nd key_create failed: %s\n", strerror (err)); |
| 99 | return 1; |
| 100 | } |
| 101 | |
| 102 | if (key1 != key2) |
| 103 | puts ("key1 != key2; no more tests performed"); |
| 104 | else |
| 105 | { |
| 106 | value = pthread_getspecific (key2); |
| 107 | if (value != NULL) |
| 108 | { |
| 109 | puts ("4th getspecific != NULL"); |
| 110 | result = 1; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return result; |
| 115 | } |
| 116 | |
| 117 | #define TEST_FUNCTION do_test () |
| 118 | #include "../test-skeleton.c" |