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. */
762 sigpause (SIGCANCEL);
764 pthread_cleanup_pop (0);
766 printf ("%s: sigpause returned\n", __FUNCTION__);
773 tf_sigsuspend (void *arg)
775 int r = pthread_barrier_wait (&b2);
776 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
778 printf ("%s: barrier_wait failed\n", __FUNCTION__);
784 r = pthread_barrier_wait (&b2);
785 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
787 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
792 pthread_cleanup_push (cl, NULL);
794 /* Just for fun block all signals. */
799 pthread_cleanup_pop (0);
801 printf ("%s: sigsuspend returned\n", __FUNCTION__);
808 tf_sigwait (void *arg)
810 int r = pthread_barrier_wait (&b2);
811 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
813 printf ("%s: barrier_wait failed\n", __FUNCTION__);
819 r = pthread_barrier_wait (&b2);
820 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
822 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
830 sigaddset (&mask, SIGUSR1);
831 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
833 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
838 pthread_cleanup_push (cl, NULL);
840 /* Wait for SIGUSR1. */
841 sigwait (&mask, &sig);
843 pthread_cleanup_pop (0);
845 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__, sig);
852 tf_sigwaitinfo (void *arg)
854 int r = pthread_barrier_wait (&b2);
855 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
857 printf ("%s: barrier_wait failed\n", __FUNCTION__);
863 r = pthread_barrier_wait (&b2);
864 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
866 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
874 sigaddset (&mask, SIGUSR1);
875 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
877 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
882 pthread_cleanup_push (cl, NULL);
884 /* Wait for SIGUSR1. */
885 sigwaitinfo (&mask, &info);
887 pthread_cleanup_pop (0);
889 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__,
897 tf_sigtimedwait (void *arg)
899 int r = pthread_barrier_wait (&b2);
900 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
902 printf ("%s: barrier_wait failed\n", __FUNCTION__);
908 r = pthread_barrier_wait (&b2);
909 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
911 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
919 sigaddset (&mask, SIGUSR1);
920 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
922 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
926 /* Wait for SIGUSR1. */
928 struct timespec ts = { .tv_sec = 60, .tv_nsec = 0 };
929 pthread_cleanup_push (cl, NULL);
931 sigtimedwait (&mask, &info, &ts);
933 pthread_cleanup_pop (0);
935 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__,
945 int r = pthread_barrier_wait (&b2);
946 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
948 printf ("%s: barrier_wait failed\n", __FUNCTION__);
954 r = pthread_barrier_wait (&b2);
955 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
957 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
962 pthread_cleanup_push (cl, NULL);
966 pthread_cleanup_pop (0);
968 printf ("%s: pause returned\n", __FUNCTION__);
975 tf_accept (void *arg)
978 struct sockaddr_un sun;
979 /* To test a non-blocking accept call we make the call file by using
980 a datagrame socket. */
981 int pf = arg == NULL ? SOCK_STREAM : SOCK_DGRAM;
983 tempfd = socket (AF_UNIX, pf, 0);
986 printf ("%s: socket call failed\n", __FUNCTION__);
995 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
998 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
999 tfd = mkstemp(sun.sun_path);
1002 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1006 sun.sun_family = AF_UNIX;
1008 while (bind (tempfd, (struct sockaddr *) &sun,
1009 offsetof (struct sockaddr_un, sun_path)
1010 + strlen (sun.sun_path) + 1) != 0);
1012 unlink (sun.sun_path);
1016 socklen_t len = sizeof (sun);
1018 int r = pthread_barrier_wait (&b2);
1019 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1021 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1027 r = pthread_barrier_wait (&b2);
1028 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1030 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1035 pthread_cleanup_push (cl, NULL);
1037 accept (tempfd, (struct sockaddr *) &sun, &len);
1039 pthread_cleanup_pop (0);
1041 printf ("%s: accept returned\n", __FUNCTION__);
1051 struct sockaddr_un sun;
1053 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1056 printf ("%s: first socket call failed\n", __FUNCTION__);
1065 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1068 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1069 tfd = mkstemp(sun.sun_path);
1072 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1076 sun.sun_family = AF_UNIX;
1078 while (bind (tempfd, (struct sockaddr *) &sun,
1079 offsetof (struct sockaddr_un, sun_path)
1080 + strlen (sun.sun_path) + 1) != 0);
1084 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1087 printf ("%s: second socket call failed\n", __FUNCTION__);
1091 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1093 printf ("%s: connect failed\n", __FUNCTION__);
1097 unlink (sun.sun_path);
1099 int r = pthread_barrier_wait (&b2);
1100 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1102 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1108 r = pthread_barrier_wait (&b2);
1109 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1111 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1116 pthread_cleanup_push (cl, NULL);
1118 /* Very large block, so that the send call blocks. */
1121 send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
1123 pthread_cleanup_pop (0);
1125 printf ("%s: send returned\n", __FUNCTION__);
1135 struct sockaddr_un sun;
1137 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1140 printf ("%s: first socket call failed\n", __FUNCTION__);
1149 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1152 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX");
1153 tfd = mkstemp(sun.sun_path);
1156 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1160 sun.sun_family = AF_UNIX;
1162 while (bind (tempfd, (struct sockaddr *) &sun,
1163 offsetof (struct sockaddr_un, sun_path)
1164 + strlen (sun.sun_path) + 1) != 0);
1168 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1171 printf ("%s: second socket call failed\n", __FUNCTION__);
1175 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1177 printf ("%s: connect failed\n", __FUNCTION__);
1181 unlink (sun.sun_path);
1183 int r = pthread_barrier_wait (&b2);
1184 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1186 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1192 r = pthread_barrier_wait (&b2);
1193 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1195 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1200 pthread_cleanup_push (cl, NULL);
1204 recv (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0);
1206 pthread_cleanup_pop (0);
1208 printf ("%s: recv returned\n", __FUNCTION__);
1215 tf_recvfrom (void *arg)
1218 struct sockaddr_un sun;
1220 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1223 printf ("%s: first socket call failed\n", __FUNCTION__);
1232 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1235 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX");
1236 tfd = mkstemp(sun.sun_path);
1239 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1243 sun.sun_family = AF_UNIX;
1245 while (bind (tempfd, (struct sockaddr *) &sun,
1246 offsetof (struct sockaddr_un, sun_path)
1247 + strlen (sun.sun_path) + 1) != 0);
1249 tempfname = strdup (sun.sun_path);
1251 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1254 printf ("%s: second socket call failed\n", __FUNCTION__);
1258 int r = pthread_barrier_wait (&b2);
1259 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1261 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1267 r = pthread_barrier_wait (&b2);
1268 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1270 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1275 pthread_cleanup_push (cl, NULL);
1278 socklen_t len = sizeof (sun);
1280 recvfrom (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0,
1281 (struct sockaddr *) &sun, &len);
1283 pthread_cleanup_pop (0);
1285 printf ("%s: recvfrom returned\n", __FUNCTION__);
1292 tf_recvmsg (void *arg)
1295 struct sockaddr_un sun;
1297 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1300 printf ("%s: first socket call failed\n", __FUNCTION__);
1309 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1312 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
1313 tfd = mkstemp(sun.sun_path);
1316 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1320 sun.sun_family = AF_UNIX;
1322 while (bind (tempfd, (struct sockaddr *) &sun,
1323 offsetof (struct sockaddr_un, sun_path)
1324 + strlen (sun.sun_path) + 1) != 0);
1326 tempfname = strdup (sun.sun_path);
1328 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1331 printf ("%s: second socket call failed\n", __FUNCTION__);
1335 int r = pthread_barrier_wait (&b2);
1336 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1338 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1344 r = pthread_barrier_wait (&b2);
1345 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1347 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1352 pthread_cleanup_push (cl, NULL);
1355 struct iovec iov[1];
1356 iov[0].iov_base = mem;
1357 iov[0].iov_len = arg == NULL ? sizeof (mem) : 0;
1361 m.msg_namelen = sizeof (sun);
1364 m.msg_control = NULL;
1365 m.msg_controllen = 0;
1367 recvmsg (tempfd2, &m, 0);
1369 pthread_cleanup_pop (0);
1371 printf ("%s: recvmsg returned\n", __FUNCTION__);
1381 // XXX If somebody can provide a portable test case in which open()
1382 // blocks we can enable this test to run in both rounds.
1385 int r = pthread_barrier_wait (&b2);
1386 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1388 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1392 r = pthread_barrier_wait (&b2);
1393 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1395 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1399 pthread_cleanup_push (cl, NULL);
1401 open ("Makefile", O_RDONLY);
1403 pthread_cleanup_pop (0);
1405 printf ("%s: open returned\n", __FUNCTION__);
1412 tf_close (void *arg)
1415 // XXX If somebody can provide a portable test case in which close()
1416 // blocks we can enable this test to run in both rounds.
1419 char fname[] = "/tmp/tst-cancel-fd-XXXXXX";
1420 tempfd = mkstemp (fname);
1423 printf ("%s: mkstemp failed\n", __FUNCTION__);
1428 int r = pthread_barrier_wait (&b2);
1429 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1431 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1435 r = pthread_barrier_wait (&b2);
1436 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1438 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1442 pthread_cleanup_push (cl, NULL);
1446 pthread_cleanup_pop (0);
1448 printf ("%s: close returned\n", __FUNCTION__);
1455 tf_pread (void *arg)
1458 // XXX If somebody can provide a portable test case in which pread()
1459 // blocks we can enable this test to run in both rounds.
1462 tempfd = open ("Makefile", O_RDONLY);
1465 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1469 int r = pthread_barrier_wait (&b2);
1470 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1472 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1476 r = pthread_barrier_wait (&b2);
1477 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1479 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1483 pthread_cleanup_push (cl, NULL);
1486 pread (tempfd, mem, sizeof (mem), 0);
1488 pthread_cleanup_pop (0);
1490 printf ("%s: pread returned\n", __FUNCTION__);
1497 tf_pwrite (void *arg)
1500 // XXX If somebody can provide a portable test case in which pwrite()
1501 // blocks we can enable this test to run in both rounds.
1504 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1505 tempfd = mkstemp (fname);
1508 printf ("%s: mkstemp failed\n", __FUNCTION__);
1513 int r = pthread_barrier_wait (&b2);
1514 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1516 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1520 r = pthread_barrier_wait (&b2);
1521 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1523 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1527 pthread_cleanup_push (cl, NULL);
1530 pwrite (tempfd, mem, sizeof (mem), 0);
1532 pthread_cleanup_pop (0);
1534 printf ("%s: pwrite returned\n", __FUNCTION__);
1541 tf_fsync (void *arg)
1544 // XXX If somebody can provide a portable test case in which fsync()
1545 // blocks we can enable this test to run in both rounds.
1548 tempfd = open ("Makefile", O_RDONLY);
1551 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1555 int r = pthread_barrier_wait (&b2);
1556 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1558 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1562 r = pthread_barrier_wait (&b2);
1563 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1565 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1569 pthread_cleanup_push (cl, NULL);
1573 pthread_cleanup_pop (0);
1575 printf ("%s: fsync returned\n", __FUNCTION__);
1582 tf_fdatasync (void *arg)
1585 // XXX If somebody can provide a portable test case in which fdatasync()
1586 // blocks we can enable this test to run in both rounds.
1589 tempfd = open ("Makefile", O_RDONLY);
1592 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1596 int r = pthread_barrier_wait (&b2);
1597 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1599 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1603 r = pthread_barrier_wait (&b2);
1604 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1606 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1610 pthread_cleanup_push (cl, NULL);
1614 pthread_cleanup_pop (0);
1616 printf ("%s: fdatasync returned\n", __FUNCTION__);
1623 tf_msync (void *arg)
1626 // XXX If somebody can provide a portable test case in which msync()
1627 // blocks we can enable this test to run in both rounds.
1630 tempfd = open ("Makefile", O_RDONLY);
1633 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1636 void *p = mmap (NULL, 10, PROT_READ, MAP_SHARED, tempfd, 0);
1637 if (p == MAP_FAILED)
1639 printf ("%s: mmap failed\n", __FUNCTION__);
1643 int r = pthread_barrier_wait (&b2);
1644 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1646 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1650 r = pthread_barrier_wait (&b2);
1651 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1653 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1657 pthread_cleanup_push (cl, NULL);
1661 pthread_cleanup_pop (0);
1663 printf ("%s: msync returned\n", __FUNCTION__);
1670 tf_sendto (void *arg)
1674 // XXX If somebody can provide a portable test case in which sendto()
1675 // blocks we can enable this test to run in both rounds.
1678 struct sockaddr_un sun;
1680 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1683 printf ("%s: first socket call failed\n", __FUNCTION__);
1692 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1695 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX");
1696 tfd = mkstemp(sun.sun_path);
1699 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1703 sun.sun_family = AF_UNIX;
1705 while (bind (tempfd, (struct sockaddr *) &sun,
1706 offsetof (struct sockaddr_un, sun_path)
1707 + strlen (sun.sun_path) + 1) != 0);
1708 tempfname = strdup (sun.sun_path);
1710 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1713 printf ("%s: second socket call failed\n", __FUNCTION__);
1717 int r = pthread_barrier_wait (&b2);
1718 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1720 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1724 r = pthread_barrier_wait (&b2);
1725 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1727 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1731 pthread_cleanup_push (cl, NULL);
1735 sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0,
1736 (struct sockaddr *) &sun,
1737 offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1);
1739 pthread_cleanup_pop (0);
1741 printf ("%s: sendto returned\n", __FUNCTION__);
1748 tf_sendmsg (void *arg)
1752 // XXX If somebody can provide a portable test case in which sendmsg()
1753 // blocks we can enable this test to run in both rounds.
1756 struct sockaddr_un sun;
1758 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1761 printf ("%s: first socket call failed\n", __FUNCTION__);
1770 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1773 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
1774 tfd = mkstemp(sun.sun_path);
1777 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1781 sun.sun_family = AF_UNIX;
1783 while (bind (tempfd, (struct sockaddr *) &sun,
1784 offsetof (struct sockaddr_un, sun_path)
1785 + strlen (sun.sun_path) + 1) != 0);
1786 tempfname = strdup (sun.sun_path);
1788 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1791 printf ("%s: second socket call failed\n", __FUNCTION__);
1795 int r = pthread_barrier_wait (&b2);
1796 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1798 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1802 r = pthread_barrier_wait (&b2);
1803 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1805 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1809 pthread_cleanup_push (cl, NULL);
1812 struct iovec iov[1];
1813 iov[0].iov_base = mem;
1818 m.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
1819 + strlen (sun.sun_path) + 1);
1822 m.msg_control = NULL;
1823 m.msg_controllen = 0;
1825 sendmsg (tempfd2, &m, 0);
1827 pthread_cleanup_pop (0);
1829 printf ("%s: sendmsg returned\n", __FUNCTION__);
1836 tf_creat (void *arg)
1839 // XXX If somebody can provide a portable test case in which sendmsg()
1840 // blocks we can enable this test to run in both rounds.
1843 int r = pthread_barrier_wait (&b2);
1844 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1846 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1850 r = pthread_barrier_wait (&b2);
1851 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1853 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1857 pthread_cleanup_push (cl, NULL);
1859 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1861 pthread_cleanup_pop (0);
1863 printf ("%s: creat returned\n", __FUNCTION__);
1870 tf_connect (void *arg)
1874 // XXX If somebody can provide a portable test case in which connect()
1875 // blocks we can enable this test to run in both rounds.
1878 struct sockaddr_un sun;
1880 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1883 printf ("%s: first socket call failed\n", __FUNCTION__);
1892 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1895 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1896 tfd = mkstemp(sun.sun_path);
1899 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1903 sun.sun_family = AF_UNIX;
1905 while (bind (tempfd, (struct sockaddr *) &sun,
1906 offsetof (struct sockaddr_un, sun_path)
1907 + strlen (sun.sun_path) + 1) != 0);
1908 tempfname = strdup (sun.sun_path);
1912 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1915 printf ("%s: second socket call failed\n", __FUNCTION__);
1919 int r = pthread_barrier_wait (&b2);
1920 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1922 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1928 r = pthread_barrier_wait (&b2);
1929 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1931 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1936 pthread_cleanup_push (cl, NULL);
1938 connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun));
1940 pthread_cleanup_pop (0);
1942 printf ("%s: connect returned\n", __FUNCTION__);
1949 tf_tcdrain (void *arg)
1952 // XXX If somebody can provide a portable test case in which tcdrain()
1953 // blocks we can enable this test to run in both rounds.
1956 int r = pthread_barrier_wait (&b2);
1957 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1959 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1965 r = pthread_barrier_wait (&b2);
1966 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1968 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1973 pthread_cleanup_push (cl, NULL);
1975 /* Regardless of stderr being a terminal, the tcdrain call should be
1977 tcdrain (STDERR_FILENO);
1979 pthread_cleanup_pop (0);
1981 printf ("%s: tcdrain returned\n", __FUNCTION__);
1988 tf_msgrcv (void *arg)
1990 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
1993 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
1997 int r = pthread_barrier_wait (&b2);
1998 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2000 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2006 r = pthread_barrier_wait (&b2);
2007 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2009 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2016 pthread_cleanup_push (cl, NULL);
2024 /* We need a positive random number. */
2026 randnr = random () % 64000;
2027 while (randnr <= 0);
2031 s = msgrcv (tempmsg, (struct msgbuf *) &m, 10, randnr, 0);
2033 while (errno == EIDRM || errno == EINTR);
2035 pthread_cleanup_pop (0);
2037 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__, s);
2039 msgctl (tempmsg, IPC_RMID, NULL);
2046 tf_msgsnd (void *arg)
2049 // XXX If somebody can provide a portable test case in which msgsnd()
2050 // blocks we can enable this test to run in both rounds.
2053 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
2056 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2060 int r = pthread_barrier_wait (&b2);
2061 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2063 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2067 r = pthread_barrier_wait (&b2);
2068 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2070 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2074 pthread_cleanup_push (cl, NULL);
2081 /* We need a positive random number. */
2083 m.type = random () % 64000;
2084 while (m.type <= 0);
2085 msgsnd (tempmsg, (struct msgbuf *) &m, sizeof (m.mem), 0);
2087 pthread_cleanup_pop (0);
2089 printf ("%s: msgsnd returned\n", __FUNCTION__);
2091 msgctl (tempmsg, IPC_RMID, NULL);
2100 void *(*tf) (void *);
2105 #define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early }
2106 ADD_TEST (read, 2, 0),
2107 ADD_TEST (readv, 2, 0),
2108 ADD_TEST (select, 2, 0),
2109 ADD_TEST (pselect, 2, 0),
2110 ADD_TEST (poll, 2, 0),
2111 ADD_TEST (ppoll, 2, 0),
2112 ADD_TEST (write, 2, 0),
2113 ADD_TEST (writev, 2, 0),
2114 ADD_TEST (sleep, 2, 0),
2115 ADD_TEST (usleep, 2, 0),
2116 ADD_TEST (nanosleep, 2, 0),
2117 ADD_TEST (wait, 2, 0),
2118 ADD_TEST (waitid, 2, 0),
2119 ADD_TEST (waitpid, 2, 0),
2120 ADD_TEST (sigpause, 2, 0),
2121 ADD_TEST (sigsuspend, 2, 0),
2122 ADD_TEST (sigwait, 2, 0),
2123 ADD_TEST (sigwaitinfo, 2, 0),
2124 ADD_TEST (sigtimedwait, 2, 0),
2125 ADD_TEST (pause, 2, 0),
2126 ADD_TEST (accept, 2, 0),
2127 ADD_TEST (send, 2, 0),
2128 ADD_TEST (recv, 2, 0),
2129 ADD_TEST (recvfrom, 2, 0),
2130 ADD_TEST (recvmsg, 2, 0),
2131 ADD_TEST (open, 2, 1),
2132 ADD_TEST (close, 2, 1),
2133 ADD_TEST (pread, 2, 1),
2134 ADD_TEST (pwrite, 2, 1),
2135 ADD_TEST (fsync, 2, 1),
2136 ADD_TEST (fdatasync, 2, 1),
2137 ADD_TEST (msync, 2, 1),
2138 ADD_TEST (sendto, 2, 1),
2139 ADD_TEST (sendmsg, 2, 1),
2140 ADD_TEST (creat, 2, 1),
2141 ADD_TEST (connect, 2, 1),
2142 ADD_TEST (tcdrain, 2, 1),
2143 ADD_TEST (msgrcv, 2, 0),
2144 ADD_TEST (msgsnd, 2, 1),
2146 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2155 if (socketpair (AF_UNIX, SOCK_STREAM, PF_UNIX, fds) != 0)
2157 perror ("socketpair");
2163 setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
2164 if (getsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, &len) < 0)
2166 perror ("getsockopt");
2169 if (val >= WRITE_BUFFER_SIZE)
2171 puts ("minimum write buffer size too large");
2174 setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
2178 for (cnt = 0; cnt < ntest_tf; ++cnt)
2180 if (tests[cnt].only_early)
2183 if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0)
2185 puts ("b2 init failed");
2189 /* Reset the counter for the cleanup handler. */
2193 if (pthread_create (&th, NULL, tests[cnt].tf, NULL) != 0)
2195 printf ("create for '%s' test failed\n", tests[cnt].name);
2200 int r = pthread_barrier_wait (&b2);
2201 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2203 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2208 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
2209 while (nanosleep (&ts, &ts) != 0)
2212 if (pthread_cancel (th) != 0)
2214 printf ("cancel for '%s' failed\n", tests[cnt].name);
2220 if (pthread_join (th, &status) != 0)
2222 printf ("join for '%s' failed\n", tests[cnt].name);
2226 if (status != PTHREAD_CANCELED)
2228 printf ("thread for '%s' not canceled\n", tests[cnt].name);
2233 if (pthread_barrier_destroy (&b2) != 0)
2235 puts ("barrier_destroy failed");
2242 printf ("cleanup handler not called for '%s'\n", tests[cnt].name);
2248 printf ("cleanup handler called more than once for '%s'\n",
2254 printf ("in-time cancel test of '%s' successful\n", tests[cnt].name);
2266 if (tempfname != NULL)
2274 msgctl (tempmsg, IPC_RMID, NULL);
2279 for (cnt = 0; cnt < ntest_tf; ++cnt)
2281 if (pthread_barrier_init (&b2, NULL, tests[cnt].nb) != 0)
2283 puts ("b2 init failed");
2287 /* Reset the counter for the cleanup handler. */
2291 if (pthread_create (&th, NULL, tests[cnt].tf, (void *) 1l) != 0)
2293 printf ("create for '%s' test failed\n", tests[cnt].name);
2298 int r = pthread_barrier_wait (&b2);
2299 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2301 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2306 if (pthread_cancel (th) != 0)
2308 printf ("cancel for '%s' failed\n", tests[cnt].name);
2313 r = pthread_barrier_wait (&b2);
2314 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2316 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2322 if (pthread_join (th, &status) != 0)
2324 printf ("join for '%s' failed\n", tests[cnt].name);
2328 if (status != PTHREAD_CANCELED)
2330 printf ("thread for '%s' not canceled\n", tests[cnt].name);
2335 if (pthread_barrier_destroy (&b2) != 0)
2337 puts ("barrier_destroy failed");
2344 printf ("cleanup handler not called for '%s'\n", tests[cnt].name);
2350 printf ("cleanup handler called more than once for '%s'\n",
2356 printf ("early cancel test of '%s' successful\n", tests[cnt].name);
2368 if (tempfname != NULL)
2376 msgctl (tempmsg, IPC_RMID, NULL);
2385 #define TEST_FUNCTION do_test ()
2386 #include "../test-skeleton.c"