Update arm, mips, powerpc-nofpu libm-test-ulps.
[glibc.git] / nptl / tst-cancel4.c
bloba68a3efb682cf83f8085d4b2cb670dbb06c11f1e
1 /* Copyright (C) 2002-2017 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. */
22 #include <stddef.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <sys/un.h>
29 #include <sys/ipc.h>
30 #include <sys/msg.h>
31 #include <unistd.h>
32 #include <errno.h>
33 #include <limits.h>
34 #include <pthread.h>
35 #include <fcntl.h>
36 #include <termios.h>
37 #include <sys/mman.h>
38 #include <sys/poll.h>
39 #include <sys/wait.h>
40 #include <sys/stat.h>
43 /* Since STREAMS are not supported in the standard Linux kernel and
44 there we don't advertise STREAMS as supported is no need to test
45 the STREAMS related functions. This affects
46 getmsg() getpmsg() putmsg()
47 putpmsg()
49 lockf() and fcntl() are tested in tst-cancel16.
51 pthread_join() is tested in tst-join5.
53 pthread_testcancel()'s only purpose is to allow cancellation. This
54 is tested in several places.
56 sem_wait() and sem_timedwait() are checked in tst-cancel1[2345] tests.
58 mq_send(), mq_timedsend(), mq_receive() and mq_timedreceive() are checked
59 in tst-mqueue8{,x} tests.
61 aio_suspend() is tested in tst-cancel17.
63 clock_nanosleep() is tested in tst-cancel18.
65 Linux sendmmsg and recvmmsg are checked in tst-cancel4_1.c and
66 tst-cancel4_2.c respectively.
69 #include "tst-cancel4-common.h"
72 #ifndef IPC_ADDVAL
73 # define IPC_ADDVAL 0
74 #endif
77 static void *
78 tf_read (void *arg)
80 int fd;
81 int r;
83 if (arg == NULL)
84 fd = fds[0];
85 else
87 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
88 tempfd = fd = mkstemp (fname);
89 if (fd == -1)
90 printf ("%s: mkstemp failed\n", __FUNCTION__);
91 unlink (fname);
93 r = pthread_barrier_wait (&b2);
94 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
96 printf ("%s: barrier_wait failed\n", __FUNCTION__);
97 exit (1);
101 r = pthread_barrier_wait (&b2);
102 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
104 printf ("%s: barrier_wait failed\n", __FUNCTION__);
105 exit (1);
108 ssize_t s;
109 pthread_cleanup_push (cl, NULL);
111 char buf[100];
112 s = read (fd, buf, sizeof (buf));
114 pthread_cleanup_pop (0);
116 printf ("%s: read returns with %zd\n", __FUNCTION__, s);
118 exit (1);
122 static void *
123 tf_readv (void *arg)
125 int fd;
126 int r;
128 if (arg == NULL)
129 fd = fds[0];
130 else
132 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
133 tempfd = fd = mkstemp (fname);
134 if (fd == -1)
135 printf ("%s: mkstemp failed\n", __FUNCTION__);
136 unlink (fname);
138 r = pthread_barrier_wait (&b2);
139 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
141 printf ("%s: barrier_wait failed\n", __FUNCTION__);
142 exit (1);
146 r = pthread_barrier_wait (&b2);
147 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
149 printf ("%s: barrier_wait failed\n", __FUNCTION__);
150 exit (1);
153 ssize_t s;
154 pthread_cleanup_push (cl, NULL);
156 char buf[100];
157 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
158 s = readv (fd, iov, 1);
160 pthread_cleanup_pop (0);
162 printf ("%s: readv returns with %zd\n", __FUNCTION__, s);
164 exit (1);
168 static void *
169 tf_write (void *arg)
171 int fd;
172 int r;
174 if (arg == NULL)
175 fd = fds[1];
176 else
178 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
179 tempfd = fd = mkstemp (fname);
180 if (fd == -1)
181 printf ("%s: mkstemp failed\n", __FUNCTION__);
182 unlink (fname);
184 r = pthread_barrier_wait (&b2);
185 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
187 printf ("%s: barrier_wait failed\n", __FUNCTION__);
188 exit (1);
192 r = pthread_barrier_wait (&b2);
193 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
195 printf ("%s: barrier_wait failed\n", __FUNCTION__);
196 exit (1);
199 ssize_t s;
200 pthread_cleanup_push (cl, NULL);
202 char buf[WRITE_BUFFER_SIZE];
203 memset (buf, '\0', sizeof (buf));
204 s = write (fd, buf, sizeof (buf));
206 pthread_cleanup_pop (0);
208 printf ("%s: write returns with %zd\n", __FUNCTION__, s);
210 exit (1);
214 static void *
215 tf_writev (void *arg)
217 int fd;
218 int r;
220 if (arg == NULL)
221 fd = fds[1];
222 else
224 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
225 tempfd = fd = mkstemp (fname);
226 if (fd == -1)
227 printf ("%s: mkstemp failed\n", __FUNCTION__);
228 unlink (fname);
230 r = pthread_barrier_wait (&b2);
231 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
233 printf ("%s: barrier_wait failed\n", __FUNCTION__);
234 exit (1);
238 r = pthread_barrier_wait (&b2);
239 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
241 printf ("%s: barrier_wait failed\n", __FUNCTION__);
242 exit (1);
245 ssize_t s;
246 pthread_cleanup_push (cl, NULL);
248 char buf[WRITE_BUFFER_SIZE];
249 memset (buf, '\0', sizeof (buf));
250 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
251 s = writev (fd, iov, 1);
253 pthread_cleanup_pop (0);
255 printf ("%s: writev returns with %zd\n", __FUNCTION__, s);
257 exit (1);
261 static void *
262 tf_sleep (void *arg)
264 int r = pthread_barrier_wait (&b2);
265 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
267 printf ("%s: barrier_wait failed\n", __FUNCTION__);
268 exit (1);
271 if (arg != NULL)
273 r = pthread_barrier_wait (&b2);
274 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
276 printf ("%s: barrier_wait failed\n", __FUNCTION__);
277 exit (1);
281 pthread_cleanup_push (cl, NULL);
283 sleep (arg == NULL ? 1000000 : 0);
285 pthread_cleanup_pop (0);
287 printf ("%s: sleep returns\n", __FUNCTION__);
289 exit (1);
293 static void *
294 tf_usleep (void *arg)
296 int r = pthread_barrier_wait (&b2);
297 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
299 printf ("%s: barrier_wait failed\n", __FUNCTION__);
300 exit (1);
303 if (arg != NULL)
305 r = pthread_barrier_wait (&b2);
306 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
308 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
309 exit (1);
313 pthread_cleanup_push (cl, NULL);
315 usleep (arg == NULL ? (useconds_t) ULONG_MAX : 0);
317 pthread_cleanup_pop (0);
319 printf ("%s: usleep returns\n", __FUNCTION__);
321 exit (1);
325 static void *
326 tf_nanosleep (void *arg)
328 int r = pthread_barrier_wait (&b2);
329 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
331 printf ("%s: barrier_wait failed\n", __FUNCTION__);
332 exit (1);
335 if (arg != NULL)
337 r = pthread_barrier_wait (&b2);
338 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
340 printf ("%s: barrier_wait failed\n", __FUNCTION__);
341 exit (1);
345 pthread_cleanup_push (cl, NULL);
347 struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 };
348 TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
350 pthread_cleanup_pop (0);
352 printf ("%s: nanosleep returns\n", __FUNCTION__);
354 exit (1);
358 static void *
359 tf_select (void *arg)
361 int fd;
362 int r;
364 if (arg == NULL)
365 fd = fds[0];
366 else
368 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
369 tempfd = fd = mkstemp (fname);
370 if (fd == -1)
371 printf ("%s: mkstemp failed\n", __FUNCTION__);
372 unlink (fname);
374 r = pthread_barrier_wait (&b2);
375 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
377 printf ("%s: barrier_wait failed\n", __FUNCTION__);
378 exit (1);
382 r = pthread_barrier_wait (&b2);
383 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
385 printf ("%s: barrier_wait failed\n", __FUNCTION__);
386 exit (1);
389 fd_set rfs;
390 FD_ZERO (&rfs);
391 FD_SET (fd, &rfs);
393 int s;
394 pthread_cleanup_push (cl, NULL);
396 s = select (fd + 1, &rfs, NULL, NULL, NULL);
398 pthread_cleanup_pop (0);
400 printf ("%s: select returns with %d (%s)\n", __FUNCTION__, s,
401 strerror (errno));
403 exit (1);
407 static void *
408 tf_pselect (void *arg)
410 int fd;
411 int r;
413 if (arg == NULL)
414 fd = fds[0];
415 else
417 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
418 tempfd = fd = mkstemp (fname);
419 if (fd == -1)
420 printf ("%s: mkstemp failed\n", __FUNCTION__);
421 unlink (fname);
423 r = pthread_barrier_wait (&b2);
424 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
426 printf ("%s: barrier_wait failed\n", __FUNCTION__);
427 exit (1);
431 r = pthread_barrier_wait (&b2);
432 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
434 printf ("%s: barrier_wait failed\n", __FUNCTION__);
435 exit (1);
438 fd_set rfs;
439 FD_ZERO (&rfs);
440 FD_SET (fd, &rfs);
442 int s;
443 pthread_cleanup_push (cl, NULL);
445 s = pselect (fd + 1, &rfs, NULL, NULL, NULL, NULL);
447 pthread_cleanup_pop (0);
449 printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__, s,
450 strerror (errno));
452 exit (1);
456 static void *
457 tf_poll (void *arg)
459 int fd;
460 int r;
462 if (arg == NULL)
463 fd = fds[0];
464 else
466 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
467 tempfd = fd = mkstemp (fname);
468 if (fd == -1)
469 printf ("%s: mkstemp failed\n", __FUNCTION__);
470 unlink (fname);
472 r = pthread_barrier_wait (&b2);
473 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
475 printf ("%s: barrier_wait failed\n", __FUNCTION__);
476 exit (1);
480 r = pthread_barrier_wait (&b2);
481 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
483 printf ("%s: barrier_wait failed\n", __FUNCTION__);
484 exit (1);
487 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
489 int s;
490 pthread_cleanup_push (cl, NULL);
492 s = poll (rfs, 1, -1);
494 pthread_cleanup_pop (0);
496 printf ("%s: poll returns with %d (%s)\n", __FUNCTION__, s,
497 strerror (errno));
499 exit (1);
503 static void *
504 tf_ppoll (void *arg)
506 int fd;
507 int r;
509 if (arg == NULL)
510 fd = fds[0];
511 else
513 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
514 tempfd = fd = mkstemp (fname);
515 if (fd == -1)
516 printf ("%s: mkstemp failed\n", __FUNCTION__);
517 unlink (fname);
519 r = pthread_barrier_wait (&b2);
520 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
522 printf ("%s: barrier_wait failed\n", __FUNCTION__);
523 exit (1);
527 r = pthread_barrier_wait (&b2);
528 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
530 printf ("%s: barrier_wait failed\n", __FUNCTION__);
531 exit (1);
534 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
536 int s;
537 pthread_cleanup_push (cl, NULL);
539 s = ppoll (rfs, 1, NULL, NULL);
541 pthread_cleanup_pop (0);
543 printf ("%s: ppoll returns with %d (%s)\n", __FUNCTION__, s,
544 strerror (errno));
546 exit (1);
550 static void *
551 tf_wait (void *arg)
553 pid_t pid = fork ();
554 if (pid == -1)
556 puts ("fork failed");
557 exit (1);
560 if (pid == 0)
562 /* Make the program disappear after a while. */
563 if (arg == NULL)
564 sleep (10);
565 exit (0);
568 int r;
569 if (arg != NULL)
571 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
572 while (nanosleep (&ts, &ts) != 0)
573 continue;
575 r = pthread_barrier_wait (&b2);
576 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
578 printf ("%s: barrier_wait failed\n", __FUNCTION__);
579 exit (1);
583 r = pthread_barrier_wait (&b2);
584 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
586 printf ("%s: barrier_wait failed\n", __FUNCTION__);
587 exit (1);
590 int s;
591 pthread_cleanup_push (cl, NULL);
593 s = wait (NULL);
595 pthread_cleanup_pop (0);
597 printf ("%s: wait returns with %d (%s)\n", __FUNCTION__, s,
598 strerror (errno));
600 exit (1);
604 static void *
605 tf_waitpid (void *arg)
608 pid_t pid = fork ();
609 if (pid == -1)
611 puts ("fork failed");
612 exit (1);
615 if (pid == 0)
617 /* Make the program disappear after a while. */
618 if (arg == NULL)
619 sleep (10);
620 exit (0);
623 int r;
624 if (arg != NULL)
626 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
627 while (nanosleep (&ts, &ts) != 0)
628 continue;
630 r = pthread_barrier_wait (&b2);
631 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
633 printf ("%s: barrier_wait failed\n", __FUNCTION__);
634 exit (1);
638 r = pthread_barrier_wait (&b2);
639 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
641 printf ("%s: barrier_wait failed\n", __FUNCTION__);
642 exit (1);
645 int s;
646 pthread_cleanup_push (cl, NULL);
648 s = waitpid (-1, NULL, 0);
650 pthread_cleanup_pop (0);
652 printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__, s,
653 strerror (errno));
655 exit (1);
659 static void *
660 tf_waitid (void *arg)
662 pid_t pid = fork ();
663 if (pid == -1)
665 puts ("fork failed");
666 exit (1);
669 if (pid == 0)
671 /* Make the program disappear after a while. */
672 if (arg == NULL)
673 sleep (10);
674 exit (0);
677 int r;
678 if (arg != NULL)
680 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
681 while (nanosleep (&ts, &ts) != 0)
682 continue;
684 r = pthread_barrier_wait (&b2);
685 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
687 printf ("%s: barrier_wait failed\n", __FUNCTION__);
688 exit (1);
692 r = pthread_barrier_wait (&b2);
693 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
695 printf ("%s: barrier_wait failed\n", __FUNCTION__);
696 exit (1);
699 int s;
700 pthread_cleanup_push (cl, NULL);
702 #ifndef WEXITED
703 # define WEXITED 0
704 #endif
705 siginfo_t si;
706 s = waitid (P_PID, pid, &si, WEXITED);
708 pthread_cleanup_pop (0);
710 printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__, s,
711 strerror (errno));
713 exit (1);
717 static void *
718 tf_sigpause (void *arg)
720 int r = pthread_barrier_wait (&b2);
721 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
723 printf ("%s: barrier_wait failed\n", __FUNCTION__);
724 exit (1);
727 if (arg != NULL)
729 r = pthread_barrier_wait (&b2);
730 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
732 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
733 exit (1);
737 pthread_cleanup_push (cl, NULL);
739 sigpause (sigmask (SIGINT));
741 pthread_cleanup_pop (0);
743 printf ("%s: sigpause returned\n", __FUNCTION__);
745 exit (1);
749 static void *
750 tf_sigsuspend (void *arg)
752 int r = pthread_barrier_wait (&b2);
753 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
755 printf ("%s: barrier_wait failed\n", __FUNCTION__);
756 exit (1);
759 if (arg != NULL)
761 r = pthread_barrier_wait (&b2);
762 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
764 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
765 exit (1);
769 pthread_cleanup_push (cl, NULL);
771 /* Just for fun block all signals. */
772 sigset_t mask;
773 sigfillset (&mask);
774 sigsuspend (&mask);
776 pthread_cleanup_pop (0);
778 printf ("%s: sigsuspend returned\n", __FUNCTION__);
780 exit (1);
784 static void *
785 tf_sigwait (void *arg)
787 int r = pthread_barrier_wait (&b2);
788 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
790 printf ("%s: barrier_wait failed\n", __FUNCTION__);
791 exit (1);
794 if (arg != NULL)
796 r = pthread_barrier_wait (&b2);
797 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
799 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
800 exit (1);
804 /* Block SIGUSR1. */
805 sigset_t mask;
806 sigemptyset (&mask);
807 sigaddset (&mask, SIGUSR1);
808 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
810 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
811 exit (1);
814 int sig;
815 pthread_cleanup_push (cl, NULL);
817 /* Wait for SIGUSR1. */
818 sigwait (&mask, &sig);
820 pthread_cleanup_pop (0);
822 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__, sig);
824 exit (1);
828 static void *
829 tf_sigwaitinfo (void *arg)
831 int r = pthread_barrier_wait (&b2);
832 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
834 printf ("%s: barrier_wait failed\n", __FUNCTION__);
835 exit (1);
838 if (arg != NULL)
840 r = pthread_barrier_wait (&b2);
841 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
843 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
844 exit (1);
848 /* Block SIGUSR1. */
849 sigset_t mask;
850 sigemptyset (&mask);
851 sigaddset (&mask, SIGUSR1);
852 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
854 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
855 exit (1);
858 siginfo_t info;
859 pthread_cleanup_push (cl, NULL);
861 /* Wait for SIGUSR1. */
862 sigwaitinfo (&mask, &info);
864 pthread_cleanup_pop (0);
866 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__,
867 info.si_signo);
869 exit (1);
873 static void *
874 tf_sigtimedwait (void *arg)
876 int r = pthread_barrier_wait (&b2);
877 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
879 printf ("%s: barrier_wait failed\n", __FUNCTION__);
880 exit (1);
883 if (arg != NULL)
885 r = pthread_barrier_wait (&b2);
886 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
888 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
889 exit (1);
893 /* Block SIGUSR1. */
894 sigset_t mask;
895 sigemptyset (&mask);
896 sigaddset (&mask, SIGUSR1);
897 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
899 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
900 exit (1);
903 /* Wait for SIGUSR1. */
904 siginfo_t info;
905 struct timespec ts = { .tv_sec = 60, .tv_nsec = 0 };
906 pthread_cleanup_push (cl, NULL);
908 sigtimedwait (&mask, &info, &ts);
910 pthread_cleanup_pop (0);
912 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__,
913 info.si_signo);
915 exit (1);
919 static void *
920 tf_pause (void *arg)
922 int r = pthread_barrier_wait (&b2);
923 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
925 printf ("%s: barrier_wait failed\n", __FUNCTION__);
926 exit (1);
929 if (arg != NULL)
931 r = pthread_barrier_wait (&b2);
932 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
934 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
935 exit (1);
939 pthread_cleanup_push (cl, NULL);
941 pause ();
943 pthread_cleanup_pop (0);
945 printf ("%s: pause returned\n", __FUNCTION__);
947 exit (1);
951 static void *
952 tf_accept (void *arg)
954 struct sockaddr_un sun;
955 /* To test a non-blocking accept call we make the call file by using
956 a datagrame socket. */
957 int pf = arg == NULL ? SOCK_STREAM : SOCK_DGRAM;
959 tempfd = socket (AF_UNIX, pf, 0);
960 if (tempfd == -1)
962 printf ("%s: socket call failed\n", __FUNCTION__);
963 exit (1);
966 int tries = 0;
969 if (++tries > 10)
971 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
974 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
975 if (mktemp (sun.sun_path) == NULL)
977 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
978 exit (1);
981 sun.sun_family = AF_UNIX;
983 while (bind (tempfd, (struct sockaddr *) &sun,
984 offsetof (struct sockaddr_un, sun_path)
985 + strlen (sun.sun_path) + 1) != 0);
987 unlink (sun.sun_path);
989 listen (tempfd, 5);
991 socklen_t len = sizeof (sun);
993 int r = pthread_barrier_wait (&b2);
994 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
996 printf ("%s: barrier_wait failed\n", __FUNCTION__);
997 exit (1);
1000 if (arg != NULL)
1002 r = pthread_barrier_wait (&b2);
1003 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1005 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1006 exit (1);
1010 pthread_cleanup_push (cl, NULL);
1012 accept (tempfd, (struct sockaddr *) &sun, &len);
1014 pthread_cleanup_pop (0);
1016 printf ("%s: accept returned\n", __FUNCTION__);
1018 exit (1);
1022 static void *
1023 tf_send (void *arg)
1025 struct sockaddr_un sun;
1027 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1028 if (tempfd == -1)
1030 printf ("%s: first socket call failed\n", __FUNCTION__);
1031 exit (1);
1034 int tries = 0;
1037 if (++tries > 10)
1039 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1042 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1043 if (mktemp (sun.sun_path) == NULL)
1045 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1046 exit (1);
1049 sun.sun_family = AF_UNIX;
1051 while (bind (tempfd, (struct sockaddr *) &sun,
1052 offsetof (struct sockaddr_un, sun_path)
1053 + strlen (sun.sun_path) + 1) != 0);
1055 listen (tempfd, 5);
1057 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1058 if (tempfd2 == -1)
1060 printf ("%s: second socket call failed\n", __FUNCTION__);
1061 exit (1);
1064 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1066 printf ("%s: connect failed\n", __FUNCTION__);
1067 exit(1);
1070 unlink (sun.sun_path);
1072 int r = pthread_barrier_wait (&b2);
1073 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1075 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1076 exit (1);
1079 if (arg != NULL)
1081 r = pthread_barrier_wait (&b2);
1082 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1084 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1085 exit (1);
1089 pthread_cleanup_push (cl, NULL);
1091 /* Very large block, so that the send call blocks. */
1092 char mem[700000];
1094 send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
1096 pthread_cleanup_pop (0);
1098 printf ("%s: send returned\n", __FUNCTION__);
1100 exit (1);
1104 static void *
1105 tf_recv (void *arg)
1107 struct sockaddr_un sun;
1109 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1110 if (tempfd == -1)
1112 printf ("%s: first socket call failed\n", __FUNCTION__);
1113 exit (1);
1116 int tries = 0;
1119 if (++tries > 10)
1121 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1124 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX");
1125 if (mktemp (sun.sun_path) == NULL)
1127 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1128 exit (1);
1131 sun.sun_family = AF_UNIX;
1133 while (bind (tempfd, (struct sockaddr *) &sun,
1134 offsetof (struct sockaddr_un, sun_path)
1135 + strlen (sun.sun_path) + 1) != 0);
1137 listen (tempfd, 5);
1139 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1140 if (tempfd2 == -1)
1142 printf ("%s: second socket call failed\n", __FUNCTION__);
1143 exit (1);
1146 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1148 printf ("%s: connect failed\n", __FUNCTION__);
1149 exit(1);
1152 unlink (sun.sun_path);
1154 int r = pthread_barrier_wait (&b2);
1155 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1157 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1158 exit (1);
1161 if (arg != NULL)
1163 r = pthread_barrier_wait (&b2);
1164 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1166 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1167 exit (1);
1171 pthread_cleanup_push (cl, NULL);
1173 char mem[70];
1175 recv (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0);
1177 pthread_cleanup_pop (0);
1179 printf ("%s: recv returned\n", __FUNCTION__);
1181 exit (1);
1185 static void *
1186 tf_recvfrom (void *arg)
1188 struct sockaddr_un sun;
1190 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1191 if (tempfd == -1)
1193 printf ("%s: first socket call failed\n", __FUNCTION__);
1194 exit (1);
1197 int tries = 0;
1200 if (++tries > 10)
1202 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1205 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX");
1206 if (mktemp (sun.sun_path) == NULL)
1208 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1209 exit (1);
1212 sun.sun_family = AF_UNIX;
1214 while (bind (tempfd, (struct sockaddr *) &sun,
1215 offsetof (struct sockaddr_un, sun_path)
1216 + strlen (sun.sun_path) + 1) != 0);
1218 tempfname = strdup (sun.sun_path);
1220 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1221 if (tempfd2 == -1)
1223 printf ("%s: second socket call failed\n", __FUNCTION__);
1224 exit (1);
1227 int r = pthread_barrier_wait (&b2);
1228 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1230 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1231 exit (1);
1234 if (arg != NULL)
1236 r = pthread_barrier_wait (&b2);
1237 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1239 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1240 exit (1);
1244 pthread_cleanup_push (cl, NULL);
1246 char mem[70];
1247 socklen_t len = sizeof (sun);
1249 recvfrom (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0,
1250 (struct sockaddr *) &sun, &len);
1252 pthread_cleanup_pop (0);
1254 printf ("%s: recvfrom returned\n", __FUNCTION__);
1256 exit (1);
1260 static void *
1261 tf_recvmsg (void *arg)
1263 struct sockaddr_un sun;
1265 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1266 if (tempfd == -1)
1268 printf ("%s: first socket call failed\n", __FUNCTION__);
1269 exit (1);
1272 int tries = 0;
1275 if (++tries > 10)
1277 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1280 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
1281 if (mktemp (sun.sun_path) == NULL)
1283 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1284 exit (1);
1287 sun.sun_family = AF_UNIX;
1289 while (bind (tempfd, (struct sockaddr *) &sun,
1290 offsetof (struct sockaddr_un, sun_path)
1291 + strlen (sun.sun_path) + 1) != 0);
1293 tempfname = strdup (sun.sun_path);
1295 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1296 if (tempfd2 == -1)
1298 printf ("%s: second socket call failed\n", __FUNCTION__);
1299 exit (1);
1302 int r = pthread_barrier_wait (&b2);
1303 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1305 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1306 exit (1);
1309 if (arg != NULL)
1311 r = pthread_barrier_wait (&b2);
1312 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1314 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1315 exit (1);
1319 pthread_cleanup_push (cl, NULL);
1321 char mem[70];
1322 struct iovec iov[1];
1323 iov[0].iov_base = mem;
1324 iov[0].iov_len = arg == NULL ? sizeof (mem) : 0;
1326 struct msghdr m;
1327 m.msg_name = &sun;
1328 m.msg_namelen = sizeof (sun);
1329 m.msg_iov = iov;
1330 m.msg_iovlen = 1;
1331 m.msg_control = NULL;
1332 m.msg_controllen = 0;
1334 recvmsg (tempfd2, &m, 0);
1336 pthread_cleanup_pop (0);
1338 printf ("%s: recvmsg returned\n", __FUNCTION__);
1340 exit (1);
1343 static void *
1344 tf_open (void *arg)
1346 if (arg == NULL)
1348 fifofd = mkfifo (fifoname, S_IWUSR | S_IRUSR);
1349 if (fifofd == -1)
1351 printf ("%s: mkfifo failed: %m\n", __func__);
1352 exit (1);
1355 else
1357 int r = pthread_barrier_wait (&b2);
1358 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1360 printf ("%s: barrier_wait failed: %m\n", __func__);
1361 exit (1);
1365 int r = pthread_barrier_wait (&b2);
1366 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1368 printf ("%s: 2nd barrier_wait failed: %m\n", __func__);
1369 exit (1);
1372 pthread_cleanup_push (cl_fifo, NULL);
1374 open (arg ? "Makefile" : fifoname, O_RDONLY);
1376 pthread_cleanup_pop (0);
1378 printf ("%s: open returned\n", __FUNCTION__);
1380 exit (1);
1384 static void *
1385 tf_close (void *arg)
1387 if (arg == NULL)
1388 // XXX If somebody can provide a portable test case in which close()
1389 // blocks we can enable this test to run in both rounds.
1390 abort ();
1392 char fname[] = "/tmp/tst-cancel-fd-XXXXXX";
1393 tempfd = mkstemp (fname);
1394 if (tempfd == -1)
1396 printf ("%s: mkstemp failed\n", __FUNCTION__);
1397 exit (1);
1399 unlink (fname);
1401 int r = pthread_barrier_wait (&b2);
1402 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1404 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1405 exit (1);
1408 r = pthread_barrier_wait (&b2);
1409 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1411 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1412 exit (1);
1415 pthread_cleanup_push (cl, NULL);
1417 close (tempfd);
1419 pthread_cleanup_pop (0);
1421 printf ("%s: close returned\n", __FUNCTION__);
1423 exit (1);
1427 static void *
1428 tf_pread (void *arg)
1430 if (arg == NULL)
1431 // XXX If somebody can provide a portable test case in which pread()
1432 // blocks we can enable this test to run in both rounds.
1433 abort ();
1435 tempfd = open ("Makefile", O_RDONLY);
1436 if (tempfd == -1)
1438 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1439 exit (1);
1442 int r = pthread_barrier_wait (&b2);
1443 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1445 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1446 exit (1);
1449 r = pthread_barrier_wait (&b2);
1450 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1452 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1453 exit (1);
1456 pthread_cleanup_push (cl, NULL);
1458 char mem[10];
1459 pread (tempfd, mem, sizeof (mem), 0);
1461 pthread_cleanup_pop (0);
1463 printf ("%s: pread returned\n", __FUNCTION__);
1465 exit (1);
1469 static void *
1470 tf_pwrite (void *arg)
1472 if (arg == NULL)
1473 // XXX If somebody can provide a portable test case in which pwrite()
1474 // blocks we can enable this test to run in both rounds.
1475 abort ();
1477 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1478 tempfd = mkstemp (fname);
1479 if (tempfd == -1)
1481 printf ("%s: mkstemp failed\n", __FUNCTION__);
1482 exit (1);
1484 unlink (fname);
1486 int r = pthread_barrier_wait (&b2);
1487 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1489 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1490 exit (1);
1493 r = pthread_barrier_wait (&b2);
1494 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1496 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1497 exit (1);
1500 pthread_cleanup_push (cl, NULL);
1502 char mem[10];
1503 pwrite (tempfd, mem, sizeof (mem), 0);
1505 pthread_cleanup_pop (0);
1507 printf ("%s: pwrite returned\n", __FUNCTION__);
1509 exit (1);
1512 static void *
1513 tf_preadv (void *arg)
1515 int fd;
1516 int r;
1518 if (arg == NULL)
1519 /* XXX If somebody can provide a portable test case in which preadv
1520 blocks we can enable this test to run in both rounds. */
1521 abort ();
1523 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1524 tempfd = fd = mkstemp (fname);
1525 if (fd == -1)
1526 printf ("%s: mkstemp failed\n", __FUNCTION__);
1527 unlink (fname);
1529 r = pthread_barrier_wait (&b2);
1530 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1532 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1533 exit (1);
1536 r = pthread_barrier_wait (&b2);
1537 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1539 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1540 exit (1);
1543 ssize_t s;
1544 pthread_cleanup_push (cl, NULL);
1546 char buf[100];
1547 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
1548 s = preadv (fd, iov, 1, 0);
1550 pthread_cleanup_pop (0);
1552 printf ("%s: preadv returns with %zd\n", __FUNCTION__, s);
1554 exit (1);
1557 static void *
1558 tf_pwritev (void *arg)
1560 int fd;
1561 int r;
1563 if (arg == NULL)
1564 /* XXX If somebody can provide a portable test case in which pwritev
1565 blocks we can enable this test to run in both rounds. */
1566 abort ();
1568 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1569 tempfd = fd = mkstemp (fname);
1570 if (fd == -1)
1571 printf ("%s: mkstemp failed\n", __FUNCTION__);
1572 unlink (fname);
1574 r = pthread_barrier_wait (&b2);
1575 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1577 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1578 exit (1);
1581 r = pthread_barrier_wait (&b2);
1582 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1584 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1585 exit (1);
1588 ssize_t s;
1589 pthread_cleanup_push (cl, NULL);
1591 char buf[WRITE_BUFFER_SIZE];
1592 memset (buf, '\0', sizeof (buf));
1593 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
1594 s = pwritev (fd, iov, 1, 0);
1596 pthread_cleanup_pop (0);
1598 printf ("%s: pwritev returns with %zd\n", __FUNCTION__, s);
1600 exit (1);
1603 static void *
1604 tf_fsync (void *arg)
1606 if (arg == NULL)
1607 // XXX If somebody can provide a portable test case in which fsync()
1608 // blocks we can enable this test to run in both rounds.
1609 abort ();
1611 tempfd = open ("Makefile", O_RDONLY);
1612 if (tempfd == -1)
1614 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1615 exit (1);
1618 int r = pthread_barrier_wait (&b2);
1619 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1621 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1622 exit (1);
1625 r = pthread_barrier_wait (&b2);
1626 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1628 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1629 exit (1);
1632 pthread_cleanup_push (cl, NULL);
1634 fsync (tempfd);
1636 pthread_cleanup_pop (0);
1638 printf ("%s: fsync returned\n", __FUNCTION__);
1640 exit (1);
1644 static void *
1645 tf_fdatasync (void *arg)
1647 if (arg == NULL)
1648 // XXX If somebody can provide a portable test case in which fdatasync()
1649 // blocks we can enable this test to run in both rounds.
1650 abort ();
1652 tempfd = open ("Makefile", O_RDONLY);
1653 if (tempfd == -1)
1655 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1656 exit (1);
1659 int r = pthread_barrier_wait (&b2);
1660 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1662 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1663 exit (1);
1666 r = pthread_barrier_wait (&b2);
1667 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1669 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1670 exit (1);
1673 pthread_cleanup_push (cl, NULL);
1675 fdatasync (tempfd);
1677 pthread_cleanup_pop (0);
1679 printf ("%s: fdatasync returned\n", __FUNCTION__);
1681 exit (1);
1685 static void *
1686 tf_msync (void *arg)
1688 if (arg == NULL)
1689 // XXX If somebody can provide a portable test case in which msync()
1690 // blocks we can enable this test to run in both rounds.
1691 abort ();
1693 tempfd = open ("Makefile", O_RDONLY);
1694 if (tempfd == -1)
1696 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1697 exit (1);
1699 void *p = mmap (NULL, 10, PROT_READ, MAP_SHARED, tempfd, 0);
1700 if (p == MAP_FAILED)
1702 printf ("%s: mmap failed\n", __FUNCTION__);
1703 exit (1);
1706 int r = pthread_barrier_wait (&b2);
1707 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1709 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1710 exit (1);
1713 r = pthread_barrier_wait (&b2);
1714 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1716 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1717 exit (1);
1720 pthread_cleanup_push (cl, NULL);
1722 msync (p, 10, 0);
1724 pthread_cleanup_pop (0);
1726 printf ("%s: msync returned\n", __FUNCTION__);
1728 exit (1);
1732 static void *
1733 tf_sendto (void *arg)
1735 if (arg == NULL)
1736 // XXX If somebody can provide a portable test case in which sendto()
1737 // blocks we can enable this test to run in both rounds.
1738 abort ();
1740 struct sockaddr_un sun;
1742 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1743 if (tempfd == -1)
1745 printf ("%s: first socket call failed\n", __FUNCTION__);
1746 exit (1);
1749 int tries = 0;
1752 if (++tries > 10)
1754 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1757 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX");
1758 if (mktemp (sun.sun_path) == NULL)
1760 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1761 exit (1);
1764 sun.sun_family = AF_UNIX;
1766 while (bind (tempfd, (struct sockaddr *) &sun,
1767 offsetof (struct sockaddr_un, sun_path)
1768 + strlen (sun.sun_path) + 1) != 0);
1769 tempfname = strdup (sun.sun_path);
1771 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1772 if (tempfd2 == -1)
1774 printf ("%s: second socket call failed\n", __FUNCTION__);
1775 exit (1);
1778 int r = pthread_barrier_wait (&b2);
1779 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1781 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1782 exit (1);
1785 r = pthread_barrier_wait (&b2);
1786 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1788 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1789 exit (1);
1792 pthread_cleanup_push (cl, NULL);
1794 char mem[1];
1796 sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0,
1797 (struct sockaddr *) &sun,
1798 offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1);
1800 pthread_cleanup_pop (0);
1802 printf ("%s: sendto returned\n", __FUNCTION__);
1804 exit (1);
1808 static void *
1809 tf_sendmsg (void *arg)
1811 if (arg == NULL)
1812 // XXX If somebody can provide a portable test case in which sendmsg()
1813 // blocks we can enable this test to run in both rounds.
1814 abort ();
1816 struct sockaddr_un sun;
1818 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1819 if (tempfd == -1)
1821 printf ("%s: first socket call failed\n", __FUNCTION__);
1822 exit (1);
1825 int tries = 0;
1828 if (++tries > 10)
1830 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1833 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
1834 if (mktemp (sun.sun_path) == NULL)
1836 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1837 exit (1);
1840 sun.sun_family = AF_UNIX;
1842 while (bind (tempfd, (struct sockaddr *) &sun,
1843 offsetof (struct sockaddr_un, sun_path)
1844 + strlen (sun.sun_path) + 1) != 0);
1845 tempfname = strdup (sun.sun_path);
1847 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1848 if (tempfd2 == -1)
1850 printf ("%s: second socket call failed\n", __FUNCTION__);
1851 exit (1);
1854 int r = pthread_barrier_wait (&b2);
1855 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1857 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1858 exit (1);
1861 r = pthread_barrier_wait (&b2);
1862 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1864 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1865 exit (1);
1868 pthread_cleanup_push (cl, NULL);
1870 char mem[1];
1871 struct iovec iov[1];
1872 iov[0].iov_base = mem;
1873 iov[0].iov_len = 1;
1875 struct msghdr m;
1876 m.msg_name = &sun;
1877 m.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
1878 + strlen (sun.sun_path) + 1);
1879 m.msg_iov = iov;
1880 m.msg_iovlen = 1;
1881 m.msg_control = NULL;
1882 m.msg_controllen = 0;
1884 sendmsg (tempfd2, &m, 0);
1886 pthread_cleanup_pop (0);
1888 printf ("%s: sendmsg returned\n", __FUNCTION__);
1890 exit (1);
1894 static void *
1895 tf_creat (void *arg)
1897 if (arg == NULL)
1898 // XXX If somebody can provide a portable test case in which sendmsg()
1899 // blocks we can enable this test to run in both rounds.
1900 abort ();
1902 int r = pthread_barrier_wait (&b2);
1903 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1905 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1906 exit (1);
1909 r = pthread_barrier_wait (&b2);
1910 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1912 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1913 exit (1);
1916 pthread_cleanup_push (cl, NULL);
1918 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1920 pthread_cleanup_pop (0);
1922 printf ("%s: creat returned\n", __FUNCTION__);
1924 exit (1);
1928 static void *
1929 tf_connect (void *arg)
1931 if (arg == NULL)
1932 // XXX If somebody can provide a portable test case in which connect()
1933 // blocks we can enable this test to run in both rounds.
1934 abort ();
1936 struct sockaddr_un sun;
1938 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1939 if (tempfd == -1)
1941 printf ("%s: first socket call failed\n", __FUNCTION__);
1942 exit (1);
1945 int tries = 0;
1948 if (++tries > 10)
1950 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1953 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1954 if (mktemp (sun.sun_path) == NULL)
1956 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1957 exit (1);
1960 sun.sun_family = AF_UNIX;
1962 while (bind (tempfd, (struct sockaddr *) &sun,
1963 offsetof (struct sockaddr_un, sun_path)
1964 + strlen (sun.sun_path) + 1) != 0);
1965 tempfname = strdup (sun.sun_path);
1967 listen (tempfd, 5);
1969 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1970 if (tempfd2 == -1)
1972 printf ("%s: second socket call failed\n", __FUNCTION__);
1973 exit (1);
1976 int r = pthread_barrier_wait (&b2);
1977 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1979 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1980 exit (1);
1983 if (arg != NULL)
1985 r = pthread_barrier_wait (&b2);
1986 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1988 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1989 exit (1);
1993 pthread_cleanup_push (cl, NULL);
1995 connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun));
1997 pthread_cleanup_pop (0);
1999 printf ("%s: connect returned\n", __FUNCTION__);
2001 exit (1);
2005 static void *
2006 tf_tcdrain (void *arg)
2008 if (arg == NULL)
2009 // XXX If somebody can provide a portable test case in which tcdrain()
2010 // blocks we can enable this test to run in both rounds.
2011 abort ();
2013 int r = pthread_barrier_wait (&b2);
2014 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2016 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2017 exit (1);
2020 if (arg != NULL)
2022 r = pthread_barrier_wait (&b2);
2023 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2025 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2026 exit (1);
2030 pthread_cleanup_push (cl, NULL);
2032 /* Regardless of stderr being a terminal, the tcdrain call should be
2033 canceled. */
2034 tcdrain (STDERR_FILENO);
2036 pthread_cleanup_pop (0);
2038 printf ("%s: tcdrain returned\n", __FUNCTION__);
2040 exit (1);
2044 static void *
2045 tf_msgrcv (void *arg)
2047 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
2048 if (tempmsg == -1)
2050 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2051 exit (1);
2054 int r = pthread_barrier_wait (&b2);
2055 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2057 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2058 exit (1);
2061 if (arg != NULL)
2063 r = pthread_barrier_wait (&b2);
2064 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2066 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2067 exit (1);
2071 ssize_t s;
2073 pthread_cleanup_push (cl, NULL);
2075 struct
2077 long int type;
2078 char mem[10];
2079 } m;
2080 int randnr;
2081 /* We need a positive random number. */
2083 randnr = random () % 64000;
2084 while (randnr <= 0);
2087 errno = 0;
2088 s = msgrcv (tempmsg, (struct msgbuf *) &m, 10, randnr, 0);
2090 while (errno == EIDRM || errno == EINTR);
2092 pthread_cleanup_pop (0);
2094 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__, s);
2096 msgctl (tempmsg, IPC_RMID, NULL);
2098 exit (1);
2102 static void *
2103 tf_msgsnd (void *arg)
2105 if (arg == NULL)
2106 // XXX If somebody can provide a portable test case in which msgsnd()
2107 // blocks we can enable this test to run in both rounds.
2108 abort ();
2110 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
2111 if (tempmsg == -1)
2113 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2114 exit (1);
2117 int r = pthread_barrier_wait (&b2);
2118 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2120 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2121 exit (1);
2124 r = pthread_barrier_wait (&b2);
2125 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2127 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2128 exit (1);
2131 pthread_cleanup_push (cl, NULL);
2133 struct
2135 long int type;
2136 char mem[1];
2137 } m;
2138 /* We need a positive random number. */
2140 m.type = random () % 64000;
2141 while (m.type <= 0);
2142 msgsnd (tempmsg, (struct msgbuf *) &m, sizeof (m.mem), 0);
2144 pthread_cleanup_pop (0);
2146 printf ("%s: msgsnd returned\n", __FUNCTION__);
2148 msgctl (tempmsg, IPC_RMID, NULL);
2150 exit (1);
2154 struct cancel_tests tests[] =
2156 ADD_TEST (read, 2, 0),
2157 ADD_TEST (readv, 2, 0),
2158 ADD_TEST (select, 2, 0),
2159 ADD_TEST (pselect, 2, 0),
2160 ADD_TEST (poll, 2, 0),
2161 ADD_TEST (ppoll, 2, 0),
2162 ADD_TEST (write, 2, 0),
2163 ADD_TEST (writev, 2, 0),
2164 ADD_TEST (sleep, 2, 0),
2165 ADD_TEST (usleep, 2, 0),
2166 ADD_TEST (nanosleep, 2, 0),
2167 ADD_TEST (wait, 2, 0),
2168 ADD_TEST (waitid, 2, 0),
2169 ADD_TEST (waitpid, 2, 0),
2170 ADD_TEST (sigpause, 2, 0),
2171 ADD_TEST (sigsuspend, 2, 0),
2172 ADD_TEST (sigwait, 2, 0),
2173 ADD_TEST (sigwaitinfo, 2, 0),
2174 ADD_TEST (sigtimedwait, 2, 0),
2175 ADD_TEST (pause, 2, 0),
2176 ADD_TEST (accept, 2, 0),
2177 ADD_TEST (send, 2, 0),
2178 ADD_TEST (recv, 2, 0),
2179 ADD_TEST (recvfrom, 2, 0),
2180 ADD_TEST (recvmsg, 2, 0),
2181 ADD_TEST (preadv, 2, 1),
2182 ADD_TEST (pwritev, 2, 1),
2183 ADD_TEST (open, 2, 1),
2184 ADD_TEST (close, 2, 1),
2185 ADD_TEST (pread, 2, 1),
2186 ADD_TEST (pwrite, 2, 1),
2187 ADD_TEST (fsync, 2, 1),
2188 ADD_TEST (fdatasync, 2, 1),
2189 ADD_TEST (msync, 2, 1),
2190 ADD_TEST (sendto, 2, 1),
2191 ADD_TEST (sendmsg, 2, 1),
2192 ADD_TEST (creat, 2, 1),
2193 ADD_TEST (connect, 2, 1),
2194 ADD_TEST (tcdrain, 2, 1),
2195 ADD_TEST (msgrcv, 2, 0),
2196 ADD_TEST (msgsnd, 2, 1),
2198 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2200 #include "tst-cancel4-common.c"