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__);
1018 /* prevent endless loop, when bind fails forever */
1022 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
1023 tfd = mkstemp(sun.sun_path);
1026 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1030 sun.sun_family = AF_UNIX;
1032 while (bind (tempfd, (struct sockaddr *) &sun,
1033 offsetof (struct sockaddr_un, sun_path)
1034 + strlen (sun.sun_path) + 1) != 0);
1036 unlink (sun.sun_path);
1040 socklen_t len = sizeof (sun);
1042 int r = pthread_barrier_wait (&b2);
1043 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1045 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1051 r = pthread_barrier_wait (&b2);
1052 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1054 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1059 pthread_cleanup_push (cl, NULL);
1061 accept (tempfd, (struct sockaddr *) &sun, &len);
1063 pthread_cleanup_pop (0);
1065 printf ("%s: accept returned\n", __FUNCTION__);
1075 struct sockaddr_un sun;
1077 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1080 printf ("%s: first socket call failed\n", __FUNCTION__);
1089 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1092 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1093 tfd = mkstemp(sun.sun_path);
1096 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1100 sun.sun_family = AF_UNIX;
1102 while (bind (tempfd, (struct sockaddr *) &sun,
1103 offsetof (struct sockaddr_un, sun_path)
1104 + strlen (sun.sun_path) + 1) != 0);
1108 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1111 printf ("%s: second socket call failed\n", __FUNCTION__);
1115 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1117 printf ("%s: connect failed\n", __FUNCTION__);
1121 unlink (sun.sun_path);
1123 int r = pthread_barrier_wait (&b2);
1124 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1126 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1132 r = pthread_barrier_wait (&b2);
1133 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1135 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1140 pthread_cleanup_push (cl, NULL);
1142 /* Very large block, so that the send call blocks. */
1145 send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
1147 pthread_cleanup_pop (0);
1149 printf ("%s: send returned\n", __FUNCTION__);
1159 struct sockaddr_un sun;
1161 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1164 printf ("%s: first socket call failed\n", __FUNCTION__);
1173 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1176 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX");
1177 tfd = mkstemp(sun.sun_path);
1180 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1184 sun.sun_family = AF_UNIX;
1186 while (bind (tempfd, (struct sockaddr *) &sun,
1187 offsetof (struct sockaddr_un, sun_path)
1188 + strlen (sun.sun_path) + 1) != 0);
1192 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1195 printf ("%s: second socket call failed\n", __FUNCTION__);
1199 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1201 printf ("%s: connect failed\n", __FUNCTION__);
1205 unlink (sun.sun_path);
1207 int r = pthread_barrier_wait (&b2);
1208 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1210 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1216 r = pthread_barrier_wait (&b2);
1217 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1219 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1224 pthread_cleanup_push (cl, NULL);
1228 recv (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0);
1230 pthread_cleanup_pop (0);
1232 printf ("%s: recv returned\n", __FUNCTION__);
1239 tf_recvfrom (void *arg)
1242 struct sockaddr_un sun;
1244 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1247 printf ("%s: first socket call failed\n", __FUNCTION__);
1256 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1259 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX");
1260 tfd = mkstemp(sun.sun_path);
1263 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1267 sun.sun_family = AF_UNIX;
1269 while (bind (tempfd, (struct sockaddr *) &sun,
1270 offsetof (struct sockaddr_un, sun_path)
1271 + strlen (sun.sun_path) + 1) != 0);
1273 tempfname = strdup (sun.sun_path);
1275 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1278 printf ("%s: second socket call failed\n", __FUNCTION__);
1282 int r = pthread_barrier_wait (&b2);
1283 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1285 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1291 r = pthread_barrier_wait (&b2);
1292 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1294 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1299 pthread_cleanup_push (cl, NULL);
1302 socklen_t len = sizeof (sun);
1304 recvfrom (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0,
1305 (struct sockaddr *) &sun, &len);
1307 pthread_cleanup_pop (0);
1309 printf ("%s: recvfrom returned\n", __FUNCTION__);
1316 tf_recvmsg (void *arg)
1319 struct sockaddr_un sun;
1321 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1324 printf ("%s: first socket call failed\n", __FUNCTION__);
1333 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1336 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
1337 tfd = mkstemp(sun.sun_path);
1340 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1344 sun.sun_family = AF_UNIX;
1346 while (bind (tempfd, (struct sockaddr *) &sun,
1347 offsetof (struct sockaddr_un, sun_path)
1348 + strlen (sun.sun_path) + 1) != 0);
1350 tempfname = strdup (sun.sun_path);
1352 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1355 printf ("%s: second socket call failed\n", __FUNCTION__);
1359 int r = pthread_barrier_wait (&b2);
1360 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1362 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1368 r = pthread_barrier_wait (&b2);
1369 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1371 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1376 pthread_cleanup_push (cl, NULL);
1379 struct iovec iov[1];
1380 iov[0].iov_base = mem;
1381 iov[0].iov_len = arg == NULL ? sizeof (mem) : 0;
1385 m.msg_namelen = sizeof (sun);
1388 m.msg_control = NULL;
1389 m.msg_controllen = 0;
1391 recvmsg (tempfd2, &m, 0);
1393 pthread_cleanup_pop (0);
1395 printf ("%s: recvmsg returned\n", __FUNCTION__);
1405 // XXX If somebody can provide a portable test case in which open()
1406 // blocks we can enable this test to run in both rounds.
1409 int r = pthread_barrier_wait (&b2);
1410 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1412 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1416 r = pthread_barrier_wait (&b2);
1417 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1419 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1423 pthread_cleanup_push (cl, NULL);
1425 open ("Makefile", O_RDONLY);
1427 pthread_cleanup_pop (0);
1429 printf ("%s: open returned\n", __FUNCTION__);
1436 tf_close (void *arg)
1439 // XXX If somebody can provide a portable test case in which close()
1440 // blocks we can enable this test to run in both rounds.
1443 char fname[] = "/tmp/tst-cancel-fd-XXXXXX";
1444 tempfd = mkstemp (fname);
1447 printf ("%s: mkstemp failed\n", __FUNCTION__);
1452 int r = pthread_barrier_wait (&b2);
1453 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1455 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1459 r = pthread_barrier_wait (&b2);
1460 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1462 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1466 pthread_cleanup_push (cl, NULL);
1470 pthread_cleanup_pop (0);
1472 printf ("%s: close returned\n", __FUNCTION__);
1479 tf_pread (void *arg)
1482 // XXX If somebody can provide a portable test case in which pread()
1483 // blocks we can enable this test to run in both rounds.
1486 tempfd = open ("Makefile", O_RDONLY);
1489 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1493 int r = pthread_barrier_wait (&b2);
1494 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1496 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1500 r = pthread_barrier_wait (&b2);
1501 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1503 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1507 pthread_cleanup_push (cl, NULL);
1510 pread (tempfd, mem, sizeof (mem), 0);
1512 pthread_cleanup_pop (0);
1514 printf ("%s: pread returned\n", __FUNCTION__);
1521 tf_pwrite (void *arg)
1524 // XXX If somebody can provide a portable test case in which pwrite()
1525 // blocks we can enable this test to run in both rounds.
1528 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1529 tempfd = mkstemp (fname);
1532 printf ("%s: mkstemp failed\n", __FUNCTION__);
1537 int r = pthread_barrier_wait (&b2);
1538 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1540 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1544 r = pthread_barrier_wait (&b2);
1545 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1547 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1551 pthread_cleanup_push (cl, NULL);
1554 pwrite (tempfd, mem, sizeof (mem), 0);
1556 pthread_cleanup_pop (0);
1558 printf ("%s: pwrite returned\n", __FUNCTION__);
1565 tf_fsync (void *arg)
1568 // XXX If somebody can provide a portable test case in which fsync()
1569 // blocks we can enable this test to run in both rounds.
1572 tempfd = open ("Makefile", O_RDONLY);
1575 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1579 int r = pthread_barrier_wait (&b2);
1580 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1582 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1586 r = pthread_barrier_wait (&b2);
1587 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1589 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1593 pthread_cleanup_push (cl, NULL);
1597 pthread_cleanup_pop (0);
1599 printf ("%s: fsync returned\n", __FUNCTION__);
1606 tf_fdatasync (void *arg)
1609 // XXX If somebody can provide a portable test case in which fdatasync()
1610 // blocks we can enable this test to run in both rounds.
1613 tempfd = open ("Makefile", O_RDONLY);
1616 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1620 int r = pthread_barrier_wait (&b2);
1621 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1623 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1627 r = pthread_barrier_wait (&b2);
1628 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1630 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1634 pthread_cleanup_push (cl, NULL);
1638 pthread_cleanup_pop (0);
1640 printf ("%s: fdatasync returned\n", __FUNCTION__);
1647 tf_msync (void *arg)
1650 // XXX If somebody can provide a portable test case in which msync()
1651 // blocks we can enable this test to run in both rounds.
1654 tempfd = open ("Makefile", O_RDONLY);
1657 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1660 void *p = mmap (NULL, 10, PROT_READ, MAP_SHARED, tempfd, 0);
1661 if (p == MAP_FAILED)
1663 printf ("%s: mmap failed\n", __FUNCTION__);
1667 int r = pthread_barrier_wait (&b2);
1668 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1670 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1674 r = pthread_barrier_wait (&b2);
1675 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1677 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1681 pthread_cleanup_push (cl, NULL);
1685 pthread_cleanup_pop (0);
1687 printf ("%s: msync returned\n", __FUNCTION__);
1694 tf_sendto (void *arg)
1698 // XXX If somebody can provide a portable test case in which sendto()
1699 // blocks we can enable this test to run in both rounds.
1702 struct sockaddr_un sun;
1704 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1707 printf ("%s: first socket call failed\n", __FUNCTION__);
1716 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1719 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX");
1720 tfd = mkstemp(sun.sun_path);
1723 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1727 sun.sun_family = AF_UNIX;
1729 while (bind (tempfd, (struct sockaddr *) &sun,
1730 offsetof (struct sockaddr_un, sun_path)
1731 + strlen (sun.sun_path) + 1) != 0);
1732 tempfname = strdup (sun.sun_path);
1734 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1737 printf ("%s: second socket call failed\n", __FUNCTION__);
1741 int r = pthread_barrier_wait (&b2);
1742 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1744 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1748 r = pthread_barrier_wait (&b2);
1749 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1751 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1755 pthread_cleanup_push (cl, NULL);
1759 sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0,
1760 (struct sockaddr *) &sun,
1761 offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1);
1763 pthread_cleanup_pop (0);
1765 printf ("%s: sendto returned\n", __FUNCTION__);
1772 tf_sendmsg (void *arg)
1776 // XXX If somebody can provide a portable test case in which sendmsg()
1777 // blocks we can enable this test to run in both rounds.
1780 struct sockaddr_un sun;
1782 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1785 printf ("%s: first socket call failed\n", __FUNCTION__);
1794 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1797 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
1798 tfd = mkstemp(sun.sun_path);
1801 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1805 sun.sun_family = AF_UNIX;
1807 while (bind (tempfd, (struct sockaddr *) &sun,
1808 offsetof (struct sockaddr_un, sun_path)
1809 + strlen (sun.sun_path) + 1) != 0);
1810 tempfname = strdup (sun.sun_path);
1812 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1815 printf ("%s: second socket call failed\n", __FUNCTION__);
1819 int r = pthread_barrier_wait (&b2);
1820 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1822 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1826 r = pthread_barrier_wait (&b2);
1827 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1829 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1833 pthread_cleanup_push (cl, NULL);
1836 struct iovec iov[1];
1837 iov[0].iov_base = mem;
1842 m.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
1843 + strlen (sun.sun_path) + 1);
1846 m.msg_control = NULL;
1847 m.msg_controllen = 0;
1849 sendmsg (tempfd2, &m, 0);
1851 pthread_cleanup_pop (0);
1853 printf ("%s: sendmsg returned\n", __FUNCTION__);
1860 tf_creat (void *arg)
1863 // XXX If somebody can provide a portable test case in which sendmsg()
1864 // blocks we can enable this test to run in both rounds.
1867 int r = pthread_barrier_wait (&b2);
1868 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1870 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1874 r = pthread_barrier_wait (&b2);
1875 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1877 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1881 pthread_cleanup_push (cl, NULL);
1883 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1885 pthread_cleanup_pop (0);
1887 printf ("%s: creat returned\n", __FUNCTION__);
1894 tf_connect (void *arg)
1898 // XXX If somebody can provide a portable test case in which connect()
1899 // blocks we can enable this test to run in both rounds.
1902 struct sockaddr_un sun;
1904 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1907 printf ("%s: first socket call failed\n", __FUNCTION__);
1916 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1919 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1920 tfd = mkstemp(sun.sun_path);
1923 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1927 sun.sun_family = AF_UNIX;
1929 while (bind (tempfd, (struct sockaddr *) &sun,
1930 offsetof (struct sockaddr_un, sun_path)
1931 + strlen (sun.sun_path) + 1) != 0);
1932 tempfname = strdup (sun.sun_path);
1936 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1939 printf ("%s: second socket call failed\n", __FUNCTION__);
1943 int r = pthread_barrier_wait (&b2);
1944 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1946 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1952 r = pthread_barrier_wait (&b2);
1953 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1955 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1960 pthread_cleanup_push (cl, NULL);
1962 connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun));
1964 pthread_cleanup_pop (0);
1966 printf ("%s: connect returned\n", __FUNCTION__);
1973 tf_tcdrain (void *arg)
1976 // XXX If somebody can provide a portable test case in which tcdrain()
1977 // blocks we can enable this test to run in both rounds.
1980 int r = pthread_barrier_wait (&b2);
1981 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1983 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1989 r = pthread_barrier_wait (&b2);
1990 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1992 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1997 pthread_cleanup_push (cl, NULL);
1999 /* Regardless of stderr being a terminal, the tcdrain call should be
2001 tcdrain (STDERR_FILENO);
2003 pthread_cleanup_pop (0);
2005 printf ("%s: tcdrain returned\n", __FUNCTION__);
2012 tf_msgrcv (void *arg)
2014 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
2017 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2021 int r = pthread_barrier_wait (&b2);
2022 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2024 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2030 r = pthread_barrier_wait (&b2);
2031 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2033 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2040 pthread_cleanup_push (cl, NULL);
2048 /* We need a positive random number. */
2050 randnr = random () % 64000;
2051 while (randnr <= 0);
2055 s = msgrcv (tempmsg, (struct msgbuf *) &m, 10, randnr, 0);
2057 while (errno == EIDRM || errno == EINTR);
2059 pthread_cleanup_pop (0);
2061 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__, s);
2063 msgctl (tempmsg, IPC_RMID, NULL);
2070 tf_msgsnd (void *arg)
2073 // XXX If somebody can provide a portable test case in which msgsnd()
2074 // blocks we can enable this test to run in both rounds.
2077 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
2080 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2084 int r = pthread_barrier_wait (&b2);
2085 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2087 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2091 r = pthread_barrier_wait (&b2);
2092 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2094 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2098 pthread_cleanup_push (cl, NULL);
2105 /* We need a positive random number. */
2107 m.type = random () % 64000;
2108 while (m.type <= 0);
2109 msgsnd (tempmsg, (struct msgbuf *) &m, sizeof (m.mem), 0);
2111 pthread_cleanup_pop (0);
2113 printf ("%s: msgsnd returned\n", __FUNCTION__);
2115 msgctl (tempmsg, IPC_RMID, NULL);
2124 void *(*tf) (void *);
2129 #define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early }
2130 ADD_TEST (read, 2, 0),
2131 ADD_TEST (readv, 2, 0),
2132 ADD_TEST (select, 2, 0),
2133 ADD_TEST (pselect, 2, 0),
2134 ADD_TEST (poll, 2, 0),
2135 ADD_TEST (ppoll, 2, 0),
2136 ADD_TEST (write, 2, 0),
2137 ADD_TEST (writev, 2, 0),
2138 ADD_TEST (sleep, 2, 0),
2139 ADD_TEST (usleep, 2, 0),
2140 ADD_TEST (nanosleep, 2, 0),
2141 ADD_TEST (wait, 2, 0),
2142 ADD_TEST (waitid, 2, 0),
2143 ADD_TEST (waitpid, 2, 0),
2144 ADD_TEST (sigpause, 2, 0),
2145 ADD_TEST (sigsuspend, 2, 0),
2146 ADD_TEST (sigwait, 2, 0),
2147 ADD_TEST (sigwaitinfo, 2, 0),
2148 ADD_TEST (sigtimedwait, 2, 0),
2149 ADD_TEST (pause, 2, 0),
2150 ADD_TEST (accept, 2, 0),
2151 ADD_TEST (send, 2, 0),
2152 ADD_TEST (recv, 2, 0),
2153 ADD_TEST (recvfrom, 2, 0),
2154 ADD_TEST (recvmsg, 2, 0),
2155 ADD_TEST (open, 2, 1),
2156 ADD_TEST (close, 2, 1),
2157 ADD_TEST (pread, 2, 1),
2158 ADD_TEST (pwrite, 2, 1),
2159 ADD_TEST (fsync, 2, 1),
2160 ADD_TEST (fdatasync, 2, 1),
2161 ADD_TEST (msync, 2, 1),
2162 ADD_TEST (sendto, 2, 1),
2163 ADD_TEST (sendmsg, 2, 1),
2164 ADD_TEST (creat, 2, 1),
2165 ADD_TEST (connect, 2, 1),
2166 ADD_TEST (tcdrain, 2, 1),
2167 ADD_TEST (msgrcv, 2, 0),
2168 ADD_TEST (msgsnd, 2, 1),
2170 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2179 if (socketpair (AF_UNIX, SOCK_STREAM, PF_UNIX, fds) != 0)
2181 perror ("socketpair");
2187 setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
2188 if (getsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, &len) < 0)
2190 perror ("getsockopt");
2193 if (val >= WRITE_BUFFER_SIZE)
2195 puts ("minimum write buffer size too large");
2198 setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
2202 for (cnt = 0; cnt < ntest_tf; ++cnt)
2204 if (tests[cnt].only_early)
2207 if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0)
2209 puts ("b2 init failed");
2213 /* Reset the counter for the cleanup handler. */
2217 if (pthread_create (&th, NULL, tests[cnt].tf, NULL) != 0)
2219 printf ("create for '%s' test failed\n", tests[cnt].name);
2224 int r = pthread_barrier_wait (&b2);
2225 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2227 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2232 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
2233 while (nanosleep (&ts, &ts) != 0)
2236 if (pthread_cancel (th) != 0)
2238 printf ("cancel for '%s' failed\n", tests[cnt].name);
2244 if (pthread_join (th, &status) != 0)
2246 printf ("join for '%s' failed\n", tests[cnt].name);
2250 if (status != PTHREAD_CANCELED)
2252 printf ("thread for '%s' not canceled\n", tests[cnt].name);
2257 if (pthread_barrier_destroy (&b2) != 0)
2259 puts ("barrier_destroy failed");
2266 printf ("cleanup handler not called for '%s'\n", tests[cnt].name);
2272 printf ("cleanup handler called more than once for '%s'\n",
2278 printf ("in-time cancel test of '%s' successful\n", tests[cnt].name);
2290 if (tempfname != NULL)
2298 msgctl (tempmsg, IPC_RMID, NULL);
2303 for (cnt = 0; cnt < ntest_tf; ++cnt)
2305 if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0)
2307 puts ("b2 init failed");
2311 /* Reset the counter for the cleanup handler. */
2315 if (pthread_create (&th, NULL, tests[cnt].tf, (void *) 1l) != 0)
2317 printf ("create for '%s' test failed\n", tests[cnt].name);
2322 int r = pthread_barrier_wait (&b2);
2323 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2325 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2330 if (pthread_cancel (th) != 0)
2332 printf ("cancel for '%s' failed\n", tests[cnt].name);
2337 r = pthread_barrier_wait (&b2);
2338 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2340 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2346 if (pthread_join (th, &status) != 0)
2348 printf ("join for '%s' failed\n", tests[cnt].name);
2352 if (status != PTHREAD_CANCELED)
2354 printf ("thread for '%s' not canceled\n", tests[cnt].name);
2359 if (pthread_barrier_destroy (&b2) != 0)
2361 puts ("barrier_destroy failed");
2368 printf ("cleanup handler not called for '%s'\n", tests[cnt].name);
2374 printf ("cleanup handler called more than once for '%s'\n",
2380 printf ("early cancel test of '%s' successful\n", tests[cnt].name);
2392 if (tempfname != NULL)
2400 msgctl (tempmsg, IPC_RMID, NULL);
2409 #define TEST_FUNCTION do_test ()
2410 #include "../test-skeleton.c"