1 /* Copyright (C) 2002-2016 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
);
785 /* Just for fun block the cancellation signal. We need to use
786 __xpg_sigpause since otherwise we will get the BSD version. */
787 __xpg_sigpause (SIGCANCEL
);
792 pthread_cleanup_pop (0);
794 printf ("%s: sigpause returned\n", __FUNCTION__
);
801 tf_sigsuspend (void *arg
)
803 int r
= pthread_barrier_wait (&b2
);
804 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
806 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
812 r
= pthread_barrier_wait (&b2
);
813 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
815 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
820 pthread_cleanup_push (cl
, NULL
);
822 /* Just for fun block all signals. */
827 pthread_cleanup_pop (0);
829 printf ("%s: sigsuspend returned\n", __FUNCTION__
);
836 tf_sigwait (void *arg
)
838 int r
= pthread_barrier_wait (&b2
);
839 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
841 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
847 r
= pthread_barrier_wait (&b2
);
848 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
850 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
858 sigaddset (&mask
, SIGUSR1
);
859 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
861 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
866 pthread_cleanup_push (cl
, NULL
);
868 /* Wait for SIGUSR1. */
869 sigwait (&mask
, &sig
);
871 pthread_cleanup_pop (0);
873 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__
, sig
);
880 tf_sigwaitinfo (void *arg
)
882 int r
= pthread_barrier_wait (&b2
);
883 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
885 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
891 r
= pthread_barrier_wait (&b2
);
892 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
894 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
902 sigaddset (&mask
, SIGUSR1
);
903 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
905 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
910 pthread_cleanup_push (cl
, NULL
);
912 /* Wait for SIGUSR1. */
913 sigwaitinfo (&mask
, &info
);
915 pthread_cleanup_pop (0);
917 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__
,
925 tf_sigtimedwait (void *arg
)
927 int r
= pthread_barrier_wait (&b2
);
928 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
930 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
936 r
= pthread_barrier_wait (&b2
);
937 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
939 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
947 sigaddset (&mask
, SIGUSR1
);
948 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
950 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
954 /* Wait for SIGUSR1. */
956 struct timespec ts
= { .tv_sec
= 60, .tv_nsec
= 0 };
957 pthread_cleanup_push (cl
, NULL
);
959 sigtimedwait (&mask
, &info
, &ts
);
961 pthread_cleanup_pop (0);
963 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__
,
973 int r
= pthread_barrier_wait (&b2
);
974 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
976 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
982 r
= pthread_barrier_wait (&b2
);
983 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
985 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
990 pthread_cleanup_push (cl
, NULL
);
994 pthread_cleanup_pop (0);
996 printf ("%s: pause returned\n", __FUNCTION__
);
1003 tf_accept (void *arg
)
1005 struct sockaddr_un sun
;
1006 /* To test a non-blocking accept call we make the call file by using
1007 a datagrame socket. */
1008 int pf
= arg
== NULL
? SOCK_STREAM
: SOCK_DGRAM
;
1010 tempfd
= socket (AF_UNIX
, pf
, 0);
1013 printf ("%s: socket call failed\n", __FUNCTION__
);
1022 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1025 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-1-XXXXXX");
1026 if (mktemp (sun
.sun_path
) == NULL
)
1028 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1032 sun
.sun_family
= AF_UNIX
;
1034 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1035 offsetof (struct sockaddr_un
, sun_path
)
1036 + strlen (sun
.sun_path
) + 1) != 0);
1038 unlink (sun
.sun_path
);
1042 socklen_t len
= sizeof (sun
);
1044 int r
= pthread_barrier_wait (&b2
);
1045 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1047 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1053 r
= pthread_barrier_wait (&b2
);
1054 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1056 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1061 pthread_cleanup_push (cl
, NULL
);
1063 accept (tempfd
, (struct sockaddr
*) &sun
, &len
);
1065 pthread_cleanup_pop (0);
1067 printf ("%s: accept returned\n", __FUNCTION__
);
1076 struct sockaddr_un sun
;
1078 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1081 printf ("%s: first socket call failed\n", __FUNCTION__
);
1090 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1093 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1094 if (mktemp (sun
.sun_path
) == NULL
)
1096 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1100 sun
.sun_family
= AF_UNIX
;
1102 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1103 offsetof (struct sockaddr_un
, sun_path
)
1104 + strlen (sun
.sun_path
) + 1) != 0);
1108 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1111 printf ("%s: second socket call failed\n", __FUNCTION__
);
1115 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1117 printf ("%s: connect failed\n", __FUNCTION__
);
1121 unlink (sun
.sun_path
);
1123 int r
= pthread_barrier_wait (&b2
);
1124 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1126 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1132 r
= pthread_barrier_wait (&b2
);
1133 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1135 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1140 pthread_cleanup_push (cl
, NULL
);
1142 /* Very large block, so that the send call blocks. */
1145 send (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0);
1147 pthread_cleanup_pop (0);
1149 printf ("%s: send returned\n", __FUNCTION__
);
1158 struct sockaddr_un sun
;
1160 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1163 printf ("%s: first socket call failed\n", __FUNCTION__
);
1172 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1175 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-3-XXXXXX");
1176 if (mktemp (sun
.sun_path
) == NULL
)
1178 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1182 sun
.sun_family
= AF_UNIX
;
1184 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1185 offsetof (struct sockaddr_un
, sun_path
)
1186 + strlen (sun
.sun_path
) + 1) != 0);
1190 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1193 printf ("%s: second socket call failed\n", __FUNCTION__
);
1197 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1199 printf ("%s: connect failed\n", __FUNCTION__
);
1203 unlink (sun
.sun_path
);
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
);
1226 recv (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0);
1228 pthread_cleanup_pop (0);
1230 printf ("%s: recv returned\n", __FUNCTION__
);
1237 tf_recvfrom (void *arg
)
1239 struct sockaddr_un sun
;
1241 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1244 printf ("%s: first socket call failed\n", __FUNCTION__
);
1253 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1256 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-4-XXXXXX");
1257 if (mktemp (sun
.sun_path
) == NULL
)
1259 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1263 sun
.sun_family
= AF_UNIX
;
1265 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1266 offsetof (struct sockaddr_un
, sun_path
)
1267 + strlen (sun
.sun_path
) + 1) != 0);
1269 tempfname
= strdup (sun
.sun_path
);
1271 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1274 printf ("%s: second socket call failed\n", __FUNCTION__
);
1278 int r
= pthread_barrier_wait (&b2
);
1279 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1281 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1287 r
= pthread_barrier_wait (&b2
);
1288 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1290 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1295 pthread_cleanup_push (cl
, NULL
);
1298 socklen_t len
= sizeof (sun
);
1300 recvfrom (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0,
1301 (struct sockaddr
*) &sun
, &len
);
1303 pthread_cleanup_pop (0);
1305 printf ("%s: recvfrom returned\n", __FUNCTION__
);
1312 tf_recvmsg (void *arg
)
1314 struct sockaddr_un sun
;
1316 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1319 printf ("%s: first socket call failed\n", __FUNCTION__
);
1328 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1331 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-5-XXXXXX");
1332 if (mktemp (sun
.sun_path
) == NULL
)
1334 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1338 sun
.sun_family
= AF_UNIX
;
1340 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1341 offsetof (struct sockaddr_un
, sun_path
)
1342 + strlen (sun
.sun_path
) + 1) != 0);
1344 tempfname
= strdup (sun
.sun_path
);
1346 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1349 printf ("%s: second socket call failed\n", __FUNCTION__
);
1353 int r
= pthread_barrier_wait (&b2
);
1354 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1356 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1362 r
= pthread_barrier_wait (&b2
);
1363 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1365 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1370 pthread_cleanup_push (cl
, NULL
);
1373 struct iovec iov
[1];
1374 iov
[0].iov_base
= mem
;
1375 iov
[0].iov_len
= arg
== NULL
? sizeof (mem
) : 0;
1379 m
.msg_namelen
= sizeof (sun
);
1382 m
.msg_control
= NULL
;
1383 m
.msg_controllen
= 0;
1385 recvmsg (tempfd2
, &m
, 0);
1387 pthread_cleanup_pop (0);
1389 printf ("%s: recvmsg returned\n", __FUNCTION__
);
1399 // XXX If somebody can provide a portable test case in which open()
1400 // blocks we can enable this test to run in both rounds.
1403 int r
= pthread_barrier_wait (&b2
);
1404 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1406 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1410 r
= pthread_barrier_wait (&b2
);
1411 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1413 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1417 pthread_cleanup_push (cl
, NULL
);
1419 open ("Makefile", O_RDONLY
);
1421 pthread_cleanup_pop (0);
1423 printf ("%s: open returned\n", __FUNCTION__
);
1430 tf_close (void *arg
)
1433 // XXX If somebody can provide a portable test case in which close()
1434 // blocks we can enable this test to run in both rounds.
1437 char fname
[] = "/tmp/tst-cancel-fd-XXXXXX";
1438 tempfd
= mkstemp (fname
);
1441 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1446 int r
= pthread_barrier_wait (&b2
);
1447 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1449 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1453 r
= pthread_barrier_wait (&b2
);
1454 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1456 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1460 pthread_cleanup_push (cl
, NULL
);
1464 pthread_cleanup_pop (0);
1466 printf ("%s: close returned\n", __FUNCTION__
);
1473 tf_pread (void *arg
)
1476 // XXX If somebody can provide a portable test case in which pread()
1477 // blocks we can enable this test to run in both rounds.
1480 tempfd
= open ("Makefile", O_RDONLY
);
1483 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1487 int r
= pthread_barrier_wait (&b2
);
1488 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1490 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1494 r
= pthread_barrier_wait (&b2
);
1495 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1497 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1501 pthread_cleanup_push (cl
, NULL
);
1504 pread (tempfd
, mem
, sizeof (mem
), 0);
1506 pthread_cleanup_pop (0);
1508 printf ("%s: pread returned\n", __FUNCTION__
);
1515 tf_pwrite (void *arg
)
1518 // XXX If somebody can provide a portable test case in which pwrite()
1519 // blocks we can enable this test to run in both rounds.
1522 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1523 tempfd
= mkstemp (fname
);
1526 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1531 int r
= pthread_barrier_wait (&b2
);
1532 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1534 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1538 r
= pthread_barrier_wait (&b2
);
1539 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1541 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1545 pthread_cleanup_push (cl
, NULL
);
1548 pwrite (tempfd
, mem
, sizeof (mem
), 0);
1550 pthread_cleanup_pop (0);
1552 printf ("%s: pwrite returned\n", __FUNCTION__
);
1558 tf_preadv (void *arg
)
1564 /* XXX If somebody can provide a portable test case in which preadv
1565 blocks we can enable this test to run in both rounds. */
1568 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1569 tempfd
= fd
= mkstemp (fname
);
1571 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1574 r
= pthread_barrier_wait (&b2
);
1575 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1577 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1581 r
= pthread_barrier_wait (&b2
);
1582 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1584 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1589 pthread_cleanup_push (cl
, NULL
);
1592 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1593 s
= preadv (fd
, iov
, 1, 0);
1595 pthread_cleanup_pop (0);
1597 printf ("%s: preadv returns with %zd\n", __FUNCTION__
, s
);
1603 tf_fsync (void *arg
)
1606 // XXX If somebody can provide a portable test case in which fsync()
1607 // blocks we can enable this test to run in both rounds.
1610 tempfd
= open ("Makefile", O_RDONLY
);
1613 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1617 int r
= pthread_barrier_wait (&b2
);
1618 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1620 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1624 r
= pthread_barrier_wait (&b2
);
1625 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1627 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1631 pthread_cleanup_push (cl
, NULL
);
1635 pthread_cleanup_pop (0);
1637 printf ("%s: fsync returned\n", __FUNCTION__
);
1644 tf_fdatasync (void *arg
)
1647 // XXX If somebody can provide a portable test case in which fdatasync()
1648 // blocks we can enable this test to run in both rounds.
1651 tempfd
= open ("Makefile", O_RDONLY
);
1654 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1658 int r
= pthread_barrier_wait (&b2
);
1659 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1661 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1665 r
= pthread_barrier_wait (&b2
);
1666 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1668 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1672 pthread_cleanup_push (cl
, NULL
);
1676 pthread_cleanup_pop (0);
1678 printf ("%s: fdatasync returned\n", __FUNCTION__
);
1685 tf_msync (void *arg
)
1688 // XXX If somebody can provide a portable test case in which msync()
1689 // blocks we can enable this test to run in both rounds.
1692 tempfd
= open ("Makefile", O_RDONLY
);
1695 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1698 void *p
= mmap (NULL
, 10, PROT_READ
, MAP_SHARED
, tempfd
, 0);
1699 if (p
== MAP_FAILED
)
1701 printf ("%s: mmap failed\n", __FUNCTION__
);
1705 int r
= pthread_barrier_wait (&b2
);
1706 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1708 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1712 r
= pthread_barrier_wait (&b2
);
1713 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1715 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1719 pthread_cleanup_push (cl
, NULL
);
1723 pthread_cleanup_pop (0);
1725 printf ("%s: msync returned\n", __FUNCTION__
);
1732 tf_sendto (void *arg
)
1735 // XXX If somebody can provide a portable test case in which sendto()
1736 // blocks we can enable this test to run in both rounds.
1739 struct sockaddr_un sun
;
1741 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1744 printf ("%s: first socket call failed\n", __FUNCTION__
);
1753 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1756 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-6-XXXXXX");
1757 if (mktemp (sun
.sun_path
) == NULL
)
1759 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1763 sun
.sun_family
= AF_UNIX
;
1765 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1766 offsetof (struct sockaddr_un
, sun_path
)
1767 + strlen (sun
.sun_path
) + 1) != 0);
1768 tempfname
= strdup (sun
.sun_path
);
1770 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1773 printf ("%s: second socket call failed\n", __FUNCTION__
);
1777 int r
= pthread_barrier_wait (&b2
);
1778 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1780 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1784 r
= pthread_barrier_wait (&b2
);
1785 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1787 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1791 pthread_cleanup_push (cl
, NULL
);
1795 sendto (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0,
1796 (struct sockaddr
*) &sun
,
1797 offsetof (struct sockaddr_un
, sun_path
) + strlen (sun
.sun_path
) + 1);
1799 pthread_cleanup_pop (0);
1801 printf ("%s: sendto returned\n", __FUNCTION__
);
1808 tf_sendmsg (void *arg
)
1811 // XXX If somebody can provide a portable test case in which sendmsg()
1812 // blocks we can enable this test to run in both rounds.
1815 struct sockaddr_un sun
;
1817 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1820 printf ("%s: first socket call failed\n", __FUNCTION__
);
1829 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1832 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-7-XXXXXX");
1833 if (mktemp (sun
.sun_path
) == NULL
)
1835 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1839 sun
.sun_family
= AF_UNIX
;
1841 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1842 offsetof (struct sockaddr_un
, sun_path
)
1843 + strlen (sun
.sun_path
) + 1) != 0);
1844 tempfname
= strdup (sun
.sun_path
);
1846 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1849 printf ("%s: second socket call failed\n", __FUNCTION__
);
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
);
1870 struct iovec iov
[1];
1871 iov
[0].iov_base
= mem
;
1876 m
.msg_namelen
= (offsetof (struct sockaddr_un
, sun_path
)
1877 + strlen (sun
.sun_path
) + 1);
1880 m
.msg_control
= NULL
;
1881 m
.msg_controllen
= 0;
1883 sendmsg (tempfd2
, &m
, 0);
1885 pthread_cleanup_pop (0);
1887 printf ("%s: sendmsg returned\n", __FUNCTION__
);
1894 tf_creat (void *arg
)
1897 // XXX If somebody can provide a portable test case in which sendmsg()
1898 // blocks we can enable this test to run in both rounds.
1901 int r
= pthread_barrier_wait (&b2
);
1902 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1904 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1908 r
= pthread_barrier_wait (&b2
);
1909 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1911 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1915 pthread_cleanup_push (cl
, NULL
);
1917 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1919 pthread_cleanup_pop (0);
1921 printf ("%s: creat returned\n", __FUNCTION__
);
1928 tf_connect (void *arg
)
1931 // XXX If somebody can provide a portable test case in which connect()
1932 // blocks we can enable this test to run in both rounds.
1935 struct sockaddr_un sun
;
1937 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1940 printf ("%s: first socket call failed\n", __FUNCTION__
);
1949 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1952 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1953 if (mktemp (sun
.sun_path
) == NULL
)
1955 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1959 sun
.sun_family
= AF_UNIX
;
1961 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1962 offsetof (struct sockaddr_un
, sun_path
)
1963 + strlen (sun
.sun_path
) + 1) != 0);
1964 tempfname
= strdup (sun
.sun_path
);
1968 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1971 printf ("%s: second socket call failed\n", __FUNCTION__
);
1975 int r
= pthread_barrier_wait (&b2
);
1976 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1978 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1984 r
= pthread_barrier_wait (&b2
);
1985 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1987 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1992 pthread_cleanup_push (cl
, NULL
);
1994 connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
));
1996 pthread_cleanup_pop (0);
1998 printf ("%s: connect returned\n", __FUNCTION__
);
2005 tf_tcdrain (void *arg
)
2008 // XXX If somebody can provide a portable test case in which tcdrain()
2009 // blocks we can enable this test to run in both rounds.
2012 int r
= pthread_barrier_wait (&b2
);
2013 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2015 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2021 r
= pthread_barrier_wait (&b2
);
2022 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2024 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
2029 pthread_cleanup_push (cl
, NULL
);
2031 /* Regardless of stderr being a terminal, the tcdrain call should be
2033 tcdrain (STDERR_FILENO
);
2035 pthread_cleanup_pop (0);
2037 printf ("%s: tcdrain returned\n", __FUNCTION__
);
2044 tf_msgrcv (void *arg
)
2046 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
2049 printf ("%s: msgget failed: %s\n", __FUNCTION__
, strerror (errno
));
2053 int r
= pthread_barrier_wait (&b2
);
2054 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2056 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2062 r
= pthread_barrier_wait (&b2
);
2063 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2065 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
2072 pthread_cleanup_push (cl
, NULL
);
2080 /* We need a positive random number. */
2082 randnr
= random () % 64000;
2083 while (randnr
<= 0);
2087 s
= msgrcv (tempmsg
, (struct msgbuf
*) &m
, 10, randnr
, 0);
2089 while (errno
== EIDRM
|| errno
== EINTR
);
2091 pthread_cleanup_pop (0);
2093 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__
, s
);
2095 msgctl (tempmsg
, IPC_RMID
, NULL
);
2102 tf_msgsnd (void *arg
)
2105 // XXX If somebody can provide a portable test case in which msgsnd()
2106 // blocks we can enable this test to run in both rounds.
2109 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
2112 printf ("%s: msgget failed: %s\n", __FUNCTION__
, strerror (errno
));
2116 int r
= pthread_barrier_wait (&b2
);
2117 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2119 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2123 r
= pthread_barrier_wait (&b2
);
2124 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2126 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
2130 pthread_cleanup_push (cl
, NULL
);
2137 /* We need a positive random number. */
2139 m
.type
= random () % 64000;
2140 while (m
.type
<= 0);
2141 msgsnd (tempmsg
, (struct msgbuf
*) &m
, sizeof (m
.mem
), 0);
2143 pthread_cleanup_pop (0);
2145 printf ("%s: msgsnd returned\n", __FUNCTION__
);
2147 msgctl (tempmsg
, IPC_RMID
, NULL
);
2156 void *(*tf
) (void *);
2161 #define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early }
2162 ADD_TEST (read
, 2, 0),
2163 ADD_TEST (readv
, 2, 0),
2164 ADD_TEST (select
, 2, 0),
2165 ADD_TEST (pselect
, 2, 0),
2166 ADD_TEST (poll
, 2, 0),
2167 ADD_TEST (ppoll
, 2, 0),
2168 ADD_TEST (write
, 2, 0),
2169 ADD_TEST (writev
, 2, 0),
2170 ADD_TEST (sleep
, 2, 0),
2171 ADD_TEST (usleep
, 2, 0),
2172 ADD_TEST (nanosleep
, 2, 0),
2173 ADD_TEST (wait
, 2, 0),
2174 ADD_TEST (waitid
, 2, 0),
2175 ADD_TEST (waitpid
, 2, 0),
2176 ADD_TEST (sigpause
, 2, 0),
2177 ADD_TEST (sigsuspend
, 2, 0),
2178 ADD_TEST (sigwait
, 2, 0),
2179 ADD_TEST (sigwaitinfo
, 2, 0),
2180 ADD_TEST (sigtimedwait
, 2, 0),
2181 ADD_TEST (pause
, 2, 0),
2182 ADD_TEST (accept
, 2, 0),
2183 ADD_TEST (send
, 2, 0),
2184 ADD_TEST (recv
, 2, 0),
2185 ADD_TEST (recvfrom
, 2, 0),
2186 ADD_TEST (recvmsg
, 2, 0),
2187 ADD_TEST (preadv
, 2, 1),
2188 ADD_TEST (open
, 2, 1),
2189 ADD_TEST (close
, 2, 1),
2190 ADD_TEST (pread
, 2, 1),
2191 ADD_TEST (pwrite
, 2, 1),
2192 ADD_TEST (fsync
, 2, 1),
2193 ADD_TEST (fdatasync
, 2, 1),
2194 ADD_TEST (msync
, 2, 1),
2195 ADD_TEST (sendto
, 2, 1),
2196 ADD_TEST (sendmsg
, 2, 1),
2197 ADD_TEST (creat
, 2, 1),
2198 ADD_TEST (connect
, 2, 1),
2199 ADD_TEST (tcdrain
, 2, 1),
2200 ADD_TEST (msgrcv
, 2, 0),
2201 ADD_TEST (msgsnd
, 2, 1),
2203 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2212 if (socketpair (AF_UNIX
, SOCK_STREAM
, PF_UNIX
, fds
) != 0)
2214 perror ("socketpair");
2220 setsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, sizeof(val
));
2221 if (getsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, &len
) < 0)
2223 perror ("getsockopt");
2226 if (val
>= WRITE_BUFFER_SIZE
)
2228 puts ("minimum write buffer size too large");
2231 setsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, sizeof(val
));
2235 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
2237 if (tests
[cnt
].only_early
)
2240 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
2242 puts ("b2 init failed");
2246 /* Reset the counter for the cleanup handler. */
2250 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, NULL
) != 0)
2252 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
2257 int r
= pthread_barrier_wait (&b2
);
2258 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2260 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2265 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
2266 while (nanosleep (&ts
, &ts
) != 0)
2269 if (pthread_cancel (th
) != 0)
2271 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
2277 if (pthread_join (th
, &status
) != 0)
2279 printf ("join for '%s' failed\n", tests
[cnt
].name
);
2283 if (status
!= PTHREAD_CANCELED
)
2285 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
2290 if (pthread_barrier_destroy (&b2
) != 0)
2292 puts ("barrier_destroy failed");
2299 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
2305 printf ("cleanup handler called more than once for '%s'\n",
2311 printf ("in-time cancel test of '%s' successful\n", tests
[cnt
].name
);
2323 if (tempfname
!= NULL
)
2331 msgctl (tempmsg
, IPC_RMID
, NULL
);
2336 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
2338 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
2340 puts ("b2 init failed");
2344 /* Reset the counter for the cleanup handler. */
2348 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, (void *) 1l) != 0)
2350 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
2355 int r
= pthread_barrier_wait (&b2
);
2356 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2358 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2363 if (pthread_cancel (th
) != 0)
2365 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
2370 r
= pthread_barrier_wait (&b2
);
2371 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2373 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2379 if (pthread_join (th
, &status
) != 0)
2381 printf ("join for '%s' failed\n", tests
[cnt
].name
);
2385 if (status
!= PTHREAD_CANCELED
)
2387 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
2392 if (pthread_barrier_destroy (&b2
) != 0)
2394 puts ("barrier_destroy failed");
2401 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
2407 printf ("cleanup handler called more than once for '%s'\n",
2413 printf ("early cancel test of '%s' successful\n", tests
[cnt
].name
);
2425 if (tempfname
!= NULL
)
2433 msgctl (tempmsg
, IPC_RMID
, NULL
);
2442 #define TEST_FUNCTION do_test ()
2443 #include "../test-skeleton.c"