]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/pthread/tst-cancel30.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / pthread / tst-cancel30.c
1 /* Check if printf like functions does not disable asynchronous cancellation
2 mode (BZ#29214).
3
4 Copyright (C) 2022-2024 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
6
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.
11
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.
16
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/>. */
20
21 #include <support/check.h>
22 #include <support/xstdio.h>
23 #include <support/xthread.h>
24 #include <sys/syscall.h>
25 #include <unistd.h>
26
27 static pthread_barrier_t b;
28
29 static void *
30 tf (void *arg)
31 {
32 int old;
33
34 TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL), 0);
35
36 TEST_COMPARE (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, &old), 0);
37 TEST_COMPARE (old, PTHREAD_CANCEL_ASYNCHRONOUS);
38
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);
44
45 xpthread_barrier_wait (&b);
46
47 /* Wait indefinitely for cancellation, which only works if asynchronous
48 cancellation is enabled. */
49 #if defined SYS_ppoll || defined SYS_ppoll_time64
50 # ifndef SYS_ppoll_time64
51 # define SYS_ppoll_time64 SYS_ppoll
52 # endif
53 syscall (SYS_ppoll_time64, NULL, 0, NULL, NULL);
54 #else
55 for (;;);
56 #endif
57
58 return 0;
59 }
60
61 static int
62 do_test (void)
63 {
64 xpthread_barrier_init (&b, NULL, 2);
65
66 pthread_t th = xpthread_create (NULL, tf, NULL);
67
68 xpthread_barrier_wait (&b);
69
70 xpthread_cancel (th);
71
72 void *status = xpthread_join (th);
73 TEST_VERIFY (status == PTHREAD_CANCELED);
74
75 return 0;
76 }
77
78 /* There is no need to wait full TIMEOUT if asynchronous is not working. */
79 #define TIMEOUT 3
80 #include <support/test-driver.c>