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 #define WRITE_BUFFER_SIZE 4096
88 /* Cleanup handling test. */
109 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
110 tempfd = fd = mkstemp (fname);
112 printf ("%s: mkstemp failed\n", __FUNCTION__);
115 r = pthread_barrier_wait (&b2);
116 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
118 printf ("%s: barrier_wait failed\n", __FUNCTION__);
123 r = pthread_barrier_wait (&b2);
124 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
126 printf ("%s: barrier_wait failed\n", __FUNCTION__);
131 pthread_cleanup_push (cl, NULL);
134 s = read (fd, buf, sizeof (buf));
136 pthread_cleanup_pop (0);
138 printf ("%s: read returns with %zd\n", __FUNCTION__, s);
154 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
155 tempfd = fd = mkstemp (fname);
157 printf ("%s: mkstemp failed\n", __FUNCTION__);
160 r = pthread_barrier_wait (&b2);
161 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
163 printf ("%s: barrier_wait failed\n", __FUNCTION__);
168 r = pthread_barrier_wait (&b2);
169 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
171 printf ("%s: barrier_wait failed\n", __FUNCTION__);
176 pthread_cleanup_push (cl, NULL);
179 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
180 s = readv (fd, iov, 1);
182 pthread_cleanup_pop (0);
184 printf ("%s: readv returns with %zd\n", __FUNCTION__, s);
200 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
201 tempfd = fd = mkstemp (fname);
203 printf ("%s: mkstemp failed\n", __FUNCTION__);
206 r = pthread_barrier_wait (&b2);
207 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
209 printf ("%s: barrier_wait failed\n", __FUNCTION__);
214 r = pthread_barrier_wait (&b2);
215 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
217 printf ("%s: barrier_wait failed\n", __FUNCTION__);
222 pthread_cleanup_push (cl, NULL);
224 char buf[WRITE_BUFFER_SIZE];
225 memset (buf, '\0', sizeof (buf));
226 s = write (fd, buf, sizeof (buf));
228 pthread_cleanup_pop (0);
230 printf ("%s: write returns with %zd\n", __FUNCTION__, s);
237 tf_writev (void *arg)
246 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
247 tempfd = fd = mkstemp (fname);
249 printf ("%s: mkstemp failed\n", __FUNCTION__);
252 r = pthread_barrier_wait (&b2);
253 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
255 printf ("%s: barrier_wait failed\n", __FUNCTION__);
260 r = pthread_barrier_wait (&b2);
261 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
263 printf ("%s: barrier_wait failed\n", __FUNCTION__);
268 pthread_cleanup_push (cl, NULL);
270 char buf[WRITE_BUFFER_SIZE];
271 memset (buf, '\0', sizeof (buf));
272 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
273 s = writev (fd, iov, 1);
275 pthread_cleanup_pop (0);
277 printf ("%s: writev returns with %zd\n", __FUNCTION__, s);
286 int r = pthread_barrier_wait (&b2);
287 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
289 printf ("%s: barrier_wait failed\n", __FUNCTION__);
295 r = pthread_barrier_wait (&b2);
296 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
298 printf ("%s: barrier_wait failed\n", __FUNCTION__);
303 pthread_cleanup_push (cl, NULL);
305 sleep (arg == NULL ? 1000000 : 0);
307 pthread_cleanup_pop (0);
309 printf ("%s: sleep returns\n", __FUNCTION__);
316 tf_usleep (void *arg)
318 int r = pthread_barrier_wait (&b2);
319 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
321 printf ("%s: barrier_wait failed\n", __FUNCTION__);
327 r = pthread_barrier_wait (&b2);
328 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
330 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
335 pthread_cleanup_push (cl, NULL);
337 usleep (arg == NULL ? (useconds_t) ULONG_MAX : 0);
339 pthread_cleanup_pop (0);
341 printf ("%s: usleep returns\n", __FUNCTION__);
348 tf_nanosleep (void *arg)
350 int r = pthread_barrier_wait (&b2);
351 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
353 printf ("%s: barrier_wait failed\n", __FUNCTION__);
359 r = pthread_barrier_wait (&b2);
360 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
362 printf ("%s: barrier_wait failed\n", __FUNCTION__);
367 pthread_cleanup_push (cl, NULL);
369 struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 };
370 TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
372 pthread_cleanup_pop (0);
374 printf ("%s: nanosleep returns\n", __FUNCTION__);
381 tf_select (void *arg)
390 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
391 tempfd = fd = mkstemp (fname);
393 printf ("%s: mkstemp failed\n", __FUNCTION__);
396 r = pthread_barrier_wait (&b2);
397 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
399 printf ("%s: barrier_wait failed\n", __FUNCTION__);
404 r = pthread_barrier_wait (&b2);
405 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
407 printf ("%s: barrier_wait failed\n", __FUNCTION__);
416 pthread_cleanup_push (cl, NULL);
418 s = select (fd + 1, &rfs, NULL, NULL, NULL);
420 pthread_cleanup_pop (0);
422 printf ("%s: select returns with %d (%s)\n", __FUNCTION__, s,
430 tf_pselect (void *arg)
439 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
440 tempfd = fd = mkstemp (fname);
442 printf ("%s: mkstemp failed\n", __FUNCTION__);
445 r = pthread_barrier_wait (&b2);
446 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
448 printf ("%s: barrier_wait failed\n", __FUNCTION__);
453 r = pthread_barrier_wait (&b2);
454 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
456 printf ("%s: barrier_wait failed\n", __FUNCTION__);
465 pthread_cleanup_push (cl, NULL);
467 s = pselect (fd + 1, &rfs, NULL, NULL, NULL, NULL);
469 pthread_cleanup_pop (0);
471 printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__, s,
488 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
489 tempfd = fd = mkstemp (fname);
491 printf ("%s: mkstemp failed\n", __FUNCTION__);
494 r = pthread_barrier_wait (&b2);
495 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
497 printf ("%s: barrier_wait failed\n", __FUNCTION__);
502 r = pthread_barrier_wait (&b2);
503 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
505 printf ("%s: barrier_wait failed\n", __FUNCTION__);
509 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
512 pthread_cleanup_push (cl, NULL);
514 s = poll (rfs, 1, -1);
516 pthread_cleanup_pop (0);
518 printf ("%s: poll returns with %d (%s)\n", __FUNCTION__, s,
535 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
536 tempfd = fd = mkstemp (fname);
538 printf ("%s: mkstemp failed\n", __FUNCTION__);
541 r = pthread_barrier_wait (&b2);
542 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
544 printf ("%s: barrier_wait failed\n", __FUNCTION__);
549 r = pthread_barrier_wait (&b2);
550 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
552 printf ("%s: barrier_wait failed\n", __FUNCTION__);
556 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
559 pthread_cleanup_push (cl, NULL);
561 s = ppoll (rfs, 1, NULL, NULL);
563 pthread_cleanup_pop (0);
565 printf ("%s: ppoll returns with %d (%s)\n", __FUNCTION__, s,
578 puts ("fork failed");
584 /* Make the program disappear after a while. */
593 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
594 while (nanosleep (&ts, &ts) != 0)
597 r = pthread_barrier_wait (&b2);
598 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
600 printf ("%s: barrier_wait failed\n", __FUNCTION__);
605 r = pthread_barrier_wait (&b2);
606 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
608 printf ("%s: barrier_wait failed\n", __FUNCTION__);
613 pthread_cleanup_push (cl, NULL);
617 pthread_cleanup_pop (0);
619 printf ("%s: wait returns with %d (%s)\n", __FUNCTION__, s,
627 tf_waitpid (void *arg)
633 puts ("fork failed");
639 /* Make the program disappear after a while. */
648 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
649 while (nanosleep (&ts, &ts) != 0)
652 r = pthread_barrier_wait (&b2);
653 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
655 printf ("%s: barrier_wait failed\n", __FUNCTION__);
660 r = pthread_barrier_wait (&b2);
661 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
663 printf ("%s: barrier_wait failed\n", __FUNCTION__);
668 pthread_cleanup_push (cl, NULL);
670 s = waitpid (-1, NULL, 0);
672 pthread_cleanup_pop (0);
674 printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__, s,
682 tf_waitid (void *arg)
687 puts ("fork failed");
693 /* Make the program disappear after a while. */
702 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
703 while (nanosleep (&ts, &ts) != 0)
706 r = pthread_barrier_wait (&b2);
707 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
709 printf ("%s: barrier_wait failed\n", __FUNCTION__);
714 r = pthread_barrier_wait (&b2);
715 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
717 printf ("%s: barrier_wait failed\n", __FUNCTION__);
722 pthread_cleanup_push (cl, NULL);
728 s = waitid (P_PID, pid, &si, WEXITED);
730 pthread_cleanup_pop (0);
732 printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__, s,
740 tf_sigpause (void *arg)
742 int r = pthread_barrier_wait (&b2);
743 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
745 printf ("%s: barrier_wait failed\n", __FUNCTION__);
751 r = pthread_barrier_wait (&b2);
752 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
754 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
759 pthread_cleanup_push (cl, NULL);
761 /* Just for fun block the cancellation signal. We need to use
762 __xpg_sigpause since otherwise we will get the BSD version. */
763 //__xpg_sigpause (SIGCANCEL);
765 __sigpause (SIGCANCEL, 1);
767 pthread_cleanup_pop (0);
769 printf ("%s: sigpause returned\n", __FUNCTION__);
776 tf_sigsuspend (void *arg)
778 int r = pthread_barrier_wait (&b2);
779 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
781 printf ("%s: barrier_wait failed\n", __FUNCTION__);
787 r = pthread_barrier_wait (&b2);
788 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
790 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
795 pthread_cleanup_push (cl, NULL);
797 /* Just for fun block all signals. */
802 pthread_cleanup_pop (0);
804 printf ("%s: sigsuspend returned\n", __FUNCTION__);
811 tf_sigwait (void *arg)
813 int r = pthread_barrier_wait (&b2);
814 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
816 printf ("%s: barrier_wait failed\n", __FUNCTION__);
822 r = pthread_barrier_wait (&b2);
823 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
825 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
833 sigaddset (&mask, SIGUSR1);
834 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
836 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
841 pthread_cleanup_push (cl, NULL);
843 /* Wait for SIGUSR1. */
844 sigwait (&mask, &sig);
846 pthread_cleanup_pop (0);
848 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__, sig);
855 tf_sigwaitinfo (void *arg)
857 int r = pthread_barrier_wait (&b2);
858 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
860 printf ("%s: barrier_wait failed\n", __FUNCTION__);
866 r = pthread_barrier_wait (&b2);
867 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
869 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
877 sigaddset (&mask, SIGUSR1);
878 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
880 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
885 pthread_cleanup_push (cl, NULL);
887 /* Wait for SIGUSR1. */
888 sigwaitinfo (&mask, &info);
890 pthread_cleanup_pop (0);
892 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__,
900 tf_sigtimedwait (void *arg)
902 int r = pthread_barrier_wait (&b2);
903 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
905 printf ("%s: barrier_wait failed\n", __FUNCTION__);
911 r = pthread_barrier_wait (&b2);
912 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
914 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
922 sigaddset (&mask, SIGUSR1);
923 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
925 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
929 /* Wait for SIGUSR1. */
931 struct timespec ts = { .tv_sec = 60, .tv_nsec = 0 };
932 pthread_cleanup_push (cl, NULL);
934 sigtimedwait (&mask, &info, &ts);
936 pthread_cleanup_pop (0);
938 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__,
948 int r = pthread_barrier_wait (&b2);
949 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
951 printf ("%s: barrier_wait failed\n", __FUNCTION__);
957 r = pthread_barrier_wait (&b2);
958 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
960 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
965 pthread_cleanup_push (cl, NULL);
969 pthread_cleanup_pop (0);
971 printf ("%s: pause returned\n", __FUNCTION__);
978 tf_accept (void *arg)
981 struct sockaddr_un sun;
982 /* To test a non-blocking accept call we make the call file by using
983 a datagrame socket. */
984 int pf = arg == NULL ? SOCK_STREAM : SOCK_DGRAM;
986 tempfd = socket (AF_UNIX, pf, 0);
989 printf ("%s: socket call failed\n", __FUNCTION__);
998 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1001 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
1002 tfd = mkstemp(sun.sun_path);
1005 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1009 sun.sun_family = AF_UNIX;
1011 while (bind (tempfd, (struct sockaddr *) &sun,
1012 offsetof (struct sockaddr_un, sun_path)
1013 + strlen (sun.sun_path) + 1) != 0);
1015 unlink (sun.sun_path);
1019 socklen_t len = sizeof (sun);
1021 int r = pthread_barrier_wait (&b2);
1022 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1024 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1030 r = pthread_barrier_wait (&b2);
1031 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1033 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1038 pthread_cleanup_push (cl, NULL);
1040 accept (tempfd, (struct sockaddr *) &sun, &len);
1042 pthread_cleanup_pop (0);
1044 printf ("%s: accept returned\n", __FUNCTION__);
1054 struct sockaddr_un sun;
1056 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1059 printf ("%s: first socket call failed\n", __FUNCTION__);
1068 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1071 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1072 tfd = mkstemp(sun.sun_path);
1075 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1079 sun.sun_family = AF_UNIX;
1081 while (bind (tempfd, (struct sockaddr *) &sun,
1082 offsetof (struct sockaddr_un, sun_path)
1083 + strlen (sun.sun_path) + 1) != 0);
1087 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1090 printf ("%s: second socket call failed\n", __FUNCTION__);
1094 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1096 printf ("%s: connect failed\n", __FUNCTION__);
1100 unlink (sun.sun_path);
1102 int r = pthread_barrier_wait (&b2);
1103 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1105 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1111 r = pthread_barrier_wait (&b2);
1112 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1114 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1119 pthread_cleanup_push (cl, NULL);
1121 /* Very large block, so that the send call blocks. */
1124 send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
1126 pthread_cleanup_pop (0);
1128 printf ("%s: send returned\n", __FUNCTION__);
1138 struct sockaddr_un sun;
1140 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1143 printf ("%s: first socket call failed\n", __FUNCTION__);
1152 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1155 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX");
1156 tfd = mkstemp(sun.sun_path);
1159 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1163 sun.sun_family = AF_UNIX;
1165 while (bind (tempfd, (struct sockaddr *) &sun,
1166 offsetof (struct sockaddr_un, sun_path)
1167 + strlen (sun.sun_path) + 1) != 0);
1171 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1174 printf ("%s: second socket call failed\n", __FUNCTION__);
1178 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1180 printf ("%s: connect failed\n", __FUNCTION__);
1184 unlink (sun.sun_path);
1186 int r = pthread_barrier_wait (&b2);
1187 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1189 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1195 r = pthread_barrier_wait (&b2);
1196 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1198 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1203 pthread_cleanup_push (cl, NULL);
1207 recv (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0);
1209 pthread_cleanup_pop (0);
1211 printf ("%s: recv returned\n", __FUNCTION__);
1218 tf_recvfrom (void *arg)
1221 struct sockaddr_un sun;
1223 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1226 printf ("%s: first socket call failed\n", __FUNCTION__);
1235 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1238 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX");
1239 tfd = mkstemp(sun.sun_path);
1242 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1246 sun.sun_family = AF_UNIX;
1248 while (bind (tempfd, (struct sockaddr *) &sun,
1249 offsetof (struct sockaddr_un, sun_path)
1250 + strlen (sun.sun_path) + 1) != 0);
1252 tempfname = strdup (sun.sun_path);
1254 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1257 printf ("%s: second socket call failed\n", __FUNCTION__);
1261 int r = pthread_barrier_wait (&b2);
1262 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1264 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1270 r = pthread_barrier_wait (&b2);
1271 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1273 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1278 pthread_cleanup_push (cl, NULL);
1281 socklen_t len = sizeof (sun);
1283 recvfrom (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0,
1284 (struct sockaddr *) &sun, &len);
1286 pthread_cleanup_pop (0);
1288 printf ("%s: recvfrom returned\n", __FUNCTION__);
1295 tf_recvmsg (void *arg)
1298 struct sockaddr_un sun;
1300 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1303 printf ("%s: first socket call failed\n", __FUNCTION__);
1312 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1315 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
1316 tfd = mkstemp(sun.sun_path);
1319 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1323 sun.sun_family = AF_UNIX;
1325 while (bind (tempfd, (struct sockaddr *) &sun,
1326 offsetof (struct sockaddr_un, sun_path)
1327 + strlen (sun.sun_path) + 1) != 0);
1329 tempfname = strdup (sun.sun_path);
1331 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1334 printf ("%s: second socket call failed\n", __FUNCTION__);
1338 int r = pthread_barrier_wait (&b2);
1339 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1341 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1347 r = pthread_barrier_wait (&b2);
1348 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1350 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1355 pthread_cleanup_push (cl, NULL);
1358 struct iovec iov[1];
1359 iov[0].iov_base = mem;
1360 iov[0].iov_len = arg == NULL ? sizeof (mem) : 0;
1364 m.msg_namelen = sizeof (sun);
1367 m.msg_control = NULL;
1368 m.msg_controllen = 0;
1370 recvmsg (tempfd2, &m, 0);
1372 pthread_cleanup_pop (0);
1374 printf ("%s: recvmsg returned\n", __FUNCTION__);
1384 // XXX If somebody can provide a portable test case in which open()
1385 // blocks we can enable this test to run in both rounds.
1388 int r = pthread_barrier_wait (&b2);
1389 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1391 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1395 r = pthread_barrier_wait (&b2);
1396 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1398 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1402 pthread_cleanup_push (cl, NULL);
1404 open ("Makefile", O_RDONLY);
1406 pthread_cleanup_pop (0);
1408 printf ("%s: open returned\n", __FUNCTION__);
1415 tf_close (void *arg)
1418 // XXX If somebody can provide a portable test case in which close()
1419 // blocks we can enable this test to run in both rounds.
1422 char fname[] = "/tmp/tst-cancel-fd-XXXXXX";
1423 tempfd = mkstemp (fname);
1426 printf ("%s: mkstemp failed\n", __FUNCTION__);
1431 int r = pthread_barrier_wait (&b2);
1432 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1434 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1438 r = pthread_barrier_wait (&b2);
1439 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1441 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1445 pthread_cleanup_push (cl, NULL);
1449 pthread_cleanup_pop (0);
1451 printf ("%s: close returned\n", __FUNCTION__);
1458 tf_pread (void *arg)
1461 // XXX If somebody can provide a portable test case in which pread()
1462 // blocks we can enable this test to run in both rounds.
1465 tempfd = open ("Makefile", O_RDONLY);
1468 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1472 int r = pthread_barrier_wait (&b2);
1473 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1475 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1479 r = pthread_barrier_wait (&b2);
1480 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1482 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1486 pthread_cleanup_push (cl, NULL);
1489 pread (tempfd, mem, sizeof (mem), 0);
1491 pthread_cleanup_pop (0);
1493 printf ("%s: pread returned\n", __FUNCTION__);
1500 tf_pwrite (void *arg)
1503 // XXX If somebody can provide a portable test case in which pwrite()
1504 // blocks we can enable this test to run in both rounds.
1507 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1508 tempfd = mkstemp (fname);
1511 printf ("%s: mkstemp failed\n", __FUNCTION__);
1516 int r = pthread_barrier_wait (&b2);
1517 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1519 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1523 r = pthread_barrier_wait (&b2);
1524 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1526 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1530 pthread_cleanup_push (cl, NULL);
1533 pwrite (tempfd, mem, sizeof (mem), 0);
1535 pthread_cleanup_pop (0);
1537 printf ("%s: pwrite returned\n", __FUNCTION__);
1544 tf_fsync (void *arg)
1547 // XXX If somebody can provide a portable test case in which fsync()
1548 // blocks we can enable this test to run in both rounds.
1551 tempfd = open ("Makefile", O_RDONLY);
1554 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1558 int r = pthread_barrier_wait (&b2);
1559 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1561 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1565 r = pthread_barrier_wait (&b2);
1566 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1568 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1572 pthread_cleanup_push (cl, NULL);
1576 pthread_cleanup_pop (0);
1578 printf ("%s: fsync returned\n", __FUNCTION__);
1585 tf_fdatasync (void *arg)
1588 // XXX If somebody can provide a portable test case in which fdatasync()
1589 // blocks we can enable this test to run in both rounds.
1592 tempfd = open ("Makefile", O_RDONLY);
1595 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1599 int r = pthread_barrier_wait (&b2);
1600 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1602 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1606 r = pthread_barrier_wait (&b2);
1607 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1609 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1613 pthread_cleanup_push (cl, NULL);
1617 pthread_cleanup_pop (0);
1619 printf ("%s: fdatasync returned\n", __FUNCTION__);
1626 tf_msync (void *arg)
1629 // XXX If somebody can provide a portable test case in which msync()
1630 // blocks we can enable this test to run in both rounds.
1633 tempfd = open ("Makefile", O_RDONLY);
1636 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1639 void *p = mmap (NULL, 10, PROT_READ, MAP_SHARED, tempfd, 0);
1640 if (p == MAP_FAILED)
1642 printf ("%s: mmap failed\n", __FUNCTION__);
1646 int r = pthread_barrier_wait (&b2);
1647 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1649 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1653 r = pthread_barrier_wait (&b2);
1654 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1656 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1660 pthread_cleanup_push (cl, NULL);
1664 pthread_cleanup_pop (0);
1666 printf ("%s: msync returned\n", __FUNCTION__);
1673 tf_sendto (void *arg)
1677 // XXX If somebody can provide a portable test case in which sendto()
1678 // blocks we can enable this test to run in both rounds.
1681 struct sockaddr_un sun;
1683 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1686 printf ("%s: first socket call failed\n", __FUNCTION__);
1695 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1698 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX");
1699 tfd = mkstemp(sun.sun_path);
1702 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1706 sun.sun_family = AF_UNIX;
1708 while (bind (tempfd, (struct sockaddr *) &sun,
1709 offsetof (struct sockaddr_un, sun_path)
1710 + strlen (sun.sun_path) + 1) != 0);
1711 tempfname = strdup (sun.sun_path);
1713 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1716 printf ("%s: second socket call failed\n", __FUNCTION__);
1720 int r = pthread_barrier_wait (&b2);
1721 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1723 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1727 r = pthread_barrier_wait (&b2);
1728 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1730 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1734 pthread_cleanup_push (cl, NULL);
1738 sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0,
1739 (struct sockaddr *) &sun,
1740 offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1);
1742 pthread_cleanup_pop (0);
1744 printf ("%s: sendto returned\n", __FUNCTION__);
1751 tf_sendmsg (void *arg)
1755 // XXX If somebody can provide a portable test case in which sendmsg()
1756 // blocks we can enable this test to run in both rounds.
1759 struct sockaddr_un sun;
1761 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1764 printf ("%s: first socket call failed\n", __FUNCTION__);
1773 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1776 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
1777 tfd = mkstemp(sun.sun_path);
1780 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1784 sun.sun_family = AF_UNIX;
1786 while (bind (tempfd, (struct sockaddr *) &sun,
1787 offsetof (struct sockaddr_un, sun_path)
1788 + strlen (sun.sun_path) + 1) != 0);
1789 tempfname = strdup (sun.sun_path);
1791 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1794 printf ("%s: second socket call failed\n", __FUNCTION__);
1798 int r = pthread_barrier_wait (&b2);
1799 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1801 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1805 r = pthread_barrier_wait (&b2);
1806 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1808 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1812 pthread_cleanup_push (cl, NULL);
1815 struct iovec iov[1];
1816 iov[0].iov_base = mem;
1821 m.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
1822 + strlen (sun.sun_path) + 1);
1825 m.msg_control = NULL;
1826 m.msg_controllen = 0;
1828 sendmsg (tempfd2, &m, 0);
1830 pthread_cleanup_pop (0);
1832 printf ("%s: sendmsg returned\n", __FUNCTION__);
1839 tf_creat (void *arg)
1842 // XXX If somebody can provide a portable test case in which sendmsg()
1843 // blocks we can enable this test to run in both rounds.
1846 int r = pthread_barrier_wait (&b2);
1847 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1849 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1853 r = pthread_barrier_wait (&b2);
1854 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1856 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1860 pthread_cleanup_push (cl, NULL);
1862 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1864 pthread_cleanup_pop (0);
1866 printf ("%s: creat returned\n", __FUNCTION__);
1873 tf_connect (void *arg)
1877 // XXX If somebody can provide a portable test case in which connect()
1878 // blocks we can enable this test to run in both rounds.
1881 struct sockaddr_un sun;
1883 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1886 printf ("%s: first socket call failed\n", __FUNCTION__);
1895 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1898 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1899 tfd = mkstemp(sun.sun_path);
1902 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1906 sun.sun_family = AF_UNIX;
1908 while (bind (tempfd, (struct sockaddr *) &sun,
1909 offsetof (struct sockaddr_un, sun_path)
1910 + strlen (sun.sun_path) + 1) != 0);
1911 tempfname = strdup (sun.sun_path);
1915 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1918 printf ("%s: second socket call failed\n", __FUNCTION__);
1922 int r = pthread_barrier_wait (&b2);
1923 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1925 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1931 r = pthread_barrier_wait (&b2);
1932 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1934 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1939 pthread_cleanup_push (cl, NULL);
1941 connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun));
1943 pthread_cleanup_pop (0);
1945 printf ("%s: connect returned\n", __FUNCTION__);
1952 tf_tcdrain (void *arg)
1955 // XXX If somebody can provide a portable test case in which tcdrain()
1956 // blocks we can enable this test to run in both rounds.
1959 int r = pthread_barrier_wait (&b2);
1960 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1962 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1968 r = pthread_barrier_wait (&b2);
1969 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1971 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1976 pthread_cleanup_push (cl, NULL);
1978 /* Regardless of stderr being a terminal, the tcdrain call should be
1980 tcdrain (STDERR_FILENO);
1982 pthread_cleanup_pop (0);
1984 printf ("%s: tcdrain returned\n", __FUNCTION__);
1991 tf_msgrcv (void *arg)
1993 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
1996 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2000 int r = pthread_barrier_wait (&b2);
2001 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2003 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2009 r = pthread_barrier_wait (&b2);
2010 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2012 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2019 pthread_cleanup_push (cl, NULL);
2027 /* We need a positive random number. */
2029 randnr = random () % 64000;
2030 while (randnr <= 0);
2034 s = msgrcv (tempmsg, (struct msgbuf *) &m, 10, randnr, 0);
2036 while (errno == EIDRM || errno == EINTR);
2038 pthread_cleanup_pop (0);
2040 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__, s);
2042 msgctl (tempmsg, IPC_RMID, NULL);
2049 tf_msgsnd (void *arg)
2052 // XXX If somebody can provide a portable test case in which msgsnd()
2053 // blocks we can enable this test to run in both rounds.
2056 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
2059 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2063 int r = pthread_barrier_wait (&b2);
2064 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2066 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2070 r = pthread_barrier_wait (&b2);
2071 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2073 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2077 pthread_cleanup_push (cl, NULL);
2084 /* We need a positive random number. */
2086 m.type = random () % 64000;
2087 while (m.type <= 0);
2088 msgsnd (tempmsg, (struct msgbuf *) &m, sizeof (m.mem), 0);
2090 pthread_cleanup_pop (0);
2092 printf ("%s: msgsnd returned\n", __FUNCTION__);
2094 msgctl (tempmsg, IPC_RMID, NULL);
2103 void *(*tf) (void *);
2108 #define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early }
2109 ADD_TEST (read, 2, 0),
2110 ADD_TEST (readv, 2, 0),
2111 ADD_TEST (select, 2, 0),
2112 ADD_TEST (pselect, 2, 0),
2113 ADD_TEST (poll, 2, 0),
2114 ADD_TEST (ppoll, 2, 0),
2115 ADD_TEST (write, 2, 0),
2116 ADD_TEST (writev, 2, 0),
2117 ADD_TEST (sleep, 2, 0),
2118 ADD_TEST (usleep, 2, 0),
2119 ADD_TEST (nanosleep, 2, 0),
2120 ADD_TEST (wait, 2, 0),
2121 ADD_TEST (waitid, 2, 0),
2122 ADD_TEST (waitpid, 2, 0),
2123 ADD_TEST (sigpause, 2, 0),
2124 ADD_TEST (sigsuspend, 2, 0),
2125 ADD_TEST (sigwait, 2, 0),
2126 ADD_TEST (sigwaitinfo, 2, 0),
2127 ADD_TEST (sigtimedwait, 2, 0),
2128 ADD_TEST (pause, 2, 0),
2129 ADD_TEST (accept, 2, 0),
2130 ADD_TEST (send, 2, 0),
2131 ADD_TEST (recv, 2, 0),
2132 ADD_TEST (recvfrom, 2, 0),
2133 ADD_TEST (recvmsg, 2, 0),
2134 ADD_TEST (open, 2, 1),
2135 ADD_TEST (close, 2, 1),
2136 ADD_TEST (pread, 2, 1),
2137 ADD_TEST (pwrite, 2, 1),
2138 ADD_TEST (fsync, 2, 1),
2139 ADD_TEST (fdatasync, 2, 1),
2140 ADD_TEST (msync, 2, 1),
2141 ADD_TEST (sendto, 2, 1),
2142 ADD_TEST (sendmsg, 2, 1),
2143 ADD_TEST (creat, 2, 1),
2144 ADD_TEST (connect, 2, 1),
2145 ADD_TEST (tcdrain, 2, 1),
2146 ADD_TEST (msgrcv, 2, 0),
2147 ADD_TEST (msgsnd, 2, 1),
2149 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2158 if (socketpair (AF_UNIX, SOCK_STREAM, PF_UNIX, fds) != 0)
2160 perror ("socketpair");
2166 setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
2167 if (getsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, &len) < 0)
2169 perror ("getsockopt");
2172 if (val >= WRITE_BUFFER_SIZE)
2174 puts ("minimum write buffer size too large");
2177 setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
2181 for (cnt = 0; cnt < ntest_tf; ++cnt)
2183 if (tests[cnt].only_early)
2186 if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0)
2188 puts ("b2 init failed");
2192 /* Reset the counter for the cleanup handler. */
2196 if (pthread_create (&th, NULL, tests[cnt].tf, NULL) != 0)
2198 printf ("create for '%s' test failed\n", tests[cnt].name);
2203 int r = pthread_barrier_wait (&b2);
2204 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2206 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2211 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
2212 while (nanosleep (&ts, &ts) != 0)
2215 if (pthread_cancel (th) != 0)
2217 printf ("cancel for '%s' failed\n", tests[cnt].name);
2223 if (pthread_join (th, &status) != 0)
2225 printf ("join for '%s' failed\n", tests[cnt].name);
2229 if (status != PTHREAD_CANCELED)
2231 printf ("thread for '%s' not canceled\n", tests[cnt].name);
2236 if (pthread_barrier_destroy (&b2) != 0)
2238 puts ("barrier_destroy failed");
2245 printf ("cleanup handler not called for '%s'\n", tests[cnt].name);
2251 printf ("cleanup handler called more than once for '%s'\n",
2257 printf ("in-time cancel test of '%s' successful\n", tests[cnt].name);
2269 if (tempfname != NULL)
2277 msgctl (tempmsg, IPC_RMID, NULL);
2282 for (cnt = 0; cnt < ntest_tf; ++cnt)
2284 if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0)
2286 puts ("b2 init failed");
2290 /* Reset the counter for the cleanup handler. */
2294 if (pthread_create (&th, NULL, tests[cnt].tf, (void *) 1l) != 0)
2296 printf ("create for '%s' test failed\n", tests[cnt].name);
2301 int r = pthread_barrier_wait (&b2);
2302 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2304 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2309 if (pthread_cancel (th) != 0)
2311 printf ("cancel for '%s' failed\n", tests[cnt].name);
2316 r = pthread_barrier_wait (&b2);
2317 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2319 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2325 if (pthread_join (th, &status) != 0)
2327 printf ("join for '%s' failed\n", tests[cnt].name);
2331 if (status != PTHREAD_CANCELED)
2333 printf ("thread for '%s' not canceled\n", tests[cnt].name);
2338 if (pthread_barrier_destroy (&b2) != 0)
2340 puts ("barrier_destroy failed");
2347 printf ("cleanup handler not called for '%s'\n", tests[cnt].name);
2353 printf ("cleanup handler called more than once for '%s'\n",
2359 printf ("early cancel test of '%s' successful\n", tests[cnt].name);
2371 if (tempfname != NULL)
2379 msgctl (tempmsg, IPC_RMID, NULL);
2388 #define TEST_FUNCTION do_test ()
2389 #include "../test-skeleton.c"