1 /* Common file for all tst-cancel4_*
3 Copyright (C) 2016-2018 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
26 if (socketpair (AF_UNIX
, SOCK_STREAM
, PF_UNIX
, fds
) != 0)
28 perror ("socketpair");
34 setsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, sizeof(val
));
35 if (getsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, &len
) < 0)
37 perror ("getsockopt");
40 if (val
>= WRITE_BUFFER_SIZE
)
42 puts ("minimum write buffer size too large");
45 setsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, sizeof(val
));
47 if (mktemp (fifoname
) == NULL
)
49 printf ("%s: cannot generate temp file name: %m\n", __func__
);
55 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
57 if (tests
[cnt
].only_early
)
60 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
62 puts ("b2 init failed");
66 /* Reset the counter for the cleanup handler. */
70 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, NULL
) != 0)
72 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
77 int r
= pthread_barrier_wait (&b2
);
78 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
80 printf ("%s: barrier_wait failed\n", __func__
);
85 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
86 while (nanosleep (&ts
, &ts
) != 0)
89 if (pthread_cancel (th
) != 0)
91 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
97 if (pthread_join (th
, &status
) != 0)
99 printf ("join for '%s' failed\n", tests
[cnt
].name
);
103 if (status
!= PTHREAD_CANCELED
)
105 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
110 if (pthread_barrier_destroy (&b2
) != 0)
112 puts ("barrier_destroy failed");
119 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
125 printf ("cleanup handler called more than once for '%s'\n",
131 printf ("in-time cancel test of '%s' successful\n", tests
[cnt
].name
);
143 if (tempfname
!= NULL
)
151 msgctl (tempmsg
, IPC_RMID
, NULL
);
156 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
158 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
160 puts ("b2 init failed");
164 /* Reset the counter for the cleanup handler. */
168 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, (void *) 1l) != 0)
170 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
175 int r
= pthread_barrier_wait (&b2
);
176 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
178 printf ("%s: barrier_wait failed\n", __func__
);
183 if (pthread_cancel (th
) != 0)
185 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
190 r
= pthread_barrier_wait (&b2
);
191 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
193 printf ("%s: barrier_wait failed\n", __func__
);
199 if (pthread_join (th
, &status
) != 0)
201 printf ("join for '%s' failed\n", tests
[cnt
].name
);
205 if (status
!= PTHREAD_CANCELED
)
207 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
212 if (pthread_barrier_destroy (&b2
) != 0)
214 puts ("barrier_destroy failed");
221 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
227 printf ("cleanup handler called more than once for '%s'\n",
233 printf ("early cancel test of '%s' successful\n", tests
[cnt
].name
);
245 if (tempfname
!= NULL
)
253 msgctl (tempmsg
, IPC_RMID
, NULL
);
262 #include <support/test-driver.c>