Remove unused localedata/th_TH.in
[glibc.git] / sysdeps / pthread / tst-tss-basic.c
blob7d00f7c76c2274283278d0edca947ab7fef88e75
1 /* C11 threads specific storage tests.
2 Copyright (C) 2018-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <threads.h>
20 #include <stdio.h>
21 #include <unistd.h>
23 #include <support/check.h>
25 /* Thread specific storage. */
26 static tss_t key;
28 #define TSS_VALUE (void*) 0xFF
30 static int
31 tss_thrd (void *arg)
33 if (tss_create (&key, NULL) != thrd_success)
34 FAIL_EXIT1 ("tss_create failed");
36 if (tss_set (key, TSS_VALUE) != thrd_success)
37 FAIL_EXIT1 ("tss_set failed");
39 void *value = tss_get (key);
40 if (value == 0)
41 FAIL_EXIT1 ("tss_get failed");
42 if (value != TSS_VALUE)
43 FAIL_EXIT1 ("tss_get returned %p, expected %p", value, TSS_VALUE);
45 thrd_exit (thrd_success);
48 static int
49 do_test (void)
51 /* Setting an invalid key should return an error. */
52 if (tss_set (key, TSS_VALUE) == thrd_success)
53 FAIL_EXIT1 ("tss_set succeed where it should have failed");
55 if (tss_create (&key, NULL) != thrd_success)
56 FAIL_EXIT1 ("tss_create failed");
58 thrd_t id;
59 if (thrd_create (&id, tss_thrd, NULL) != thrd_success)
60 FAIL_EXIT1 ("thrd_create failed");
62 if (thrd_join (id, NULL) != thrd_success)
63 FAIL_EXIT1 ("thrd failed");
65 /* The value set in tss_thrd should not be visible here. */
66 void *value = tss_get (key);
67 if (value != 0)
68 FAIL_EXIT1 ("tss_get succeed where it should have failed");
70 tss_delete (key);
72 return 0;
75 #include <support/test-driver.c>