1 /* Copyright (C) 2002, 2003, 2004, 2006, 2007 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 #define WRITE_BUFFER_SIZE 4096
88 /* Cleanup handling test. */
109 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
110 tempfd
= fd
= mkstemp (fname
);
112 printf ("%s: mkstemp failed\n", __FUNCTION__
);
115 r
= pthread_barrier_wait (&b2
);
116 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
118 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
123 r
= pthread_barrier_wait (&b2
);
124 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
126 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
131 pthread_cleanup_push (cl
, NULL
);
134 s
= read (fd
, buf
, sizeof (buf
));
136 pthread_cleanup_pop (0);
138 printf ("%s: read returns with %zd\n", __FUNCTION__
, s
);
154 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
155 tempfd
= fd
= mkstemp (fname
);
157 printf ("%s: mkstemp failed\n", __FUNCTION__
);
160 r
= pthread_barrier_wait (&b2
);
161 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
163 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
168 r
= pthread_barrier_wait (&b2
);
169 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
171 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
176 pthread_cleanup_push (cl
, NULL
);
179 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
180 s
= readv (fd
, iov
, 1);
182 pthread_cleanup_pop (0);
184 printf ("%s: readv returns with %zd\n", __FUNCTION__
, s
);
200 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
201 tempfd
= fd
= mkstemp (fname
);
203 printf ("%s: mkstemp failed\n", __FUNCTION__
);
206 r
= pthread_barrier_wait (&b2
);
207 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
209 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
214 r
= pthread_barrier_wait (&b2
);
215 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
217 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
222 pthread_cleanup_push (cl
, NULL
);
224 char buf
[WRITE_BUFFER_SIZE
];
225 memset (buf
, '\0', sizeof (buf
));
226 s
= write (fd
, buf
, sizeof (buf
));
228 pthread_cleanup_pop (0);
230 printf ("%s: write returns with %zd\n", __FUNCTION__
, s
);
237 tf_writev (void *arg
)
246 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
247 tempfd
= fd
= mkstemp (fname
);
249 printf ("%s: mkstemp failed\n", __FUNCTION__
);
252 r
= pthread_barrier_wait (&b2
);
253 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
255 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
260 r
= pthread_barrier_wait (&b2
);
261 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
263 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
268 pthread_cleanup_push (cl
, NULL
);
270 char buf
[WRITE_BUFFER_SIZE
];
271 memset (buf
, '\0', sizeof (buf
));
272 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
273 s
= writev (fd
, iov
, 1);
275 pthread_cleanup_pop (0);
277 printf ("%s: writev returns with %zd\n", __FUNCTION__
, s
);
286 int r
= pthread_barrier_wait (&b2
);
287 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
289 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
295 r
= pthread_barrier_wait (&b2
);
296 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
298 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
303 pthread_cleanup_push (cl
, NULL
);
305 sleep (arg
== NULL
? 1000000 : 0);
307 pthread_cleanup_pop (0);
309 printf ("%s: sleep returns\n", __FUNCTION__
);
316 tf_usleep (void *arg
)
318 int r
= pthread_barrier_wait (&b2
);
319 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
321 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
327 r
= pthread_barrier_wait (&b2
);
328 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
330 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
335 pthread_cleanup_push (cl
, NULL
);
337 usleep (arg
== NULL
? (useconds_t
) ULONG_MAX
: 0);
339 pthread_cleanup_pop (0);
341 printf ("%s: usleep returns\n", __FUNCTION__
);
348 tf_nanosleep (void *arg
)
350 int r
= pthread_barrier_wait (&b2
);
351 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
353 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
359 r
= pthread_barrier_wait (&b2
);
360 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
362 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
367 pthread_cleanup_push (cl
, NULL
);
369 struct timespec ts
= { .tv_sec
= arg
== NULL
? 10000000 : 0, .tv_nsec
= 0 };
370 TEMP_FAILURE_RETRY (nanosleep (&ts
, &ts
));
372 pthread_cleanup_pop (0);
374 printf ("%s: nanosleep returns\n", __FUNCTION__
);
381 tf_select (void *arg
)
390 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
391 tempfd
= fd
= mkstemp (fname
);
393 printf ("%s: mkstemp failed\n", __FUNCTION__
);
396 r
= pthread_barrier_wait (&b2
);
397 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
399 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
404 r
= pthread_barrier_wait (&b2
);
405 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
407 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
416 pthread_cleanup_push (cl
, NULL
);
418 s
= select (fd
+ 1, &rfs
, NULL
, NULL
, NULL
);
420 pthread_cleanup_pop (0);
422 printf ("%s: select returns with %d (%s)\n", __FUNCTION__
, s
,
430 tf_pselect (void *arg
)
439 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
440 tempfd
= fd
= mkstemp (fname
);
442 printf ("%s: mkstemp failed\n", __FUNCTION__
);
445 r
= pthread_barrier_wait (&b2
);
446 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
448 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
453 r
= pthread_barrier_wait (&b2
);
454 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
456 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
465 pthread_cleanup_push (cl
, NULL
);
467 s
= pselect (fd
+ 1, &rfs
, NULL
, NULL
, NULL
, NULL
);
469 pthread_cleanup_pop (0);
471 printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__
, s
,
488 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
489 tempfd
= fd
= mkstemp (fname
);
491 printf ("%s: mkstemp failed\n", __FUNCTION__
);
494 r
= pthread_barrier_wait (&b2
);
495 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
497 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
502 r
= pthread_barrier_wait (&b2
);
503 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
505 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
509 struct pollfd rfs
[1] = { [0] = { .fd
= fd
, .events
= POLLIN
} };
512 pthread_cleanup_push (cl
, NULL
);
514 s
= poll (rfs
, 1, -1);
516 pthread_cleanup_pop (0);
518 printf ("%s: poll returns with %d (%s)\n", __FUNCTION__
, s
,
535 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
536 tempfd
= fd
= mkstemp (fname
);
538 printf ("%s: mkstemp failed\n", __FUNCTION__
);
541 r
= pthread_barrier_wait (&b2
);
542 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
544 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
549 r
= pthread_barrier_wait (&b2
);
550 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
552 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
556 struct pollfd rfs
[1] = { [0] = { .fd
= fd
, .events
= POLLIN
} };
559 pthread_cleanup_push (cl
, NULL
);
561 s
= ppoll (rfs
, 1, NULL
, NULL
);
563 pthread_cleanup_pop (0);
565 printf ("%s: ppoll returns with %d (%s)\n", __FUNCTION__
, s
,
578 puts ("fork failed");
584 /* Make the program disappear after a while. */
593 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
594 while (nanosleep (&ts
, &ts
) != 0)
597 r
= pthread_barrier_wait (&b2
);
598 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
600 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
605 r
= pthread_barrier_wait (&b2
);
606 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
608 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
613 pthread_cleanup_push (cl
, NULL
);
617 pthread_cleanup_pop (0);
619 printf ("%s: wait returns with %d (%s)\n", __FUNCTION__
, s
,
627 tf_waitpid (void *arg
)
633 puts ("fork failed");
639 /* Make the program disappear after a while. */
648 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
649 while (nanosleep (&ts
, &ts
) != 0)
652 r
= pthread_barrier_wait (&b2
);
653 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
655 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
660 r
= pthread_barrier_wait (&b2
);
661 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
663 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
668 pthread_cleanup_push (cl
, NULL
);
670 s
= waitpid (-1, NULL
, 0);
672 pthread_cleanup_pop (0);
674 printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__
, s
,
682 tf_waitid (void *arg
)
687 puts ("fork failed");
693 /* Make the program disappear after a while. */
702 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
703 while (nanosleep (&ts
, &ts
) != 0)
706 r
= pthread_barrier_wait (&b2
);
707 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
709 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
714 r
= pthread_barrier_wait (&b2
);
715 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
717 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
722 pthread_cleanup_push (cl
, NULL
);
728 s
= waitid (P_PID
, pid
, &si
, WEXITED
);
730 pthread_cleanup_pop (0);
732 printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__
, s
,
740 tf_sigpause (void *arg
)
742 int r
= pthread_barrier_wait (&b2
);
743 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
745 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
751 r
= pthread_barrier_wait (&b2
);
752 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
754 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
759 pthread_cleanup_push (cl
, NULL
);
761 /* Just for fun block the cancellation signal. We need to use
762 __xpg_sigpause since otherwise we will get the BSD version. */
763 __xpg_sigpause (SIGCANCEL
);
765 pthread_cleanup_pop (0);
767 printf ("%s: sigpause returned\n", __FUNCTION__
);
774 tf_sigsuspend (void *arg
)
776 int r
= pthread_barrier_wait (&b2
);
777 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
779 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
785 r
= pthread_barrier_wait (&b2
);
786 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
788 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
793 pthread_cleanup_push (cl
, NULL
);
795 /* Just for fun block all signals. */
800 pthread_cleanup_pop (0);
802 printf ("%s: sigsuspend returned\n", __FUNCTION__
);
809 tf_sigwait (void *arg
)
811 int r
= pthread_barrier_wait (&b2
);
812 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
814 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
820 r
= pthread_barrier_wait (&b2
);
821 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
823 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
831 sigaddset (&mask
, SIGUSR1
);
832 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
834 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
839 pthread_cleanup_push (cl
, NULL
);
841 /* Wait for SIGUSR1. */
842 sigwait (&mask
, &sig
);
844 pthread_cleanup_pop (0);
846 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__
, sig
);
853 tf_sigwaitinfo (void *arg
)
855 int r
= pthread_barrier_wait (&b2
);
856 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
858 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
864 r
= pthread_barrier_wait (&b2
);
865 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
867 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
875 sigaddset (&mask
, SIGUSR1
);
876 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
878 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
883 pthread_cleanup_push (cl
, NULL
);
885 /* Wait for SIGUSR1. */
886 sigwaitinfo (&mask
, &info
);
888 pthread_cleanup_pop (0);
890 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__
,
898 tf_sigtimedwait (void *arg
)
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__
);
920 sigaddset (&mask
, SIGUSR1
);
921 if (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) != 0)
923 printf ("%s: pthread_sigmask failed\n", __FUNCTION__
);
927 /* Wait for SIGUSR1. */
929 struct timespec ts
= { .tv_sec
= 60, .tv_nsec
= 0 };
930 pthread_cleanup_push (cl
, NULL
);
932 sigtimedwait (&mask
, &info
, &ts
);
934 pthread_cleanup_pop (0);
936 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__
,
946 int r
= pthread_barrier_wait (&b2
);
947 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
949 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
955 r
= pthread_barrier_wait (&b2
);
956 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
958 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
963 pthread_cleanup_push (cl
, NULL
);
967 pthread_cleanup_pop (0);
969 printf ("%s: pause returned\n", __FUNCTION__
);
976 tf_accept (void *arg
)
978 struct sockaddr_un sun
;
979 /* To test a non-blocking accept call we make the call file by using
980 a datagrame socket. */
981 int pf
= arg
== NULL
? SOCK_STREAM
: SOCK_DGRAM
;
983 tempfd
= socket (AF_UNIX
, pf
, 0);
986 printf ("%s: socket call failed\n", __FUNCTION__
);
995 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
998 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-1-XXXXXX");
999 if (mktemp (sun
.sun_path
) == NULL
)
1001 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1005 sun
.sun_family
= AF_UNIX
;
1007 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1008 offsetof (struct sockaddr_un
, sun_path
)
1009 + strlen (sun
.sun_path
) + 1) != 0);
1011 unlink (sun
.sun_path
);
1015 socklen_t len
= sizeof (sun
);
1017 int r
= pthread_barrier_wait (&b2
);
1018 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1020 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1026 r
= pthread_barrier_wait (&b2
);
1027 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1029 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1034 pthread_cleanup_push (cl
, NULL
);
1036 accept (tempfd
, (struct sockaddr
*) &sun
, &len
);
1038 pthread_cleanup_pop (0);
1040 printf ("%s: accept returned\n", __FUNCTION__
);
1049 struct sockaddr_un sun
;
1051 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1054 printf ("%s: first socket call failed\n", __FUNCTION__
);
1063 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1066 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1067 if (mktemp (sun
.sun_path
) == NULL
)
1069 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1073 sun
.sun_family
= AF_UNIX
;
1075 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1076 offsetof (struct sockaddr_un
, sun_path
)
1077 + strlen (sun
.sun_path
) + 1) != 0);
1081 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1084 printf ("%s: second socket call failed\n", __FUNCTION__
);
1088 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1090 printf ("%s: connect failed\n", __FUNCTION__
);
1094 unlink (sun
.sun_path
);
1096 int r
= pthread_barrier_wait (&b2
);
1097 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1099 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1105 r
= pthread_barrier_wait (&b2
);
1106 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1108 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1113 pthread_cleanup_push (cl
, NULL
);
1115 /* Very large block, so that the send call blocks. */
1118 send (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0);
1120 pthread_cleanup_pop (0);
1122 printf ("%s: send returned\n", __FUNCTION__
);
1131 struct sockaddr_un sun
;
1133 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1136 printf ("%s: first socket call failed\n", __FUNCTION__
);
1145 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1148 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-3-XXXXXX");
1149 if (mktemp (sun
.sun_path
) == NULL
)
1151 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1155 sun
.sun_family
= AF_UNIX
;
1157 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1158 offsetof (struct sockaddr_un
, sun_path
)
1159 + strlen (sun
.sun_path
) + 1) != 0);
1163 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1166 printf ("%s: second socket call failed\n", __FUNCTION__
);
1170 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1172 printf ("%s: connect failed\n", __FUNCTION__
);
1176 unlink (sun
.sun_path
);
1178 int r
= pthread_barrier_wait (&b2
);
1179 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1181 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1187 r
= pthread_barrier_wait (&b2
);
1188 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1190 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1195 pthread_cleanup_push (cl
, NULL
);
1199 recv (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0);
1201 pthread_cleanup_pop (0);
1203 printf ("%s: recv returned\n", __FUNCTION__
);
1210 tf_recvfrom (void *arg
)
1212 struct sockaddr_un sun
;
1214 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1217 printf ("%s: first socket call failed\n", __FUNCTION__
);
1226 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1229 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-4-XXXXXX");
1230 if (mktemp (sun
.sun_path
) == NULL
)
1232 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1236 sun
.sun_family
= AF_UNIX
;
1238 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1239 offsetof (struct sockaddr_un
, sun_path
)
1240 + strlen (sun
.sun_path
) + 1) != 0);
1242 tempfname
= strdup (sun
.sun_path
);
1244 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1247 printf ("%s: second socket call failed\n", __FUNCTION__
);
1251 int r
= pthread_barrier_wait (&b2
);
1252 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1254 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1260 r
= pthread_barrier_wait (&b2
);
1261 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1263 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1268 pthread_cleanup_push (cl
, NULL
);
1271 socklen_t len
= sizeof (sun
);
1273 recvfrom (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0,
1274 (struct sockaddr
*) &sun
, &len
);
1276 pthread_cleanup_pop (0);
1278 printf ("%s: recvfrom returned\n", __FUNCTION__
);
1285 tf_recvmsg (void *arg
)
1287 struct sockaddr_un sun
;
1289 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1292 printf ("%s: first socket call failed\n", __FUNCTION__
);
1301 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1304 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-5-XXXXXX");
1305 if (mktemp (sun
.sun_path
) == NULL
)
1307 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1311 sun
.sun_family
= AF_UNIX
;
1313 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1314 offsetof (struct sockaddr_un
, sun_path
)
1315 + strlen (sun
.sun_path
) + 1) != 0);
1317 tempfname
= strdup (sun
.sun_path
);
1319 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1322 printf ("%s: second socket call failed\n", __FUNCTION__
);
1326 int r
= pthread_barrier_wait (&b2
);
1327 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1329 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1335 r
= pthread_barrier_wait (&b2
);
1336 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1338 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1343 pthread_cleanup_push (cl
, NULL
);
1346 struct iovec iov
[1];
1347 iov
[0].iov_base
= mem
;
1348 iov
[0].iov_len
= arg
== NULL
? sizeof (mem
) : 0;
1352 m
.msg_namelen
= sizeof (sun
);
1355 m
.msg_control
= NULL
;
1356 m
.msg_controllen
= 0;
1358 recvmsg (tempfd2
, &m
, 0);
1360 pthread_cleanup_pop (0);
1362 printf ("%s: recvmsg returned\n", __FUNCTION__
);
1372 // XXX If somebody can provide a portable test case in which open()
1373 // blocks we can enable this test to run in both rounds.
1376 int r
= pthread_barrier_wait (&b2
);
1377 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1379 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1383 r
= pthread_barrier_wait (&b2
);
1384 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1386 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1390 pthread_cleanup_push (cl
, NULL
);
1392 open ("Makefile", O_RDONLY
);
1394 pthread_cleanup_pop (0);
1396 printf ("%s: open returned\n", __FUNCTION__
);
1403 tf_close (void *arg
)
1406 // XXX If somebody can provide a portable test case in which close()
1407 // blocks we can enable this test to run in both rounds.
1410 char fname
[] = "/tmp/tst-cancel-fd-XXXXXX";
1411 tempfd
= mkstemp (fname
);
1414 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1419 int r
= pthread_barrier_wait (&b2
);
1420 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1422 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1426 r
= pthread_barrier_wait (&b2
);
1427 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1429 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1433 pthread_cleanup_push (cl
, NULL
);
1437 pthread_cleanup_pop (0);
1439 printf ("%s: close returned\n", __FUNCTION__
);
1446 tf_pread (void *arg
)
1449 // XXX If somebody can provide a portable test case in which pread()
1450 // blocks we can enable this test to run in both rounds.
1453 tempfd
= open ("Makefile", O_RDONLY
);
1456 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1460 int r
= pthread_barrier_wait (&b2
);
1461 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1463 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1467 r
= pthread_barrier_wait (&b2
);
1468 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1470 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1474 pthread_cleanup_push (cl
, NULL
);
1477 pread (tempfd
, mem
, sizeof (mem
), 0);
1479 pthread_cleanup_pop (0);
1481 printf ("%s: pread returned\n", __FUNCTION__
);
1488 tf_pwrite (void *arg
)
1491 // XXX If somebody can provide a portable test case in which pwrite()
1492 // blocks we can enable this test to run in both rounds.
1495 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1496 tempfd
= mkstemp (fname
);
1499 printf ("%s: mkstemp failed\n", __FUNCTION__
);
1504 int r
= pthread_barrier_wait (&b2
);
1505 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1507 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1511 r
= pthread_barrier_wait (&b2
);
1512 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1514 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1518 pthread_cleanup_push (cl
, NULL
);
1521 pwrite (tempfd
, mem
, sizeof (mem
), 0);
1523 pthread_cleanup_pop (0);
1525 printf ("%s: pwrite returned\n", __FUNCTION__
);
1532 tf_fsync (void *arg
)
1535 // XXX If somebody can provide a portable test case in which fsync()
1536 // blocks we can enable this test to run in both rounds.
1539 tempfd
= open ("Makefile", O_RDONLY
);
1542 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1546 int r
= pthread_barrier_wait (&b2
);
1547 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1549 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1553 r
= pthread_barrier_wait (&b2
);
1554 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1556 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1560 pthread_cleanup_push (cl
, NULL
);
1564 pthread_cleanup_pop (0);
1566 printf ("%s: fsync returned\n", __FUNCTION__
);
1573 tf_fdatasync (void *arg
)
1576 // XXX If somebody can provide a portable test case in which fdatasync()
1577 // blocks we can enable this test to run in both rounds.
1580 tempfd
= open ("Makefile", O_RDONLY
);
1583 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1587 int r
= pthread_barrier_wait (&b2
);
1588 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1590 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1594 r
= pthread_barrier_wait (&b2
);
1595 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1597 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1601 pthread_cleanup_push (cl
, NULL
);
1605 pthread_cleanup_pop (0);
1607 printf ("%s: fdatasync returned\n", __FUNCTION__
);
1614 tf_msync (void *arg
)
1617 // XXX If somebody can provide a portable test case in which msync()
1618 // blocks we can enable this test to run in both rounds.
1621 tempfd
= open ("Makefile", O_RDONLY
);
1624 printf ("%s: cannot open Makefile\n", __FUNCTION__
);
1627 void *p
= mmap (NULL
, 10, PROT_READ
, MAP_SHARED
, tempfd
, 0);
1628 if (p
== MAP_FAILED
)
1630 printf ("%s: mmap failed\n", __FUNCTION__
);
1634 int r
= pthread_barrier_wait (&b2
);
1635 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1637 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1641 r
= pthread_barrier_wait (&b2
);
1642 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1644 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1648 pthread_cleanup_push (cl
, NULL
);
1652 pthread_cleanup_pop (0);
1654 printf ("%s: msync returned\n", __FUNCTION__
);
1661 tf_sendto (void *arg
)
1664 // XXX If somebody can provide a portable test case in which sendto()
1665 // blocks we can enable this test to run in both rounds.
1668 struct sockaddr_un sun
;
1670 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1673 printf ("%s: first socket call failed\n", __FUNCTION__
);
1682 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1685 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-6-XXXXXX");
1686 if (mktemp (sun
.sun_path
) == NULL
)
1688 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1692 sun
.sun_family
= AF_UNIX
;
1694 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1695 offsetof (struct sockaddr_un
, sun_path
)
1696 + strlen (sun
.sun_path
) + 1) != 0);
1697 tempfname
= strdup (sun
.sun_path
);
1699 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1702 printf ("%s: second socket call failed\n", __FUNCTION__
);
1706 int r
= pthread_barrier_wait (&b2
);
1707 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1709 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1713 r
= pthread_barrier_wait (&b2
);
1714 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1716 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1720 pthread_cleanup_push (cl
, NULL
);
1724 sendto (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0,
1725 (struct sockaddr
*) &sun
,
1726 offsetof (struct sockaddr_un
, sun_path
) + strlen (sun
.sun_path
) + 1);
1728 pthread_cleanup_pop (0);
1730 printf ("%s: sendto returned\n", __FUNCTION__
);
1737 tf_sendmsg (void *arg
)
1740 // XXX If somebody can provide a portable test case in which sendmsg()
1741 // blocks we can enable this test to run in both rounds.
1744 struct sockaddr_un sun
;
1746 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1749 printf ("%s: first socket call failed\n", __FUNCTION__
);
1758 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1761 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-7-XXXXXX");
1762 if (mktemp (sun
.sun_path
) == NULL
)
1764 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1768 sun
.sun_family
= AF_UNIX
;
1770 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1771 offsetof (struct sockaddr_un
, sun_path
)
1772 + strlen (sun
.sun_path
) + 1) != 0);
1773 tempfname
= strdup (sun
.sun_path
);
1775 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1778 printf ("%s: second socket call failed\n", __FUNCTION__
);
1782 int r
= pthread_barrier_wait (&b2
);
1783 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1785 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1789 r
= pthread_barrier_wait (&b2
);
1790 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1792 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1796 pthread_cleanup_push (cl
, NULL
);
1799 struct iovec iov
[1];
1800 iov
[0].iov_base
= mem
;
1805 m
.msg_namelen
= (offsetof (struct sockaddr_un
, sun_path
)
1806 + strlen (sun
.sun_path
) + 1);
1809 m
.msg_control
= NULL
;
1810 m
.msg_controllen
= 0;
1812 sendmsg (tempfd2
, &m
, 0);
1814 pthread_cleanup_pop (0);
1816 printf ("%s: sendmsg returned\n", __FUNCTION__
);
1823 tf_creat (void *arg
)
1826 // XXX If somebody can provide a portable test case in which sendmsg()
1827 // blocks we can enable this test to run in both rounds.
1830 int r
= pthread_barrier_wait (&b2
);
1831 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1833 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1837 r
= pthread_barrier_wait (&b2
);
1838 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1840 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1844 pthread_cleanup_push (cl
, NULL
);
1846 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1848 pthread_cleanup_pop (0);
1850 printf ("%s: creat returned\n", __FUNCTION__
);
1857 tf_connect (void *arg
)
1860 // XXX If somebody can provide a portable test case in which connect()
1861 // blocks we can enable this test to run in both rounds.
1864 struct sockaddr_un sun
;
1866 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1869 printf ("%s: first socket call failed\n", __FUNCTION__
);
1878 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__
);
1881 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1882 if (mktemp (sun
.sun_path
) == NULL
)
1884 printf ("%s: cannot generate temp file name\n", __FUNCTION__
);
1888 sun
.sun_family
= AF_UNIX
;
1890 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1891 offsetof (struct sockaddr_un
, sun_path
)
1892 + strlen (sun
.sun_path
) + 1) != 0);
1893 tempfname
= strdup (sun
.sun_path
);
1897 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1900 printf ("%s: second socket call failed\n", __FUNCTION__
);
1904 int r
= pthread_barrier_wait (&b2
);
1905 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1907 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1913 r
= pthread_barrier_wait (&b2
);
1914 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1916 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1921 pthread_cleanup_push (cl
, NULL
);
1923 connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
));
1925 pthread_cleanup_pop (0);
1927 printf ("%s: connect returned\n", __FUNCTION__
);
1934 tf_tcdrain (void *arg
)
1937 // XXX If somebody can provide a portable test case in which tcdrain()
1938 // blocks we can enable this test to run in both rounds.
1941 int r
= pthread_barrier_wait (&b2
);
1942 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1944 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1950 r
= pthread_barrier_wait (&b2
);
1951 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1953 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
1958 pthread_cleanup_push (cl
, NULL
);
1960 /* Regardless of stderr being a terminal, the tcdrain call should be
1962 tcdrain (STDERR_FILENO
);
1964 pthread_cleanup_pop (0);
1966 printf ("%s: tcdrain returned\n", __FUNCTION__
);
1973 tf_msgrcv (void *arg
)
1975 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1978 printf ("%s: msgget failed: %s\n", __FUNCTION__
, strerror (errno
));
1982 int r
= pthread_barrier_wait (&b2
);
1983 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1985 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
1991 r
= pthread_barrier_wait (&b2
);
1992 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
1994 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
2001 pthread_cleanup_push (cl
, NULL
);
2009 /* We need a positive random number. */
2011 randnr
= random () % 64000;
2012 while (randnr
<= 0);
2016 s
= msgrcv (tempmsg
, (struct msgbuf
*) &m
, 10, randnr
, 0);
2018 while (errno
== EIDRM
|| errno
== EINTR
);
2020 pthread_cleanup_pop (0);
2022 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__
, s
);
2024 msgctl (tempmsg
, IPC_RMID
, NULL
);
2031 tf_msgsnd (void *arg
)
2034 // XXX If somebody can provide a portable test case in which msgsnd()
2035 // blocks we can enable this test to run in both rounds.
2038 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
2041 printf ("%s: msgget failed: %s\n", __FUNCTION__
, strerror (errno
));
2045 int r
= pthread_barrier_wait (&b2
);
2046 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2048 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2052 r
= pthread_barrier_wait (&b2
);
2053 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2055 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__
);
2059 pthread_cleanup_push (cl
, NULL
);
2066 /* We need a positive random number. */
2068 m
.type
= random () % 64000;
2069 while (m
.type
<= 0);
2070 msgsnd (tempmsg
, (struct msgbuf
*) &m
, sizeof (m
.mem
), 0);
2072 pthread_cleanup_pop (0);
2074 printf ("%s: msgsnd returned\n", __FUNCTION__
);
2076 msgctl (tempmsg
, IPC_RMID
, NULL
);
2085 void *(*tf
) (void *);
2090 #define ADD_TEST(name, nbar, early) { #name, tf_##name, nbar, early }
2091 ADD_TEST (read
, 2, 0),
2092 ADD_TEST (readv
, 2, 0),
2093 ADD_TEST (select
, 2, 0),
2094 ADD_TEST (pselect
, 2, 0),
2095 ADD_TEST (poll
, 2, 0),
2096 ADD_TEST (ppoll
, 2, 0),
2097 ADD_TEST (write
, 2, 0),
2098 ADD_TEST (writev
, 2, 0),
2099 ADD_TEST (sleep
, 2, 0),
2100 ADD_TEST (usleep
, 2, 0),
2101 ADD_TEST (nanosleep
, 2, 0),
2102 ADD_TEST (wait
, 2, 0),
2103 ADD_TEST (waitid
, 2, 0),
2104 ADD_TEST (waitpid
, 2, 0),
2105 ADD_TEST (sigpause
, 2, 0),
2106 ADD_TEST (sigsuspend
, 2, 0),
2107 ADD_TEST (sigwait
, 2, 0),
2108 ADD_TEST (sigwaitinfo
, 2, 0),
2109 ADD_TEST (sigtimedwait
, 2, 0),
2110 ADD_TEST (pause
, 2, 0),
2111 ADD_TEST (accept
, 2, 0),
2112 ADD_TEST (send
, 2, 0),
2113 ADD_TEST (recv
, 2, 0),
2114 ADD_TEST (recvfrom
, 2, 0),
2115 ADD_TEST (recvmsg
, 2, 0),
2116 ADD_TEST (open
, 2, 1),
2117 ADD_TEST (close
, 2, 1),
2118 ADD_TEST (pread
, 2, 1),
2119 ADD_TEST (pwrite
, 2, 1),
2120 ADD_TEST (fsync
, 2, 1),
2121 ADD_TEST (fdatasync
, 2, 1),
2122 ADD_TEST (msync
, 2, 1),
2123 ADD_TEST (sendto
, 2, 1),
2124 ADD_TEST (sendmsg
, 2, 1),
2125 ADD_TEST (creat
, 2, 1),
2126 ADD_TEST (connect
, 2, 1),
2127 ADD_TEST (tcdrain
, 2, 1),
2128 ADD_TEST (msgrcv
, 2, 0),
2129 ADD_TEST (msgsnd
, 2, 1),
2131 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2140 if (socketpair (AF_UNIX
, SOCK_STREAM
, PF_UNIX
, fds
) != 0)
2142 perror ("socketpair");
2148 setsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, sizeof(val
));
2149 if (getsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, &len
) < 0)
2151 perror ("getsockopt");
2154 if (val
>= WRITE_BUFFER_SIZE
)
2156 puts ("minimum write buffer size too large");
2159 setsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, sizeof(val
));
2163 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
2165 if (tests
[cnt
].only_early
)
2168 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
2170 puts ("b2 init failed");
2174 /* Reset the counter for the cleanup handler. */
2178 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, NULL
) != 0)
2180 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
2185 int r
= pthread_barrier_wait (&b2
);
2186 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2188 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2193 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
2194 while (nanosleep (&ts
, &ts
) != 0)
2197 if (pthread_cancel (th
) != 0)
2199 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
2205 if (pthread_join (th
, &status
) != 0)
2207 printf ("join for '%s' failed\n", tests
[cnt
].name
);
2211 if (status
!= PTHREAD_CANCELED
)
2213 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
2218 if (pthread_barrier_destroy (&b2
) != 0)
2220 puts ("barrier_destroy failed");
2227 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
2233 printf ("cleanup handler called more than once for '%s'\n",
2239 printf ("in-time cancel test of '%s' successful\n", tests
[cnt
].name
);
2251 if (tempfname
!= NULL
)
2259 msgctl (tempmsg
, IPC_RMID
, NULL
);
2264 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
2266 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
2268 puts ("b2 init failed");
2272 /* Reset the counter for the cleanup handler. */
2276 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, (void *) 1l) != 0)
2278 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
2283 int r
= pthread_barrier_wait (&b2
);
2284 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2286 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2291 if (pthread_cancel (th
) != 0)
2293 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
2298 r
= pthread_barrier_wait (&b2
);
2299 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
2301 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
2307 if (pthread_join (th
, &status
) != 0)
2309 printf ("join for '%s' failed\n", tests
[cnt
].name
);
2313 if (status
!= PTHREAD_CANCELED
)
2315 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
2320 if (pthread_barrier_destroy (&b2
) != 0)
2322 puts ("barrier_destroy failed");
2329 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
2335 printf ("cleanup handler called more than once for '%s'\n",
2341 printf ("early cancel test of '%s' successful\n", tests
[cnt
].name
);
2353 if (tempfname
!= NULL
)
2361 msgctl (tempmsg
, IPC_RMID
, NULL
);
2370 #define TEST_FUNCTION do_test ()
2371 #include "../test-skeleton.c"