]>
Commit | Line | Data |
---|---|---|
d614a753 | 1 | /* Copyright (C) 2002-2020 Free Software Foundation, Inc. |
76a50749 UD |
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 | |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
76a50749 UD |
18 | |
19 | #include <pthread.h> | |
20 | #include <stdio.h> | |
21 | #include <string.h> | |
22 | ||
23 | ||
24 | static int | |
25 | do_test (void) | |
26 | { | |
27 | pthread_key_t key1; | |
28 | pthread_key_t key2; | |
29 | void *value; | |
30 | int result = 0; | |
31 | int err; | |
32 | ||
33 | err = pthread_key_create (&key1, NULL); | |
34 | if (err != 0) | |
35 | { | |
36 | printf ("1st key_create failed: %s\n", strerror (err)); | |
37 | return 1; | |
38 | } | |
39 | ||
40 | /* Initial value must be NULL. */ | |
41 | value = pthread_getspecific (key1); | |
42 | if (value != NULL) | |
43 | { | |
44 | puts ("1st getspecific != NULL"); | |
45 | result = 1; | |
46 | } | |
47 | ||
48 | err = pthread_setspecific (key1, (void *) -2l); | |
49 | if (err != 0) | |
50 | { | |
51 | printf ("1st setspecific failed: %s\n", strerror (err)); | |
52 | return 1; | |
53 | } | |
54 | ||
55 | value = pthread_getspecific (key1); | |
56 | if (value == NULL) | |
57 | { | |
58 | puts ("2nd getspecific == NULL\n"); | |
59 | result = 1; | |
60 | } | |
61 | else if (value != (void *) -2l) | |
62 | { | |
63 | puts ("2nd getspecific != -2l\n"); | |
64 | result = 1; | |
65 | } | |
66 | ||
67 | err = pthread_setspecific (key1, (void *) -3l); | |
68 | if (err != 0) | |
69 | { | |
70 | printf ("2nd setspecific failed: %s\n", strerror (err)); | |
71 | return 1; | |
72 | } | |
73 | ||
74 | value = pthread_getspecific (key1); | |
75 | if (value == NULL) | |
76 | { | |
77 | puts ("3rd getspecific == NULL\n"); | |
78 | result = 1; | |
79 | } | |
80 | else if (value != (void *) -3l) | |
81 | { | |
82 | puts ("3rd getspecific != -2l\n"); | |
83 | result = 1; | |
84 | } | |
85 | ||
86 | err = pthread_key_delete (key1); | |
87 | if (err != 0) | |
88 | { | |
89 | printf ("key_delete failed: %s\n", strerror (err)); | |
90 | result = 1; | |
91 | } | |
92 | ||
93 | ||
94 | err = pthread_key_create (&key2, NULL); | |
95 | if (err != 0) | |
96 | { | |
97 | printf ("2nd key_create failed: %s\n", strerror (err)); | |
98 | return 1; | |
99 | } | |
100 | ||
101 | if (key1 != key2) | |
102 | puts ("key1 != key2; no more tests performed"); | |
103 | else | |
104 | { | |
105 | value = pthread_getspecific (key2); | |
106 | if (value != NULL) | |
107 | { | |
108 | puts ("4th getspecific != NULL"); | |
109 | result = 1; | |
110 | } | |
111 | } | |
112 | ||
113 | return result; | |
114 | } | |
115 | ||
116 | #define TEST_FUNCTION do_test () | |
117 | #include "../test-skeleton.c" |