1 /* Copyright (C) 2002-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 /* NOTE: this tests functionality beyond POSIX. POSIX does not allow
20 exit to be called more than once. */
35 #include <sys/select.h>
36 #include <sys/socket.h>
44 /* Since STREAMS are not supported in the standard Linux kernel and
45 there we don't advertise STREAMS as supported is no need to test
46 the STREAMS related functions. This affects
47 getmsg() getpmsg() putmsg()
50 lockf() and fcntl() are tested in tst-cancel16.
52 pthread_join() is tested in tst-join5.
54 pthread_testcancel()'s only purpose is to allow cancellation. This
55 is tested in several places.
57 sem_wait() and sem_timedwait() are checked in tst-cancel1[2345] tests.
59 mq_send(), mq_timedsend(), mq_receive() and mq_timedreceive() are checked
60 in tst-mqueue8{,x} tests.
62 aio_suspend() is tested in tst-cancel17.
64 clock_nanosleep() is tested in tst-cancel18.
67 /* Pipe descriptors. */
70 /* Temporary file descriptor, to be closed after each round. */
71 static int tempfd
= -1;
72 static int tempfd2
= -1;
73 /* Name of temporary file to be removed after each round. */
74 static char *tempfname
;
75 /* Temporary message queue. */
76 static int tempmsg
= -1;
78 /* Often used barrier for two threads. */
79 static pthread_barrier_t b2
;
86 /* The WRITE_BUFFER_SIZE value needs to be chosen such that if we set
87 the socket send buffer size to '1', a write of this size on that
90 The Linux kernel imposes a minimum send socket buffer size which
91 has changed over the years. As of Linux 3.10 the value is:
93 2 * (2048 + SKB_DATA_ALIGN(sizeof(struct sk_buff)))
95 which is attempting to make sure that with standard MTUs,
96 TCP can always queue up at least 2 full sized packets.
98 Furthermore, there is logic in the socket send paths that
99 will allow one more packet (of any size) to be queued up as
100 long as some socket buffer space remains. Blocking only
101 occurs when we try to queue up a new packet and the send
102 buffer space has already been fully consumed.
104 Therefore we must set this value to the largest possible value of
105 the formula above (and since it depends upon the size of "struct
106 sk_buff", it is dependent upon machine word size etc.) plus some
109 #define WRITE_BUFFER_SIZE 16384
111 /* Cleanup handling test. */
112 static int cl_called
;
132 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
133 tempfd
= fd
= mkstemp (fname
);
135 printf ("%s: mkstemp failed\n", __FUNCTION__
);
138 r
= pthread_barrier_wait (&b2
);
139 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
141 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
146 r
= pthread_barrier_wait (&b2
);
147 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
149 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
154 pthread_cleanup_push (cl
, NULL
);
157 s
= read (fd
, buf
, sizeof (buf
));
159 pthread_cleanup_pop (0);
161 printf ("%s: read returns with %zd\n", __FUNCTION__
, s
);
177 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
178 tempfd
= fd
= mkstemp (fname
);
180 printf ("%s: mkstemp failed\n", __FUNCTION__
);
183 r
= pthread_barrier_wait (&b2
);
184 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
186 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
191 r
= pthread_barrier_wait (&b2
);
192 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
194 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
199 pthread_cleanup_push (cl
, NULL
);
202 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
203 s
= readv (fd
, iov
, 1);
205 pthread_cleanup_pop (0);
207 printf ("%s: readv returns with %zd\n", __FUNCTION__
, s
);
223 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
224 tempfd
= fd
= mkstemp (fname
);
226 printf ("%s: mkstemp failed\n", __FUNCTION__
);
229 r
= pthread_barrier_wait (&b2
);
230 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
232 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
237 r
= pthread_barrier_wait (&b2
);
238 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
240 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
245 pthread_cleanup_push (cl
, NULL
);
247 char buf
[WRITE_BUFFER_SIZE
];
248 memset (buf
, '\0', sizeof (buf
));
249 s
= write (fd
, buf
, sizeof (buf
));
251 pthread_cleanup_pop (0);
253 printf ("%s: write returns with %zd\n", __FUNCTION__
, s
);
260 tf_writev (void *arg
)
269 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
270 tempfd
= fd
= mkstemp (fname
);
272 printf ("%s: mkstemp failed\n", __FUNCTION__
);
275 r
= pthread_barrier_wait (&b2
);
276 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
278 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
283 r
= pthread_barrier_wait (&b2
);
284 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
286 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
291 pthread_cleanup_push (cl
, NULL
);
293 char buf
[WRITE_BUFFER_SIZE
];
294 memset (buf
, '\0', sizeof (buf
));
295 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
296 s
= writev (fd
, iov
, 1);
298 pthread_cleanup_pop (0);
300 printf ("%s: writev returns with %zd\n", __FUNCTION__
, s
);
309 int r
= pthread_barrier_wait (&b2
);
310 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
312 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
318 r
= pthread_barrier_wait (&b2
);
319 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
321 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
326 pthread_cleanup_push (cl
, NULL
);
328 sleep (arg
== NULL
? 1000000 : 0);
330 pthread_cleanup_pop (0);
332 printf ("%s: sleep returns\n", __FUNCTION__
);
339 tf_usleep (void *arg
)
341 int r
= pthread_barrier_wait (&b2
);
342 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
344 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
350 r
= pthread_barrier_wait (&b2
);
351 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
353 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
358 pthread_cleanup_push (cl
, NULL
);
360 usleep (arg
== NULL
? (useconds_t
) ULONG_MAX
: 0);
362 pthread_cleanup_pop (0);
364 printf ("%s: usleep returns\n", __FUNCTION__
);
371 tf_nanosleep (void *arg
)
373 int r
= pthread_barrier_wait (&b2
);
374 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
376 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
382 r
= pthread_barrier_wait (&b2
);
383 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
385 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
390 pthread_cleanup_push (cl
, NULL
);
392 struct timespec ts
= { .tv_sec
= arg
== NULL
? 10000000 : 0, .tv_nsec
= 0 };
393 TEMP_FAILURE_RETRY (nanosleep (&ts
, &ts
));
395 pthread_cleanup_pop (0);
397 printf ("%s: nanosleep returns\n", __FUNCTION__
);
404 tf_select (void *arg
)
413 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
414 tempfd
= fd
= mkstemp (fname
);
416 printf ("%s: mkstemp failed\n", __FUNCTION__
);
419 r
= pthread_barrier_wait (&b2
);
420 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
422 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
427 r
= pthread_barrier_wait (&b2
);
428 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
430 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
439 pthread_cleanup_push (cl
, NULL
);
441 s
= select (fd
+ 1, &rfs
, NULL
, NULL
, NULL
);
443 pthread_cleanup_pop (0);
445 printf ("%s: select returns with %d (%s)\n", __FUNCTION__
, s
,
453 tf_pselect (void *arg
)
462 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
463 tempfd
= fd
= mkstemp (fname
);
465 printf ("%s: mkstemp failed\n", __FUNCTION__
);
468 r
= pthread_barrier_wait (&b2
);
469 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
471 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
476 r
= pthread_barrier_wait (&b2
);
477 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
479 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
488 pthread_cleanup_push (cl
, NULL
);
490 s
= pselect (fd
+ 1, &rfs
, NULL
, NULL
, NULL
, NULL
);
492 pthread_cleanup_pop (0);
494 printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__
, s
,
511 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
512 tempfd
= fd
= mkstemp (fname
);
514 printf ("%s: mkstemp failed\n", __FUNCTION__
);
517 r
= pthread_barrier_wait (&b2
);
518 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
520 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
525 r
= pthread_barrier_wait (&b2
);
526 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
528 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
532 struct pollfd rfs
[1] = { [0] = { .fd
= fd
, .events
= POLLIN
} };
535 pthread_cleanup_push (cl
, NULL
);
537 s
= poll (rfs
, 1, -1);
539 pthread_cleanup_pop (0);
541 printf ("%s: poll returns with %d (%s)\n", __FUNCTION__
, s
,
558 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
559 tempfd
= fd
= mkstemp (fname
);
561 printf ("%s: mkstemp failed\n", __FUNCTION__
);
564 r
= pthread_barrier_wait (&b2
);
565 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
567 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
572 r
= pthread_barrier_wait (&b2
);
573 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
575 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
579 struct pollfd rfs
[1] = { [0] = { .fd
= fd
, .events
= POLLIN
} };
582 pthread_cleanup_push (cl
, NULL
);
584 s
= ppoll (rfs
, 1, NULL
, NULL
);
586 pthread_cleanup_pop (0);
588 printf ("%s: ppoll returns with %d (%s)\n", __FUNCTION__
, s
,
601 puts ("fork failed");
607 /* Make the program disappear after a while. */
616 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
617 while (nanosleep (&ts
, &ts
) != 0)
620 r
= pthread_barrier_wait (&b2
);
621 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
623 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
628 r
= pthread_barrier_wait (&b2
);
629 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
631 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
636 pthread_cleanup_push (cl
, NULL
);
640 pthread_cleanup_pop (0);
642 printf ("%s: wait returns with %d (%s)\n", __FUNCTION__
, s
,
650 tf_waitpid (void *arg
)
656 puts ("fork failed");
662 /* Make the program disappear after a while. */
671 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
672 while (nanosleep (&ts
, &ts
) != 0)
675 r
= pthread_barrier_wait (&b2
);
676 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
678 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
683 r
= pthread_barrier_wait (&b2
);
684 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
686 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
691 pthread_cleanup_push (cl
, NULL
);
693 s
= waitpid (-1, NULL
, 0);
695 pthread_cleanup_pop (0);
697 printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__
, s
,
705 tf_waitid (void *arg
)
710 puts ("fork failed");
716 /* Make the program disappear after a while. */
725 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
726 while (nanosleep (&ts
, &ts
) != 0)
729 r
= pthread_barrier_wait (&b2
);
730 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
732 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: barrier_wait failed\n", __FUNCTION__
);
745 pthread_cleanup_push (cl
, NULL
);
751 s
= waitid (P_PID
, pid
, &si
, WEXITED
);
753 pthread_cleanup_pop (0);
755 printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__
, s
,
763 tf_sigpause (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__
);
782 pthread_cleanup_push (cl
, NULL
);
784 /* Just for fun block the cancellation signal. We need to use
785 __xpg_sigpause since otherwise we will get the BSD version. */
786 __xpg_sigpause (SIGCANCEL
);
788 pthread_cleanup_pop (0);
790 printf ("%s: sigpause returned\n", __FUNCTION__
);
797 tf_sigsuspend (void *arg
)
799 int r
= pthread_barrier_wait (&b2
);
800 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
802 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
808 r
= pthread_barrier_wait (&b2
);
809 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
811 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
816 pthread_cleanup_push (cl
, NULL
);
818 /* Just for fun block all signals. */
823 pthread_cleanup_pop (0);
825 printf ("%s: sigsuspend returned\n", __FUNCTION__
);
832 tf_sigwait (void *arg
)
834 int r
= pthread_barrier_wait (&b2
);
835 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
837 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
843 r
= pthread_barrier_wait (&b2
);
844 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
846 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
854 sigaddset (&mask
, SIGUSR1
);
855 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
857 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
862 pthread_cleanup_push (cl
, NULL
);
864 /* Wait for SIGUSR1. */
865 sigwait (&mask
, &sig
);
867 pthread_cleanup_pop (0);
869 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__
, sig
);
876 tf_sigwaitinfo (void *arg
)
878 int r
= pthread_barrier_wait (&b2
);
879 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
881 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
887 r
= pthread_barrier_wait (&b2
);
888 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
890 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
898 sigaddset (&mask
, SIGUSR1
);
899 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
901 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
906 pthread_cleanup_push (cl
, NULL
);
908 /* Wait for SIGUSR1. */
909 sigwaitinfo (&mask
, &info
);
911 pthread_cleanup_pop (0);
913 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__
,
921 tf_sigtimedwait (void *arg
)
923 int r
= pthread_barrier_wait (&b2
);
924 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
926 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
932 r
= pthread_barrier_wait (&b2
);
933 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
935 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
943 sigaddset (&mask
, SIGUSR1
);
944 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
946 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
950 /* Wait for SIGUSR1. */
952 struct timespec ts
= { .tv_sec
= 60, .tv_nsec
= 0 };
953 pthread_cleanup_push (cl
, NULL
);
955 sigtimedwait (&mask
, &info
, &ts
);
957 pthread_cleanup_pop (0);
959 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__
,
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
);
990 pthread_cleanup_pop (0);
992 printf ("%s: pause returned\n", __FUNCTION__
);
999 tf_accept (void *arg
)
1001 struct sockaddr_un sun
;
1002 /* To test a non-blocking accept call we make the call file by using
1003 a datagrame socket. */
1004 int pf
= arg
== NULL
? SOCK_STREAM
: SOCK_DGRAM
;
1006 tempfd
= socket (AF_UNIX
, pf
, 0);
1009 printf ("%s: socket call failed\n", __FUNCTION__
);
1018 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1021 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-1-XXXXXX");
1022 if (mktemp (sun
.sun_path
) == NULL
)
1024 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1028 sun
.sun_family
= AF_UNIX
;
1030 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1031 offsetof (struct sockaddr_un
, sun_path
)
1032 + strlen (sun
.sun_path
) + 1) != 0);
1034 unlink (sun
.sun_path
);
1038 socklen_t len
= sizeof (sun
);
1040 int r
= pthread_barrier_wait (&b2
);
1041 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1043 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1049 r
= pthread_barrier_wait (&b2
);
1050 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1052 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1057 pthread_cleanup_push (cl
, NULL
);
1059 accept (tempfd
, (struct sockaddr
*) &sun
, &len
);
1061 pthread_cleanup_pop (0);
1063 printf ("%s: accept returned\n", __FUNCTION__
);
1072 struct sockaddr_un sun
;
1074 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1077 printf ("%s: first socket call failed\n", __FUNCTION__
);
1086 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1089 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1090 if (mktemp (sun
.sun_path
) == NULL
)
1092 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1096 sun
.sun_family
= AF_UNIX
;
1098 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1099 offsetof (struct sockaddr_un
, sun_path
)
1100 + strlen (sun
.sun_path
) + 1) != 0);
1104 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1107 printf ("%s: second socket call failed\n", __FUNCTION__
);
1111 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1113 printf ("%s: connect failed\n", __FUNCTION__
);
1117 unlink (sun
.sun_path
);
1119 int r
= pthread_barrier_wait (&b2
);
1120 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1122 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1128 r
= pthread_barrier_wait (&b2
);
1129 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1131 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1136 pthread_cleanup_push (cl
, NULL
);
1138 /* Very large block, so that the send call blocks. */
1141 send (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0);
1143 pthread_cleanup_pop (0);
1145 printf ("%s: send returned\n", __FUNCTION__
);
1154 struct sockaddr_un sun
;
1156 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1159 printf ("%s: first socket call failed\n", __FUNCTION__
);
1168 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1171 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-3-XXXXXX");
1172 if (mktemp (sun
.sun_path
) == NULL
)
1174 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1178 sun
.sun_family
= AF_UNIX
;
1180 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1181 offsetof (struct sockaddr_un
, sun_path
)
1182 + strlen (sun
.sun_path
) + 1) != 0);
1186 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1189 printf ("%s: second socket call failed\n", __FUNCTION__
);
1193 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1195 printf ("%s: connect failed\n", __FUNCTION__
);
1199 unlink (sun
.sun_path
);
1201 int r
= pthread_barrier_wait (&b2
);
1202 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1204 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1210 r
= pthread_barrier_wait (&b2
);
1211 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1213 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1218 pthread_cleanup_push (cl
, NULL
);
1222 recv (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0);
1224 pthread_cleanup_pop (0);
1226 printf ("%s: recv returned\n", __FUNCTION__
);
1233 tf_recvfrom (void *arg
)
1235 struct sockaddr_un sun
;
1237 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1240 printf ("%s: first socket call failed\n", __FUNCTION__
);
1249 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1252 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-4-XXXXXX");
1253 if (mktemp (sun
.sun_path
) == NULL
)
1255 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1259 sun
.sun_family
= AF_UNIX
;
1261 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1262 offsetof (struct sockaddr_un
, sun_path
)
1263 + strlen (sun
.sun_path
) + 1) != 0);
1265 tempfname
= strdup (sun
.sun_path
);
1267 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1270 printf ("%s: second socket call failed\n", __FUNCTION__
);
1274 int r
= pthread_barrier_wait (&b2
);
1275 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1277 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1283 r
= pthread_barrier_wait (&b2
);
1284 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1286 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1291 pthread_cleanup_push (cl
, NULL
);
1294 socklen_t len
= sizeof (sun
);
1296 recvfrom (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0,
1297 (struct sockaddr
*) &sun
, &len
);
1299 pthread_cleanup_pop (0);
1301 printf ("%s: recvfrom returned\n", __FUNCTION__
);
1308 tf_recvmsg (void *arg
)
1310 struct sockaddr_un sun
;
1312 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1315 printf ("%s: first socket call failed\n", __FUNCTION__
);
1324 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1327 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-5-XXXXXX");
1328 if (mktemp (sun
.sun_path
) == NULL
)
1330 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1334 sun
.sun_family
= AF_UNIX
;
1336 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1337 offsetof (struct sockaddr_un
, sun_path
)
1338 + strlen (sun
.sun_path
) + 1) != 0);
1340 tempfname
= strdup (sun
.sun_path
);
1342 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1345 printf ("%s: second socket call failed\n", __FUNCTION__
);
1349 int r
= pthread_barrier_wait (&b2
);
1350 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1352 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1358 r
= pthread_barrier_wait (&b2
);
1359 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1361 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1366 pthread_cleanup_push (cl
, NULL
);
1369 struct iovec iov
[1];
1370 iov
[0].iov_base
= mem
;
1371 iov
[0].iov_len
= arg
== NULL
? sizeof (mem
) : 0;
1375 m
.msg_namelen
= sizeof (sun
);
1378 m
.msg_control
= NULL
;
1379 m
.msg_controllen
= 0;
1381 recvmsg (tempfd2
, &m
, 0);
1383 pthread_cleanup_pop (0);
1385 printf ("%s: recvmsg returned\n", __FUNCTION__
);
1395 // XXX If somebody can provide a portable test case in which open()
1396 // blocks we can enable this test to run in both rounds.
1399 int r
= pthread_barrier_wait (&b2
);
1400 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1402 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1406 r
= pthread_barrier_wait (&b2
);
1407 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1409 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1413 pthread_cleanup_push (cl
, NULL
);
1415 open ("Makefile", O_RDONLY
);
1417 pthread_cleanup_pop (0);
1419 printf ("%s: open returned\n", __FUNCTION__
);
1426 tf_close (void *arg
)
1429 // XXX If somebody can provide a portable test case in which close()
1430 // blocks we can enable this test to run in both rounds.
1433 char fname
[] = "/tmp/tst-cancel-fd-XXXXXX";
1434 tempfd
= mkstemp (fname
);
1437 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1442 int r
= pthread_barrier_wait (&b2
);
1443 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1445 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1449 r
= pthread_barrier_wait (&b2
);
1450 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1452 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1456 pthread_cleanup_push (cl
, NULL
);
1460 pthread_cleanup_pop (0);
1462 printf ("%s: close returned\n", __FUNCTION__
);
1469 tf_pread (void *arg
)
1472 // XXX If somebody can provide a portable test case in which pread()
1473 // blocks we can enable this test to run in both rounds.
1476 tempfd
= open ("Makefile", O_RDONLY
);
1479 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1483 int r
= pthread_barrier_wait (&b2
);
1484 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1486 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1490 r
= pthread_barrier_wait (&b2
);
1491 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1493 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1497 pthread_cleanup_push (cl
, NULL
);
1500 pread (tempfd
, mem
, sizeof (mem
), 0);
1502 pthread_cleanup_pop (0);
1504 printf ("%s: pread returned\n", __FUNCTION__
);
1511 tf_pwrite (void *arg
)
1514 // XXX If somebody can provide a portable test case in which pwrite()
1515 // blocks we can enable this test to run in both rounds.
1518 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1519 tempfd
= mkstemp (fname
);
1522 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1527 int r
= pthread_barrier_wait (&b2
);
1528 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1530 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1534 r
= pthread_barrier_wait (&b2
);
1535 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1537 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1541 pthread_cleanup_push (cl
, NULL
);
1544 pwrite (tempfd
, mem
, sizeof (mem
), 0);
1546 pthread_cleanup_pop (0);
1548 printf ("%s: pwrite returned\n", __FUNCTION__
);
1555 tf_fsync (void *arg
)
1558 // XXX If somebody can provide a portable test case in which fsync()
1559 // blocks we can enable this test to run in both rounds.
1562 tempfd
= open ("Makefile", O_RDONLY
);
1565 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1569 int r
= pthread_barrier_wait (&b2
);
1570 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1572 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1576 r
= pthread_barrier_wait (&b2
);
1577 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1579 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1583 pthread_cleanup_push (cl
, NULL
);
1587 pthread_cleanup_pop (0);
1589 printf ("%s: fsync returned\n", __FUNCTION__
);
1596 tf_fdatasync (void *arg
)
1599 // XXX If somebody can provide a portable test case in which fdatasync()
1600 // blocks we can enable this test to run in both rounds.
1603 tempfd
= open ("Makefile", O_RDONLY
);
1606 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1610 int r
= pthread_barrier_wait (&b2
);
1611 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1613 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1617 r
= pthread_barrier_wait (&b2
);
1618 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1620 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1624 pthread_cleanup_push (cl
, NULL
);
1628 pthread_cleanup_pop (0);
1630 printf ("%s: fdatasync returned\n", __FUNCTION__
);
1637 tf_msync (void *arg
)
1640 // XXX If somebody can provide a portable test case in which msync()
1641 // blocks we can enable this test to run in both rounds.
1644 tempfd
= open ("Makefile", O_RDONLY
);
1647 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1650 void *p
= mmap (NULL
, 10, PROT_READ
, MAP_SHARED
, tempfd
, 0);
1651 if (p
== MAP_FAILED
)
1653 printf ("%s: mmap failed\n", __FUNCTION__
);
1657 int r
= pthread_barrier_wait (&b2
);
1658 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1660 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1664 r
= pthread_barrier_wait (&b2
);
1665 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1667 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1671 pthread_cleanup_push (cl
, NULL
);
1675 pthread_cleanup_pop (0);
1677 printf ("%s: msync returned\n", __FUNCTION__
);
1684 tf_sendto (void *arg
)
1687 // XXX If somebody can provide a portable test case in which sendto()
1688 // blocks we can enable this test to run in both rounds.
1691 struct sockaddr_un sun
;
1693 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1696 printf ("%s: first socket call failed\n", __FUNCTION__
);
1705 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1708 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-6-XXXXXX");
1709 if (mktemp (sun
.sun_path
) == NULL
)
1711 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1715 sun
.sun_family
= AF_UNIX
;
1717 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1718 offsetof (struct sockaddr_un
, sun_path
)
1719 + strlen (sun
.sun_path
) + 1) != 0);
1720 tempfname
= strdup (sun
.sun_path
);
1722 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1725 printf ("%s: second socket call failed\n", __FUNCTION__
);
1729 int r
= pthread_barrier_wait (&b2
);
1730 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1732 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1736 r
= pthread_barrier_wait (&b2
);
1737 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1739 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1743 pthread_cleanup_push (cl
, NULL
);
1747 sendto (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0,
1748 (struct sockaddr
*) &sun
,
1749 offsetof (struct sockaddr_un
, sun_path
) + strlen (sun
.sun_path
) + 1);
1751 pthread_cleanup_pop (0);
1753 printf ("%s: sendto returned\n", __FUNCTION__
);
1760 tf_sendmsg (void *arg
)
1763 // XXX If somebody can provide a portable test case in which sendmsg()
1764 // blocks we can enable this test to run in both rounds.
1767 struct sockaddr_un sun
;
1769 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1772 printf ("%s: first socket call failed\n", __FUNCTION__
);
1781 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1784 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-7-XXXXXX");
1785 if (mktemp (sun
.sun_path
) == NULL
)
1787 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1791 sun
.sun_family
= AF_UNIX
;
1793 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1794 offsetof (struct sockaddr_un
, sun_path
)
1795 + strlen (sun
.sun_path
) + 1) != 0);
1796 tempfname
= strdup (sun
.sun_path
);
1798 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1801 printf ("%s: second socket call failed\n", __FUNCTION__
);
1805 int r
= pthread_barrier_wait (&b2
);
1806 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1808 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1812 r
= pthread_barrier_wait (&b2
);
1813 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1815 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1819 pthread_cleanup_push (cl
, NULL
);
1822 struct iovec iov
[1];
1823 iov
[0].iov_base
= mem
;
1828 m
.msg_namelen
= (offsetof (struct sockaddr_un
, sun_path
)
1829 + strlen (sun
.sun_path
) + 1);
1832 m
.msg_control
= NULL
;
1833 m
.msg_controllen
= 0;
1835 sendmsg (tempfd2
, &m
, 0);
1837 pthread_cleanup_pop (0);
1839 printf ("%s: sendmsg returned\n", __FUNCTION__
);
1846 tf_creat (void *arg
)
1849 // XXX If somebody can provide a portable test case in which sendmsg()
1850 // blocks we can enable this test to run in both rounds.
1853 int r
= pthread_barrier_wait (&b2
);
1854 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1856 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1860 r
= pthread_barrier_wait (&b2
);
1861 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1863 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1867 pthread_cleanup_push (cl
, NULL
);
1869 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1871 pthread_cleanup_pop (0);
1873 printf ("%s: creat returned\n", __FUNCTION__
);
1880 tf_connect (void *arg
)
1883 // XXX If somebody can provide a portable test case in which connect()
1884 // blocks we can enable this test to run in both rounds.
1887 struct sockaddr_un sun
;
1889 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1892 printf ("%s: first socket call failed\n", __FUNCTION__
);
1901 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1904 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1905 if (mktemp (sun
.sun_path
) == NULL
)
1907 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1911 sun
.sun_family
= AF_UNIX
;
1913 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1914 offsetof (struct sockaddr_un
, sun_path
)
1915 + strlen (sun
.sun_path
) + 1) != 0);
1916 tempfname
= strdup (sun
.sun_path
);
1920 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1923 printf ("%s: second socket call failed\n", __FUNCTION__
);
1927 int r
= pthread_barrier_wait (&b2
);
1928 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1930 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1936 r
= pthread_barrier_wait (&b2
);
1937 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1939 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1944 pthread_cleanup_push (cl
, NULL
);
1946 connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
));
1948 pthread_cleanup_pop (0);
1950 printf ("%s: connect returned\n", __FUNCTION__
);
1957 tf_tcdrain (void *arg
)
1960 // XXX If somebody can provide a portable test case in which tcdrain()
1961 // blocks we can enable this test to run in both rounds.
1964 int r
= pthread_barrier_wait (&b2
);
1965 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1967 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1973 r
= pthread_barrier_wait (&b2
);
1974 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1976 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1981 pthread_cleanup_push (cl
, NULL
);
1983 /* Regardless of stderr being a terminal, the tcdrain call should be
1985 tcdrain (STDERR_FILENO
);
1987 pthread_cleanup_pop (0);
1989 printf ("%s: tcdrain returned\n", __FUNCTION__
);
1996 tf_msgrcv (void *arg
)
1998 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
2001 printf ("%s: msgget failed: %s\n", __FUNCTION__
, strerror (errno
));
2005 int r
= pthread_barrier_wait (&b2
);
2006 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2008 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2014 r
= pthread_barrier_wait (&b2
);
2015 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2017 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
2024 pthread_cleanup_push (cl
, NULL
);
2032 /* We need a positive random number. */
2034 randnr
= random () % 64000;
2035 while (randnr
<= 0);
2039 s
= msgrcv (tempmsg
, (struct msgbuf
*) &m
, 10, randnr
, 0);
2041 while (errno
== EIDRM
|| errno
== EINTR
);
2043 pthread_cleanup_pop (0);
2045 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__
, s
);
2047 msgctl (tempmsg
, IPC_RMID
, NULL
);
2054 tf_msgsnd (void *arg
)
2057 // XXX If somebody can provide a portable test case in which msgsnd()
2058 // blocks we can enable this test to run in both rounds.
2061 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
2064 printf ("%s: msgget failed: %s\n", __FUNCTION__
, strerror (errno
));
2068 int r
= pthread_barrier_wait (&b2
);
2069 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2071 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2075 r
= pthread_barrier_wait (&b2
);
2076 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2078 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
2082 pthread_cleanup_push (cl
, NULL
);
2089 /* We need a positive random number. */
2091 m
.type
= random () % 64000;
2092 while (m
.type
<= 0);
2093 msgsnd (tempmsg
, (struct msgbuf
*) &m
, sizeof (m
.mem
), 0);
2095 pthread_cleanup_pop (0);
2097 printf ("%s: msgsnd returned\n", __FUNCTION__
);
2099 msgctl (tempmsg
, IPC_RMID
, NULL
);
2108 void *(*tf
) (void *);
2113 #define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early }
2114 ADD_TEST (read
, 2, 0),
2115 ADD_TEST (readv
, 2, 0),
2116 ADD_TEST (select
, 2, 0),
2117 ADD_TEST (pselect
, 2, 0),
2118 ADD_TEST (poll
, 2, 0),
2119 ADD_TEST (ppoll
, 2, 0),
2120 ADD_TEST (write
, 2, 0),
2121 ADD_TEST (writev
, 2, 0),
2122 ADD_TEST (sleep
, 2, 0),
2123 ADD_TEST (usleep
, 2, 0),
2124 ADD_TEST (nanosleep
, 2, 0),
2125 ADD_TEST (wait
, 2, 0),
2126 ADD_TEST (waitid
, 2, 0),
2127 ADD_TEST (waitpid
, 2, 0),
2128 ADD_TEST (sigpause
, 2, 0),
2129 ADD_TEST (sigsuspend
, 2, 0),
2130 ADD_TEST (sigwait
, 2, 0),
2131 ADD_TEST (sigwaitinfo
, 2, 0),
2132 ADD_TEST (sigtimedwait
, 2, 0),
2133 ADD_TEST (pause
, 2, 0),
2134 ADD_TEST (accept
, 2, 0),
2135 ADD_TEST (send
, 2, 0),
2136 ADD_TEST (recv
, 2, 0),
2137 ADD_TEST (recvfrom
, 2, 0),
2138 ADD_TEST (recvmsg
, 2, 0),
2139 ADD_TEST (open
, 2, 1),
2140 ADD_TEST (close
, 2, 1),
2141 ADD_TEST (pread
, 2, 1),
2142 ADD_TEST (pwrite
, 2, 1),
2143 ADD_TEST (fsync
, 2, 1),
2144 ADD_TEST (fdatasync
, 2, 1),
2145 ADD_TEST (msync
, 2, 1),
2146 ADD_TEST (sendto
, 2, 1),
2147 ADD_TEST (sendmsg
, 2, 1),
2148 ADD_TEST (creat
, 2, 1),
2149 ADD_TEST (connect
, 2, 1),
2150 ADD_TEST (tcdrain
, 2, 1),
2151 ADD_TEST (msgrcv
, 2, 0),
2152 ADD_TEST (msgsnd
, 2, 1),
2154 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2163 if (socketpair (AF_UNIX
, SOCK_STREAM
, PF_UNIX
, fds
) != 0)
2165 perror ("socketpair");
2171 setsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, sizeof(val
));
2172 if (getsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, &len
) < 0)
2174 perror ("getsockopt");
2177 if (val
>= WRITE_BUFFER_SIZE
)
2179 puts ("minimum write buffer size too large");
2182 setsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, sizeof(val
));
2186 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
2188 if (tests
[cnt
].only_early
)
2191 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
2193 puts ("b2 init failed");
2197 /* Reset the counter for the cleanup handler. */
2201 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, NULL
) != 0)
2203 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
2208 int r
= pthread_barrier_wait (&b2
);
2209 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2211 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2216 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
2217 while (nanosleep (&ts
, &ts
) != 0)
2220 if (pthread_cancel (th
) != 0)
2222 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
2228 if (pthread_join (th
, &status
) != 0)
2230 printf ("join for '%s' failed\n", tests
[cnt
].name
);
2234 if (status
!= PTHREAD_CANCELED
)
2236 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
2241 if (pthread_barrier_destroy (&b2
) != 0)
2243 puts ("barrier_destroy failed");
2250 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
2256 printf ("cleanup handler called more than once for '%s'\n",
2262 printf ("in-time cancel test of '%s' successful\n", tests
[cnt
].name
);
2274 if (tempfname
!= NULL
)
2282 msgctl (tempmsg
, IPC_RMID
, NULL
);
2287 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
2289 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
2291 puts ("b2 init failed");
2295 /* Reset the counter for the cleanup handler. */
2299 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, (void *) 1l) != 0)
2301 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
2306 int r
= pthread_barrier_wait (&b2
);
2307 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2309 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2314 if (pthread_cancel (th
) != 0)
2316 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
2321 r
= pthread_barrier_wait (&b2
);
2322 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2324 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2330 if (pthread_join (th
, &status
) != 0)
2332 printf ("join for '%s' failed\n", tests
[cnt
].name
);
2336 if (status
!= PTHREAD_CANCELED
)
2338 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
2343 if (pthread_barrier_destroy (&b2
) != 0)
2345 puts ("barrier_destroy failed");
2352 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
2358 printf ("cleanup handler called more than once for '%s'\n",
2364 printf ("early cancel test of '%s' successful\n", tests
[cnt
].name
);
2376 if (tempfname
!= NULL
)
2384 msgctl (tempmsg
, IPC_RMID
, NULL
);
2393 #define TEST_FUNCTION do_test ()
2394 #include "../test-skeleton.c"