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 #define WRITE_BUFFER_SIZE 4096
89 /* Cleanup handling test. */
110 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
111 tempfd
= fd
= mkstemp (fname
);
113 printf ("%s: mkstemp failed\n", __FUNCTION__
);
116 r
= pthread_barrier_wait (&b2
);
117 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
119 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
124 r
= pthread_barrier_wait (&b2
);
125 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
127 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
132 pthread_cleanup_push (cl
, NULL
);
135 s
= read (fd
, buf
, sizeof (buf
));
137 pthread_cleanup_pop (0);
139 printf ("%s: read returns with %zd\n", __FUNCTION__
, s
);
155 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
156 tempfd
= fd
= mkstemp (fname
);
158 printf ("%s: mkstemp failed\n", __FUNCTION__
);
161 r
= pthread_barrier_wait (&b2
);
162 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
164 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
169 r
= pthread_barrier_wait (&b2
);
170 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
172 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
177 pthread_cleanup_push (cl
, NULL
);
180 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
181 s
= readv (fd
, iov
, 1);
183 pthread_cleanup_pop (0);
185 printf ("%s: readv returns with %zd\n", __FUNCTION__
, s
);
201 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
202 tempfd
= fd
= mkstemp (fname
);
204 printf ("%s: mkstemp failed\n", __FUNCTION__
);
207 r
= pthread_barrier_wait (&b2
);
208 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
210 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
215 r
= pthread_barrier_wait (&b2
);
216 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
218 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
223 pthread_cleanup_push (cl
, NULL
);
225 char buf
[WRITE_BUFFER_SIZE
];
226 memset (buf
, '\0', sizeof (buf
));
227 s
= write (fd
, buf
, sizeof (buf
));
229 pthread_cleanup_pop (0);
231 printf ("%s: write returns with %zd\n", __FUNCTION__
, s
);
238 tf_writev (void *arg
)
247 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
248 tempfd
= fd
= mkstemp (fname
);
250 printf ("%s: mkstemp failed\n", __FUNCTION__
);
253 r
= pthread_barrier_wait (&b2
);
254 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
256 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
261 r
= pthread_barrier_wait (&b2
);
262 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
264 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
269 pthread_cleanup_push (cl
, NULL
);
271 char buf
[WRITE_BUFFER_SIZE
];
272 memset (buf
, '\0', sizeof (buf
));
273 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
274 s
= writev (fd
, iov
, 1);
276 pthread_cleanup_pop (0);
278 printf ("%s: writev returns with %zd\n", __FUNCTION__
, s
);
287 int r
= pthread_barrier_wait (&b2
);
288 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
290 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
296 r
= pthread_barrier_wait (&b2
);
297 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
299 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
304 pthread_cleanup_push (cl
, NULL
);
306 sleep (arg
== NULL
? 1000000 : 0);
308 pthread_cleanup_pop (0);
310 printf ("%s: sleep returns\n", __FUNCTION__
);
317 tf_usleep (void *arg
)
319 int r
= pthread_barrier_wait (&b2
);
320 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
322 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
328 r
= pthread_barrier_wait (&b2
);
329 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
331 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
336 pthread_cleanup_push (cl
, NULL
);
338 usleep (arg
== NULL
? (useconds_t
) ULONG_MAX
: 0);
340 pthread_cleanup_pop (0);
342 printf ("%s: usleep returns\n", __FUNCTION__
);
349 tf_nanosleep (void *arg
)
351 int r
= pthread_barrier_wait (&b2
);
352 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
354 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
360 r
= pthread_barrier_wait (&b2
);
361 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
363 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
368 pthread_cleanup_push (cl
, NULL
);
370 struct timespec ts
= { .tv_sec
= arg
== NULL
? 10000000 : 0, .tv_nsec
= 0 };
371 TEMP_FAILURE_RETRY (nanosleep (&ts
, &ts
));
373 pthread_cleanup_pop (0);
375 printf ("%s: nanosleep returns\n", __FUNCTION__
);
382 tf_select (void *arg
)
391 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
392 tempfd
= fd
= mkstemp (fname
);
394 printf ("%s: mkstemp failed\n", __FUNCTION__
);
397 r
= pthread_barrier_wait (&b2
);
398 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
400 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
405 r
= pthread_barrier_wait (&b2
);
406 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
408 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
417 pthread_cleanup_push (cl
, NULL
);
419 s
= select (fd
+ 1, &rfs
, NULL
, NULL
, NULL
);
421 pthread_cleanup_pop (0);
423 printf ("%s: select returns with %d (%s)\n", __FUNCTION__
, s
,
431 tf_pselect (void *arg
)
440 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
441 tempfd
= fd
= mkstemp (fname
);
443 printf ("%s: mkstemp failed\n", __FUNCTION__
);
446 r
= pthread_barrier_wait (&b2
);
447 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
449 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
454 r
= pthread_barrier_wait (&b2
);
455 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
457 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
466 pthread_cleanup_push (cl
, NULL
);
468 s
= pselect (fd
+ 1, &rfs
, NULL
, NULL
, NULL
, NULL
);
470 pthread_cleanup_pop (0);
472 printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__
, s
,
489 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
490 tempfd
= fd
= mkstemp (fname
);
492 printf ("%s: mkstemp failed\n", __FUNCTION__
);
495 r
= pthread_barrier_wait (&b2
);
496 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
498 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
503 r
= pthread_barrier_wait (&b2
);
504 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
506 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
510 struct pollfd rfs
[1] = { [0] = { .fd
= fd
, .events
= POLLIN
} };
513 pthread_cleanup_push (cl
, NULL
);
515 s
= poll (rfs
, 1, -1);
517 pthread_cleanup_pop (0);
519 printf ("%s: poll returns with %d (%s)\n", __FUNCTION__
, s
,
532 puts ("fork failed");
538 /* Make the program disappear after a while. */
547 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
548 while (nanosleep (&ts
, &ts
) != 0)
551 r
= pthread_barrier_wait (&b2
);
552 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
554 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
559 r
= pthread_barrier_wait (&b2
);
560 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
562 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
567 pthread_cleanup_push (cl
, NULL
);
571 pthread_cleanup_pop (0);
573 printf ("%s: wait returns with %d (%s)\n", __FUNCTION__
, s
,
581 tf_waitpid (void *arg
)
587 puts ("fork failed");
593 /* Make the program disappear after a while. */
602 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
603 while (nanosleep (&ts
, &ts
) != 0)
606 r
= pthread_barrier_wait (&b2
);
607 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
609 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
614 r
= pthread_barrier_wait (&b2
);
615 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
617 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
622 pthread_cleanup_push (cl
, NULL
);
624 s
= waitpid (-1, NULL
, 0);
626 pthread_cleanup_pop (0);
628 printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__
, s
,
636 tf_waitid (void *arg
)
641 puts ("fork failed");
647 /* Make the program disappear after a while. */
656 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
657 while (nanosleep (&ts
, &ts
) != 0)
660 r
= pthread_barrier_wait (&b2
);
661 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
663 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
668 r
= pthread_barrier_wait (&b2
);
669 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
671 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
676 pthread_cleanup_push (cl
, NULL
);
682 s
= waitid (P_PID
, pid
, &si
, WEXITED
);
684 pthread_cleanup_pop (0);
686 printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__
, s
,
694 tf_sigpause (void *arg
)
696 int r
= pthread_barrier_wait (&b2
);
697 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
699 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
705 r
= pthread_barrier_wait (&b2
);
706 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
708 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
713 pthread_cleanup_push (cl
, NULL
);
715 /* Just for fun block the cancellation signal. We need to use
716 __xpg_sigpause since otherwise we will get the BSD version. */
717 __xpg_sigpause (SIGCANCEL
);
719 pthread_cleanup_pop (0);
721 printf ("%s: sigpause returned\n", __FUNCTION__
);
728 tf_sigsuspend (void *arg
)
730 int r
= pthread_barrier_wait (&b2
);
731 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
733 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
739 r
= pthread_barrier_wait (&b2
);
740 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
742 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
747 pthread_cleanup_push (cl
, NULL
);
749 /* Just for fun block all signals. */
754 pthread_cleanup_pop (0);
756 printf ("%s: sigsuspend returned\n", __FUNCTION__
);
763 tf_sigwait (void *arg
)
765 int r
= pthread_barrier_wait (&b2
);
766 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
768 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
774 r
= pthread_barrier_wait (&b2
);
775 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
777 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
785 sigaddset (&mask
, SIGUSR1
);
786 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
788 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
793 pthread_cleanup_push (cl
, NULL
);
795 /* Wait for SIGUSR1. */
796 sigwait (&mask
, &sig
);
798 pthread_cleanup_pop (0);
800 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__
, sig
);
807 tf_sigwaitinfo (void *arg
)
809 int r
= pthread_barrier_wait (&b2
);
810 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
812 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
818 r
= pthread_barrier_wait (&b2
);
819 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
821 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
829 sigaddset (&mask
, SIGUSR1
);
830 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
832 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
837 pthread_cleanup_push (cl
, NULL
);
839 /* Wait for SIGUSR1. */
840 sigwaitinfo (&mask
, &info
);
842 pthread_cleanup_pop (0);
844 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__
,
852 tf_sigtimedwait (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__
);
881 /* Wait for SIGUSR1. */
883 struct timespec ts
= { .tv_sec
= 60, .tv_nsec
= 0 };
884 pthread_cleanup_push (cl
, NULL
);
886 sigtimedwait (&mask
, &info
, &ts
);
888 pthread_cleanup_pop (0);
890 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__
,
900 int r
= pthread_barrier_wait (&b2
);
901 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
903 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
909 r
= pthread_barrier_wait (&b2
);
910 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
912 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
917 pthread_cleanup_push (cl
, NULL
);
921 pthread_cleanup_pop (0);
923 printf ("%s: pause returned\n", __FUNCTION__
);
930 tf_accept (void *arg
)
932 struct sockaddr_un sun
;
933 /* To test a non-blocking accept call we make the call file by using
934 a datagrame socket. */
935 int pf
= arg
== NULL
? SOCK_STREAM
: SOCK_DGRAM
;
937 tempfd
= socket (AF_UNIX
, pf
, 0);
940 printf ("%s: socket call failed\n", __FUNCTION__
);
949 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
952 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-1-XXXXXX");
953 if (mktemp (sun
.sun_path
) == NULL
)
955 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
959 sun
.sun_family
= AF_UNIX
;
961 while (bind (tempfd
, (struct sockaddr
*) &sun
,
962 offsetof (struct sockaddr_un
, sun_path
)
963 + strlen (sun
.sun_path
) + 1) != 0);
965 unlink (sun
.sun_path
);
969 socklen_t len
= sizeof (sun
);
971 int r
= pthread_barrier_wait (&b2
);
972 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
974 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
980 r
= pthread_barrier_wait (&b2
);
981 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
983 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
988 pthread_cleanup_push (cl
, NULL
);
990 accept (tempfd
, (struct sockaddr
*) &sun
, &len
);
992 pthread_cleanup_pop (0);
994 printf ("%s: accept returned\n", __FUNCTION__
);
1003 struct sockaddr_un sun
;
1005 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1008 printf ("%s: first socket call failed\n", __FUNCTION__
);
1017 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1020 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1021 if (mktemp (sun
.sun_path
) == NULL
)
1023 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1027 sun
.sun_family
= AF_UNIX
;
1029 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1030 offsetof (struct sockaddr_un
, sun_path
)
1031 + strlen (sun
.sun_path
) + 1) != 0);
1035 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1038 printf ("%s: second socket call failed\n", __FUNCTION__
);
1042 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1044 printf ("%s: connect failed\n", __FUNCTION__
);
1048 unlink (sun
.sun_path
);
1050 int r
= pthread_barrier_wait (&b2
);
1051 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1053 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1059 r
= pthread_barrier_wait (&b2
);
1060 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1062 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1067 pthread_cleanup_push (cl
, NULL
);
1069 /* Very large block, so that the send call blocks. */
1072 send (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0);
1074 pthread_cleanup_pop (0);
1076 printf ("%s: send returned\n", __FUNCTION__
);
1085 struct sockaddr_un sun
;
1087 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1090 printf ("%s: first socket call failed\n", __FUNCTION__
);
1099 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1102 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-3-XXXXXX");
1103 if (mktemp (sun
.sun_path
) == NULL
)
1105 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1109 sun
.sun_family
= AF_UNIX
;
1111 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1112 offsetof (struct sockaddr_un
, sun_path
)
1113 + strlen (sun
.sun_path
) + 1) != 0);
1117 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1120 printf ("%s: second socket call failed\n", __FUNCTION__
);
1124 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1126 printf ("%s: connect failed\n", __FUNCTION__
);
1130 unlink (sun
.sun_path
);
1132 int r
= pthread_barrier_wait (&b2
);
1133 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1135 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1141 r
= pthread_barrier_wait (&b2
);
1142 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1144 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1149 pthread_cleanup_push (cl
, NULL
);
1153 recv (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0);
1155 pthread_cleanup_pop (0);
1157 printf ("%s: recv returned\n", __FUNCTION__
);
1164 tf_recvfrom (void *arg
)
1166 struct sockaddr_un sun
;
1168 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1171 printf ("%s: first socket call failed\n", __FUNCTION__
);
1180 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1183 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-4-XXXXXX");
1184 if (mktemp (sun
.sun_path
) == NULL
)
1186 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1190 sun
.sun_family
= AF_UNIX
;
1192 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1193 offsetof (struct sockaddr_un
, sun_path
)
1194 + strlen (sun
.sun_path
) + 1) != 0);
1196 tempfname
= strdup (sun
.sun_path
);
1198 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1201 printf ("%s: second socket call failed\n", __FUNCTION__
);
1205 int r
= pthread_barrier_wait (&b2
);
1206 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1208 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1214 r
= pthread_barrier_wait (&b2
);
1215 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1217 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1222 pthread_cleanup_push (cl
, NULL
);
1225 socklen_t len
= sizeof (sun
);
1227 recvfrom (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0,
1228 (struct sockaddr
*) &sun
, &len
);
1230 pthread_cleanup_pop (0);
1232 printf ("%s: recvfrom returned\n", __FUNCTION__
);
1239 tf_recvmsg (void *arg
)
1241 struct sockaddr_un sun
;
1243 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1246 printf ("%s: first socket call failed\n", __FUNCTION__
);
1255 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1258 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-5-XXXXXX");
1259 if (mktemp (sun
.sun_path
) == NULL
)
1261 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1265 sun
.sun_family
= AF_UNIX
;
1267 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1268 offsetof (struct sockaddr_un
, sun_path
)
1269 + strlen (sun
.sun_path
) + 1) != 0);
1271 tempfname
= strdup (sun
.sun_path
);
1273 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1276 printf ("%s: second socket call failed\n", __FUNCTION__
);
1280 int r
= pthread_barrier_wait (&b2
);
1281 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1283 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1289 r
= pthread_barrier_wait (&b2
);
1290 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1292 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1297 pthread_cleanup_push (cl
, NULL
);
1300 struct iovec iov
[1];
1301 iov
[0].iov_base
= mem
;
1302 iov
[0].iov_len
= arg
== NULL
? sizeof (mem
) : 0;
1306 m
.msg_namelen
= sizeof (sun
);
1309 m
.msg_control
= NULL
;
1310 m
.msg_controllen
= 0;
1312 recvmsg (tempfd2
, &m
, 0);
1314 pthread_cleanup_pop (0);
1316 printf ("%s: recvmsg returned\n", __FUNCTION__
);
1326 // XXX If somebody can provide a portable test case in which open()
1327 // blocks we can enable this test to run in both rounds.
1330 int r
= pthread_barrier_wait (&b2
);
1331 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1333 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1337 r
= pthread_barrier_wait (&b2
);
1338 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1340 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1344 pthread_cleanup_push (cl
, NULL
);
1346 open ("Makefile", O_RDONLY
);
1348 pthread_cleanup_pop (0);
1350 printf ("%s: open returned\n", __FUNCTION__
);
1357 tf_close (void *arg
)
1360 // XXX If somebody can provide a portable test case in which close()
1361 // blocks we can enable this test to run in both rounds.
1364 char fname
[] = "/tmp/tst-cancel-fd-XXXXXX";
1365 tempfd
= mkstemp (fname
);
1368 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1373 int r
= pthread_barrier_wait (&b2
);
1374 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1376 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1380 r
= pthread_barrier_wait (&b2
);
1381 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1383 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1387 pthread_cleanup_push (cl
, NULL
);
1391 pthread_cleanup_pop (0);
1393 printf ("%s: close returned\n", __FUNCTION__
);
1400 tf_pread (void *arg
)
1403 // XXX If somebody can provide a portable test case in which pread()
1404 // blocks we can enable this test to run in both rounds.
1407 tempfd
= open ("Makefile", O_RDONLY
);
1410 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1414 int r
= pthread_barrier_wait (&b2
);
1415 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1417 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1421 r
= pthread_barrier_wait (&b2
);
1422 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1424 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1428 pthread_cleanup_push (cl
, NULL
);
1431 pread (tempfd
, mem
, sizeof (mem
), 0);
1433 pthread_cleanup_pop (0);
1435 printf ("%s: pread returned\n", __FUNCTION__
);
1442 tf_pwrite (void *arg
)
1445 // XXX If somebody can provide a portable test case in which pwrite()
1446 // blocks we can enable this test to run in both rounds.
1449 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1450 tempfd
= mkstemp (fname
);
1453 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1458 int r
= pthread_barrier_wait (&b2
);
1459 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1461 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1465 r
= pthread_barrier_wait (&b2
);
1466 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1468 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1472 pthread_cleanup_push (cl
, NULL
);
1475 pwrite (tempfd
, mem
, sizeof (mem
), 0);
1477 pthread_cleanup_pop (0);
1479 printf ("%s: pwrite returned\n", __FUNCTION__
);
1486 tf_fsync (void *arg
)
1489 // XXX If somebody can provide a portable test case in which fsync()
1490 // blocks we can enable this test to run in both rounds.
1493 tempfd
= open ("Makefile", O_RDONLY
);
1496 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1500 int r
= pthread_barrier_wait (&b2
);
1501 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1503 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1507 r
= pthread_barrier_wait (&b2
);
1508 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1510 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1514 pthread_cleanup_push (cl
, NULL
);
1518 pthread_cleanup_pop (0);
1520 printf ("%s: fsync returned\n", __FUNCTION__
);
1527 tf_msync (void *arg
)
1530 // XXX If somebody can provide a portable test case in which msync()
1531 // blocks we can enable this test to run in both rounds.
1534 tempfd
= open ("Makefile", O_RDONLY
);
1537 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1540 void *p
= mmap (NULL
, 10, PROT_READ
, MAP_SHARED
, tempfd
, 0);
1541 if (p
== MAP_FAILED
)
1543 printf ("%s: mmap failed\n", __FUNCTION__
);
1547 int r
= pthread_barrier_wait (&b2
);
1548 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1550 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1554 r
= pthread_barrier_wait (&b2
);
1555 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1557 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1561 pthread_cleanup_push (cl
, NULL
);
1565 pthread_cleanup_pop (0);
1567 printf ("%s: msync returned\n", __FUNCTION__
);
1574 tf_sendto (void *arg
)
1577 // XXX If somebody can provide a portable test case in which sendto()
1578 // blocks we can enable this test to run in both rounds.
1581 struct sockaddr_un sun
;
1583 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1586 printf ("%s: first socket call failed\n", __FUNCTION__
);
1595 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1598 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-6-XXXXXX");
1599 if (mktemp (sun
.sun_path
) == NULL
)
1601 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1605 sun
.sun_family
= AF_UNIX
;
1607 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1608 offsetof (struct sockaddr_un
, sun_path
)
1609 + strlen (sun
.sun_path
) + 1) != 0);
1610 tempfname
= strdup (sun
.sun_path
);
1612 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1615 printf ("%s: second socket call failed\n", __FUNCTION__
);
1619 int r
= pthread_barrier_wait (&b2
);
1620 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1622 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1626 r
= pthread_barrier_wait (&b2
);
1627 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1629 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1633 pthread_cleanup_push (cl
, NULL
);
1637 sendto (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0,
1638 (struct sockaddr
*) &sun
,
1639 offsetof (struct sockaddr_un
, sun_path
) + strlen (sun
.sun_path
) + 1);
1641 pthread_cleanup_pop (0);
1643 printf ("%s: sendto returned\n", __FUNCTION__
);
1650 tf_sendmsg (void *arg
)
1653 // XXX If somebody can provide a portable test case in which sendmsg()
1654 // blocks we can enable this test to run in both rounds.
1657 struct sockaddr_un sun
;
1659 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1662 printf ("%s: first socket call failed\n", __FUNCTION__
);
1671 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1674 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-7-XXXXXX");
1675 if (mktemp (sun
.sun_path
) == NULL
)
1677 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1681 sun
.sun_family
= AF_UNIX
;
1683 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1684 offsetof (struct sockaddr_un
, sun_path
)
1685 + strlen (sun
.sun_path
) + 1) != 0);
1686 tempfname
= strdup (sun
.sun_path
);
1688 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1691 printf ("%s: second socket call failed\n", __FUNCTION__
);
1695 int r
= pthread_barrier_wait (&b2
);
1696 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1698 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1702 r
= pthread_barrier_wait (&b2
);
1703 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1705 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1709 pthread_cleanup_push (cl
, NULL
);
1712 struct iovec iov
[1];
1713 iov
[0].iov_base
= mem
;
1718 m
.msg_namelen
= (offsetof (struct sockaddr_un
, sun_path
)
1719 + strlen (sun
.sun_path
) + 1);
1722 m
.msg_control
= NULL
;
1723 m
.msg_controllen
= 0;
1725 sendmsg (tempfd2
, &m
, 0);
1727 pthread_cleanup_pop (0);
1729 printf ("%s: sendmsg returned\n", __FUNCTION__
);
1736 tf_creat (void *arg
)
1739 // XXX If somebody can provide a portable test case in which sendmsg()
1740 // blocks we can enable this test to run in both rounds.
1743 int r
= pthread_barrier_wait (&b2
);
1744 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1746 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1750 r
= pthread_barrier_wait (&b2
);
1751 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1753 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1757 pthread_cleanup_push (cl
, NULL
);
1759 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1761 pthread_cleanup_pop (0);
1763 printf ("%s: creat returned\n", __FUNCTION__
);
1770 tf_connect (void *arg
)
1773 // XXX If somebody can provide a portable test case in which connect()
1774 // blocks we can enable this test to run in both rounds.
1777 struct sockaddr_un sun
;
1779 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1782 printf ("%s: first socket call failed\n", __FUNCTION__
);
1791 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1794 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1795 if (mktemp (sun
.sun_path
) == NULL
)
1797 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1801 sun
.sun_family
= AF_UNIX
;
1803 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1804 offsetof (struct sockaddr_un
, sun_path
)
1805 + strlen (sun
.sun_path
) + 1) != 0);
1806 tempfname
= strdup (sun
.sun_path
);
1810 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1813 printf ("%s: second socket call failed\n", __FUNCTION__
);
1817 int r
= pthread_barrier_wait (&b2
);
1818 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1820 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1826 r
= pthread_barrier_wait (&b2
);
1827 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1829 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1834 pthread_cleanup_push (cl
, NULL
);
1836 connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
));
1838 pthread_cleanup_pop (0);
1840 printf ("%s: connect returned\n", __FUNCTION__
);
1847 tf_tcdrain (void *arg
)
1850 // XXX If somebody can provide a portable test case in which tcdrain()
1851 // blocks we can enable this test to run in both rounds.
1854 int r
= pthread_barrier_wait (&b2
);
1855 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1857 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1863 r
= pthread_barrier_wait (&b2
);
1864 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1866 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1871 pthread_cleanup_push (cl
, NULL
);
1873 /* Regardless of stderr being a terminal, the tcdrain call should be
1875 tcdrain (STDERR_FILENO
);
1877 pthread_cleanup_pop (0);
1879 printf ("%s: tcdrain returned\n", __FUNCTION__
);
1886 tf_msgrcv (void *arg
)
1888 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1891 printf ("%s: msgget failed: %s\n", __FUNCTION__
, strerror (errno
));
1895 int r
= pthread_barrier_wait (&b2
);
1896 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1898 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1904 r
= pthread_barrier_wait (&b2
);
1905 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1907 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1914 pthread_cleanup_push (cl
, NULL
);
1922 /* We need a positive random number. */
1924 randnr
= random () % 64000;
1925 while (randnr
<= 0);
1929 s
= msgrcv (tempmsg
, (struct msgbuf
*) &m
, 10, randnr
, 0);
1931 while (errno
== EIDRM
|| errno
== EINTR
);
1933 pthread_cleanup_pop (0);
1935 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__
, s
);
1937 msgctl (tempmsg
, IPC_RMID
, NULL
);
1944 tf_msgsnd (void *arg
)
1947 // XXX If somebody can provide a portable test case in which msgsnd()
1948 // blocks we can enable this test to run in both rounds.
1951 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1954 printf ("%s: msgget failed: %s\n", __FUNCTION__
, strerror (errno
));
1958 int r
= pthread_barrier_wait (&b2
);
1959 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1961 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__
);
1972 pthread_cleanup_push (cl
, NULL
);
1979 /* We need a positive random number. */
1981 m
.type
= random () % 64000;
1982 while (m
.type
<= 0);
1983 msgsnd (tempmsg
, (struct msgbuf
*) &m
, sizeof (m
.mem
), 0);
1985 pthread_cleanup_pop (0);
1987 printf ("%s: msgsnd returned\n", __FUNCTION__
);
1989 msgctl (tempmsg
, IPC_RMID
, NULL
);
1998 void *(*tf
) (void *);
2003 #define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early }
2004 ADD_TEST (read
, 2, 0),
2005 ADD_TEST (readv
, 2, 0),
2006 ADD_TEST (select
, 2, 0),
2007 ADD_TEST (pselect
, 2, 0),
2008 ADD_TEST (poll
, 2, 0),
2009 ADD_TEST (write
, 2, 0),
2010 ADD_TEST (writev
, 2, 0),
2011 ADD_TEST (sleep
, 2, 0),
2012 ADD_TEST (usleep
, 2, 0),
2013 ADD_TEST (nanosleep
, 2, 0),
2014 ADD_TEST (wait
, 2, 0),
2015 ADD_TEST (waitid
, 2, 0),
2016 ADD_TEST (waitpid
, 2, 0),
2017 ADD_TEST (sigpause
, 2, 0),
2018 ADD_TEST (sigsuspend
, 2, 0),
2019 ADD_TEST (sigwait
, 2, 0),
2020 ADD_TEST (sigwaitinfo
, 2, 0),
2021 ADD_TEST (sigtimedwait
, 2, 0),
2022 ADD_TEST (pause
, 2, 0),
2023 ADD_TEST (accept
, 2, 0),
2024 ADD_TEST (send
, 2, 0),
2025 ADD_TEST (recv
, 2, 0),
2026 ADD_TEST (recvfrom
, 2, 0),
2027 ADD_TEST (recvmsg
, 2, 0),
2028 ADD_TEST (open
, 2, 1),
2029 ADD_TEST (close
, 2, 1),
2030 ADD_TEST (pread
, 2, 1),
2031 ADD_TEST (pwrite
, 2, 1),
2032 ADD_TEST (fsync
, 2, 1),
2033 ADD_TEST (msync
, 2, 1),
2034 ADD_TEST (sendto
, 2, 1),
2035 ADD_TEST (sendmsg
, 2, 1),
2036 ADD_TEST (creat
, 2, 1),
2037 ADD_TEST (connect
, 2, 1),
2038 ADD_TEST (tcdrain
, 2, 1),
2039 ADD_TEST (msgrcv
, 2, 0),
2040 ADD_TEST (msgsnd
, 2, 1),
2042 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2051 if (socketpair (AF_UNIX
, SOCK_STREAM
, PF_UNIX
, fds
) != 0)
2053 perror ("socketpair");
2059 setsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, sizeof(val
));
2060 if (getsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, &len
) < 0)
2062 perror ("getsockopt");
2065 if (val
>= WRITE_BUFFER_SIZE
)
2067 puts ("minimum write buffer size too large");
2070 setsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, sizeof(val
));
2074 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
2076 if (tests
[cnt
].only_early
)
2079 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
2081 puts ("b2 init failed");
2085 /* Reset the counter for the cleanup handler. */
2089 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, NULL
) != 0)
2091 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
2096 int r
= pthread_barrier_wait (&b2
);
2097 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2099 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2104 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
2105 while (nanosleep (&ts
, &ts
) != 0)
2108 if (pthread_cancel (th
) != 0)
2110 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
2116 if (pthread_join (th
, &status
) != 0)
2118 printf ("join for '%s' failed\n", tests
[cnt
].name
);
2122 if (status
!= PTHREAD_CANCELED
)
2124 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
2129 if (pthread_barrier_destroy (&b2
) != 0)
2131 puts ("barrier_destroy failed");
2138 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
2144 printf ("cleanup handler called more than once for '%s'\n",
2150 printf ("in-time cancel test of '%s' successful\n", tests
[cnt
].name
);
2162 if (tempfname
!= NULL
)
2170 msgctl (tempmsg
, IPC_RMID
, NULL
);
2175 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
2177 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
2179 puts ("b2 init failed");
2183 /* Reset the counter for the cleanup handler. */
2187 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, (void *) 1l) != 0)
2189 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
2194 int r
= pthread_barrier_wait (&b2
);
2195 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2197 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2202 if (pthread_cancel (th
) != 0)
2204 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
2209 r
= pthread_barrier_wait (&b2
);
2210 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2212 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2218 if (pthread_join (th
, &status
) != 0)
2220 printf ("join for '%s' failed\n", tests
[cnt
].name
);
2224 if (status
!= PTHREAD_CANCELED
)
2226 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
2231 if (pthread_barrier_destroy (&b2
) != 0)
2233 puts ("barrier_destroy failed");
2240 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
2246 printf ("cleanup handler called more than once for '%s'\n",
2252 printf ("early cancel test of '%s' successful\n", tests
[cnt
].name
);
2264 if (tempfname
!= NULL
)
2272 msgctl (tempmsg
, IPC_RMID
, NULL
);
2281 #define TEST_FUNCTION do_test ()
2282 #include "../test-skeleton.c"