Update copyright dates with scripts/update-copyrights
[glibc.git] / sysdeps / pthread / tst-cancel30.c
blob6eb4eb5b42bb8922c5a1322248ec45e998bbeec4
1 /* Check if printf like functions does not disable asynchronous cancellation
2 mode (BZ#29214).
4 Copyright (C) 2022-2023 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <https://www.gnu.org/licenses/>. */
21 #include <support/check.h>
22 #include <support/xstdio.h>
23 #include <support/xthread.h>
24 #include <sys/syscall.h>
25 #include <unistd.h>
27 static pthread_barrier_t b;
29 static void *
30 tf (void *arg)
32 int old;
34 TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL), 0);
36 TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old), 0);
37 TEST_COMPARE (old, PTHREAD_CANCEL_ASYNCHRONOUS);
39 /* Check if internal lock cleanup routines restore the cancellation type
40 correctly. */
41 printf ("...\n");
42 TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old), 0);
43 TEST_COMPARE (old, PTHREAD_CANCEL_ASYNCHRONOUS);
45 xpthread_barrier_wait (&b);
47 /* Wait indefinitely for cancellation, which only works if asynchronous
48 cancellation is enabled. */
49 #ifdef SYS_pause
50 syscall (SYS_pause);
51 #elif defined SYS_ppoll || defined SYS_ppoll_time64
52 # ifndef SYS_ppoll_time64
53 # define SYS_ppoll_time64 SYS_ppoll
54 # endif
55 syscall (SYS_ppoll_time64, NULL, 0, NULL, NULL);
56 #else
57 for (;;);
58 #endif
60 return 0;
63 static int
64 do_test (void)
66 xpthread_barrier_init (&b, NULL, 2);
68 pthread_t th = xpthread_create (NULL, tf, NULL);
70 xpthread_barrier_wait (&b);
72 xpthread_cancel (th);
74 void *status = xpthread_join (th);
75 TEST_VERIFY (status == PTHREAD_CANCELED);
77 return 0;
80 /* There is no need to wait full TIMEOUT if asynchronous is not working. */
81 #define TIMEOUT 3
82 #include <support/test-driver.c>