1 /* Copyright (C) 2002, 2003, 2004 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 /* Cleanup handling test. */
108 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
109 tempfd
= fd
= mkstemp (fname
);
111 printf ("%s: mkstemp failed\n", __FUNCTION__
);
114 r
= pthread_barrier_wait (&b2
);
115 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
117 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
122 r
= pthread_barrier_wait (&b2
);
123 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
125 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
130 pthread_cleanup_push (cl
, NULL
);
133 s
= read (fd
, buf
, sizeof (buf
));
135 pthread_cleanup_pop (0);
137 printf ("%s: read returns with %zd\n", __FUNCTION__
, s
);
153 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
154 tempfd
= fd
= mkstemp (fname
);
156 printf ("%s: mkstemp failed\n", __FUNCTION__
);
159 r
= pthread_barrier_wait (&b2
);
160 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
162 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
167 r
= pthread_barrier_wait (&b2
);
168 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
170 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
175 pthread_cleanup_push (cl
, NULL
);
178 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
179 s
= readv (fd
, iov
, 1);
181 pthread_cleanup_pop (0);
183 printf ("%s: readv returns with %zd\n", __FUNCTION__
, s
);
199 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
200 tempfd
= fd
= mkstemp (fname
);
202 printf ("%s: mkstemp failed\n", __FUNCTION__
);
205 r
= pthread_barrier_wait (&b2
);
206 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
208 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
213 r
= pthread_barrier_wait (&b2
);
214 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
216 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
221 pthread_cleanup_push (cl
, NULL
);
224 memset (buf
, '\0', sizeof (buf
));
225 s
= write (fd
, buf
, sizeof (buf
));
227 pthread_cleanup_pop (0);
229 printf ("%s: write returns with %zd\n", __FUNCTION__
, s
);
236 tf_writev (void *arg
)
245 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
246 tempfd
= fd
= mkstemp (fname
);
248 printf ("%s: mkstemp failed\n", __FUNCTION__
);
251 r
= pthread_barrier_wait (&b2
);
252 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
254 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
259 r
= pthread_barrier_wait (&b2
);
260 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
262 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
267 pthread_cleanup_push (cl
, NULL
);
270 memset (buf
, '\0', sizeof (buf
));
271 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
272 s
= writev (fd
, iov
, 1);
274 pthread_cleanup_pop (0);
276 printf ("%s: writev returns with %zd\n", __FUNCTION__
, s
);
285 int r
= pthread_barrier_wait (&b2
);
286 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
288 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
294 r
= pthread_barrier_wait (&b2
);
295 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
297 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
302 pthread_cleanup_push (cl
, NULL
);
304 sleep (arg
== NULL
? 1000000 : 0);
306 pthread_cleanup_pop (0);
308 printf ("%s: sleep returns\n", __FUNCTION__
);
315 tf_usleep (void *arg
)
317 int r
= pthread_barrier_wait (&b2
);
318 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
320 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
326 r
= pthread_barrier_wait (&b2
);
327 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
329 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
334 pthread_cleanup_push (cl
, NULL
);
336 usleep (arg
== NULL
? (useconds_t
) ULONG_MAX
: 0);
338 pthread_cleanup_pop (0);
340 printf ("%s: usleep returns\n", __FUNCTION__
);
347 tf_nanosleep (void *arg
)
349 int r
= pthread_barrier_wait (&b2
);
350 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
352 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
358 r
= pthread_barrier_wait (&b2
);
359 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
361 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
366 pthread_cleanup_push (cl
, NULL
);
368 struct timespec ts
= { .tv_sec
= arg
== NULL
? 10000000 : 0, .tv_nsec
= 0 };
369 TEMP_FAILURE_RETRY (nanosleep (&ts
, &ts
));
371 pthread_cleanup_pop (0);
373 printf ("%s: nanosleep returns\n", __FUNCTION__
);
380 tf_select (void *arg
)
389 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
390 tempfd
= fd
= mkstemp (fname
);
392 printf ("%s: mkstemp failed\n", __FUNCTION__
);
395 r
= pthread_barrier_wait (&b2
);
396 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
398 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
403 r
= pthread_barrier_wait (&b2
);
404 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
406 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
415 pthread_cleanup_push (cl
, NULL
);
417 s
= select (fd
+ 1, &rfs
, NULL
, NULL
, NULL
);
419 pthread_cleanup_pop (0);
421 printf ("%s: select returns with %d (%s)\n", __FUNCTION__
, s
,
429 tf_pselect (void *arg
)
438 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
439 tempfd
= fd
= mkstemp (fname
);
441 printf ("%s: mkstemp failed\n", __FUNCTION__
);
444 r
= pthread_barrier_wait (&b2
);
445 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
447 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
452 r
= pthread_barrier_wait (&b2
);
453 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
455 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
464 pthread_cleanup_push (cl
, NULL
);
466 s
= pselect (fd
+ 1, &rfs
, NULL
, NULL
, NULL
, NULL
);
468 pthread_cleanup_pop (0);
470 printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__
, s
,
487 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
488 tempfd
= fd
= mkstemp (fname
);
490 printf ("%s: mkstemp failed\n", __FUNCTION__
);
493 r
= pthread_barrier_wait (&b2
);
494 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
496 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
501 r
= pthread_barrier_wait (&b2
);
502 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
504 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
508 struct pollfd rfs
[1] = { [0] = { .fd
= fd
, .events
= POLLIN
} };
511 pthread_cleanup_push (cl
, NULL
);
513 s
= poll (rfs
, 1, -1);
515 pthread_cleanup_pop (0);
517 printf ("%s: poll returns with %d (%s)\n", __FUNCTION__
, s
,
530 puts ("fork failed");
536 /* Make the program disappear after a while. */
545 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
546 while (nanosleep (&ts
, &ts
) != 0)
549 r
= pthread_barrier_wait (&b2
);
550 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
552 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
557 r
= pthread_barrier_wait (&b2
);
558 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
560 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
565 pthread_cleanup_push (cl
, NULL
);
569 pthread_cleanup_pop (0);
571 printf ("%s: wait returns with %d (%s)\n", __FUNCTION__
, s
,
579 tf_waitpid (void *arg
)
585 puts ("fork failed");
591 /* Make the program disappear after a while. */
600 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
601 while (nanosleep (&ts
, &ts
) != 0)
604 r
= pthread_barrier_wait (&b2
);
605 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
607 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
612 r
= pthread_barrier_wait (&b2
);
613 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
615 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
620 pthread_cleanup_push (cl
, NULL
);
622 s
= waitpid (-1, NULL
, 0);
624 pthread_cleanup_pop (0);
626 printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__
, s
,
634 tf_waitid (void *arg
)
639 puts ("fork failed");
645 /* Make the program disappear after a while. */
654 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
655 while (nanosleep (&ts
, &ts
) != 0)
658 r
= pthread_barrier_wait (&b2
);
659 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
661 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
666 r
= pthread_barrier_wait (&b2
);
667 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
669 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
674 pthread_cleanup_push (cl
, NULL
);
680 s
= waitid (P_PID
, pid
, &si
, WEXITED
);
682 pthread_cleanup_pop (0);
684 printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__
, s
,
692 tf_sigpause (void *arg
)
694 int r
= pthread_barrier_wait (&b2
);
695 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
697 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
703 r
= pthread_barrier_wait (&b2
);
704 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
706 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
711 pthread_cleanup_push (cl
, NULL
);
713 /* Just for fun block the cancellation signal. We need to use
714 __xpg_sigpause since otherwise we will get the BSD version. */
715 __xpg_sigpause (SIGCANCEL
);
717 pthread_cleanup_pop (0);
719 printf ("%s: sigpause returned\n", __FUNCTION__
);
726 tf_sigsuspend (void *arg
)
728 int r
= pthread_barrier_wait (&b2
);
729 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
731 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
737 r
= pthread_barrier_wait (&b2
);
738 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
740 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
745 pthread_cleanup_push (cl
, NULL
);
747 /* Just for fun block all signals. */
752 pthread_cleanup_pop (0);
754 printf ("%s: sigsuspend returned\n", __FUNCTION__
);
761 tf_sigwait (void *arg
)
763 int r
= pthread_barrier_wait (&b2
);
764 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
766 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
772 r
= pthread_barrier_wait (&b2
);
773 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
775 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
783 sigaddset (&mask
, SIGUSR1
);
784 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
786 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
791 pthread_cleanup_push (cl
, NULL
);
793 /* Wait for SIGUSR1. */
794 sigwait (&mask
, &sig
);
796 pthread_cleanup_pop (0);
798 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__
, sig
);
805 tf_sigwaitinfo (void *arg
)
807 int r
= pthread_barrier_wait (&b2
);
808 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
810 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
816 r
= pthread_barrier_wait (&b2
);
817 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
819 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
827 sigaddset (&mask
, SIGUSR1
);
828 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
830 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
835 pthread_cleanup_push (cl
, NULL
);
837 /* Wait for SIGUSR1. */
838 sigwaitinfo (&mask
, &info
);
840 pthread_cleanup_pop (0);
842 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__
,
850 tf_sigtimedwait (void *arg
)
852 int r
= pthread_barrier_wait (&b2
);
853 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
855 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
861 r
= pthread_barrier_wait (&b2
);
862 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
864 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
872 sigaddset (&mask
, SIGUSR1
);
873 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
875 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
879 /* Wait for SIGUSR1. */
881 struct timespec ts
= { .tv_sec
= 60, .tv_nsec
= 0 };
882 pthread_cleanup_push (cl
, NULL
);
884 sigtimedwait (&mask
, &info
, &ts
);
886 pthread_cleanup_pop (0);
888 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__
,
898 int r
= pthread_barrier_wait (&b2
);
899 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
901 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
907 r
= pthread_barrier_wait (&b2
);
908 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
910 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
915 pthread_cleanup_push (cl
, NULL
);
919 pthread_cleanup_pop (0);
921 printf ("%s: pause returned\n", __FUNCTION__
);
928 tf_accept (void *arg
)
930 struct sockaddr_un sun
;
931 /* To test a non-blocking accept call we make the call file by using
932 a datagrame socket. */
933 int pf
= arg
== NULL
? SOCK_STREAM
: SOCK_DGRAM
;
935 tempfd
= socket (AF_UNIX
, pf
, 0);
938 printf ("%s: socket call failed\n", __FUNCTION__
);
947 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
950 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-1-XXXXXX");
951 if (mktemp (sun
.sun_path
) == NULL
)
953 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
957 sun
.sun_family
= AF_UNIX
;
959 while (bind (tempfd
, (struct sockaddr
*) &sun
,
960 offsetof (struct sockaddr_un
, sun_path
)
961 + strlen (sun
.sun_path
) + 1) != 0);
963 unlink (sun
.sun_path
);
967 socklen_t len
= sizeof (sun
);
969 int r
= pthread_barrier_wait (&b2
);
970 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
972 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
978 r
= pthread_barrier_wait (&b2
);
979 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
981 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
986 pthread_cleanup_push (cl
, NULL
);
988 accept (tempfd
, (struct sockaddr
*) &sun
, &len
);
990 pthread_cleanup_pop (0);
992 printf ("%s: accept returned\n", __FUNCTION__
);
1001 struct sockaddr_un sun
;
1003 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1006 printf ("%s: first socket call failed\n", __FUNCTION__
);
1015 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1018 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1019 if (mktemp (sun
.sun_path
) == NULL
)
1021 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1025 sun
.sun_family
= AF_UNIX
;
1027 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1028 offsetof (struct sockaddr_un
, sun_path
)
1029 + strlen (sun
.sun_path
) + 1) != 0);
1033 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1036 printf ("%s: second socket call failed\n", __FUNCTION__
);
1040 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1042 printf ("%s: connect failed\n", __FUNCTION__
);
1046 unlink (sun
.sun_path
);
1048 int r
= pthread_barrier_wait (&b2
);
1049 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1051 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1057 r
= pthread_barrier_wait (&b2
);
1058 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1060 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1065 pthread_cleanup_push (cl
, NULL
);
1067 /* Very large block, so that the send call blocks. */
1070 send (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0);
1072 pthread_cleanup_pop (0);
1074 printf ("%s: send returned\n", __FUNCTION__
);
1083 struct sockaddr_un sun
;
1085 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1088 printf ("%s: first socket call failed\n", __FUNCTION__
);
1097 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1100 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-3-XXXXXX");
1101 if (mktemp (sun
.sun_path
) == NULL
)
1103 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1107 sun
.sun_family
= AF_UNIX
;
1109 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1110 offsetof (struct sockaddr_un
, sun_path
)
1111 + strlen (sun
.sun_path
) + 1) != 0);
1115 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1118 printf ("%s: second socket call failed\n", __FUNCTION__
);
1122 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1124 printf ("%s: connect failed\n", __FUNCTION__
);
1128 unlink (sun
.sun_path
);
1130 int r
= pthread_barrier_wait (&b2
);
1131 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1133 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1139 r
= pthread_barrier_wait (&b2
);
1140 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1142 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1147 pthread_cleanup_push (cl
, NULL
);
1151 recv (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0);
1153 pthread_cleanup_pop (0);
1155 printf ("%s: recv returned\n", __FUNCTION__
);
1162 tf_recvfrom (void *arg
)
1164 struct sockaddr_un sun
;
1166 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1169 printf ("%s: first socket call failed\n", __FUNCTION__
);
1178 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1181 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-4-XXXXXX");
1182 if (mktemp (sun
.sun_path
) == NULL
)
1184 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1188 sun
.sun_family
= AF_UNIX
;
1190 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1191 offsetof (struct sockaddr_un
, sun_path
)
1192 + strlen (sun
.sun_path
) + 1) != 0);
1194 tempfname
= strdup (sun
.sun_path
);
1196 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1199 printf ("%s: second socket call failed\n", __FUNCTION__
);
1203 int r
= pthread_barrier_wait (&b2
);
1204 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1206 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1212 r
= pthread_barrier_wait (&b2
);
1213 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1215 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1220 pthread_cleanup_push (cl
, NULL
);
1223 socklen_t len
= sizeof (sun
);
1225 recvfrom (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0,
1226 (struct sockaddr
*) &sun
, &len
);
1228 pthread_cleanup_pop (0);
1230 printf ("%s: recvfrom returned\n", __FUNCTION__
);
1237 tf_recvmsg (void *arg
)
1239 struct sockaddr_un sun
;
1241 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1244 printf ("%s: first socket call failed\n", __FUNCTION__
);
1253 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1256 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-5-XXXXXX");
1257 if (mktemp (sun
.sun_path
) == NULL
)
1259 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1263 sun
.sun_family
= AF_UNIX
;
1265 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1266 offsetof (struct sockaddr_un
, sun_path
)
1267 + strlen (sun
.sun_path
) + 1) != 0);
1269 tempfname
= strdup (sun
.sun_path
);
1271 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1274 printf ("%s: second socket call failed\n", __FUNCTION__
);
1278 int r
= pthread_barrier_wait (&b2
);
1279 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1281 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1287 r
= pthread_barrier_wait (&b2
);
1288 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1290 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1295 pthread_cleanup_push (cl
, NULL
);
1298 struct iovec iov
[1];
1299 iov
[0].iov_base
= mem
;
1300 iov
[0].iov_len
= arg
== NULL
? sizeof (mem
) : 0;
1304 m
.msg_namelen
= sizeof (sun
);
1307 m
.msg_control
= NULL
;
1308 m
.msg_controllen
= 0;
1310 recvmsg (tempfd2
, &m
, 0);
1312 pthread_cleanup_pop (0);
1314 printf ("%s: recvmsg returned\n", __FUNCTION__
);
1324 // XXX If somebody can provide a portable test case in which open()
1325 // blocks we can enable this test to run in both rounds.
1328 int r
= pthread_barrier_wait (&b2
);
1329 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1331 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1335 r
= pthread_barrier_wait (&b2
);
1336 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1338 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1342 pthread_cleanup_push (cl
, NULL
);
1344 open ("Makefile", O_RDONLY
);
1346 pthread_cleanup_pop (0);
1348 printf ("%s: open returned\n", __FUNCTION__
);
1355 tf_close (void *arg
)
1358 // XXX If somebody can provide a portable test case in which close()
1359 // blocks we can enable this test to run in both rounds.
1362 char fname
[] = "/tmp/tst-cancel-fd-XXXXXX";
1363 tempfd
= mkstemp (fname
);
1366 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1371 int r
= pthread_barrier_wait (&b2
);
1372 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1374 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1378 r
= pthread_barrier_wait (&b2
);
1379 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1381 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1385 pthread_cleanup_push (cl
, NULL
);
1389 pthread_cleanup_pop (0);
1391 printf ("%s: close returned\n", __FUNCTION__
);
1398 tf_pread (void *arg
)
1401 // XXX If somebody can provide a portable test case in which pread()
1402 // blocks we can enable this test to run in both rounds.
1405 tempfd
= open ("Makefile", O_RDONLY
);
1408 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1412 int r
= pthread_barrier_wait (&b2
);
1413 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1415 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1419 r
= pthread_barrier_wait (&b2
);
1420 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1422 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1426 pthread_cleanup_push (cl
, NULL
);
1429 pread (tempfd
, mem
, sizeof (mem
), 0);
1431 pthread_cleanup_pop (0);
1433 printf ("%s: pread returned\n", __FUNCTION__
);
1440 tf_pwrite (void *arg
)
1443 // XXX If somebody can provide a portable test case in which pwrite()
1444 // blocks we can enable this test to run in both rounds.
1447 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1448 tempfd
= mkstemp (fname
);
1451 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1456 int r
= pthread_barrier_wait (&b2
);
1457 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1459 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1463 r
= pthread_barrier_wait (&b2
);
1464 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1466 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1470 pthread_cleanup_push (cl
, NULL
);
1473 pwrite (tempfd
, mem
, sizeof (mem
), 0);
1475 pthread_cleanup_pop (0);
1477 printf ("%s: pwrite returned\n", __FUNCTION__
);
1484 tf_fsync (void *arg
)
1487 // XXX If somebody can provide a portable test case in which fsync()
1488 // blocks we can enable this test to run in both rounds.
1491 tempfd
= open ("Makefile", O_RDONLY
);
1494 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1498 int r
= pthread_barrier_wait (&b2
);
1499 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1501 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1505 r
= pthread_barrier_wait (&b2
);
1506 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1508 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1512 pthread_cleanup_push (cl
, NULL
);
1516 pthread_cleanup_pop (0);
1518 printf ("%s: fsync returned\n", __FUNCTION__
);
1525 tf_msync (void *arg
)
1528 // XXX If somebody can provide a portable test case in which msync()
1529 // blocks we can enable this test to run in both rounds.
1532 tempfd
= open ("Makefile", O_RDONLY
);
1535 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1538 void *p
= mmap (NULL
, 10, PROT_READ
, MAP_SHARED
, tempfd
, 0);
1539 if (p
== MAP_FAILED
)
1541 printf ("%s: mmap failed\n", __FUNCTION__
);
1545 int r
= pthread_barrier_wait (&b2
);
1546 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1548 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1552 r
= pthread_barrier_wait (&b2
);
1553 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1555 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1559 pthread_cleanup_push (cl
, NULL
);
1563 pthread_cleanup_pop (0);
1565 printf ("%s: msync returned\n", __FUNCTION__
);
1572 tf_sendto (void *arg
)
1575 // XXX If somebody can provide a portable test case in which sendto()
1576 // blocks we can enable this test to run in both rounds.
1579 struct sockaddr_un sun
;
1581 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1584 printf ("%s: first socket call failed\n", __FUNCTION__
);
1593 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1596 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-6-XXXXXX");
1597 if (mktemp (sun
.sun_path
) == NULL
)
1599 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1603 sun
.sun_family
= AF_UNIX
;
1605 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1606 offsetof (struct sockaddr_un
, sun_path
)
1607 + strlen (sun
.sun_path
) + 1) != 0);
1608 tempfname
= strdup (sun
.sun_path
);
1610 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1613 printf ("%s: second socket call failed\n", __FUNCTION__
);
1617 int r
= pthread_barrier_wait (&b2
);
1618 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1620 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1624 r
= pthread_barrier_wait (&b2
);
1625 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1627 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1631 pthread_cleanup_push (cl
, NULL
);
1635 sendto (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0,
1636 (struct sockaddr
*) &sun
,
1637 offsetof (struct sockaddr_un
, sun_path
) + strlen (sun
.sun_path
) + 1);
1639 pthread_cleanup_pop (0);
1641 printf ("%s: sendto returned\n", __FUNCTION__
);
1648 tf_sendmsg (void *arg
)
1651 // XXX If somebody can provide a portable test case in which sendmsg()
1652 // blocks we can enable this test to run in both rounds.
1655 struct sockaddr_un sun
;
1657 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1660 printf ("%s: first socket call failed\n", __FUNCTION__
);
1669 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1672 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-7-XXXXXX");
1673 if (mktemp (sun
.sun_path
) == NULL
)
1675 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1679 sun
.sun_family
= AF_UNIX
;
1681 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1682 offsetof (struct sockaddr_un
, sun_path
)
1683 + strlen (sun
.sun_path
) + 1) != 0);
1684 tempfname
= strdup (sun
.sun_path
);
1686 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1689 printf ("%s: second socket call failed\n", __FUNCTION__
);
1693 int r
= pthread_barrier_wait (&b2
);
1694 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1696 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1700 r
= pthread_barrier_wait (&b2
);
1701 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1703 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1707 pthread_cleanup_push (cl
, NULL
);
1710 struct iovec iov
[1];
1711 iov
[0].iov_base
= mem
;
1716 m
.msg_namelen
= (offsetof (struct sockaddr_un
, sun_path
)
1717 + strlen (sun
.sun_path
) + 1);
1720 m
.msg_control
= NULL
;
1721 m
.msg_controllen
= 0;
1723 sendmsg (tempfd2
, &m
, 0);
1725 pthread_cleanup_pop (0);
1727 printf ("%s: sendmsg returned\n", __FUNCTION__
);
1734 tf_creat (void *arg
)
1737 // XXX If somebody can provide a portable test case in which sendmsg()
1738 // blocks we can enable this test to run in both rounds.
1741 int r
= pthread_barrier_wait (&b2
);
1742 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1744 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1748 r
= pthread_barrier_wait (&b2
);
1749 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1751 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1755 pthread_cleanup_push (cl
, NULL
);
1757 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1759 pthread_cleanup_pop (0);
1761 printf ("%s: creat returned\n", __FUNCTION__
);
1768 tf_connect (void *arg
)
1771 // XXX If somebody can provide a portable test case in which connect()
1772 // blocks we can enable this test to run in both rounds.
1775 struct sockaddr_un sun
;
1777 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1780 printf ("%s: first socket call failed\n", __FUNCTION__
);
1789 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1792 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1793 if (mktemp (sun
.sun_path
) == NULL
)
1795 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1799 sun
.sun_family
= AF_UNIX
;
1801 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1802 offsetof (struct sockaddr_un
, sun_path
)
1803 + strlen (sun
.sun_path
) + 1) != 0);
1804 tempfname
= strdup (sun
.sun_path
);
1808 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1811 printf ("%s: second socket call failed\n", __FUNCTION__
);
1815 int r
= pthread_barrier_wait (&b2
);
1816 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1818 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1824 r
= pthread_barrier_wait (&b2
);
1825 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1827 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1832 pthread_cleanup_push (cl
, NULL
);
1834 connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
));
1836 pthread_cleanup_pop (0);
1838 printf ("%s: connect returned\n", __FUNCTION__
);
1845 tf_tcdrain (void *arg
)
1848 // XXX If somebody can provide a portable test case in which tcdrain()
1849 // blocks we can enable this test to run in both rounds.
1852 int r
= pthread_barrier_wait (&b2
);
1853 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1855 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1861 r
= pthread_barrier_wait (&b2
);
1862 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1864 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1869 pthread_cleanup_push (cl
, NULL
);
1871 /* Regardless of stderr being a terminal, the tcdrain call should be
1873 tcdrain (STDERR_FILENO
);
1875 pthread_cleanup_pop (0);
1877 printf ("%s: tcdrain returned\n", __FUNCTION__
);
1884 tf_msgrcv (void *arg
)
1886 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1889 printf ("%s: msgget failed: %s\n", __FUNCTION__
, strerror (errno
));
1893 int r
= pthread_barrier_wait (&b2
);
1894 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1896 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1902 r
= pthread_barrier_wait (&b2
);
1903 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1905 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1912 pthread_cleanup_push (cl
, NULL
);
1920 /* We need a positive random number. */
1922 randnr
= random () % 64000;
1923 while (randnr
<= 0);
1927 s
= msgrcv (tempmsg
, (struct msgbuf
*) &m
, 10, randnr
, 0);
1929 while (errno
== EIDRM
|| errno
== EINTR
);
1931 pthread_cleanup_pop (0);
1933 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__
, s
);
1935 msgctl (tempmsg
, IPC_RMID
, NULL
);
1942 tf_msgsnd (void *arg
)
1945 // XXX If somebody can provide a portable test case in which msgsnd()
1946 // blocks we can enable this test to run in both rounds.
1949 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1952 printf ("%s: msgget failed: %s\n", __FUNCTION__
, strerror (errno
));
1956 int r
= pthread_barrier_wait (&b2
);
1957 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1959 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1963 r
= pthread_barrier_wait (&b2
);
1964 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1966 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1970 pthread_cleanup_push (cl
, NULL
);
1977 /* We need a positive random number. */
1979 m
.type
= random () % 64000;
1980 while (m
.type
<= 0);
1981 msgsnd (tempmsg
, (struct msgbuf
*) &m
, sizeof (m
.mem
), 0);
1983 pthread_cleanup_pop (0);
1985 printf ("%s: msgsnd returned\n", __FUNCTION__
);
1987 msgctl (tempmsg
, IPC_RMID
, NULL
);
1996 void *(*tf
) (void *);
2001 #define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early }
2002 ADD_TEST (read
, 2, 0),
2003 ADD_TEST (readv
, 2, 0),
2004 ADD_TEST (select
, 2, 0),
2005 ADD_TEST (pselect
, 2, 0),
2006 ADD_TEST (poll
, 2, 0),
2007 ADD_TEST (write
, 2, 0),
2008 ADD_TEST (writev
, 2, 0),
2009 ADD_TEST (sleep
, 2, 0),
2010 ADD_TEST (usleep
, 2, 0),
2011 ADD_TEST (nanosleep
, 2, 0),
2012 ADD_TEST (wait
, 2, 0),
2013 ADD_TEST (waitid
, 2, 0),
2014 ADD_TEST (waitpid
, 2, 0),
2015 ADD_TEST (sigpause
, 2, 0),
2016 ADD_TEST (sigsuspend
, 2, 0),
2017 ADD_TEST (sigwait
, 2, 0),
2018 ADD_TEST (sigwaitinfo
, 2, 0),
2019 ADD_TEST (sigtimedwait
, 2, 0),
2020 ADD_TEST (pause
, 2, 0),
2021 ADD_TEST (accept
, 2, 0),
2022 ADD_TEST (send
, 2, 0),
2023 ADD_TEST (recv
, 2, 0),
2024 ADD_TEST (recvfrom
, 2, 0),
2025 ADD_TEST (recvmsg
, 2, 0),
2026 ADD_TEST (open
, 2, 1),
2027 ADD_TEST (close
, 2, 1),
2028 ADD_TEST (pread
, 2, 1),
2029 ADD_TEST (pwrite
, 2, 1),
2030 ADD_TEST (fsync
, 2, 1),
2031 ADD_TEST (msync
, 2, 1),
2032 ADD_TEST (sendto
, 2, 1),
2033 ADD_TEST (sendmsg
, 2, 1),
2034 ADD_TEST (creat
, 2, 1),
2035 ADD_TEST (connect
, 2, 1),
2036 ADD_TEST (tcdrain
, 2, 1),
2037 ADD_TEST (msgrcv
, 2, 0),
2038 ADD_TEST (msgsnd
, 2, 1),
2040 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2046 if (pipe (fds
) != 0)
2048 puts ("pipe failed");
2054 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
2056 if (tests
[cnt
].only_early
)
2059 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
2061 puts ("b2 init failed");
2065 /* Reset the counter for the cleanup handler. */
2069 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, NULL
) != 0)
2071 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
2076 int r
= pthread_barrier_wait (&b2
);
2077 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2079 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2084 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
2085 while (nanosleep (&ts
, &ts
) != 0)
2088 if (pthread_cancel (th
) != 0)
2090 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
2096 if (pthread_join (th
, &status
) != 0)
2098 printf ("join for '%s' failed\n", tests
[cnt
].name
);
2102 if (status
!= PTHREAD_CANCELED
)
2104 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
2109 if (pthread_barrier_destroy (&b2
) != 0)
2111 puts ("barrier_destroy failed");
2118 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
2124 printf ("cleanup handler called more than once for '%s'\n",
2130 printf ("in-time cancel test of '%s' successful\n", tests
[cnt
].name
);
2142 if (tempfname
!= NULL
)
2150 msgctl (tempmsg
, IPC_RMID
, NULL
);
2155 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
2157 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
2159 puts ("b2 init failed");
2163 /* Reset the counter for the cleanup handler. */
2167 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, (void *) 1l) != 0)
2169 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
2174 int r
= pthread_barrier_wait (&b2
);
2175 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2177 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2182 if (pthread_cancel (th
) != 0)
2184 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
2189 r
= pthread_barrier_wait (&b2
);
2190 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2192 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2198 if (pthread_join (th
, &status
) != 0)
2200 printf ("join for '%s' failed\n", tests
[cnt
].name
);
2204 if (status
!= PTHREAD_CANCELED
)
2206 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
2211 if (pthread_barrier_destroy (&b2
) != 0)
2213 puts ("barrier_destroy failed");
2220 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
2226 printf ("cleanup handler called more than once for '%s'\n",
2232 printf ("early cancel test of '%s' successful\n", tests
[cnt
].name
);
2244 if (tempfname
!= NULL
)
2252 msgctl (tempmsg
, IPC_RMID
, NULL
);
2261 #define TEST_FUNCTION do_test ()
2262 #include "../test-skeleton.c"