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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 /* NOTE: this tests functionality beyond POSIX. POSIX does not allow
21 exit to be called more than once. */
36 #include <sys/select.h>
37 #include <sys/socket.h>
45 /* Since STREAMS are not supported in the standard Linux kernel and
46 there we don't advertise STREAMS as supported is no need to test
47 the STREAMS related functions. This affects
48 getmsg() getpmsg() putmsg()
51 lockf() and fcntl() are tested in tst-cancel16.
53 pthread_join() is tested in tst-join5.
55 pthread_testcancel()'s only purpose is to allow cancellation. This
56 is tested in several places.
58 sem_wait() and sem_timedwait() are checked in tst-cancel1[2345] tests.
60 mq_send(), mq_timedsend(), mq_receive() and mq_timedreceive() are checked
61 in tst-mqueue8{,x} tests.
63 aio_suspend() is tested in tst-cancel17.
65 clock_nanosleep() is tested in tst-cancel18.
68 /* Pipe descriptors. */
71 /* Temporary file descriptor, to be closed after each round. */
72 static int tempfd = -1;
73 static int tempfd2 = -1;
74 /* Name of temporary file to be removed after each round. */
75 static char *tempfname;
76 /* Temporary message queue. */
77 static int tempmsg = -1;
79 /* Often used barrier for two threads. */
80 static pthread_barrier_t b2;
87 #define WRITE_BUFFER_SIZE 4096
89 /* Cleanup handling test. */
110 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
111 tempfd = fd = mkstemp (fname);
113 printf ("%s: mkstemp failed\n", __FUNCTION__);
116 r = pthread_barrier_wait (&b2);
117 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
119 printf ("%s: barrier_wait failed\n", __FUNCTION__);
124 r = pthread_barrier_wait (&b2);
125 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
127 printf ("%s: barrier_wait failed\n", __FUNCTION__);
132 pthread_cleanup_push (cl, NULL);
135 s = read (fd, buf, sizeof (buf));
137 pthread_cleanup_pop (0);
139 printf ("%s: read returns with %zd\n", __FUNCTION__, s);
155 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
156 tempfd = fd = mkstemp (fname);
158 printf ("%s: mkstemp failed\n", __FUNCTION__);
161 r = pthread_barrier_wait (&b2);
162 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
164 printf ("%s: barrier_wait failed\n", __FUNCTION__);
169 r = pthread_barrier_wait (&b2);
170 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
172 printf ("%s: barrier_wait failed\n", __FUNCTION__);
177 pthread_cleanup_push (cl, NULL);
180 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
181 s = readv (fd, iov, 1);
183 pthread_cleanup_pop (0);
185 printf ("%s: readv returns with %zd\n", __FUNCTION__, s);
201 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
202 tempfd = fd = mkstemp (fname);
204 printf ("%s: mkstemp failed\n", __FUNCTION__);
207 r = pthread_barrier_wait (&b2);
208 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
210 printf ("%s: barrier_wait failed\n", __FUNCTION__);
215 r = pthread_barrier_wait (&b2);
216 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
218 printf ("%s: barrier_wait failed\n", __FUNCTION__);
223 pthread_cleanup_push (cl, NULL);
225 char buf[WRITE_BUFFER_SIZE];
226 memset (buf, '\0', sizeof (buf));
227 s = write (fd, buf, sizeof (buf));
229 pthread_cleanup_pop (0);
231 printf ("%s: write returns with %zd\n", __FUNCTION__, s);
238 tf_writev (void *arg)
247 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
248 tempfd = fd = mkstemp (fname);
250 printf ("%s: mkstemp failed\n", __FUNCTION__);
253 r = pthread_barrier_wait (&b2);
254 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
256 printf ("%s: barrier_wait failed\n", __FUNCTION__);
261 r = pthread_barrier_wait (&b2);
262 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
264 printf ("%s: barrier_wait failed\n", __FUNCTION__);
269 pthread_cleanup_push (cl, NULL);
271 char buf[WRITE_BUFFER_SIZE];
272 memset (buf, '\0', sizeof (buf));
273 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
274 s = writev (fd, iov, 1);
276 pthread_cleanup_pop (0);
278 printf ("%s: writev returns with %zd\n", __FUNCTION__, s);
287 int r = pthread_barrier_wait (&b2);
288 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
290 printf ("%s: barrier_wait failed\n", __FUNCTION__);
296 r = pthread_barrier_wait (&b2);
297 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
299 printf ("%s: barrier_wait failed\n", __FUNCTION__);
304 pthread_cleanup_push (cl, NULL);
306 sleep (arg == NULL ? 1000000 : 0);
308 pthread_cleanup_pop (0);
310 printf ("%s: sleep returns\n", __FUNCTION__);
317 tf_usleep (void *arg)
319 int r = pthread_barrier_wait (&b2);
320 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
322 printf ("%s: barrier_wait failed\n", __FUNCTION__);
328 r = pthread_barrier_wait (&b2);
329 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
331 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
336 pthread_cleanup_push (cl, NULL);
338 usleep (arg == NULL ? (useconds_t) ULONG_MAX : 0);
340 pthread_cleanup_pop (0);
342 printf ("%s: usleep returns\n", __FUNCTION__);
349 tf_nanosleep (void *arg)
351 int r = pthread_barrier_wait (&b2);
352 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
354 printf ("%s: barrier_wait failed\n", __FUNCTION__);
360 r = pthread_barrier_wait (&b2);
361 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
363 printf ("%s: barrier_wait failed\n", __FUNCTION__);
368 pthread_cleanup_push (cl, NULL);
370 struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 };
371 TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
373 pthread_cleanup_pop (0);
375 printf ("%s: nanosleep returns\n", __FUNCTION__);
382 tf_select (void *arg)
391 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
392 tempfd = fd = mkstemp (fname);
394 printf ("%s: mkstemp failed\n", __FUNCTION__);
397 r = pthread_barrier_wait (&b2);
398 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
400 printf ("%s: barrier_wait failed\n", __FUNCTION__);
405 r = pthread_barrier_wait (&b2);
406 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
408 printf ("%s: barrier_wait failed\n", __FUNCTION__);
417 pthread_cleanup_push (cl, NULL);
419 s = select (fd + 1, &rfs, NULL, NULL, NULL);
421 pthread_cleanup_pop (0);
423 printf ("%s: select returns with %d (%s)\n", __FUNCTION__, s,
431 tf_pselect (void *arg)
440 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
441 tempfd = fd = mkstemp (fname);
443 printf ("%s: mkstemp failed\n", __FUNCTION__);
446 r = pthread_barrier_wait (&b2);
447 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
449 printf ("%s: barrier_wait failed\n", __FUNCTION__);
454 r = pthread_barrier_wait (&b2);
455 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
457 printf ("%s: barrier_wait failed\n", __FUNCTION__);
466 pthread_cleanup_push (cl, NULL);
468 s = pselect (fd + 1, &rfs, NULL, NULL, NULL, NULL);
470 pthread_cleanup_pop (0);
472 printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__, s,
489 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
490 tempfd = fd = mkstemp (fname);
492 printf ("%s: mkstemp failed\n", __FUNCTION__);
495 r = pthread_barrier_wait (&b2);
496 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
498 printf ("%s: barrier_wait failed\n", __FUNCTION__);
503 r = pthread_barrier_wait (&b2);
504 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
506 printf ("%s: barrier_wait failed\n", __FUNCTION__);
510 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
513 pthread_cleanup_push (cl, NULL);
515 s = poll (rfs, 1, -1);
517 pthread_cleanup_pop (0);
519 printf ("%s: poll returns with %d (%s)\n", __FUNCTION__, s,
536 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
537 tempfd = fd = mkstemp (fname);
539 printf ("%s: mkstemp failed\n", __FUNCTION__);
542 r = pthread_barrier_wait (&b2);
543 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
545 printf ("%s: barrier_wait failed\n", __FUNCTION__);
550 r = pthread_barrier_wait (&b2);
551 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
553 printf ("%s: barrier_wait failed\n", __FUNCTION__);
557 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
560 pthread_cleanup_push (cl, NULL);
562 s = ppoll (rfs, 1, NULL, NULL);
564 pthread_cleanup_pop (0);
566 printf ("%s: ppoll returns with %d (%s)\n", __FUNCTION__, s,
579 puts ("fork failed");
585 /* Make the program disappear after a while. */
594 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
595 while (nanosleep (&ts, &ts) != 0)
598 r = pthread_barrier_wait (&b2);
599 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
601 printf ("%s: barrier_wait failed\n", __FUNCTION__);
606 r = pthread_barrier_wait (&b2);
607 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
609 printf ("%s: barrier_wait failed\n", __FUNCTION__);
614 pthread_cleanup_push (cl, NULL);
618 pthread_cleanup_pop (0);
620 printf ("%s: wait returns with %d (%s)\n", __FUNCTION__, s,
628 tf_waitpid (void *arg)
634 puts ("fork failed");
640 /* Make the program disappear after a while. */
649 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
650 while (nanosleep (&ts, &ts) != 0)
653 r = pthread_barrier_wait (&b2);
654 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
656 printf ("%s: barrier_wait failed\n", __FUNCTION__);
661 r = pthread_barrier_wait (&b2);
662 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
664 printf ("%s: barrier_wait failed\n", __FUNCTION__);
669 pthread_cleanup_push (cl, NULL);
671 s = waitpid (-1, NULL, 0);
673 pthread_cleanup_pop (0);
675 printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__, s,
683 tf_waitid (void *arg)
688 puts ("fork failed");
694 /* Make the program disappear after a while. */
703 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
704 while (nanosleep (&ts, &ts) != 0)
707 r = pthread_barrier_wait (&b2);
708 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
710 printf ("%s: barrier_wait failed\n", __FUNCTION__);
715 r = pthread_barrier_wait (&b2);
716 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
718 printf ("%s: barrier_wait failed\n", __FUNCTION__);
723 pthread_cleanup_push (cl, NULL);
729 s = waitid (P_PID, pid, &si, WEXITED);
731 pthread_cleanup_pop (0);
733 printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__, s,
741 tf_sigpause (void *arg)
743 int r = pthread_barrier_wait (&b2);
744 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
746 printf ("%s: barrier_wait failed\n", __FUNCTION__);
752 r = pthread_barrier_wait (&b2);
753 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
755 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
760 pthread_cleanup_push (cl, NULL);
762 /* Just for fun block the cancellation signal. We need to use
763 __xpg_sigpause since otherwise we will get the BSD version. */
764 //__xpg_sigpause (SIGCANCEL);
766 __sigpause (SIGCANCEL, 1);
768 pthread_cleanup_pop (0);
770 printf ("%s: sigpause returned\n", __FUNCTION__);
777 tf_sigsuspend (void *arg)
779 int r = pthread_barrier_wait (&b2);
780 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
782 printf ("%s: barrier_wait failed\n", __FUNCTION__);
788 r = pthread_barrier_wait (&b2);
789 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
791 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
796 pthread_cleanup_push (cl, NULL);
798 /* Just for fun block all signals. */
803 pthread_cleanup_pop (0);
805 printf ("%s: sigsuspend returned\n", __FUNCTION__);
812 tf_sigwait (void *arg)
814 int r = pthread_barrier_wait (&b2);
815 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
817 printf ("%s: barrier_wait failed\n", __FUNCTION__);
823 r = pthread_barrier_wait (&b2);
824 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
826 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
834 sigaddset (&mask, SIGUSR1);
835 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
837 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
842 pthread_cleanup_push (cl, NULL);
844 /* Wait for SIGUSR1. */
845 sigwait (&mask, &sig);
847 pthread_cleanup_pop (0);
849 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__, sig);
856 tf_sigwaitinfo (void *arg)
858 int r = pthread_barrier_wait (&b2);
859 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
861 printf ("%s: barrier_wait failed\n", __FUNCTION__);
867 r = pthread_barrier_wait (&b2);
868 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
870 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
878 sigaddset (&mask, SIGUSR1);
879 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
881 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
886 pthread_cleanup_push (cl, NULL);
888 /* Wait for SIGUSR1. */
889 sigwaitinfo (&mask, &info);
891 pthread_cleanup_pop (0);
893 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__,
901 tf_sigtimedwait (void *arg)
903 int r = pthread_barrier_wait (&b2);
904 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
906 printf ("%s: barrier_wait failed\n", __FUNCTION__);
912 r = pthread_barrier_wait (&b2);
913 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
915 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
923 sigaddset (&mask, SIGUSR1);
924 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
926 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
930 /* Wait for SIGUSR1. */
932 struct timespec ts = { .tv_sec = 60, .tv_nsec = 0 };
933 pthread_cleanup_push (cl, NULL);
935 sigtimedwait (&mask, &info, &ts);
937 pthread_cleanup_pop (0);
939 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__,
949 int r = pthread_barrier_wait (&b2);
950 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
952 printf ("%s: barrier_wait failed\n", __FUNCTION__);
958 r = pthread_barrier_wait (&b2);
959 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
961 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
966 pthread_cleanup_push (cl, NULL);
970 pthread_cleanup_pop (0);
972 printf ("%s: pause returned\n", __FUNCTION__);
979 tf_accept (void *arg)
982 struct sockaddr_un sun;
983 /* To test a non-blocking accept call we make the call file by using
984 a datagrame socket. */
985 int pf = arg == NULL ? SOCK_STREAM : SOCK_DGRAM;
987 tempfd = socket (AF_UNIX, pf, 0);
990 printf ("%s: socket call failed\n", __FUNCTION__);
999 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1002 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
1003 tfd = mkstemp(sun.sun_path);
1006 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1010 sun.sun_family = AF_UNIX;
1012 while (bind (tempfd, (struct sockaddr *) &sun,
1013 offsetof (struct sockaddr_un, sun_path)
1014 + strlen (sun.sun_path) + 1) != 0);
1016 unlink (sun.sun_path);
1020 socklen_t len = sizeof (sun);
1022 int r = pthread_barrier_wait (&b2);
1023 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1025 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1031 r = pthread_barrier_wait (&b2);
1032 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1034 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1039 pthread_cleanup_push (cl, NULL);
1041 accept (tempfd, (struct sockaddr *) &sun, &len);
1043 pthread_cleanup_pop (0);
1045 printf ("%s: accept returned\n", __FUNCTION__);
1055 struct sockaddr_un sun;
1057 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1060 printf ("%s: first socket call failed\n", __FUNCTION__);
1069 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1072 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1073 tfd = mkstemp(sun.sun_path);
1076 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1080 sun.sun_family = AF_UNIX;
1082 while (bind (tempfd, (struct sockaddr *) &sun,
1083 offsetof (struct sockaddr_un, sun_path)
1084 + strlen (sun.sun_path) + 1) != 0);
1088 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1091 printf ("%s: second socket call failed\n", __FUNCTION__);
1095 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1097 printf ("%s: connect failed\n", __FUNCTION__);
1101 unlink (sun.sun_path);
1103 int r = pthread_barrier_wait (&b2);
1104 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1106 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1112 r = pthread_barrier_wait (&b2);
1113 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1115 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1120 pthread_cleanup_push (cl, NULL);
1122 /* Very large block, so that the send call blocks. */
1125 send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
1127 pthread_cleanup_pop (0);
1129 printf ("%s: send returned\n", __FUNCTION__);
1139 struct sockaddr_un sun;
1141 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1144 printf ("%s: first socket call failed\n", __FUNCTION__);
1153 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1156 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX");
1157 tfd = mkstemp(sun.sun_path);
1160 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1164 sun.sun_family = AF_UNIX;
1166 while (bind (tempfd, (struct sockaddr *) &sun,
1167 offsetof (struct sockaddr_un, sun_path)
1168 + strlen (sun.sun_path) + 1) != 0);
1172 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1175 printf ("%s: second socket call failed\n", __FUNCTION__);
1179 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1181 printf ("%s: connect failed\n", __FUNCTION__);
1185 unlink (sun.sun_path);
1187 int r = pthread_barrier_wait (&b2);
1188 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1190 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1196 r = pthread_barrier_wait (&b2);
1197 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1199 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1204 pthread_cleanup_push (cl, NULL);
1208 recv (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0);
1210 pthread_cleanup_pop (0);
1212 printf ("%s: recv returned\n", __FUNCTION__);
1219 tf_recvfrom (void *arg)
1222 struct sockaddr_un sun;
1224 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1227 printf ("%s: first socket call failed\n", __FUNCTION__);
1236 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1239 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX");
1240 tfd = mkstemp(sun.sun_path);
1243 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1247 sun.sun_family = AF_UNIX;
1249 while (bind (tempfd, (struct sockaddr *) &sun,
1250 offsetof (struct sockaddr_un, sun_path)
1251 + strlen (sun.sun_path) + 1) != 0);
1253 tempfname = strdup (sun.sun_path);
1255 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1258 printf ("%s: second socket call failed\n", __FUNCTION__);
1262 int r = pthread_barrier_wait (&b2);
1263 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1265 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1271 r = pthread_barrier_wait (&b2);
1272 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1274 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1279 pthread_cleanup_push (cl, NULL);
1282 socklen_t len = sizeof (sun);
1284 recvfrom (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0,
1285 (struct sockaddr *) &sun, &len);
1287 pthread_cleanup_pop (0);
1289 printf ("%s: recvfrom returned\n", __FUNCTION__);
1296 tf_recvmsg (void *arg)
1299 struct sockaddr_un sun;
1301 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1304 printf ("%s: first socket call failed\n", __FUNCTION__);
1313 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1316 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
1317 tfd = mkstemp(sun.sun_path);
1320 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1324 sun.sun_family = AF_UNIX;
1326 while (bind (tempfd, (struct sockaddr *) &sun,
1327 offsetof (struct sockaddr_un, sun_path)
1328 + strlen (sun.sun_path) + 1) != 0);
1330 tempfname = strdup (sun.sun_path);
1332 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1335 printf ("%s: second socket call failed\n", __FUNCTION__);
1339 int r = pthread_barrier_wait (&b2);
1340 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1342 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1348 r = pthread_barrier_wait (&b2);
1349 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1351 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1356 pthread_cleanup_push (cl, NULL);
1359 struct iovec iov[1];
1360 iov[0].iov_base = mem;
1361 iov[0].iov_len = arg == NULL ? sizeof (mem) : 0;
1365 m.msg_namelen = sizeof (sun);
1368 m.msg_control = NULL;
1369 m.msg_controllen = 0;
1371 recvmsg (tempfd2, &m, 0);
1373 pthread_cleanup_pop (0);
1375 printf ("%s: recvmsg returned\n", __FUNCTION__);
1385 // XXX If somebody can provide a portable test case in which open()
1386 // blocks we can enable this test to run in both rounds.
1389 int r = pthread_barrier_wait (&b2);
1390 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1392 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1396 r = pthread_barrier_wait (&b2);
1397 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1399 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1403 pthread_cleanup_push (cl, NULL);
1405 open ("Makefile", O_RDONLY);
1407 pthread_cleanup_pop (0);
1409 printf ("%s: open returned\n", __FUNCTION__);
1416 tf_close (void *arg)
1419 // XXX If somebody can provide a portable test case in which close()
1420 // blocks we can enable this test to run in both rounds.
1423 char fname[] = "/tmp/tst-cancel-fd-XXXXXX";
1424 tempfd = mkstemp (fname);
1427 printf ("%s: mkstemp failed\n", __FUNCTION__);
1432 int r = pthread_barrier_wait (&b2);
1433 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1435 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1439 r = pthread_barrier_wait (&b2);
1440 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1442 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1446 pthread_cleanup_push (cl, NULL);
1450 pthread_cleanup_pop (0);
1452 printf ("%s: close returned\n", __FUNCTION__);
1459 tf_pread (void *arg)
1462 // XXX If somebody can provide a portable test case in which pread()
1463 // blocks we can enable this test to run in both rounds.
1466 tempfd = open ("Makefile", O_RDONLY);
1469 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1473 int r = pthread_barrier_wait (&b2);
1474 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1476 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1480 r = pthread_barrier_wait (&b2);
1481 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1483 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1487 pthread_cleanup_push (cl, NULL);
1490 pread (tempfd, mem, sizeof (mem), 0);
1492 pthread_cleanup_pop (0);
1494 printf ("%s: pread returned\n", __FUNCTION__);
1501 tf_pwrite (void *arg)
1504 // XXX If somebody can provide a portable test case in which pwrite()
1505 // blocks we can enable this test to run in both rounds.
1508 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1509 tempfd = mkstemp (fname);
1512 printf ("%s: mkstemp failed\n", __FUNCTION__);
1517 int r = pthread_barrier_wait (&b2);
1518 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1520 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1524 r = pthread_barrier_wait (&b2);
1525 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1527 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1531 pthread_cleanup_push (cl, NULL);
1534 pwrite (tempfd, mem, sizeof (mem), 0);
1536 pthread_cleanup_pop (0);
1538 printf ("%s: pwrite returned\n", __FUNCTION__);
1545 tf_fsync (void *arg)
1548 // XXX If somebody can provide a portable test case in which fsync()
1549 // blocks we can enable this test to run in both rounds.
1552 tempfd = open ("Makefile", O_RDONLY);
1555 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1559 int r = pthread_barrier_wait (&b2);
1560 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1562 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1566 r = pthread_barrier_wait (&b2);
1567 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1569 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1573 pthread_cleanup_push (cl, NULL);
1577 pthread_cleanup_pop (0);
1579 printf ("%s: fsync returned\n", __FUNCTION__);
1586 tf_fdatasync (void *arg)
1589 // XXX If somebody can provide a portable test case in which fdatasync()
1590 // blocks we can enable this test to run in both rounds.
1593 tempfd = open ("Makefile", O_RDONLY);
1596 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1600 int r = pthread_barrier_wait (&b2);
1601 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1603 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1607 r = pthread_barrier_wait (&b2);
1608 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1610 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1614 pthread_cleanup_push (cl, NULL);
1618 pthread_cleanup_pop (0);
1620 printf ("%s: fdatasync returned\n", __FUNCTION__);
1627 tf_msync (void *arg)
1630 // XXX If somebody can provide a portable test case in which msync()
1631 // blocks we can enable this test to run in both rounds.
1634 tempfd = open ("Makefile", O_RDONLY);
1637 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1640 void *p = mmap (NULL, 10, PROT_READ, MAP_SHARED, tempfd, 0);
1641 if (p == MAP_FAILED)
1643 printf ("%s: mmap failed\n", __FUNCTION__);
1647 int r = pthread_barrier_wait (&b2);
1648 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1650 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1654 r = pthread_barrier_wait (&b2);
1655 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1657 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1661 pthread_cleanup_push (cl, NULL);
1665 pthread_cleanup_pop (0);
1667 printf ("%s: msync returned\n", __FUNCTION__);
1674 tf_sendto (void *arg)
1678 // XXX If somebody can provide a portable test case in which sendto()
1679 // blocks we can enable this test to run in both rounds.
1682 struct sockaddr_un sun;
1684 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1687 printf ("%s: first socket call failed\n", __FUNCTION__);
1696 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1699 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX");
1700 tfd = mkstemp(sun.sun_path);
1703 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1707 sun.sun_family = AF_UNIX;
1709 while (bind (tempfd, (struct sockaddr *) &sun,
1710 offsetof (struct sockaddr_un, sun_path)
1711 + strlen (sun.sun_path) + 1) != 0);
1712 tempfname = strdup (sun.sun_path);
1714 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1717 printf ("%s: second socket call failed\n", __FUNCTION__);
1721 int r = pthread_barrier_wait (&b2);
1722 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1724 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1728 r = pthread_barrier_wait (&b2);
1729 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1731 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1735 pthread_cleanup_push (cl, NULL);
1739 sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0,
1740 (struct sockaddr *) &sun,
1741 offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1);
1743 pthread_cleanup_pop (0);
1745 printf ("%s: sendto returned\n", __FUNCTION__);
1752 tf_sendmsg (void *arg)
1756 // XXX If somebody can provide a portable test case in which sendmsg()
1757 // blocks we can enable this test to run in both rounds.
1760 struct sockaddr_un sun;
1762 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1765 printf ("%s: first socket call failed\n", __FUNCTION__);
1774 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1777 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
1778 tfd = mkstemp(sun.sun_path);
1781 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1785 sun.sun_family = AF_UNIX;
1787 while (bind (tempfd, (struct sockaddr *) &sun,
1788 offsetof (struct sockaddr_un, sun_path)
1789 + strlen (sun.sun_path) + 1) != 0);
1790 tempfname = strdup (sun.sun_path);
1792 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1795 printf ("%s: second socket call failed\n", __FUNCTION__);
1799 int r = pthread_barrier_wait (&b2);
1800 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1802 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1806 r = pthread_barrier_wait (&b2);
1807 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1809 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1813 pthread_cleanup_push (cl, NULL);
1816 struct iovec iov[1];
1817 iov[0].iov_base = mem;
1822 m.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
1823 + strlen (sun.sun_path) + 1);
1826 m.msg_control = NULL;
1827 m.msg_controllen = 0;
1829 sendmsg (tempfd2, &m, 0);
1831 pthread_cleanup_pop (0);
1833 printf ("%s: sendmsg returned\n", __FUNCTION__);
1840 tf_creat (void *arg)
1843 // XXX If somebody can provide a portable test case in which sendmsg()
1844 // blocks we can enable this test to run in both rounds.
1847 int r = pthread_barrier_wait (&b2);
1848 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1850 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1854 r = pthread_barrier_wait (&b2);
1855 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1857 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1861 pthread_cleanup_push (cl, NULL);
1863 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1865 pthread_cleanup_pop (0);
1867 printf ("%s: creat returned\n", __FUNCTION__);
1874 tf_connect (void *arg)
1878 // XXX If somebody can provide a portable test case in which connect()
1879 // blocks we can enable this test to run in both rounds.
1882 struct sockaddr_un sun;
1884 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1887 printf ("%s: first socket call failed\n", __FUNCTION__);
1896 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1899 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1900 tfd = mkstemp(sun.sun_path);
1903 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1907 sun.sun_family = AF_UNIX;
1909 while (bind (tempfd, (struct sockaddr *) &sun,
1910 offsetof (struct sockaddr_un, sun_path)
1911 + strlen (sun.sun_path) + 1) != 0);
1912 tempfname = strdup (sun.sun_path);
1916 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1919 printf ("%s: second socket call failed\n", __FUNCTION__);
1923 int r = pthread_barrier_wait (&b2);
1924 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1926 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1932 r = pthread_barrier_wait (&b2);
1933 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1935 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1940 pthread_cleanup_push (cl, NULL);
1942 connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun));
1944 pthread_cleanup_pop (0);
1946 printf ("%s: connect returned\n", __FUNCTION__);
1953 tf_tcdrain (void *arg)
1956 // XXX If somebody can provide a portable test case in which tcdrain()
1957 // blocks we can enable this test to run in both rounds.
1960 int r = pthread_barrier_wait (&b2);
1961 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1963 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1969 r = pthread_barrier_wait (&b2);
1970 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1972 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1977 pthread_cleanup_push (cl, NULL);
1979 /* Regardless of stderr being a terminal, the tcdrain call should be
1981 tcdrain (STDERR_FILENO);
1983 pthread_cleanup_pop (0);
1985 printf ("%s: tcdrain returned\n", __FUNCTION__);
1992 tf_msgrcv (void *arg)
1994 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
1997 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2001 int r = pthread_barrier_wait (&b2);
2002 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2004 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2010 r = pthread_barrier_wait (&b2);
2011 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2013 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2020 pthread_cleanup_push (cl, NULL);
2028 /* We need a positive random number. */
2030 randnr = random () % 64000;
2031 while (randnr <= 0);
2035 s = msgrcv (tempmsg, (struct msgbuf *) &m, 10, randnr, 0);
2037 while (errno == EIDRM || errno == EINTR);
2039 pthread_cleanup_pop (0);
2041 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__, s);
2043 msgctl (tempmsg, IPC_RMID, NULL);
2050 tf_msgsnd (void *arg)
2053 // XXX If somebody can provide a portable test case in which msgsnd()
2054 // blocks we can enable this test to run in both rounds.
2057 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
2060 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2064 int r = pthread_barrier_wait (&b2);
2065 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2067 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2071 r = pthread_barrier_wait (&b2);
2072 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2074 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2078 pthread_cleanup_push (cl, NULL);
2085 /* We need a positive random number. */
2087 m.type = random () % 64000;
2088 while (m.type <= 0);
2089 msgsnd (tempmsg, (struct msgbuf *) &m, sizeof (m.mem), 0);
2091 pthread_cleanup_pop (0);
2093 printf ("%s: msgsnd returned\n", __FUNCTION__);
2095 msgctl (tempmsg, IPC_RMID, NULL);
2104 void *(*tf) (void *);
2109 #define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early }
2110 ADD_TEST (read, 2, 0),
2111 ADD_TEST (readv, 2, 0),
2112 ADD_TEST (select, 2, 0),
2113 ADD_TEST (pselect, 2, 0),
2114 ADD_TEST (poll, 2, 0),
2115 ADD_TEST (ppoll, 2, 0),
2116 ADD_TEST (write, 2, 0),
2117 ADD_TEST (writev, 2, 0),
2118 ADD_TEST (sleep, 2, 0),
2119 ADD_TEST (usleep, 2, 0),
2120 ADD_TEST (nanosleep, 2, 0),
2121 ADD_TEST (wait, 2, 0),
2122 ADD_TEST (waitid, 2, 0),
2123 ADD_TEST (waitpid, 2, 0),
2124 ADD_TEST (sigpause, 2, 0),
2125 ADD_TEST (sigsuspend, 2, 0),
2126 ADD_TEST (sigwait, 2, 0),
2127 ADD_TEST (sigwaitinfo, 2, 0),
2128 ADD_TEST (sigtimedwait, 2, 0),
2129 ADD_TEST (pause, 2, 0),
2130 ADD_TEST (accept, 2, 0),
2131 ADD_TEST (send, 2, 0),
2132 ADD_TEST (recv, 2, 0),
2133 ADD_TEST (recvfrom, 2, 0),
2134 ADD_TEST (recvmsg, 2, 0),
2135 ADD_TEST (open, 2, 1),
2136 ADD_TEST (close, 2, 1),
2137 ADD_TEST (pread, 2, 1),
2138 ADD_TEST (pwrite, 2, 1),
2139 ADD_TEST (fsync, 2, 1),
2140 ADD_TEST (fdatasync, 2, 1),
2141 ADD_TEST (msync, 2, 1),
2142 ADD_TEST (sendto, 2, 1),
2143 ADD_TEST (sendmsg, 2, 1),
2144 ADD_TEST (creat, 2, 1),
2145 ADD_TEST (connect, 2, 1),
2146 ADD_TEST (tcdrain, 2, 1),
2147 ADD_TEST (msgrcv, 2, 0),
2148 ADD_TEST (msgsnd, 2, 1),
2150 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2159 if (socketpair (AF_UNIX, SOCK_STREAM, PF_UNIX, fds) != 0)
2161 perror ("socketpair");
2167 setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
2168 if (getsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, &len) < 0)
2170 perror ("getsockopt");
2173 if (val >= WRITE_BUFFER_SIZE)
2175 puts ("minimum write buffer size too large");
2178 setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
2182 for (cnt = 0; cnt < ntest_tf; ++cnt)
2184 if (tests[cnt].only_early)
2187 if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0)
2189 puts ("b2 init failed");
2193 /* Reset the counter for the cleanup handler. */
2197 if (pthread_create (&th, NULL, tests[cnt].tf, NULL) != 0)
2199 printf ("create for '%s' test failed\n", tests[cnt].name);
2204 int r = pthread_barrier_wait (&b2);
2205 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2207 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2212 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
2213 while (nanosleep (&ts, &ts) != 0)
2216 if (pthread_cancel (th) != 0)
2218 printf ("cancel for '%s' failed\n", tests[cnt].name);
2224 if (pthread_join (th, &status) != 0)
2226 printf ("join for '%s' failed\n", tests[cnt].name);
2230 if (status != PTHREAD_CANCELED)
2232 printf ("thread for '%s' not canceled\n", tests[cnt].name);
2237 if (pthread_barrier_destroy (&b2) != 0)
2239 puts ("barrier_destroy failed");
2246 printf ("cleanup handler not called for '%s'\n", tests[cnt].name);
2252 printf ("cleanup handler called more than once for '%s'\n",
2258 printf ("in-time cancel test of '%s' successful\n", tests[cnt].name);
2270 if (tempfname != NULL)
2278 msgctl (tempmsg, IPC_RMID, NULL);
2283 for (cnt = 0; cnt < ntest_tf; ++cnt)
2285 if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0)
2287 puts ("b2 init failed");
2291 /* Reset the counter for the cleanup handler. */
2295 if (pthread_create (&th, NULL, tests[cnt].tf, (void *) 1l) != 0)
2297 printf ("create for '%s' test failed\n", tests[cnt].name);
2302 int r = pthread_barrier_wait (&b2);
2303 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2305 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2310 if (pthread_cancel (th) != 0)
2312 printf ("cancel for '%s' failed\n", tests[cnt].name);
2317 r = pthread_barrier_wait (&b2);
2318 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2320 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2326 if (pthread_join (th, &status) != 0)
2328 printf ("join for '%s' failed\n", tests[cnt].name);
2332 if (status != PTHREAD_CANCELED)
2334 printf ("thread for '%s' not canceled\n", tests[cnt].name);
2339 if (pthread_barrier_destroy (&b2) != 0)
2341 puts ("barrier_destroy failed");
2348 printf ("cleanup handler not called for '%s'\n", tests[cnt].name);
2354 printf ("cleanup handler called more than once for '%s'\n",
2360 printf ("early cancel test of '%s' successful\n", tests[cnt].name);
2372 if (tempfname != NULL)
2380 msgctl (tempmsg, IPC_RMID, NULL);
2389 #define TEST_FUNCTION do_test ()
2390 #include "../test-skeleton.c"