1 /* Copyright (C) 2002, 2003 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 POSIX message queues aren't implemented yet. This affects
61 mq_receive() mq_send() mq_timedreceive() mq_timedsend()
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
);
677 s
= waitid (P_PID
, pid
, &si
, 0);
679 pthread_cleanup_pop (0);
681 printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__
, s
,
689 tf_sigpause (void *arg
)
691 int r
= pthread_barrier_wait (&b2
);
692 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
694 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
700 r
= pthread_barrier_wait (&b2
);
701 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
703 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
708 pthread_cleanup_push (cl
, NULL
);
710 /* Just for fun block the cancellation signal. We need to use
711 __xpg_sigpause since otherwise we will get the BSD version. */
712 __xpg_sigpause (SIGCANCEL
);
714 pthread_cleanup_pop (0);
716 printf ("%s: sigpause returned\n", __FUNCTION__
);
723 tf_sigsuspend (void *arg
)
725 int r
= pthread_barrier_wait (&b2
);
726 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
728 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
734 r
= pthread_barrier_wait (&b2
);
735 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
737 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
742 pthread_cleanup_push (cl
, NULL
);
744 /* Just for fun block all signals. */
749 pthread_cleanup_pop (0);
751 printf ("%s: sigsuspend returned\n", __FUNCTION__
);
758 tf_sigwait (void *arg
)
760 int r
= pthread_barrier_wait (&b2
);
761 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
763 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
769 r
= pthread_barrier_wait (&b2
);
770 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
772 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
780 sigaddset (&mask
, SIGUSR1
);
781 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
783 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
788 pthread_cleanup_push (cl
, NULL
);
790 /* Wait for SIGUSR1. */
791 sigwait (&mask
, &sig
);
793 pthread_cleanup_pop (0);
795 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__
, sig
);
802 tf_sigwaitinfo (void *arg
)
804 int r
= pthread_barrier_wait (&b2
);
805 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
807 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
813 r
= pthread_barrier_wait (&b2
);
814 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
816 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
824 sigaddset (&mask
, SIGUSR1
);
825 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
827 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
832 pthread_cleanup_push (cl
, NULL
);
834 /* Wait for SIGUSR1. */
835 sigwaitinfo (&mask
, &info
);
837 pthread_cleanup_pop (0);
839 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__
,
847 tf_sigtimedwait (void *arg
)
849 int r
= pthread_barrier_wait (&b2
);
850 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
852 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
858 r
= pthread_barrier_wait (&b2
);
859 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
861 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
869 sigaddset (&mask
, SIGUSR1
);
870 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
872 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
876 /* Wait for SIGUSR1. */
878 struct timespec ts
= { .tv_sec
= 60, .tv_nsec
= 0 };
879 pthread_cleanup_push (cl
, NULL
);
881 sigtimedwait (&mask
, &info
, &ts
);
883 pthread_cleanup_pop (0);
885 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__
,
895 int r
= pthread_barrier_wait (&b2
);
896 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
898 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
904 r
= pthread_barrier_wait (&b2
);
905 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
907 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
912 pthread_cleanup_push (cl
, NULL
);
916 pthread_cleanup_pop (0);
918 printf ("%s: pause returned\n", __FUNCTION__
);
925 tf_accept (void *arg
)
927 struct sockaddr_un sun
;
928 /* To test a non-blocking accept call we make the call file by using
929 a datagrame socket. */
930 int pf
= arg
== NULL
? SOCK_STREAM
: SOCK_DGRAM
;
932 tempfd
= socket (AF_UNIX
, pf
, 0);
935 printf ("%s: socket call failed\n", __FUNCTION__
);
944 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
947 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-1-XXXXXX");
948 if (mktemp (sun
.sun_path
) == NULL
)
950 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
954 sun
.sun_family
= AF_UNIX
;
956 while (bind (tempfd
, (struct sockaddr
*) &sun
,
957 offsetof (struct sockaddr_un
, sun_path
)
958 + strlen (sun
.sun_path
) + 1) != 0);
960 unlink (sun
.sun_path
);
964 socklen_t len
= sizeof (sun
);
966 int r
= pthread_barrier_wait (&b2
);
967 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
969 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
975 r
= pthread_barrier_wait (&b2
);
976 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
978 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
983 pthread_cleanup_push (cl
, NULL
);
985 accept (tempfd
, (struct sockaddr
*) &sun
, &len
);
987 pthread_cleanup_pop (0);
989 printf ("%s: accept returned\n", __FUNCTION__
);
998 struct sockaddr_un sun
;
1000 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1003 printf ("%s: first socket call failed\n", __FUNCTION__
);
1012 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1015 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1016 if (mktemp (sun
.sun_path
) == NULL
)
1018 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1022 sun
.sun_family
= AF_UNIX
;
1024 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1025 offsetof (struct sockaddr_un
, sun_path
)
1026 + strlen (sun
.sun_path
) + 1) != 0);
1030 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1033 printf ("%s: second socket call failed\n", __FUNCTION__
);
1037 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1039 printf ("%s: connect failed\n", __FUNCTION__
);
1043 unlink (sun
.sun_path
);
1045 int r
= pthread_barrier_wait (&b2
);
1046 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1048 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1054 r
= pthread_barrier_wait (&b2
);
1055 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1057 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1062 pthread_cleanup_push (cl
, NULL
);
1064 /* Very large block, so that the send call blocks. */
1067 send (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0);
1069 pthread_cleanup_pop (0);
1071 printf ("%s: send returned\n", __FUNCTION__
);
1080 struct sockaddr_un sun
;
1082 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1085 printf ("%s: first socket call failed\n", __FUNCTION__
);
1094 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1097 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-3-XXXXXX");
1098 if (mktemp (sun
.sun_path
) == NULL
)
1100 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1104 sun
.sun_family
= AF_UNIX
;
1106 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1107 offsetof (struct sockaddr_un
, sun_path
)
1108 + strlen (sun
.sun_path
) + 1) != 0);
1112 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1115 printf ("%s: second socket call failed\n", __FUNCTION__
);
1119 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1121 printf ("%s: connect failed\n", __FUNCTION__
);
1125 unlink (sun
.sun_path
);
1127 int r
= pthread_barrier_wait (&b2
);
1128 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1130 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1136 r
= pthread_barrier_wait (&b2
);
1137 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1139 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1144 pthread_cleanup_push (cl
, NULL
);
1148 recv (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0);
1150 pthread_cleanup_pop (0);
1152 printf ("%s: recv returned\n", __FUNCTION__
);
1159 tf_recvfrom (void *arg
)
1161 struct sockaddr_un sun
;
1163 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1166 printf ("%s: first socket call failed\n", __FUNCTION__
);
1175 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1178 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-4-XXXXXX");
1179 if (mktemp (sun
.sun_path
) == NULL
)
1181 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1185 sun
.sun_family
= AF_UNIX
;
1187 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1188 offsetof (struct sockaddr_un
, sun_path
)
1189 + strlen (sun
.sun_path
) + 1) != 0);
1191 tempfname
= strdup (sun
.sun_path
);
1193 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1196 printf ("%s: second socket call failed\n", __FUNCTION__
);
1200 int r
= pthread_barrier_wait (&b2
);
1201 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1203 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1209 r
= pthread_barrier_wait (&b2
);
1210 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1212 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1217 pthread_cleanup_push (cl
, NULL
);
1220 socklen_t len
= sizeof (sun
);
1222 recvfrom (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0,
1223 (struct sockaddr
*) &sun
, &len
);
1225 pthread_cleanup_pop (0);
1227 printf ("%s: recvfrom returned\n", __FUNCTION__
);
1234 tf_recvmsg (void *arg
)
1236 struct sockaddr_un sun
;
1238 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1241 printf ("%s: first socket call failed\n", __FUNCTION__
);
1250 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1253 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-5-XXXXXX");
1254 if (mktemp (sun
.sun_path
) == NULL
)
1256 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1260 sun
.sun_family
= AF_UNIX
;
1262 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1263 offsetof (struct sockaddr_un
, sun_path
)
1264 + strlen (sun
.sun_path
) + 1) != 0);
1266 tempfname
= strdup (sun
.sun_path
);
1268 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1271 printf ("%s: second socket call failed\n", __FUNCTION__
);
1275 int r
= pthread_barrier_wait (&b2
);
1276 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1278 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1284 r
= pthread_barrier_wait (&b2
);
1285 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1287 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1292 pthread_cleanup_push (cl
, NULL
);
1295 struct iovec iov
[1];
1296 iov
[0].iov_base
= mem
;
1297 iov
[0].iov_len
= arg
== NULL
? sizeof (mem
) : 0;
1301 m
.msg_namelen
= sizeof (sun
);
1304 m
.msg_control
= NULL
;
1305 m
.msg_controllen
= 0;
1307 recvmsg (tempfd2
, &m
, 0);
1309 pthread_cleanup_pop (0);
1311 printf ("%s: recvmsg returned\n", __FUNCTION__
);
1321 // XXX If somebody can provide a portable test case in which open()
1322 // blocks we can enable this test to run in both rounds.
1325 int r
= pthread_barrier_wait (&b2
);
1326 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1328 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1332 r
= pthread_barrier_wait (&b2
);
1333 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1335 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1339 pthread_cleanup_push (cl
, NULL
);
1341 open ("Makefile", O_RDONLY
);
1343 pthread_cleanup_pop (0);
1345 printf ("%s: open returned\n", __FUNCTION__
);
1352 tf_close (void *arg
)
1355 // XXX If somebody can provide a portable test case in which close()
1356 // blocks we can enable this test to run in both rounds.
1359 char fname
[] = "/tmp/tst-cancel-fd-XXXXXX";
1360 tempfd
= mkstemp (fname
);
1363 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1368 int r
= pthread_barrier_wait (&b2
);
1369 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1371 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1375 r
= pthread_barrier_wait (&b2
);
1376 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1378 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1382 pthread_cleanup_push (cl
, NULL
);
1386 pthread_cleanup_pop (0);
1388 printf ("%s: close returned\n", __FUNCTION__
);
1395 tf_pread (void *arg
)
1398 // XXX If somebody can provide a portable test case in which pread()
1399 // blocks we can enable this test to run in both rounds.
1402 tempfd
= open ("Makefile", O_RDONLY
);
1405 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1409 int r
= pthread_barrier_wait (&b2
);
1410 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1412 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1416 r
= pthread_barrier_wait (&b2
);
1417 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1419 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1423 pthread_cleanup_push (cl
, NULL
);
1426 pread (tempfd
, mem
, sizeof (mem
), 0);
1428 pthread_cleanup_pop (0);
1430 printf ("%s: pread returned\n", __FUNCTION__
);
1437 tf_pwrite (void *arg
)
1440 // XXX If somebody can provide a portable test case in which pwrite()
1441 // blocks we can enable this test to run in both rounds.
1444 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1445 tempfd
= mkstemp (fname
);
1448 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1453 int r
= pthread_barrier_wait (&b2
);
1454 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1456 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1460 r
= pthread_barrier_wait (&b2
);
1461 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1463 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1467 pthread_cleanup_push (cl
, NULL
);
1470 pwrite (tempfd
, mem
, sizeof (mem
), 0);
1472 pthread_cleanup_pop (0);
1474 printf ("%s: pwrite returned\n", __FUNCTION__
);
1481 tf_fsync (void *arg
)
1484 // XXX If somebody can provide a portable test case in which fsync()
1485 // blocks we can enable this test to run in both rounds.
1488 tempfd
= open ("Makefile", O_RDONLY
);
1491 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1495 int r
= pthread_barrier_wait (&b2
);
1496 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1498 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1502 r
= pthread_barrier_wait (&b2
);
1503 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1505 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1509 pthread_cleanup_push (cl
, NULL
);
1513 pthread_cleanup_pop (0);
1515 printf ("%s: fsync returned\n", __FUNCTION__
);
1522 tf_msync (void *arg
)
1525 // XXX If somebody can provide a portable test case in which msync()
1526 // blocks we can enable this test to run in both rounds.
1529 tempfd
= open ("Makefile", O_RDONLY
);
1532 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1535 void *p
= mmap (NULL
, 10, PROT_READ
, MAP_SHARED
, tempfd
, 0);
1536 if (p
== MAP_FAILED
)
1538 printf ("%s: mmap failed\n", __FUNCTION__
);
1542 int r
= pthread_barrier_wait (&b2
);
1543 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1545 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1549 r
= pthread_barrier_wait (&b2
);
1550 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1552 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1556 pthread_cleanup_push (cl
, NULL
);
1560 pthread_cleanup_pop (0);
1562 printf ("%s: msync returned\n", __FUNCTION__
);
1569 tf_sendto (void *arg
)
1572 // XXX If somebody can provide a portable test case in which sendto()
1573 // blocks we can enable this test to run in both rounds.
1576 struct sockaddr_un sun
;
1578 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1581 printf ("%s: first socket call failed\n", __FUNCTION__
);
1590 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1593 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-6-XXXXXX");
1594 if (mktemp (sun
.sun_path
) == NULL
)
1596 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1600 sun
.sun_family
= AF_UNIX
;
1602 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1603 offsetof (struct sockaddr_un
, sun_path
)
1604 + strlen (sun
.sun_path
) + 1) != 0);
1605 tempfname
= strdup (sun
.sun_path
);
1607 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1610 printf ("%s: second socket call failed\n", __FUNCTION__
);
1614 int r
= pthread_barrier_wait (&b2
);
1615 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1617 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1621 r
= pthread_barrier_wait (&b2
);
1622 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1624 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1628 pthread_cleanup_push (cl
, NULL
);
1632 sendto (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0,
1633 (struct sockaddr
*) &sun
,
1634 offsetof (struct sockaddr_un
, sun_path
) + strlen (sun
.sun_path
) + 1);
1636 pthread_cleanup_pop (0);
1638 printf ("%s: sendto returned\n", __FUNCTION__
);
1645 tf_sendmsg (void *arg
)
1648 // XXX If somebody can provide a portable test case in which sendmsg()
1649 // blocks we can enable this test to run in both rounds.
1652 struct sockaddr_un sun
;
1654 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1657 printf ("%s: first socket call failed\n", __FUNCTION__
);
1666 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1669 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-7-XXXXXX");
1670 if (mktemp (sun
.sun_path
) == NULL
)
1672 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1676 sun
.sun_family
= AF_UNIX
;
1678 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1679 offsetof (struct sockaddr_un
, sun_path
)
1680 + strlen (sun
.sun_path
) + 1) != 0);
1681 tempfname
= strdup (sun
.sun_path
);
1683 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1686 printf ("%s: second socket call failed\n", __FUNCTION__
);
1690 int r
= pthread_barrier_wait (&b2
);
1691 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1693 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1697 r
= pthread_barrier_wait (&b2
);
1698 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1700 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1704 pthread_cleanup_push (cl
, NULL
);
1707 struct iovec iov
[1];
1708 iov
[0].iov_base
= mem
;
1713 m
.msg_namelen
= (offsetof (struct sockaddr_un
, sun_path
)
1714 + strlen (sun
.sun_path
) + 1);
1717 m
.msg_control
= NULL
;
1718 m
.msg_controllen
= 0;
1720 sendmsg (tempfd2
, &m
, 0);
1722 pthread_cleanup_pop (0);
1724 printf ("%s: sendmsg returned\n", __FUNCTION__
);
1731 tf_creat (void *arg
)
1734 // XXX If somebody can provide a portable test case in which sendmsg()
1735 // blocks we can enable this test to run in both rounds.
1738 int r
= pthread_barrier_wait (&b2
);
1739 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1741 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1745 r
= pthread_barrier_wait (&b2
);
1746 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1748 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1752 pthread_cleanup_push (cl
, NULL
);
1754 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1756 pthread_cleanup_pop (0);
1758 printf ("%s: creat returned\n", __FUNCTION__
);
1765 tf_connect (void *arg
)
1768 // XXX If somebody can provide a portable test case in which connect()
1769 // blocks we can enable this test to run in both rounds.
1772 struct sockaddr_un sun
;
1774 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1777 printf ("%s: first socket call failed\n", __FUNCTION__
);
1786 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1789 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1790 if (mktemp (sun
.sun_path
) == NULL
)
1792 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1796 sun
.sun_family
= AF_UNIX
;
1798 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1799 offsetof (struct sockaddr_un
, sun_path
)
1800 + strlen (sun
.sun_path
) + 1) != 0);
1801 tempfname
= strdup (sun
.sun_path
);
1805 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1808 printf ("%s: second socket call failed\n", __FUNCTION__
);
1812 int r
= pthread_barrier_wait (&b2
);
1813 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1815 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1821 r
= pthread_barrier_wait (&b2
);
1822 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1824 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1829 pthread_cleanup_push (cl
, NULL
);
1831 connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
));
1833 pthread_cleanup_pop (0);
1835 printf ("%s: connect returned\n", __FUNCTION__
);
1842 tf_tcdrain (void *arg
)
1845 // XXX If somebody can provide a portable test case in which tcdrain()
1846 // blocks we can enable this test to run in both rounds.
1849 int r
= pthread_barrier_wait (&b2
);
1850 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1852 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1858 r
= pthread_barrier_wait (&b2
);
1859 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1861 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1866 pthread_cleanup_push (cl
, NULL
);
1868 /* Regardless of stderr being a terminal, the tcdrain call should be
1870 tcdrain (STDERR_FILENO
);
1872 pthread_cleanup_pop (0);
1874 printf ("%s: tcdrain returned\n", __FUNCTION__
);
1881 tf_msgrcv (void *arg
)
1883 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1885 int r
= pthread_barrier_wait (&b2
);
1886 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1888 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1894 r
= pthread_barrier_wait (&b2
);
1895 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1897 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1904 pthread_cleanup_push (cl
, NULL
);
1912 /* We need a positive random number. */
1914 randnr
= random () % 64000;
1915 while (randnr
<= 0);
1919 s
= msgrcv (tempmsg
, (struct msgbuf
*) &m
, 10, randnr
, 0);
1921 while (errno
== EIDRM
|| errno
== EINTR
);
1923 pthread_cleanup_pop (0);
1925 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__
, s
);
1932 tf_msgsnd (void *arg
)
1935 // XXX If somebody can provide a portable test case in which msgsnd()
1936 // blocks we can enable this test to run in both rounds.
1939 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1941 int r
= pthread_barrier_wait (&b2
);
1942 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1944 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1948 r
= pthread_barrier_wait (&b2
);
1949 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1951 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1955 pthread_cleanup_push (cl
, NULL
);
1962 /* We need a positive random number. */
1964 m
.type
= random () % 64000;
1965 while (m
.type
<= 0);
1966 msgsnd (tempmsg
, (struct msgbuf
*) &m
, sizeof (m
.mem
), 0);
1968 pthread_cleanup_pop (0);
1970 printf ("%s: msgsnd returned\n", __FUNCTION__
);
1979 void *(*tf
) (void *);
1984 #define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early }
1985 ADD_TEST (read
, 2, 0),
1986 ADD_TEST (readv
, 2, 0),
1987 ADD_TEST (select
, 2, 0),
1988 ADD_TEST (pselect
, 2, 0),
1989 ADD_TEST (poll
, 2, 0),
1990 ADD_TEST (write
, 2, 0),
1991 ADD_TEST (writev
, 2, 0),
1992 ADD_TEST (sleep
, 2, 0),
1993 ADD_TEST (usleep
, 2, 0),
1994 ADD_TEST (nanosleep
, 2, 0),
1995 ADD_TEST (wait
, 2, 0),
1996 ADD_TEST (waitid
, 2, 0),
1997 ADD_TEST (waitpid
, 2, 0),
1998 ADD_TEST (sigpause
, 2, 0),
1999 ADD_TEST (sigsuspend
, 2, 0),
2000 ADD_TEST (sigwait
, 2, 0),
2001 ADD_TEST (sigwaitinfo
, 2, 0),
2002 ADD_TEST (sigtimedwait
, 2, 0),
2003 ADD_TEST (pause
, 2, 0),
2004 ADD_TEST (accept
, 2, 0),
2005 ADD_TEST (send
, 2, 0),
2006 ADD_TEST (recv
, 2, 0),
2007 ADD_TEST (recvfrom
, 2, 0),
2008 ADD_TEST (recvmsg
, 2, 0),
2009 ADD_TEST (open
, 2, 1),
2010 ADD_TEST (close
, 2, 1),
2011 ADD_TEST (pread
, 2, 1),
2012 ADD_TEST (pwrite
, 2, 1),
2013 ADD_TEST (fsync
, 2, 1),
2014 ADD_TEST (msync
, 2, 1),
2015 ADD_TEST (sendto
, 2, 1),
2016 ADD_TEST (sendmsg
, 2, 1),
2017 ADD_TEST (creat
, 2, 1),
2018 ADD_TEST (connect
, 2, 1),
2019 ADD_TEST (tcdrain
, 2, 1),
2020 ADD_TEST (msgrcv
, 2, 0),
2021 ADD_TEST (msgsnd
, 2, 1),
2023 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2029 if (pipe (fds
) != 0)
2031 puts ("pipe failed");
2037 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
2039 if (tests
[cnt
].only_early
)
2042 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
2044 puts ("b2 init failed");
2048 /* Reset the counter for the cleanup handler. */
2052 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, NULL
) != 0)
2054 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
2059 int r
= pthread_barrier_wait (&b2
);
2060 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2062 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2067 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
2068 while (nanosleep (&ts
, &ts
) != 0)
2071 if (pthread_cancel (th
) != 0)
2073 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
2079 if (pthread_join (th
, &status
) != 0)
2081 printf ("join for '%s' failed\n", tests
[cnt
].name
);
2085 if (status
!= PTHREAD_CANCELED
)
2087 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
2092 if (pthread_barrier_destroy (&b2
) != 0)
2094 puts ("barrier_destroy failed");
2101 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
2107 printf ("cleanup handler called more than once for '%s'\n",
2113 printf ("in-time cancel test of '%s' successful\n", tests
[cnt
].name
);
2125 if (tempfname
!= NULL
)
2133 msgctl (tempmsg
, IPC_RMID
, NULL
);
2138 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
2140 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
2142 puts ("b2 init failed");
2146 /* Reset the counter for the cleanup handler. */
2150 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, (void *) 1l) != 0)
2152 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
2157 int r
= pthread_barrier_wait (&b2
);
2158 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2160 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2165 if (pthread_cancel (th
) != 0)
2167 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
2172 r
= pthread_barrier_wait (&b2
);
2173 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2175 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2181 if (pthread_join (th
, &status
) != 0)
2183 printf ("join for '%s' failed\n", tests
[cnt
].name
);
2187 if (status
!= PTHREAD_CANCELED
)
2189 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
2194 if (pthread_barrier_destroy (&b2
) != 0)
2196 puts ("barrier_destroy failed");
2203 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
2209 printf ("cleanup handler called more than once for '%s'\n",
2215 printf ("early cancel test of '%s' successful\n", tests
[cnt
].name
);
2227 if (tempfname
!= NULL
)
2235 msgctl (tempmsg
, IPC_RMID
, NULL
);
2244 #define TEST_FUNCTION do_test ()
2245 #include "../test-skeleton.c"