1 /* Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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 <http://www.gnu.org/licenses/>. */
19 /* NOTE: this tests functionality beyond POSIX. POSIX does not allow
20 exit to be called more than once. */
35 #include <sys/select.h>
36 #include <sys/socket.h>
44 /* Since STREAMS are not supported in the standard Linux kernel and
45 there we don't advertise STREAMS as supported is no need to test
46 the STREAMS related functions. This affects
47 getmsg() getpmsg() putmsg()
50 lockf() and fcntl() are tested in tst-cancel16.
52 pthread_join() is tested in tst-join5.
54 pthread_testcancel()'s only purpose is to allow cancellation. This
55 is tested in several places.
57 sem_wait() and sem_timedwait() are checked in tst-cancel1[2345] tests.
59 mq_send(), mq_timedsend(), mq_receive() and mq_timedreceive() are checked
60 in tst-mqueue8{,x} tests.
62 aio_suspend() is tested in tst-cancel17.
64 clock_nanosleep() is tested in tst-cancel18.
67 /* Pipe descriptors. */
70 /* Temporary file descriptor, to be closed after each round. */
71 static int tempfd = -1;
72 static int tempfd2 = -1;
73 /* Name of temporary file to be removed after each round. */
74 static char *tempfname;
75 /* Temporary message queue. */
76 static int tempmsg = -1;
78 /* Often used barrier for two threads. */
79 static pthread_barrier_t b2;
86 /* The WRITE_BUFFER_SIZE value needs to be chosen such that if we set
87 the socket send buffer size to '1', a write of this size on that
90 The Linux kernel imposes a minimum send socket buffer size which
91 has changed over the years. As of Linux 3.10 the value is:
93 2 * (2048 + SKB_DATA_ALIGN(sizeof(struct sk_buff)))
95 which is attempting to make sure that with standard MTUs,
96 TCP can always queue up at least 2 full sized packets.
98 Furthermore, there is logic in the socket send paths that
99 will allow one more packet (of any size) to be queued up as
100 long as some socket buffer space remains. Blocking only
101 occurs when we try to queue up a new packet and the send
102 buffer space has already been fully consumed.
104 Therefore we must set this value to the largest possible value of
105 the formula above (and since it depends upon the size of "struct
106 sk_buff", it is dependent upon machine word size etc.) plus some
109 #define WRITE_BUFFER_SIZE 16384
111 /* Cleanup handling test. */
112 static int cl_called;
132 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
133 tempfd = fd = mkstemp (fname);
135 printf ("%s: mkstemp failed\n", __FUNCTION__);
138 r = pthread_barrier_wait (&b2);
139 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
141 printf ("%s: barrier_wait failed\n", __FUNCTION__);
146 r = pthread_barrier_wait (&b2);
147 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
149 printf ("%s: barrier_wait failed\n", __FUNCTION__);
154 pthread_cleanup_push (cl, NULL);
157 s = read (fd, buf, sizeof (buf));
159 pthread_cleanup_pop (0);
161 printf ("%s: read returns with %zd\n", __FUNCTION__, s);
177 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
178 tempfd = fd = mkstemp (fname);
180 printf ("%s: mkstemp failed\n", __FUNCTION__);
183 r = pthread_barrier_wait (&b2);
184 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
186 printf ("%s: barrier_wait failed\n", __FUNCTION__);
191 r = pthread_barrier_wait (&b2);
192 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
194 printf ("%s: barrier_wait failed\n", __FUNCTION__);
199 pthread_cleanup_push (cl, NULL);
202 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
203 s = readv (fd, iov, 1);
205 pthread_cleanup_pop (0);
207 printf ("%s: readv returns with %zd\n", __FUNCTION__, s);
223 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
224 tempfd = fd = mkstemp (fname);
226 printf ("%s: mkstemp failed\n", __FUNCTION__);
229 r = pthread_barrier_wait (&b2);
230 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
232 printf ("%s: barrier_wait failed\n", __FUNCTION__);
237 r = pthread_barrier_wait (&b2);
238 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
240 printf ("%s: barrier_wait failed\n", __FUNCTION__);
245 pthread_cleanup_push (cl, NULL);
247 char buf[WRITE_BUFFER_SIZE];
248 memset (buf, '\0', sizeof (buf));
249 s = write (fd, buf, sizeof (buf));
251 pthread_cleanup_pop (0);
253 printf ("%s: write returns with %zd\n", __FUNCTION__, s);
260 tf_writev (void *arg)
269 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
270 tempfd = fd = mkstemp (fname);
272 printf ("%s: mkstemp failed\n", __FUNCTION__);
275 r = pthread_barrier_wait (&b2);
276 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
278 printf ("%s: barrier_wait failed\n", __FUNCTION__);
283 r = pthread_barrier_wait (&b2);
284 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
286 printf ("%s: barrier_wait failed\n", __FUNCTION__);
291 pthread_cleanup_push (cl, NULL);
293 char buf[WRITE_BUFFER_SIZE];
294 memset (buf, '\0', sizeof (buf));
295 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
296 s = writev (fd, iov, 1);
298 pthread_cleanup_pop (0);
300 printf ("%s: writev returns with %zd\n", __FUNCTION__, s);
309 int r = pthread_barrier_wait (&b2);
310 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
312 printf ("%s: barrier_wait failed\n", __FUNCTION__);
318 r = pthread_barrier_wait (&b2);
319 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
321 printf ("%s: barrier_wait failed\n", __FUNCTION__);
326 pthread_cleanup_push (cl, NULL);
328 sleep (arg == NULL ? 1000000 : 0);
330 pthread_cleanup_pop (0);
332 printf ("%s: sleep returns\n", __FUNCTION__);
339 tf_usleep (void *arg)
341 int r = pthread_barrier_wait (&b2);
342 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
344 printf ("%s: barrier_wait failed\n", __FUNCTION__);
350 r = pthread_barrier_wait (&b2);
351 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
353 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
358 pthread_cleanup_push (cl, NULL);
360 usleep (arg == NULL ? (useconds_t) ULONG_MAX : 0);
362 pthread_cleanup_pop (0);
364 printf ("%s: usleep returns\n", __FUNCTION__);
371 tf_nanosleep (void *arg)
373 int r = pthread_barrier_wait (&b2);
374 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
376 printf ("%s: barrier_wait failed\n", __FUNCTION__);
382 r = pthread_barrier_wait (&b2);
383 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
385 printf ("%s: barrier_wait failed\n", __FUNCTION__);
390 pthread_cleanup_push (cl, NULL);
392 struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 };
393 TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
395 pthread_cleanup_pop (0);
397 printf ("%s: nanosleep returns\n", __FUNCTION__);
404 tf_select (void *arg)
413 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
414 tempfd = fd = mkstemp (fname);
416 printf ("%s: mkstemp failed\n", __FUNCTION__);
419 r = pthread_barrier_wait (&b2);
420 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
422 printf ("%s: barrier_wait failed\n", __FUNCTION__);
427 r = pthread_barrier_wait (&b2);
428 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
430 printf ("%s: barrier_wait failed\n", __FUNCTION__);
439 pthread_cleanup_push (cl, NULL);
441 s = select (fd + 1, &rfs, NULL, NULL, NULL);
443 pthread_cleanup_pop (0);
445 printf ("%s: select returns with %d (%s)\n", __FUNCTION__, s,
453 tf_pselect (void *arg)
462 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
463 tempfd = fd = mkstemp (fname);
465 printf ("%s: mkstemp failed\n", __FUNCTION__);
468 r = pthread_barrier_wait (&b2);
469 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
471 printf ("%s: barrier_wait failed\n", __FUNCTION__);
476 r = pthread_barrier_wait (&b2);
477 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
479 printf ("%s: barrier_wait failed\n", __FUNCTION__);
488 pthread_cleanup_push (cl, NULL);
490 s = pselect (fd + 1, &rfs, NULL, NULL, NULL, NULL);
492 pthread_cleanup_pop (0);
494 printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__, s,
511 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
512 tempfd = fd = mkstemp (fname);
514 printf ("%s: mkstemp failed\n", __FUNCTION__);
517 r = pthread_barrier_wait (&b2);
518 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
520 printf ("%s: barrier_wait failed\n", __FUNCTION__);
525 r = pthread_barrier_wait (&b2);
526 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
528 printf ("%s: barrier_wait failed\n", __FUNCTION__);
532 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
535 pthread_cleanup_push (cl, NULL);
537 s = poll (rfs, 1, -1);
539 pthread_cleanup_pop (0);
541 printf ("%s: poll returns with %d (%s)\n", __FUNCTION__, s,
558 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
559 tempfd = fd = mkstemp (fname);
561 printf ("%s: mkstemp failed\n", __FUNCTION__);
564 r = pthread_barrier_wait (&b2);
565 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
567 printf ("%s: barrier_wait failed\n", __FUNCTION__);
572 r = pthread_barrier_wait (&b2);
573 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
575 printf ("%s: barrier_wait failed\n", __FUNCTION__);
579 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
582 pthread_cleanup_push (cl, NULL);
584 s = ppoll (rfs, 1, NULL, NULL);
586 pthread_cleanup_pop (0);
588 printf ("%s: ppoll returns with %d (%s)\n", __FUNCTION__, s,
601 puts ("fork failed");
607 /* Make the program disappear after a while. */
616 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
617 while (nanosleep (&ts, &ts) != 0)
620 r = pthread_barrier_wait (&b2);
621 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
623 printf ("%s: barrier_wait failed\n", __FUNCTION__);
628 r = pthread_barrier_wait (&b2);
629 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
631 printf ("%s: barrier_wait failed\n", __FUNCTION__);
636 pthread_cleanup_push (cl, NULL);
640 pthread_cleanup_pop (0);
642 printf ("%s: wait returns with %d (%s)\n", __FUNCTION__, s,
650 tf_waitpid (void *arg)
656 puts ("fork failed");
662 /* Make the program disappear after a while. */
671 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
672 while (nanosleep (&ts, &ts) != 0)
675 r = pthread_barrier_wait (&b2);
676 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
678 printf ("%s: barrier_wait failed\n", __FUNCTION__);
683 r = pthread_barrier_wait (&b2);
684 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
686 printf ("%s: barrier_wait failed\n", __FUNCTION__);
691 pthread_cleanup_push (cl, NULL);
693 s = waitpid (-1, NULL, 0);
695 pthread_cleanup_pop (0);
697 printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__, s,
705 tf_waitid (void *arg)
710 puts ("fork failed");
716 /* Make the program disappear after a while. */
725 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
726 while (nanosleep (&ts, &ts) != 0)
729 r = pthread_barrier_wait (&b2);
730 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
732 printf ("%s: barrier_wait failed\n", __FUNCTION__);
737 r = pthread_barrier_wait (&b2);
738 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
740 printf ("%s: barrier_wait failed\n", __FUNCTION__);
745 pthread_cleanup_push (cl, NULL);
751 s = waitid (P_PID, pid, &si, WEXITED);
753 pthread_cleanup_pop (0);
755 printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__, s,
763 tf_sigpause (void *arg)
765 int r = pthread_barrier_wait (&b2);
766 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
768 printf ("%s: barrier_wait failed\n", __FUNCTION__);
774 r = pthread_barrier_wait (&b2);
775 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
777 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
782 pthread_cleanup_push (cl, NULL);
784 sigpause (SIGCANCEL);
786 pthread_cleanup_pop (0);
788 printf ("%s: sigpause returned\n", __FUNCTION__);
795 tf_sigsuspend (void *arg)
797 int r = pthread_barrier_wait (&b2);
798 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
800 printf ("%s: barrier_wait failed\n", __FUNCTION__);
806 r = pthread_barrier_wait (&b2);
807 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
809 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
814 pthread_cleanup_push (cl, NULL);
816 /* Just for fun block all signals. */
821 pthread_cleanup_pop (0);
823 printf ("%s: sigsuspend returned\n", __FUNCTION__);
830 tf_sigwait (void *arg)
832 int r = pthread_barrier_wait (&b2);
833 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
835 printf ("%s: barrier_wait failed\n", __FUNCTION__);
841 r = pthread_barrier_wait (&b2);
842 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
844 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
852 sigaddset (&mask, SIGUSR1);
853 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
855 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
860 pthread_cleanup_push (cl, NULL);
862 /* Wait for SIGUSR1. */
863 sigwait (&mask, &sig);
865 pthread_cleanup_pop (0);
867 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__, sig);
874 tf_sigwaitinfo (void *arg)
876 int r = pthread_barrier_wait (&b2);
877 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
879 printf ("%s: barrier_wait failed\n", __FUNCTION__);
885 r = pthread_barrier_wait (&b2);
886 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
888 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
896 sigaddset (&mask, SIGUSR1);
897 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
899 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
904 pthread_cleanup_push (cl, NULL);
906 /* Wait for SIGUSR1. */
907 sigwaitinfo (&mask, &info);
909 pthread_cleanup_pop (0);
911 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__,
919 tf_sigtimedwait (void *arg)
921 int r = pthread_barrier_wait (&b2);
922 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
924 printf ("%s: barrier_wait failed\n", __FUNCTION__);
930 r = pthread_barrier_wait (&b2);
931 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
933 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
941 sigaddset (&mask, SIGUSR1);
942 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
944 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
948 /* Wait for SIGUSR1. */
950 struct timespec ts = { .tv_sec = 60, .tv_nsec = 0 };
951 pthread_cleanup_push (cl, NULL);
953 sigtimedwait (&mask, &info, &ts);
955 pthread_cleanup_pop (0);
957 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__,
967 int r = pthread_barrier_wait (&b2);
968 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
970 printf ("%s: barrier_wait failed\n", __FUNCTION__);
976 r = pthread_barrier_wait (&b2);
977 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
979 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
984 pthread_cleanup_push (cl, NULL);
988 pthread_cleanup_pop (0);
990 printf ("%s: pause returned\n", __FUNCTION__);
997 tf_accept (void *arg)
1000 struct sockaddr_un sun;
1001 /* To test a non-blocking accept call we make the call file by using
1002 a datagrame socket. */
1003 int pf = arg == NULL ? SOCK_STREAM : SOCK_DGRAM;
1005 tempfd = socket (AF_UNIX, pf, 0);
1008 printf ("%s: socket call failed\n", __FUNCTION__);
1017 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1020 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
1021 tfd = mkstemp(sun.sun_path);
1024 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1028 sun.sun_family = AF_UNIX;
1030 while (bind (tempfd, (struct sockaddr *) &sun,
1031 offsetof (struct sockaddr_un, sun_path)
1032 + strlen (sun.sun_path) + 1) != 0);
1034 unlink (sun.sun_path);
1038 socklen_t len = sizeof (sun);
1040 int r = pthread_barrier_wait (&b2);
1041 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1043 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1049 r = pthread_barrier_wait (&b2);
1050 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1052 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1057 pthread_cleanup_push (cl, NULL);
1059 accept (tempfd, (struct sockaddr *) &sun, &len);
1061 pthread_cleanup_pop (0);
1063 printf ("%s: accept returned\n", __FUNCTION__);
1073 struct sockaddr_un sun;
1075 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1078 printf ("%s: first socket call failed\n", __FUNCTION__);
1087 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1090 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1091 tfd = mkstemp(sun.sun_path);
1094 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1098 sun.sun_family = AF_UNIX;
1100 while (bind (tempfd, (struct sockaddr *) &sun,
1101 offsetof (struct sockaddr_un, sun_path)
1102 + strlen (sun.sun_path) + 1) != 0);
1106 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1109 printf ("%s: second socket call failed\n", __FUNCTION__);
1113 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1115 printf ("%s: connect failed\n", __FUNCTION__);
1119 unlink (sun.sun_path);
1121 int r = pthread_barrier_wait (&b2);
1122 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1124 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1130 r = pthread_barrier_wait (&b2);
1131 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1133 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1138 pthread_cleanup_push (cl, NULL);
1140 /* Very large block, so that the send call blocks. */
1143 send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
1145 pthread_cleanup_pop (0);
1147 printf ("%s: send returned\n", __FUNCTION__);
1157 struct sockaddr_un sun;
1159 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1162 printf ("%s: first socket call failed\n", __FUNCTION__);
1171 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1174 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX");
1175 tfd = mkstemp(sun.sun_path);
1178 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1182 sun.sun_family = AF_UNIX;
1184 while (bind (tempfd, (struct sockaddr *) &sun,
1185 offsetof (struct sockaddr_un, sun_path)
1186 + strlen (sun.sun_path) + 1) != 0);
1190 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1193 printf ("%s: second socket call failed\n", __FUNCTION__);
1197 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1199 printf ("%s: connect failed\n", __FUNCTION__);
1203 unlink (sun.sun_path);
1205 int r = pthread_barrier_wait (&b2);
1206 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1208 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1214 r = pthread_barrier_wait (&b2);
1215 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1217 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1222 pthread_cleanup_push (cl, NULL);
1226 recv (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0);
1228 pthread_cleanup_pop (0);
1230 printf ("%s: recv returned\n", __FUNCTION__);
1237 tf_recvfrom (void *arg)
1240 struct sockaddr_un sun;
1242 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1245 printf ("%s: first socket call failed\n", __FUNCTION__);
1254 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1257 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX");
1258 tfd = mkstemp(sun.sun_path);
1261 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1265 sun.sun_family = AF_UNIX;
1267 while (bind (tempfd, (struct sockaddr *) &sun,
1268 offsetof (struct sockaddr_un, sun_path)
1269 + strlen (sun.sun_path) + 1) != 0);
1271 tempfname = strdup (sun.sun_path);
1273 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1276 printf ("%s: second socket call failed\n", __FUNCTION__);
1280 int r = pthread_barrier_wait (&b2);
1281 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1283 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1289 r = pthread_barrier_wait (&b2);
1290 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1292 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1297 pthread_cleanup_push (cl, NULL);
1300 socklen_t len = sizeof (sun);
1302 recvfrom (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0,
1303 (struct sockaddr *) &sun, &len);
1305 pthread_cleanup_pop (0);
1307 printf ("%s: recvfrom returned\n", __FUNCTION__);
1314 tf_recvmsg (void *arg)
1317 struct sockaddr_un sun;
1319 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1322 printf ("%s: first socket call failed\n", __FUNCTION__);
1331 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1334 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
1335 tfd = mkstemp(sun.sun_path);
1338 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1342 sun.sun_family = AF_UNIX;
1344 while (bind (tempfd, (struct sockaddr *) &sun,
1345 offsetof (struct sockaddr_un, sun_path)
1346 + strlen (sun.sun_path) + 1) != 0);
1348 tempfname = strdup (sun.sun_path);
1350 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1353 printf ("%s: second socket call failed\n", __FUNCTION__);
1357 int r = pthread_barrier_wait (&b2);
1358 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1360 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1366 r = pthread_barrier_wait (&b2);
1367 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1369 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1374 pthread_cleanup_push (cl, NULL);
1377 struct iovec iov[1];
1378 iov[0].iov_base = mem;
1379 iov[0].iov_len = arg == NULL ? sizeof (mem) : 0;
1383 m.msg_namelen = sizeof (sun);
1386 m.msg_control = NULL;
1387 m.msg_controllen = 0;
1389 recvmsg (tempfd2, &m, 0);
1391 pthread_cleanup_pop (0);
1393 printf ("%s: recvmsg returned\n", __FUNCTION__);
1403 // XXX If somebody can provide a portable test case in which open()
1404 // blocks we can enable this test to run in both rounds.
1407 int r = pthread_barrier_wait (&b2);
1408 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1410 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1414 r = pthread_barrier_wait (&b2);
1415 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1417 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1421 pthread_cleanup_push (cl, NULL);
1423 open ("Makefile", O_RDONLY);
1425 pthread_cleanup_pop (0);
1427 printf ("%s: open returned\n", __FUNCTION__);
1434 tf_close (void *arg)
1437 // XXX If somebody can provide a portable test case in which close()
1438 // blocks we can enable this test to run in both rounds.
1441 char fname[] = "/tmp/tst-cancel-fd-XXXXXX";
1442 tempfd = mkstemp (fname);
1445 printf ("%s: mkstemp failed\n", __FUNCTION__);
1450 int r = pthread_barrier_wait (&b2);
1451 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1453 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1457 r = pthread_barrier_wait (&b2);
1458 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1460 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1464 pthread_cleanup_push (cl, NULL);
1468 pthread_cleanup_pop (0);
1470 printf ("%s: close returned\n", __FUNCTION__);
1477 tf_pread (void *arg)
1480 // XXX If somebody can provide a portable test case in which pread()
1481 // blocks we can enable this test to run in both rounds.
1484 tempfd = open ("Makefile", O_RDONLY);
1487 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1491 int r = pthread_barrier_wait (&b2);
1492 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1494 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1498 r = pthread_barrier_wait (&b2);
1499 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1501 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1505 pthread_cleanup_push (cl, NULL);
1508 pread (tempfd, mem, sizeof (mem), 0);
1510 pthread_cleanup_pop (0);
1512 printf ("%s: pread returned\n", __FUNCTION__);
1519 tf_pwrite (void *arg)
1522 // XXX If somebody can provide a portable test case in which pwrite()
1523 // blocks we can enable this test to run in both rounds.
1526 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1527 tempfd = mkstemp (fname);
1530 printf ("%s: mkstemp failed\n", __FUNCTION__);
1535 int r = pthread_barrier_wait (&b2);
1536 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1538 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1542 r = pthread_barrier_wait (&b2);
1543 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1545 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1549 pthread_cleanup_push (cl, NULL);
1552 pwrite (tempfd, mem, sizeof (mem), 0);
1554 pthread_cleanup_pop (0);
1556 printf ("%s: pwrite returned\n", __FUNCTION__);
1563 tf_fsync (void *arg)
1566 // XXX If somebody can provide a portable test case in which fsync()
1567 // blocks we can enable this test to run in both rounds.
1570 tempfd = open ("Makefile", O_RDONLY);
1573 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1577 int r = pthread_barrier_wait (&b2);
1578 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1580 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1584 r = pthread_barrier_wait (&b2);
1585 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1587 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1591 pthread_cleanup_push (cl, NULL);
1595 pthread_cleanup_pop (0);
1597 printf ("%s: fsync returned\n", __FUNCTION__);
1604 tf_fdatasync (void *arg)
1607 // XXX If somebody can provide a portable test case in which fdatasync()
1608 // blocks we can enable this test to run in both rounds.
1611 tempfd = open ("Makefile", O_RDONLY);
1614 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1618 int r = pthread_barrier_wait (&b2);
1619 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1621 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1625 r = pthread_barrier_wait (&b2);
1626 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1628 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1632 pthread_cleanup_push (cl, NULL);
1636 pthread_cleanup_pop (0);
1638 printf ("%s: fdatasync returned\n", __FUNCTION__);
1645 tf_msync (void *arg)
1648 // XXX If somebody can provide a portable test case in which msync()
1649 // blocks we can enable this test to run in both rounds.
1652 tempfd = open ("Makefile", O_RDONLY);
1655 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1658 void *p = mmap (NULL, 10, PROT_READ, MAP_SHARED, tempfd, 0);
1659 if (p == MAP_FAILED)
1661 printf ("%s: mmap failed\n", __FUNCTION__);
1665 int r = pthread_barrier_wait (&b2);
1666 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1668 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1672 r = pthread_barrier_wait (&b2);
1673 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1675 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1679 pthread_cleanup_push (cl, NULL);
1683 pthread_cleanup_pop (0);
1685 printf ("%s: msync returned\n", __FUNCTION__);
1692 tf_sendto (void *arg)
1696 // XXX If somebody can provide a portable test case in which sendto()
1697 // blocks we can enable this test to run in both rounds.
1700 struct sockaddr_un sun;
1702 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1705 printf ("%s: first socket call failed\n", __FUNCTION__);
1714 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1717 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX");
1718 tfd = mkstemp(sun.sun_path);
1721 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1725 sun.sun_family = AF_UNIX;
1727 while (bind (tempfd, (struct sockaddr *) &sun,
1728 offsetof (struct sockaddr_un, sun_path)
1729 + strlen (sun.sun_path) + 1) != 0);
1730 tempfname = strdup (sun.sun_path);
1732 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1735 printf ("%s: second socket call failed\n", __FUNCTION__);
1739 int r = pthread_barrier_wait (&b2);
1740 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1742 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1746 r = pthread_barrier_wait (&b2);
1747 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1749 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1753 pthread_cleanup_push (cl, NULL);
1757 sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0,
1758 (struct sockaddr *) &sun,
1759 offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1);
1761 pthread_cleanup_pop (0);
1763 printf ("%s: sendto returned\n", __FUNCTION__);
1770 tf_sendmsg (void *arg)
1774 // XXX If somebody can provide a portable test case in which sendmsg()
1775 // blocks we can enable this test to run in both rounds.
1778 struct sockaddr_un sun;
1780 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1783 printf ("%s: first socket call failed\n", __FUNCTION__);
1792 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1795 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
1796 tfd = mkstemp(sun.sun_path);
1799 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1803 sun.sun_family = AF_UNIX;
1805 while (bind (tempfd, (struct sockaddr *) &sun,
1806 offsetof (struct sockaddr_un, sun_path)
1807 + strlen (sun.sun_path) + 1) != 0);
1808 tempfname = strdup (sun.sun_path);
1810 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1813 printf ("%s: second socket call failed\n", __FUNCTION__);
1817 int r = pthread_barrier_wait (&b2);
1818 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1820 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1824 r = pthread_barrier_wait (&b2);
1825 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1827 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1831 pthread_cleanup_push (cl, NULL);
1834 struct iovec iov[1];
1835 iov[0].iov_base = mem;
1840 m.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
1841 + strlen (sun.sun_path) + 1);
1844 m.msg_control = NULL;
1845 m.msg_controllen = 0;
1847 sendmsg (tempfd2, &m, 0);
1849 pthread_cleanup_pop (0);
1851 printf ("%s: sendmsg returned\n", __FUNCTION__);
1858 tf_creat (void *arg)
1861 // XXX If somebody can provide a portable test case in which sendmsg()
1862 // blocks we can enable this test to run in both rounds.
1865 int r = pthread_barrier_wait (&b2);
1866 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1868 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1872 r = pthread_barrier_wait (&b2);
1873 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1875 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1879 pthread_cleanup_push (cl, NULL);
1881 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1883 pthread_cleanup_pop (0);
1885 printf ("%s: creat returned\n", __FUNCTION__);
1892 tf_connect (void *arg)
1896 // XXX If somebody can provide a portable test case in which connect()
1897 // blocks we can enable this test to run in both rounds.
1900 struct sockaddr_un sun;
1902 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1905 printf ("%s: first socket call failed\n", __FUNCTION__);
1914 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1917 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1918 tfd = mkstemp(sun.sun_path);
1921 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1925 sun.sun_family = AF_UNIX;
1927 while (bind (tempfd, (struct sockaddr *) &sun,
1928 offsetof (struct sockaddr_un, sun_path)
1929 + strlen (sun.sun_path) + 1) != 0);
1930 tempfname = strdup (sun.sun_path);
1934 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1937 printf ("%s: second socket call failed\n", __FUNCTION__);
1941 int r = pthread_barrier_wait (&b2);
1942 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1944 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1950 r = pthread_barrier_wait (&b2);
1951 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1953 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1958 pthread_cleanup_push (cl, NULL);
1960 connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun));
1962 pthread_cleanup_pop (0);
1964 printf ("%s: connect returned\n", __FUNCTION__);
1971 tf_tcdrain (void *arg)
1974 // XXX If somebody can provide a portable test case in which tcdrain()
1975 // blocks we can enable this test to run in both rounds.
1978 int r = pthread_barrier_wait (&b2);
1979 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1981 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1987 r = pthread_barrier_wait (&b2);
1988 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1990 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1995 pthread_cleanup_push (cl, NULL);
1997 /* Regardless of stderr being a terminal, the tcdrain call should be
1999 tcdrain (STDERR_FILENO);
2001 pthread_cleanup_pop (0);
2003 printf ("%s: tcdrain returned\n", __FUNCTION__);
2010 tf_msgrcv (void *arg)
2012 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
2015 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2019 int r = pthread_barrier_wait (&b2);
2020 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2022 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2028 r = pthread_barrier_wait (&b2);
2029 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2031 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2038 pthread_cleanup_push (cl, NULL);
2046 /* We need a positive random number. */
2048 randnr = random () % 64000;
2049 while (randnr <= 0);
2053 s = msgrcv (tempmsg, (struct msgbuf *) &m, 10, randnr, 0);
2055 while (errno == EIDRM || errno == EINTR);
2057 pthread_cleanup_pop (0);
2059 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__, s);
2061 msgctl (tempmsg, IPC_RMID, NULL);
2068 tf_msgsnd (void *arg)
2071 // XXX If somebody can provide a portable test case in which msgsnd()
2072 // blocks we can enable this test to run in both rounds.
2075 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
2078 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2082 int r = pthread_barrier_wait (&b2);
2083 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2085 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2089 r = pthread_barrier_wait (&b2);
2090 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2092 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2096 pthread_cleanup_push (cl, NULL);
2103 /* We need a positive random number. */
2105 m.type = random () % 64000;
2106 while (m.type <= 0);
2107 msgsnd (tempmsg, (struct msgbuf *) &m, sizeof (m.mem), 0);
2109 pthread_cleanup_pop (0);
2111 printf ("%s: msgsnd returned\n", __FUNCTION__);
2113 msgctl (tempmsg, IPC_RMID, NULL);
2122 void *(*tf) (void *);
2127 #define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early }
2128 ADD_TEST (read, 2, 0),
2129 ADD_TEST (readv, 2, 0),
2130 ADD_TEST (select, 2, 0),
2131 ADD_TEST (pselect, 2, 0),
2132 ADD_TEST (poll, 2, 0),
2133 ADD_TEST (ppoll, 2, 0),
2134 ADD_TEST (write, 2, 0),
2135 ADD_TEST (writev, 2, 0),
2136 ADD_TEST (sleep, 2, 0),
2137 ADD_TEST (usleep, 2, 0),
2138 ADD_TEST (nanosleep, 2, 0),
2139 ADD_TEST (wait, 2, 0),
2140 ADD_TEST (waitid, 2, 0),
2141 ADD_TEST (waitpid, 2, 0),
2142 ADD_TEST (sigpause, 2, 0),
2143 ADD_TEST (sigsuspend, 2, 0),
2144 ADD_TEST (sigwait, 2, 0),
2145 ADD_TEST (sigwaitinfo, 2, 0),
2146 ADD_TEST (sigtimedwait, 2, 0),
2147 ADD_TEST (pause, 2, 0),
2148 ADD_TEST (accept, 2, 0),
2149 ADD_TEST (send, 2, 0),
2150 ADD_TEST (recv, 2, 0),
2151 ADD_TEST (recvfrom, 2, 0),
2152 ADD_TEST (recvmsg, 2, 0),
2153 ADD_TEST (open, 2, 1),
2154 ADD_TEST (close, 2, 1),
2155 ADD_TEST (pread, 2, 1),
2156 ADD_TEST (pwrite, 2, 1),
2157 ADD_TEST (fsync, 2, 1),
2158 ADD_TEST (fdatasync, 2, 1),
2159 ADD_TEST (msync, 2, 1),
2160 ADD_TEST (sendto, 2, 1),
2161 ADD_TEST (sendmsg, 2, 1),
2162 ADD_TEST (creat, 2, 1),
2163 ADD_TEST (connect, 2, 1),
2164 ADD_TEST (tcdrain, 2, 1),
2165 ADD_TEST (msgrcv, 2, 0),
2166 ADD_TEST (msgsnd, 2, 1),
2168 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2177 if (socketpair (AF_UNIX, SOCK_STREAM, PF_UNIX, fds) != 0)
2179 perror ("socketpair");
2185 setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
2186 if (getsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, &len) < 0)
2188 perror ("getsockopt");
2191 if (val >= WRITE_BUFFER_SIZE)
2193 puts ("minimum write buffer size too large");
2196 setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
2200 for (cnt = 0; cnt < ntest_tf; ++cnt)
2202 if (tests[cnt].only_early)
2205 if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0)
2207 puts ("b2 init failed");
2211 /* Reset the counter for the cleanup handler. */
2215 if (pthread_create (&th, NULL, tests[cnt].tf, NULL) != 0)
2217 printf ("create for '%s' test failed\n", tests[cnt].name);
2222 int r = pthread_barrier_wait (&b2);
2223 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2225 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2230 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
2231 while (nanosleep (&ts, &ts) != 0)
2234 if (pthread_cancel (th) != 0)
2236 printf ("cancel for '%s' failed\n", tests[cnt].name);
2242 if (pthread_join (th, &status) != 0)
2244 printf ("join for '%s' failed\n", tests[cnt].name);
2248 if (status != PTHREAD_CANCELED)
2250 printf ("thread for '%s' not canceled\n", tests[cnt].name);
2255 if (pthread_barrier_destroy (&b2) != 0)
2257 puts ("barrier_destroy failed");
2264 printf ("cleanup handler not called for '%s'\n", tests[cnt].name);
2270 printf ("cleanup handler called more than once for '%s'\n",
2276 printf ("in-time cancel test of '%s' successful\n", tests[cnt].name);
2288 if (tempfname != NULL)
2296 msgctl (tempmsg, IPC_RMID, NULL);
2301 for (cnt = 0; cnt < ntest_tf; ++cnt)
2303 if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0)
2305 puts ("b2 init failed");
2309 /* Reset the counter for the cleanup handler. */
2313 if (pthread_create (&th, NULL, tests[cnt].tf, (void *) 1l) != 0)
2315 printf ("create for '%s' test failed\n", tests[cnt].name);
2320 int r = pthread_barrier_wait (&b2);
2321 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2323 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2328 if (pthread_cancel (th) != 0)
2330 printf ("cancel for '%s' failed\n", tests[cnt].name);
2335 r = pthread_barrier_wait (&b2);
2336 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2338 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2344 if (pthread_join (th, &status) != 0)
2346 printf ("join for '%s' failed\n", tests[cnt].name);
2350 if (status != PTHREAD_CANCELED)
2352 printf ("thread for '%s' not canceled\n", tests[cnt].name);
2357 if (pthread_barrier_destroy (&b2) != 0)
2359 puts ("barrier_destroy failed");
2366 printf ("cleanup handler not called for '%s'\n", tests[cnt].name);
2372 printf ("cleanup handler called more than once for '%s'\n",
2378 printf ("early cancel test of '%s' successful\n", tests[cnt].name);
2390 if (tempfname != NULL)
2398 msgctl (tempmsg, IPC_RMID, NULL);
2407 #define TEST_FUNCTION do_test ()
2408 #include "../test-skeleton.c"