m68k: suppress -Wframe-address warning
[glibc.git] / nptl / tst-cancel4.c
blob4221af4bdf55bc23af9989f6ef8b35e62afe85ed
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. */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <sys/un.h>
28 #include <sys/ipc.h>
29 #include <sys/msg.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <pthread.h>
33 #include <fcntl.h>
34 #include <termios.h>
35 #include <sys/mman.h>
36 #include <sys/poll.h>
37 #include <sys/wait.h>
39 #include "pthreadP.h"
42 /* Since STREAMS are not supported in the standard Linux kernel and
43 there we don't advertise STREAMS as supported is no need to test
44 the STREAMS related functions. This affects
45 getmsg() getpmsg() putmsg()
46 putpmsg()
48 lockf() and fcntl() are tested in tst-cancel16.
50 pthread_join() is tested in tst-join5.
52 pthread_testcancel()'s only purpose is to allow cancellation. This
53 is tested in several places.
55 sem_wait() and sem_timedwait() are checked in tst-cancel1[2345] tests.
57 mq_send(), mq_timedsend(), mq_receive() and mq_timedreceive() are checked
58 in tst-mqueue8{,x} tests.
60 aio_suspend() is tested in tst-cancel17.
62 clock_nanosleep() is tested in tst-cancel18.
64 Linux sendmmsg and recvmmsg are checked in tst-cancel4_1.c and
65 tst-cancel4_2.c respectively.
68 #include "tst-cancel4-common.h"
70 #ifndef IPC_ADDVAL
71 # define IPC_ADDVAL 0
72 #endif
75 static void *
76 tf_read (void *arg)
78 int fd;
79 int r;
81 if (arg == NULL)
82 fd = fds[0];
83 else
85 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
86 tempfd = fd = mkstemp (fname);
87 if (fd == -1)
88 printf ("%s: mkstemp failed\n", __FUNCTION__);
89 unlink (fname);
91 r = pthread_barrier_wait (&b2);
92 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
94 printf ("%s: barrier_wait failed\n", __FUNCTION__);
95 exit (1);
99 r = pthread_barrier_wait (&b2);
100 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
102 printf ("%s: barrier_wait failed\n", __FUNCTION__);
103 exit (1);
106 ssize_t s;
107 pthread_cleanup_push (cl, NULL);
109 char buf[100];
110 s = read (fd, buf, sizeof (buf));
112 pthread_cleanup_pop (0);
114 printf ("%s: read returns with %zd\n", __FUNCTION__, s);
116 exit (1);
120 static void *
121 tf_readv (void *arg)
123 int fd;
124 int r;
126 if (arg == NULL)
127 fd = fds[0];
128 else
130 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
131 tempfd = fd = mkstemp (fname);
132 if (fd == -1)
133 printf ("%s: mkstemp failed\n", __FUNCTION__);
134 unlink (fname);
136 r = pthread_barrier_wait (&b2);
137 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
139 printf ("%s: barrier_wait failed\n", __FUNCTION__);
140 exit (1);
144 r = pthread_barrier_wait (&b2);
145 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
147 printf ("%s: barrier_wait failed\n", __FUNCTION__);
148 exit (1);
151 ssize_t s;
152 pthread_cleanup_push (cl, NULL);
154 char buf[100];
155 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
156 s = readv (fd, iov, 1);
158 pthread_cleanup_pop (0);
160 printf ("%s: readv returns with %zd\n", __FUNCTION__, s);
162 exit (1);
166 static void *
167 tf_write (void *arg)
169 int fd;
170 int r;
172 if (arg == NULL)
173 fd = fds[1];
174 else
176 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
177 tempfd = fd = mkstemp (fname);
178 if (fd == -1)
179 printf ("%s: mkstemp failed\n", __FUNCTION__);
180 unlink (fname);
182 r = pthread_barrier_wait (&b2);
183 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
185 printf ("%s: barrier_wait failed\n", __FUNCTION__);
186 exit (1);
190 r = pthread_barrier_wait (&b2);
191 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
193 printf ("%s: barrier_wait failed\n", __FUNCTION__);
194 exit (1);
197 ssize_t s;
198 pthread_cleanup_push (cl, NULL);
200 char buf[WRITE_BUFFER_SIZE];
201 memset (buf, '\0', sizeof (buf));
202 s = write (fd, buf, sizeof (buf));
204 pthread_cleanup_pop (0);
206 printf ("%s: write returns with %zd\n", __FUNCTION__, s);
208 exit (1);
212 static void *
213 tf_writev (void *arg)
215 int fd;
216 int r;
218 if (arg == NULL)
219 fd = fds[1];
220 else
222 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
223 tempfd = fd = mkstemp (fname);
224 if (fd == -1)
225 printf ("%s: mkstemp failed\n", __FUNCTION__);
226 unlink (fname);
228 r = pthread_barrier_wait (&b2);
229 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
231 printf ("%s: barrier_wait failed\n", __FUNCTION__);
232 exit (1);
236 r = pthread_barrier_wait (&b2);
237 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
239 printf ("%s: barrier_wait failed\n", __FUNCTION__);
240 exit (1);
243 ssize_t s;
244 pthread_cleanup_push (cl, NULL);
246 char buf[WRITE_BUFFER_SIZE];
247 memset (buf, '\0', sizeof (buf));
248 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
249 s = writev (fd, iov, 1);
251 pthread_cleanup_pop (0);
253 printf ("%s: writev returns with %zd\n", __FUNCTION__, s);
255 exit (1);
259 static void *
260 tf_sleep (void *arg)
262 int r = pthread_barrier_wait (&b2);
263 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
265 printf ("%s: barrier_wait failed\n", __FUNCTION__);
266 exit (1);
269 if (arg != NULL)
271 r = pthread_barrier_wait (&b2);
272 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
274 printf ("%s: barrier_wait failed\n", __FUNCTION__);
275 exit (1);
279 pthread_cleanup_push (cl, NULL);
281 sleep (arg == NULL ? 1000000 : 0);
283 pthread_cleanup_pop (0);
285 printf ("%s: sleep returns\n", __FUNCTION__);
287 exit (1);
291 static void *
292 tf_usleep (void *arg)
294 int r = pthread_barrier_wait (&b2);
295 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
297 printf ("%s: barrier_wait failed\n", __FUNCTION__);
298 exit (1);
301 if (arg != NULL)
303 r = pthread_barrier_wait (&b2);
304 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
306 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
307 exit (1);
311 pthread_cleanup_push (cl, NULL);
313 usleep (arg == NULL ? (useconds_t) ULONG_MAX : 0);
315 pthread_cleanup_pop (0);
317 printf ("%s: usleep returns\n", __FUNCTION__);
319 exit (1);
323 static void *
324 tf_nanosleep (void *arg)
326 int r = pthread_barrier_wait (&b2);
327 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
329 printf ("%s: barrier_wait failed\n", __FUNCTION__);
330 exit (1);
333 if (arg != NULL)
335 r = pthread_barrier_wait (&b2);
336 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
338 printf ("%s: barrier_wait failed\n", __FUNCTION__);
339 exit (1);
343 pthread_cleanup_push (cl, NULL);
345 struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 };
346 TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
348 pthread_cleanup_pop (0);
350 printf ("%s: nanosleep returns\n", __FUNCTION__);
352 exit (1);
356 static void *
357 tf_select (void *arg)
359 int fd;
360 int r;
362 if (arg == NULL)
363 fd = fds[0];
364 else
366 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
367 tempfd = fd = mkstemp (fname);
368 if (fd == -1)
369 printf ("%s: mkstemp failed\n", __FUNCTION__);
370 unlink (fname);
372 r = pthread_barrier_wait (&b2);
373 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
375 printf ("%s: barrier_wait failed\n", __FUNCTION__);
376 exit (1);
380 r = pthread_barrier_wait (&b2);
381 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
383 printf ("%s: barrier_wait failed\n", __FUNCTION__);
384 exit (1);
387 fd_set rfs;
388 FD_ZERO (&rfs);
389 FD_SET (fd, &rfs);
391 int s;
392 pthread_cleanup_push (cl, NULL);
394 s = select (fd + 1, &rfs, NULL, NULL, NULL);
396 pthread_cleanup_pop (0);
398 printf ("%s: select returns with %d (%s)\n", __FUNCTION__, s,
399 strerror (errno));
401 exit (1);
405 static void *
406 tf_pselect (void *arg)
408 int fd;
409 int r;
411 if (arg == NULL)
412 fd = fds[0];
413 else
415 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
416 tempfd = fd = mkstemp (fname);
417 if (fd == -1)
418 printf ("%s: mkstemp failed\n", __FUNCTION__);
419 unlink (fname);
421 r = pthread_barrier_wait (&b2);
422 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
424 printf ("%s: barrier_wait failed\n", __FUNCTION__);
425 exit (1);
429 r = pthread_barrier_wait (&b2);
430 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
432 printf ("%s: barrier_wait failed\n", __FUNCTION__);
433 exit (1);
436 fd_set rfs;
437 FD_ZERO (&rfs);
438 FD_SET (fd, &rfs);
440 int s;
441 pthread_cleanup_push (cl, NULL);
443 s = pselect (fd + 1, &rfs, NULL, NULL, NULL, NULL);
445 pthread_cleanup_pop (0);
447 printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__, s,
448 strerror (errno));
450 exit (1);
454 static void *
455 tf_poll (void *arg)
457 int fd;
458 int r;
460 if (arg == NULL)
461 fd = fds[0];
462 else
464 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
465 tempfd = fd = mkstemp (fname);
466 if (fd == -1)
467 printf ("%s: mkstemp failed\n", __FUNCTION__);
468 unlink (fname);
470 r = pthread_barrier_wait (&b2);
471 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
473 printf ("%s: barrier_wait failed\n", __FUNCTION__);
474 exit (1);
478 r = pthread_barrier_wait (&b2);
479 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
481 printf ("%s: barrier_wait failed\n", __FUNCTION__);
482 exit (1);
485 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
487 int s;
488 pthread_cleanup_push (cl, NULL);
490 s = poll (rfs, 1, -1);
492 pthread_cleanup_pop (0);
494 printf ("%s: poll returns with %d (%s)\n", __FUNCTION__, s,
495 strerror (errno));
497 exit (1);
501 static void *
502 tf_ppoll (void *arg)
504 int fd;
505 int r;
507 if (arg == NULL)
508 fd = fds[0];
509 else
511 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
512 tempfd = fd = mkstemp (fname);
513 if (fd == -1)
514 printf ("%s: mkstemp failed\n", __FUNCTION__);
515 unlink (fname);
517 r = pthread_barrier_wait (&b2);
518 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
520 printf ("%s: barrier_wait failed\n", __FUNCTION__);
521 exit (1);
525 r = pthread_barrier_wait (&b2);
526 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
528 printf ("%s: barrier_wait failed\n", __FUNCTION__);
529 exit (1);
532 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
534 int s;
535 pthread_cleanup_push (cl, NULL);
537 s = ppoll (rfs, 1, NULL, NULL);
539 pthread_cleanup_pop (0);
541 printf ("%s: ppoll returns with %d (%s)\n", __FUNCTION__, s,
542 strerror (errno));
544 exit (1);
548 static void *
549 tf_wait (void *arg)
551 pid_t pid = fork ();
552 if (pid == -1)
554 puts ("fork failed");
555 exit (1);
558 if (pid == 0)
560 /* Make the program disappear after a while. */
561 if (arg == NULL)
562 sleep (10);
563 exit (0);
566 int r;
567 if (arg != NULL)
569 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
570 while (nanosleep (&ts, &ts) != 0)
571 continue;
573 r = pthread_barrier_wait (&b2);
574 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
576 printf ("%s: barrier_wait failed\n", __FUNCTION__);
577 exit (1);
581 r = pthread_barrier_wait (&b2);
582 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
584 printf ("%s: barrier_wait failed\n", __FUNCTION__);
585 exit (1);
588 int s;
589 pthread_cleanup_push (cl, NULL);
591 s = wait (NULL);
593 pthread_cleanup_pop (0);
595 printf ("%s: wait returns with %d (%s)\n", __FUNCTION__, s,
596 strerror (errno));
598 exit (1);
602 static void *
603 tf_waitpid (void *arg)
606 pid_t pid = fork ();
607 if (pid == -1)
609 puts ("fork failed");
610 exit (1);
613 if (pid == 0)
615 /* Make the program disappear after a while. */
616 if (arg == NULL)
617 sleep (10);
618 exit (0);
621 int r;
622 if (arg != NULL)
624 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
625 while (nanosleep (&ts, &ts) != 0)
626 continue;
628 r = pthread_barrier_wait (&b2);
629 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
631 printf ("%s: barrier_wait failed\n", __FUNCTION__);
632 exit (1);
636 r = pthread_barrier_wait (&b2);
637 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
639 printf ("%s: barrier_wait failed\n", __FUNCTION__);
640 exit (1);
643 int s;
644 pthread_cleanup_push (cl, NULL);
646 s = waitpid (-1, NULL, 0);
648 pthread_cleanup_pop (0);
650 printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__, s,
651 strerror (errno));
653 exit (1);
657 static void *
658 tf_waitid (void *arg)
660 pid_t pid = fork ();
661 if (pid == -1)
663 puts ("fork failed");
664 exit (1);
667 if (pid == 0)
669 /* Make the program disappear after a while. */
670 if (arg == NULL)
671 sleep (10);
672 exit (0);
675 int r;
676 if (arg != NULL)
678 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
679 while (nanosleep (&ts, &ts) != 0)
680 continue;
682 r = pthread_barrier_wait (&b2);
683 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
685 printf ("%s: barrier_wait failed\n", __FUNCTION__);
686 exit (1);
690 r = pthread_barrier_wait (&b2);
691 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
693 printf ("%s: barrier_wait failed\n", __FUNCTION__);
694 exit (1);
697 int s;
698 pthread_cleanup_push (cl, NULL);
700 #ifndef WEXITED
701 # define WEXITED 0
702 #endif
703 siginfo_t si;
704 s = waitid (P_PID, pid, &si, WEXITED);
706 pthread_cleanup_pop (0);
708 printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__, s,
709 strerror (errno));
711 exit (1);
715 static void *
716 tf_sigpause (void *arg)
718 int r = pthread_barrier_wait (&b2);
719 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
721 printf ("%s: barrier_wait failed\n", __FUNCTION__);
722 exit (1);
725 if (arg != NULL)
727 r = pthread_barrier_wait (&b2);
728 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
730 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
731 exit (1);
735 pthread_cleanup_push (cl, NULL);
737 #ifdef SIGCANCEL
738 /* Just for fun block the cancellation signal. We need to use
739 __xpg_sigpause since otherwise we will get the BSD version. */
740 __xpg_sigpause (SIGCANCEL);
741 #else
742 pause ();
743 #endif
745 pthread_cleanup_pop (0);
747 printf ("%s: sigpause returned\n", __FUNCTION__);
749 exit (1);
753 static void *
754 tf_sigsuspend (void *arg)
756 int r = pthread_barrier_wait (&b2);
757 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
759 printf ("%s: barrier_wait failed\n", __FUNCTION__);
760 exit (1);
763 if (arg != NULL)
765 r = pthread_barrier_wait (&b2);
766 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
768 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
769 exit (1);
773 pthread_cleanup_push (cl, NULL);
775 /* Just for fun block all signals. */
776 sigset_t mask;
777 sigfillset (&mask);
778 sigsuspend (&mask);
780 pthread_cleanup_pop (0);
782 printf ("%s: sigsuspend returned\n", __FUNCTION__);
784 exit (1);
788 static void *
789 tf_sigwait (void *arg)
791 int r = pthread_barrier_wait (&b2);
792 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
794 printf ("%s: barrier_wait failed\n", __FUNCTION__);
795 exit (1);
798 if (arg != NULL)
800 r = pthread_barrier_wait (&b2);
801 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
803 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
804 exit (1);
808 /* Block SIGUSR1. */
809 sigset_t mask;
810 sigemptyset (&mask);
811 sigaddset (&mask, SIGUSR1);
812 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
814 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
815 exit (1);
818 int sig;
819 pthread_cleanup_push (cl, NULL);
821 /* Wait for SIGUSR1. */
822 sigwait (&mask, &sig);
824 pthread_cleanup_pop (0);
826 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__, sig);
828 exit (1);
832 static void *
833 tf_sigwaitinfo (void *arg)
835 int r = pthread_barrier_wait (&b2);
836 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
838 printf ("%s: barrier_wait failed\n", __FUNCTION__);
839 exit (1);
842 if (arg != NULL)
844 r = pthread_barrier_wait (&b2);
845 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
847 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
848 exit (1);
852 /* Block SIGUSR1. */
853 sigset_t mask;
854 sigemptyset (&mask);
855 sigaddset (&mask, SIGUSR1);
856 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
858 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
859 exit (1);
862 siginfo_t info;
863 pthread_cleanup_push (cl, NULL);
865 /* Wait for SIGUSR1. */
866 sigwaitinfo (&mask, &info);
868 pthread_cleanup_pop (0);
870 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__,
871 info.si_signo);
873 exit (1);
877 static void *
878 tf_sigtimedwait (void *arg)
880 int r = pthread_barrier_wait (&b2);
881 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
883 printf ("%s: barrier_wait failed\n", __FUNCTION__);
884 exit (1);
887 if (arg != NULL)
889 r = pthread_barrier_wait (&b2);
890 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
892 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
893 exit (1);
897 /* Block SIGUSR1. */
898 sigset_t mask;
899 sigemptyset (&mask);
900 sigaddset (&mask, SIGUSR1);
901 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
903 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
904 exit (1);
907 /* Wait for SIGUSR1. */
908 siginfo_t info;
909 struct timespec ts = { .tv_sec = 60, .tv_nsec = 0 };
910 pthread_cleanup_push (cl, NULL);
912 sigtimedwait (&mask, &info, &ts);
914 pthread_cleanup_pop (0);
916 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__,
917 info.si_signo);
919 exit (1);
923 static void *
924 tf_pause (void *arg)
926 int r = pthread_barrier_wait (&b2);
927 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
929 printf ("%s: barrier_wait failed\n", __FUNCTION__);
930 exit (1);
933 if (arg != NULL)
935 r = pthread_barrier_wait (&b2);
936 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
938 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
939 exit (1);
943 pthread_cleanup_push (cl, NULL);
945 pause ();
947 pthread_cleanup_pop (0);
949 printf ("%s: pause returned\n", __FUNCTION__);
951 exit (1);
955 static void *
956 tf_accept (void *arg)
958 struct sockaddr_un sun;
959 /* To test a non-blocking accept call we make the call file by using
960 a datagrame socket. */
961 int pf = arg == NULL ? SOCK_STREAM : SOCK_DGRAM;
963 tempfd = socket (AF_UNIX, pf, 0);
964 if (tempfd == -1)
966 printf ("%s: socket call failed\n", __FUNCTION__);
967 exit (1);
970 int tries = 0;
973 if (++tries > 10)
975 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
978 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
979 if (mktemp (sun.sun_path) == NULL)
981 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
982 exit (1);
985 sun.sun_family = AF_UNIX;
987 while (bind (tempfd, (struct sockaddr *) &sun,
988 offsetof (struct sockaddr_un, sun_path)
989 + strlen (sun.sun_path) + 1) != 0);
991 unlink (sun.sun_path);
993 listen (tempfd, 5);
995 socklen_t len = sizeof (sun);
997 int r = pthread_barrier_wait (&b2);
998 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1000 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1001 exit (1);
1004 if (arg != NULL)
1006 r = pthread_barrier_wait (&b2);
1007 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1009 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1010 exit (1);
1014 pthread_cleanup_push (cl, NULL);
1016 accept (tempfd, (struct sockaddr *) &sun, &len);
1018 pthread_cleanup_pop (0);
1020 printf ("%s: accept returned\n", __FUNCTION__);
1022 exit (1);
1026 static void *
1027 tf_send (void *arg)
1029 struct sockaddr_un sun;
1031 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1032 if (tempfd == -1)
1034 printf ("%s: first socket call failed\n", __FUNCTION__);
1035 exit (1);
1038 int tries = 0;
1041 if (++tries > 10)
1043 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1046 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1047 if (mktemp (sun.sun_path) == NULL)
1049 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1050 exit (1);
1053 sun.sun_family = AF_UNIX;
1055 while (bind (tempfd, (struct sockaddr *) &sun,
1056 offsetof (struct sockaddr_un, sun_path)
1057 + strlen (sun.sun_path) + 1) != 0);
1059 listen (tempfd, 5);
1061 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1062 if (tempfd2 == -1)
1064 printf ("%s: second socket call failed\n", __FUNCTION__);
1065 exit (1);
1068 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1070 printf ("%s: connect failed\n", __FUNCTION__);
1071 exit(1);
1074 unlink (sun.sun_path);
1076 int r = pthread_barrier_wait (&b2);
1077 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1079 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1080 exit (1);
1083 if (arg != NULL)
1085 r = pthread_barrier_wait (&b2);
1086 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1088 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1089 exit (1);
1093 pthread_cleanup_push (cl, NULL);
1095 /* Very large block, so that the send call blocks. */
1096 char mem[700000];
1098 send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
1100 pthread_cleanup_pop (0);
1102 printf ("%s: send returned\n", __FUNCTION__);
1104 exit (1);
1108 static void *
1109 tf_recv (void *arg)
1111 struct sockaddr_un sun;
1113 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1114 if (tempfd == -1)
1116 printf ("%s: first socket call failed\n", __FUNCTION__);
1117 exit (1);
1120 int tries = 0;
1123 if (++tries > 10)
1125 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1128 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX");
1129 if (mktemp (sun.sun_path) == NULL)
1131 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1132 exit (1);
1135 sun.sun_family = AF_UNIX;
1137 while (bind (tempfd, (struct sockaddr *) &sun,
1138 offsetof (struct sockaddr_un, sun_path)
1139 + strlen (sun.sun_path) + 1) != 0);
1141 listen (tempfd, 5);
1143 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1144 if (tempfd2 == -1)
1146 printf ("%s: second socket call failed\n", __FUNCTION__);
1147 exit (1);
1150 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1152 printf ("%s: connect failed\n", __FUNCTION__);
1153 exit(1);
1156 unlink (sun.sun_path);
1158 int r = pthread_barrier_wait (&b2);
1159 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1161 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1162 exit (1);
1165 if (arg != NULL)
1167 r = pthread_barrier_wait (&b2);
1168 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1170 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1171 exit (1);
1175 pthread_cleanup_push (cl, NULL);
1177 char mem[70];
1179 recv (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0);
1181 pthread_cleanup_pop (0);
1183 printf ("%s: recv returned\n", __FUNCTION__);
1185 exit (1);
1189 static void *
1190 tf_recvfrom (void *arg)
1192 struct sockaddr_un sun;
1194 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1195 if (tempfd == -1)
1197 printf ("%s: first socket call failed\n", __FUNCTION__);
1198 exit (1);
1201 int tries = 0;
1204 if (++tries > 10)
1206 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1209 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX");
1210 if (mktemp (sun.sun_path) == NULL)
1212 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1213 exit (1);
1216 sun.sun_family = AF_UNIX;
1218 while (bind (tempfd, (struct sockaddr *) &sun,
1219 offsetof (struct sockaddr_un, sun_path)
1220 + strlen (sun.sun_path) + 1) != 0);
1222 tempfname = strdup (sun.sun_path);
1224 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1225 if (tempfd2 == -1)
1227 printf ("%s: second socket call failed\n", __FUNCTION__);
1228 exit (1);
1231 int r = pthread_barrier_wait (&b2);
1232 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1234 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1235 exit (1);
1238 if (arg != NULL)
1240 r = pthread_barrier_wait (&b2);
1241 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1243 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1244 exit (1);
1248 pthread_cleanup_push (cl, NULL);
1250 char mem[70];
1251 socklen_t len = sizeof (sun);
1253 recvfrom (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0,
1254 (struct sockaddr *) &sun, &len);
1256 pthread_cleanup_pop (0);
1258 printf ("%s: recvfrom returned\n", __FUNCTION__);
1260 exit (1);
1264 static void *
1265 tf_recvmsg (void *arg)
1267 struct sockaddr_un sun;
1269 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1270 if (tempfd == -1)
1272 printf ("%s: first socket call failed\n", __FUNCTION__);
1273 exit (1);
1276 int tries = 0;
1279 if (++tries > 10)
1281 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1284 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
1285 if (mktemp (sun.sun_path) == NULL)
1287 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1288 exit (1);
1291 sun.sun_family = AF_UNIX;
1293 while (bind (tempfd, (struct sockaddr *) &sun,
1294 offsetof (struct sockaddr_un, sun_path)
1295 + strlen (sun.sun_path) + 1) != 0);
1297 tempfname = strdup (sun.sun_path);
1299 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1300 if (tempfd2 == -1)
1302 printf ("%s: second socket call failed\n", __FUNCTION__);
1303 exit (1);
1306 int r = pthread_barrier_wait (&b2);
1307 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1309 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1310 exit (1);
1313 if (arg != NULL)
1315 r = pthread_barrier_wait (&b2);
1316 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1318 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1319 exit (1);
1323 pthread_cleanup_push (cl, NULL);
1325 char mem[70];
1326 struct iovec iov[1];
1327 iov[0].iov_base = mem;
1328 iov[0].iov_len = arg == NULL ? sizeof (mem) : 0;
1330 struct msghdr m;
1331 m.msg_name = &sun;
1332 m.msg_namelen = sizeof (sun);
1333 m.msg_iov = iov;
1334 m.msg_iovlen = 1;
1335 m.msg_control = NULL;
1336 m.msg_controllen = 0;
1338 recvmsg (tempfd2, &m, 0);
1340 pthread_cleanup_pop (0);
1342 printf ("%s: recvmsg returned\n", __FUNCTION__);
1344 exit (1);
1347 static void *
1348 tf_open (void *arg)
1350 if (arg == NULL)
1351 // XXX If somebody can provide a portable test case in which open()
1352 // blocks we can enable this test to run in both rounds.
1353 abort ();
1355 int r = pthread_barrier_wait (&b2);
1356 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1358 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1359 exit (1);
1362 r = pthread_barrier_wait (&b2);
1363 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1365 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1366 exit (1);
1369 pthread_cleanup_push (cl, NULL);
1371 open ("Makefile", O_RDONLY);
1373 pthread_cleanup_pop (0);
1375 printf ("%s: open returned\n", __FUNCTION__);
1377 exit (1);
1381 static void *
1382 tf_close (void *arg)
1384 if (arg == NULL)
1385 // XXX If somebody can provide a portable test case in which close()
1386 // blocks we can enable this test to run in both rounds.
1387 abort ();
1389 char fname[] = "/tmp/tst-cancel-fd-XXXXXX";
1390 tempfd = mkstemp (fname);
1391 if (tempfd == -1)
1393 printf ("%s: mkstemp failed\n", __FUNCTION__);
1394 exit (1);
1396 unlink (fname);
1398 int r = pthread_barrier_wait (&b2);
1399 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1401 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1402 exit (1);
1405 r = pthread_barrier_wait (&b2);
1406 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1408 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1409 exit (1);
1412 pthread_cleanup_push (cl, NULL);
1414 close (tempfd);
1416 pthread_cleanup_pop (0);
1418 printf ("%s: close returned\n", __FUNCTION__);
1420 exit (1);
1424 static void *
1425 tf_pread (void *arg)
1427 if (arg == NULL)
1428 // XXX If somebody can provide a portable test case in which pread()
1429 // blocks we can enable this test to run in both rounds.
1430 abort ();
1432 tempfd = open ("Makefile", O_RDONLY);
1433 if (tempfd == -1)
1435 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1436 exit (1);
1439 int r = pthread_barrier_wait (&b2);
1440 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1442 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1443 exit (1);
1446 r = pthread_barrier_wait (&b2);
1447 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1449 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1450 exit (1);
1453 pthread_cleanup_push (cl, NULL);
1455 char mem[10];
1456 pread (tempfd, mem, sizeof (mem), 0);
1458 pthread_cleanup_pop (0);
1460 printf ("%s: pread returned\n", __FUNCTION__);
1462 exit (1);
1466 static void *
1467 tf_pwrite (void *arg)
1469 if (arg == NULL)
1470 // XXX If somebody can provide a portable test case in which pwrite()
1471 // blocks we can enable this test to run in both rounds.
1472 abort ();
1474 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1475 tempfd = mkstemp (fname);
1476 if (tempfd == -1)
1478 printf ("%s: mkstemp failed\n", __FUNCTION__);
1479 exit (1);
1481 unlink (fname);
1483 int r = pthread_barrier_wait (&b2);
1484 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1486 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1487 exit (1);
1490 r = pthread_barrier_wait (&b2);
1491 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1493 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1494 exit (1);
1497 pthread_cleanup_push (cl, NULL);
1499 char mem[10];
1500 pwrite (tempfd, mem, sizeof (mem), 0);
1502 pthread_cleanup_pop (0);
1504 printf ("%s: pwrite returned\n", __FUNCTION__);
1506 exit (1);
1509 static void *
1510 tf_preadv (void *arg)
1512 int fd;
1513 int r;
1515 if (arg == NULL)
1516 /* XXX If somebody can provide a portable test case in which preadv
1517 blocks we can enable this test to run in both rounds. */
1518 abort ();
1520 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1521 tempfd = fd = mkstemp (fname);
1522 if (fd == -1)
1523 printf ("%s: mkstemp failed\n", __FUNCTION__);
1524 unlink (fname);
1526 r = pthread_barrier_wait (&b2);
1527 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1529 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1530 exit (1);
1533 r = pthread_barrier_wait (&b2);
1534 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1536 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1537 exit (1);
1540 ssize_t s;
1541 pthread_cleanup_push (cl, NULL);
1543 char buf[100];
1544 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
1545 s = preadv (fd, iov, 1, 0);
1547 pthread_cleanup_pop (0);
1549 printf ("%s: preadv returns with %zd\n", __FUNCTION__, s);
1551 exit (1);
1554 static void *
1555 tf_pwritev (void *arg)
1557 int fd;
1558 int r;
1560 if (arg == NULL)
1561 /* XXX If somebody can provide a portable test case in which pwritev
1562 blocks we can enable this test to run in both rounds. */
1563 abort ();
1565 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1566 tempfd = fd = mkstemp (fname);
1567 if (fd == -1)
1568 printf ("%s: mkstemp failed\n", __FUNCTION__);
1569 unlink (fname);
1571 r = pthread_barrier_wait (&b2);
1572 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1574 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1575 exit (1);
1578 r = pthread_barrier_wait (&b2);
1579 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1581 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1582 exit (1);
1585 ssize_t s;
1586 pthread_cleanup_push (cl, NULL);
1588 char buf[WRITE_BUFFER_SIZE];
1589 memset (buf, '\0', sizeof (buf));
1590 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
1591 s = pwritev (fd, iov, 1, 0);
1593 pthread_cleanup_pop (0);
1595 printf ("%s: pwritev returns with %zd\n", __FUNCTION__, s);
1597 exit (1);
1600 static void *
1601 tf_fsync (void *arg)
1603 if (arg == NULL)
1604 // XXX If somebody can provide a portable test case in which fsync()
1605 // blocks we can enable this test to run in both rounds.
1606 abort ();
1608 tempfd = open ("Makefile", O_RDONLY);
1609 if (tempfd == -1)
1611 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1612 exit (1);
1615 int r = pthread_barrier_wait (&b2);
1616 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1618 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1619 exit (1);
1622 r = pthread_barrier_wait (&b2);
1623 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1625 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1626 exit (1);
1629 pthread_cleanup_push (cl, NULL);
1631 fsync (tempfd);
1633 pthread_cleanup_pop (0);
1635 printf ("%s: fsync returned\n", __FUNCTION__);
1637 exit (1);
1641 static void *
1642 tf_fdatasync (void *arg)
1644 if (arg == NULL)
1645 // XXX If somebody can provide a portable test case in which fdatasync()
1646 // blocks we can enable this test to run in both rounds.
1647 abort ();
1649 tempfd = open ("Makefile", O_RDONLY);
1650 if (tempfd == -1)
1652 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1653 exit (1);
1656 int r = pthread_barrier_wait (&b2);
1657 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1659 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1660 exit (1);
1663 r = pthread_barrier_wait (&b2);
1664 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1666 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1667 exit (1);
1670 pthread_cleanup_push (cl, NULL);
1672 fdatasync (tempfd);
1674 pthread_cleanup_pop (0);
1676 printf ("%s: fdatasync returned\n", __FUNCTION__);
1678 exit (1);
1682 static void *
1683 tf_msync (void *arg)
1685 if (arg == NULL)
1686 // XXX If somebody can provide a portable test case in which msync()
1687 // blocks we can enable this test to run in both rounds.
1688 abort ();
1690 tempfd = open ("Makefile", O_RDONLY);
1691 if (tempfd == -1)
1693 printf ("%s: cannot open Makefile\n", __FUNCTION__);
1694 exit (1);
1696 void *p = mmap (NULL, 10, PROT_READ, MAP_SHARED, tempfd, 0);
1697 if (p == MAP_FAILED)
1699 printf ("%s: mmap failed\n", __FUNCTION__);
1700 exit (1);
1703 int r = pthread_barrier_wait (&b2);
1704 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1706 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1707 exit (1);
1710 r = pthread_barrier_wait (&b2);
1711 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1713 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1714 exit (1);
1717 pthread_cleanup_push (cl, NULL);
1719 msync (p, 10, 0);
1721 pthread_cleanup_pop (0);
1723 printf ("%s: msync returned\n", __FUNCTION__);
1725 exit (1);
1729 static void *
1730 tf_sendto (void *arg)
1732 if (arg == NULL)
1733 // XXX If somebody can provide a portable test case in which sendto()
1734 // blocks we can enable this test to run in both rounds.
1735 abort ();
1737 struct sockaddr_un sun;
1739 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1740 if (tempfd == -1)
1742 printf ("%s: first socket call failed\n", __FUNCTION__);
1743 exit (1);
1746 int tries = 0;
1749 if (++tries > 10)
1751 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1754 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX");
1755 if (mktemp (sun.sun_path) == NULL)
1757 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1758 exit (1);
1761 sun.sun_family = AF_UNIX;
1763 while (bind (tempfd, (struct sockaddr *) &sun,
1764 offsetof (struct sockaddr_un, sun_path)
1765 + strlen (sun.sun_path) + 1) != 0);
1766 tempfname = strdup (sun.sun_path);
1768 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1769 if (tempfd2 == -1)
1771 printf ("%s: second socket call failed\n", __FUNCTION__);
1772 exit (1);
1775 int r = pthread_barrier_wait (&b2);
1776 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1778 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1779 exit (1);
1782 r = pthread_barrier_wait (&b2);
1783 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1785 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1786 exit (1);
1789 pthread_cleanup_push (cl, NULL);
1791 char mem[1];
1793 sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0,
1794 (struct sockaddr *) &sun,
1795 offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1);
1797 pthread_cleanup_pop (0);
1799 printf ("%s: sendto returned\n", __FUNCTION__);
1801 exit (1);
1805 static void *
1806 tf_sendmsg (void *arg)
1808 if (arg == NULL)
1809 // XXX If somebody can provide a portable test case in which sendmsg()
1810 // blocks we can enable this test to run in both rounds.
1811 abort ();
1813 struct sockaddr_un sun;
1815 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1816 if (tempfd == -1)
1818 printf ("%s: first socket call failed\n", __FUNCTION__);
1819 exit (1);
1822 int tries = 0;
1825 if (++tries > 10)
1827 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1830 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
1831 if (mktemp (sun.sun_path) == NULL)
1833 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1834 exit (1);
1837 sun.sun_family = AF_UNIX;
1839 while (bind (tempfd, (struct sockaddr *) &sun,
1840 offsetof (struct sockaddr_un, sun_path)
1841 + strlen (sun.sun_path) + 1) != 0);
1842 tempfname = strdup (sun.sun_path);
1844 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1845 if (tempfd2 == -1)
1847 printf ("%s: second socket call failed\n", __FUNCTION__);
1848 exit (1);
1851 int r = pthread_barrier_wait (&b2);
1852 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1854 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1855 exit (1);
1858 r = pthread_barrier_wait (&b2);
1859 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1861 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1862 exit (1);
1865 pthread_cleanup_push (cl, NULL);
1867 char mem[1];
1868 struct iovec iov[1];
1869 iov[0].iov_base = mem;
1870 iov[0].iov_len = 1;
1872 struct msghdr m;
1873 m.msg_name = &sun;
1874 m.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
1875 + strlen (sun.sun_path) + 1);
1876 m.msg_iov = iov;
1877 m.msg_iovlen = 1;
1878 m.msg_control = NULL;
1879 m.msg_controllen = 0;
1881 sendmsg (tempfd2, &m, 0);
1883 pthread_cleanup_pop (0);
1885 printf ("%s: sendmsg returned\n", __FUNCTION__);
1887 exit (1);
1891 static void *
1892 tf_creat (void *arg)
1894 if (arg == NULL)
1895 // XXX If somebody can provide a portable test case in which sendmsg()
1896 // blocks we can enable this test to run in both rounds.
1897 abort ();
1899 int r = pthread_barrier_wait (&b2);
1900 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1902 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1903 exit (1);
1906 r = pthread_barrier_wait (&b2);
1907 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1909 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1910 exit (1);
1913 pthread_cleanup_push (cl, NULL);
1915 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1917 pthread_cleanup_pop (0);
1919 printf ("%s: creat returned\n", __FUNCTION__);
1921 exit (1);
1925 static void *
1926 tf_connect (void *arg)
1928 if (arg == NULL)
1929 // XXX If somebody can provide a portable test case in which connect()
1930 // blocks we can enable this test to run in both rounds.
1931 abort ();
1933 struct sockaddr_un sun;
1935 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1936 if (tempfd == -1)
1938 printf ("%s: first socket call failed\n", __FUNCTION__);
1939 exit (1);
1942 int tries = 0;
1945 if (++tries > 10)
1947 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1950 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1951 if (mktemp (sun.sun_path) == NULL)
1953 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1954 exit (1);
1957 sun.sun_family = AF_UNIX;
1959 while (bind (tempfd, (struct sockaddr *) &sun,
1960 offsetof (struct sockaddr_un, sun_path)
1961 + strlen (sun.sun_path) + 1) != 0);
1962 tempfname = strdup (sun.sun_path);
1964 listen (tempfd, 5);
1966 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1967 if (tempfd2 == -1)
1969 printf ("%s: second socket call failed\n", __FUNCTION__);
1970 exit (1);
1973 int r = pthread_barrier_wait (&b2);
1974 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1976 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1977 exit (1);
1980 if (arg != NULL)
1982 r = pthread_barrier_wait (&b2);
1983 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1985 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1986 exit (1);
1990 pthread_cleanup_push (cl, NULL);
1992 connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun));
1994 pthread_cleanup_pop (0);
1996 printf ("%s: connect returned\n", __FUNCTION__);
1998 exit (1);
2002 static void *
2003 tf_tcdrain (void *arg)
2005 if (arg == NULL)
2006 // XXX If somebody can provide a portable test case in which tcdrain()
2007 // blocks we can enable this test to run in both rounds.
2008 abort ();
2010 int r = pthread_barrier_wait (&b2);
2011 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2013 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2014 exit (1);
2017 if (arg != NULL)
2019 r = pthread_barrier_wait (&b2);
2020 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2022 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2023 exit (1);
2027 pthread_cleanup_push (cl, NULL);
2029 /* Regardless of stderr being a terminal, the tcdrain call should be
2030 canceled. */
2031 tcdrain (STDERR_FILENO);
2033 pthread_cleanup_pop (0);
2035 printf ("%s: tcdrain returned\n", __FUNCTION__);
2037 exit (1);
2041 static void *
2042 tf_msgrcv (void *arg)
2044 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
2045 if (tempmsg == -1)
2047 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2048 exit (1);
2051 int r = pthread_barrier_wait (&b2);
2052 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2054 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2055 exit (1);
2058 if (arg != NULL)
2060 r = pthread_barrier_wait (&b2);
2061 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2063 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2064 exit (1);
2068 ssize_t s;
2070 pthread_cleanup_push (cl, NULL);
2072 struct
2074 long int type;
2075 char mem[10];
2076 } m;
2077 int randnr;
2078 /* We need a positive random number. */
2080 randnr = random () % 64000;
2081 while (randnr <= 0);
2084 errno = 0;
2085 s = msgrcv (tempmsg, (struct msgbuf *) &m, 10, randnr, 0);
2087 while (errno == EIDRM || errno == EINTR);
2089 pthread_cleanup_pop (0);
2091 printf ("%s: msgrcv returned %zd with errno = %m\n", __FUNCTION__, s);
2093 msgctl (tempmsg, IPC_RMID, NULL);
2095 exit (1);
2099 static void *
2100 tf_msgsnd (void *arg)
2102 if (arg == NULL)
2103 // XXX If somebody can provide a portable test case in which msgsnd()
2104 // blocks we can enable this test to run in both rounds.
2105 abort ();
2107 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
2108 if (tempmsg == -1)
2110 printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno));
2111 exit (1);
2114 int r = pthread_barrier_wait (&b2);
2115 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2117 printf ("%s: barrier_wait failed\n", __FUNCTION__);
2118 exit (1);
2121 r = pthread_barrier_wait (&b2);
2122 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
2124 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
2125 exit (1);
2128 pthread_cleanup_push (cl, NULL);
2130 struct
2132 long int type;
2133 char mem[1];
2134 } m;
2135 /* We need a positive random number. */
2137 m.type = random () % 64000;
2138 while (m.type <= 0);
2139 msgsnd (tempmsg, (struct msgbuf *) &m, sizeof (m.mem), 0);
2141 pthread_cleanup_pop (0);
2143 printf ("%s: msgsnd returned\n", __FUNCTION__);
2145 msgctl (tempmsg, IPC_RMID, NULL);
2147 exit (1);
2151 struct cancel_tests tests[] =
2153 ADD_TEST (read, 2, 0),
2154 ADD_TEST (readv, 2, 0),
2155 ADD_TEST (select, 2, 0),
2156 ADD_TEST (pselect, 2, 0),
2157 ADD_TEST (poll, 2, 0),
2158 ADD_TEST (ppoll, 2, 0),
2159 ADD_TEST (write, 2, 0),
2160 ADD_TEST (writev, 2, 0),
2161 ADD_TEST (sleep, 2, 0),
2162 ADD_TEST (usleep, 2, 0),
2163 ADD_TEST (nanosleep, 2, 0),
2164 ADD_TEST (wait, 2, 0),
2165 ADD_TEST (waitid, 2, 0),
2166 ADD_TEST (waitpid, 2, 0),
2167 ADD_TEST (sigpause, 2, 0),
2168 ADD_TEST (sigsuspend, 2, 0),
2169 ADD_TEST (sigwait, 2, 0),
2170 ADD_TEST (sigwaitinfo, 2, 0),
2171 ADD_TEST (sigtimedwait, 2, 0),
2172 ADD_TEST (pause, 2, 0),
2173 ADD_TEST (accept, 2, 0),
2174 ADD_TEST (send, 2, 0),
2175 ADD_TEST (recv, 2, 0),
2176 ADD_TEST (recvfrom, 2, 0),
2177 ADD_TEST (recvmsg, 2, 0),
2178 ADD_TEST (preadv, 2, 1),
2179 ADD_TEST (pwritev, 2, 1),
2180 ADD_TEST (open, 2, 1),
2181 ADD_TEST (close, 2, 1),
2182 ADD_TEST (pread, 2, 1),
2183 ADD_TEST (pwrite, 2, 1),
2184 ADD_TEST (fsync, 2, 1),
2185 ADD_TEST (fdatasync, 2, 1),
2186 ADD_TEST (msync, 2, 1),
2187 ADD_TEST (sendto, 2, 1),
2188 ADD_TEST (sendmsg, 2, 1),
2189 ADD_TEST (creat, 2, 1),
2190 ADD_TEST (connect, 2, 1),
2191 ADD_TEST (tcdrain, 2, 1),
2192 ADD_TEST (msgrcv, 2, 0),
2193 ADD_TEST (msgsnd, 2, 1),
2195 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
2197 #include "tst-cancel4-common.c"