1 /* C11 threads specific storage tests.
2 Copyright (C) 2018-2020 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/>. */
23 #include <support/check.h>
25 /* Thread specific storage. */
28 #define TSS_VALUE (void*) 0xFF
33 if (tss_create (&key
, NULL
) != thrd_success
)
34 FAIL_EXIT1 ("tss_create failed");
36 if (tss_set (key
, TSS_VALUE
))
37 FAIL_EXIT1 ("tss_set failed");
39 void *value
= tss_get (key
);
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
);
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");
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
);
68 FAIL_EXIT1 ("tss_get succeed where it should have failed");
75 #include <support/test-driver.c>