1 /* Copyright (C) 2002-2018 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. */
26 #include <sys/types.h>
27 #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.
66 Linux sendmmsg and recvmmsg are checked in tst-cancel4_1.c and
67 tst-cancel4_2.c respectively.
70 #include "tst-cancel4-common.h"
87 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
88 tempfd
= fd
= mkstemp (fname
);
90 FAIL_EXIT1 ("mkstemp failed: %m");
93 xpthread_barrier_wait (&b2
);
96 xpthread_barrier_wait (&b2
);
99 pthread_cleanup_push (cl
, NULL
);
102 s
= read (fd
, buf
, sizeof (buf
));
104 pthread_cleanup_pop (0);
106 FAIL_EXIT1 ("read returns with %zd", s
);
119 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
120 tempfd
= fd
= mkstemp (fname
);
122 FAIL_EXIT1 ("mkstemp failed: %m");
125 xpthread_barrier_wait (&b2
);
128 xpthread_barrier_wait (&b2
);
131 pthread_cleanup_push (cl
, NULL
);
134 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
135 s
= readv (fd
, iov
, 1);
137 pthread_cleanup_pop (0);
139 FAIL_EXIT1 ("readv returns with %zd", s
);
152 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
153 tempfd
= fd
= mkstemp (fname
);
155 FAIL_EXIT1 ("mkstemp failed: %m");
158 xpthread_barrier_wait (&b2
);
161 xpthread_barrier_wait (&b2
);
164 pthread_cleanup_push (cl
, NULL
);
166 char buf
[WRITE_BUFFER_SIZE
];
167 memset (buf
, '\0', sizeof (buf
));
168 s
= write (fd
, buf
, sizeof (buf
));
170 pthread_cleanup_pop (0);
172 FAIL_EXIT1 ("write returns with %zd", s
);
177 tf_writev (void *arg
)
185 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
186 tempfd
= fd
= mkstemp (fname
);
188 FAIL_EXIT1 ("mkstemp failed: %m");
191 xpthread_barrier_wait (&b2
);
194 xpthread_barrier_wait (&b2
);
197 pthread_cleanup_push (cl
, NULL
);
199 char buf
[WRITE_BUFFER_SIZE
];
200 memset (buf
, '\0', sizeof (buf
));
201 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
202 s
= writev (fd
, iov
, 1);
204 pthread_cleanup_pop (0);
206 FAIL_EXIT1 ("writev returns with %zd", s
);
213 xpthread_barrier_wait (&b2
);
216 xpthread_barrier_wait (&b2
);
218 pthread_cleanup_push (cl
, NULL
);
220 sleep (arg
== NULL
? 1000000 : 0);
222 pthread_cleanup_pop (0);
224 FAIL_EXIT1 ("sleep returns");
229 tf_usleep (void *arg
)
231 xpthread_barrier_wait (&b2
);
234 xpthread_barrier_wait (&b2
);
236 pthread_cleanup_push (cl
, NULL
);
238 usleep (arg
== NULL
? (useconds_t
) ULONG_MAX
: 0);
240 pthread_cleanup_pop (0);
242 FAIL_EXIT1 ("usleep returns");
247 tf_nanosleep (void *arg
)
249 xpthread_barrier_wait (&b2
);
252 xpthread_barrier_wait (&b2
);
254 pthread_cleanup_push (cl
, NULL
);
256 struct timespec ts
= { .tv_sec
= arg
== NULL
? 10000000 : 0, .tv_nsec
= 0 };
257 TEMP_FAILURE_RETRY (nanosleep (&ts
, &ts
));
259 pthread_cleanup_pop (0);
261 FAIL_EXIT1 ("nanosleep returns");
266 tf_select (void *arg
)
274 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
275 tempfd
= fd
= mkstemp (fname
);
277 FAIL_EXIT1 ("mkstemp failed: %m");
280 xpthread_barrier_wait (&b2
);
283 xpthread_barrier_wait (&b2
);
290 pthread_cleanup_push (cl
, NULL
);
292 s
= select (fd
+ 1, &rfs
, NULL
, NULL
, NULL
);
294 pthread_cleanup_pop (0);
296 FAIL_EXIT1 ("select returns with %d: %m", s
);
301 tf_pselect (void *arg
)
309 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
310 tempfd
= fd
= mkstemp (fname
);
312 FAIL_EXIT1 ("mkstemp failed: %m");
315 xpthread_barrier_wait (&b2
);
318 xpthread_barrier_wait (&b2
);
325 pthread_cleanup_push (cl
, NULL
);
327 s
= pselect (fd
+ 1, &rfs
, NULL
, NULL
, NULL
, NULL
);
329 pthread_cleanup_pop (0);
331 FAIL_EXIT1 ("pselect returns with %d: %m", s
);
344 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
345 tempfd
= fd
= mkstemp (fname
);
347 FAIL_EXIT1 ("mkstemp failed: %m");
350 xpthread_barrier_wait (&b2
);
353 xpthread_barrier_wait (&b2
);
355 struct pollfd rfs
[1] = { [0] = { .fd
= fd
, .events
= POLLIN
} };
358 pthread_cleanup_push (cl
, NULL
);
360 s
= poll (rfs
, 1, -1);
362 pthread_cleanup_pop (0);
364 FAIL_EXIT1 ("poll returns with %d: %m", s
);
377 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
378 tempfd
= fd
= mkstemp (fname
);
380 FAIL_EXIT1 ("mkstemp failed: %m");
383 xpthread_barrier_wait (&b2
);
386 xpthread_barrier_wait (&b2
);
388 struct pollfd rfs
[1] = { [0] = { .fd
= fd
, .events
= POLLIN
} };
391 pthread_cleanup_push (cl
, NULL
);
393 s
= ppoll (rfs
, 1, NULL
, NULL
);
395 pthread_cleanup_pop (0);
397 FAIL_EXIT1 ("ppoll returns with %d: %m", s
);
406 FAIL_EXIT1 ("fork: %m");
410 /* Make the program disappear after a while. */
418 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
419 while (nanosleep (&ts
, &ts
) != 0)
422 xpthread_barrier_wait (&b2
);
425 xpthread_barrier_wait (&b2
);
428 pthread_cleanup_push (cl
, NULL
);
432 pthread_cleanup_pop (0);
434 FAIL_EXIT1 ("wait returns with %d: %m", s
);
439 tf_waitpid (void *arg
)
443 FAIL_EXIT1 ("fork: %m");
447 /* Make the program disappear after a while. */
455 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
456 while (nanosleep (&ts
, &ts
) != 0)
459 xpthread_barrier_wait (&b2
);
462 xpthread_barrier_wait (&b2
);
465 pthread_cleanup_push (cl
, NULL
);
467 s
= waitpid (-1, NULL
, 0);
469 pthread_cleanup_pop (0);
471 FAIL_EXIT1 ("waitpid returns with %d: %m", s
);
476 tf_waitid (void *arg
)
480 FAIL_EXIT1 ("fork: %m");
484 /* Make the program disappear after a while. */
492 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
493 while (nanosleep (&ts
, &ts
) != 0)
496 xpthread_barrier_wait (&b2
);
499 xpthread_barrier_wait (&b2
);
502 pthread_cleanup_push (cl
, NULL
);
508 s
= waitid (P_PID
, pid
, &si
, WEXITED
);
510 pthread_cleanup_pop (0);
512 FAIL_EXIT1 ("waitid returns with %d: %m", s
);
517 tf_sigpause (void *arg
)
519 xpthread_barrier_wait (&b2
);
522 xpthread_barrier_wait (&b2
);
524 pthread_cleanup_push (cl
, NULL
);
526 sigpause (sigmask (SIGINT
));
528 pthread_cleanup_pop (0);
530 FAIL_EXIT1 ("sigpause returned");
535 tf_sigsuspend (void *arg
)
537 xpthread_barrier_wait (&b2
);
540 xpthread_barrier_wait (&b2
);
542 pthread_cleanup_push (cl
, NULL
);
544 /* Just for fun block all signals. */
549 pthread_cleanup_pop (0);
551 FAIL_EXIT1 ("sigsuspend returned");
556 tf_sigwait (void *arg
)
558 xpthread_barrier_wait (&b2
);
561 xpthread_barrier_wait (&b2
);
566 sigaddset (&mask
, SIGUSR1
);
567 TEST_VERIFY_EXIT (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) == 0);
570 pthread_cleanup_push (cl
, NULL
);
572 /* Wait for SIGUSR1. */
573 sigwait (&mask
, &sig
);
575 pthread_cleanup_pop (0);
577 FAIL_EXIT1 ("sigwait returned with signal %d", sig
);
582 tf_sigwaitinfo (void *arg
)
584 xpthread_barrier_wait (&b2
);
587 xpthread_barrier_wait (&b2
);
592 sigaddset (&mask
, SIGUSR1
);
593 TEST_VERIFY_EXIT (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) == 0);
596 pthread_cleanup_push (cl
, NULL
);
598 /* Wait for SIGUSR1. */
599 sigwaitinfo (&mask
, &info
);
601 pthread_cleanup_pop (0);
603 FAIL_EXIT1 ("sigwaitinfo returned with signal %d", info
.si_signo
);
608 tf_sigtimedwait (void *arg
)
610 xpthread_barrier_wait (&b2
);
613 xpthread_barrier_wait (&b2
);
618 sigaddset (&mask
, SIGUSR1
);
619 TEST_VERIFY_EXIT (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) == 0);
621 /* Wait for SIGUSR1. */
623 struct timespec ts
= { .tv_sec
= 60, .tv_nsec
= 0 };
624 pthread_cleanup_push (cl
, NULL
);
626 sigtimedwait (&mask
, &info
, &ts
);
628 pthread_cleanup_pop (0);
630 FAIL_EXIT1 ("sigtimedwait returned with signal %d", info
.si_signo
);
637 xpthread_barrier_wait (&b2
);
640 xpthread_barrier_wait (&b2
);
642 pthread_cleanup_push (cl
, NULL
);
646 pthread_cleanup_pop (0);
648 FAIL_EXIT1 ("pause returned");
653 tf_accept (void *arg
)
655 struct sockaddr_un sun
;
656 /* To test a non-blocking accept call we make the call file by using
657 a datagrame socket. */
658 int pf
= arg
== NULL
? SOCK_STREAM
: SOCK_DGRAM
;
660 tempfd
= socket (AF_UNIX
, pf
, 0);
662 FAIL_EXIT1 ("socket (AF_UNIX, %s, 0): %m", arg
== NULL
? "SOCK_STREAM"
668 TEST_VERIFY_EXIT (tries
++ < 10);
670 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-1-XXXXXX");
671 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
673 sun
.sun_family
= AF_UNIX
;
675 while (bind (tempfd
, (struct sockaddr
*) &sun
,
676 offsetof (struct sockaddr_un
, sun_path
)
677 + strlen (sun
.sun_path
) + 1) != 0);
679 unlink (sun
.sun_path
);
683 socklen_t len
= sizeof (sun
);
685 xpthread_barrier_wait (&b2
);
688 xpthread_barrier_wait (&b2
);
690 pthread_cleanup_push (cl
, NULL
);
692 accept (tempfd
, (struct sockaddr
*) &sun
, &len
);
694 pthread_cleanup_pop (0);
696 FAIL_EXIT1 ("accept returned");
703 struct sockaddr_un sun
;
705 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
707 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
712 TEST_VERIFY_EXIT (tries
++ < 10);
714 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
715 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
717 sun
.sun_family
= AF_UNIX
;
719 while (bind (tempfd
, (struct sockaddr
*) &sun
,
720 offsetof (struct sockaddr_un
, sun_path
)
721 + strlen (sun
.sun_path
) + 1) != 0);
725 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
727 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
729 set_socket_buffer (tempfd2
);
731 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
732 FAIL_EXIT1 ("connect: %m");
734 unlink (sun
.sun_path
);
736 xpthread_barrier_wait (&b2
);
739 xpthread_barrier_wait (&b2
);
741 pthread_cleanup_push (cl
, NULL
);
743 char mem
[WRITE_BUFFER_SIZE
];
745 send (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0);
747 pthread_cleanup_pop (0);
749 FAIL_EXIT1 ("send returned");
756 struct sockaddr_un sun
;
758 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
760 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
765 TEST_VERIFY_EXIT (tries
++ < 10);
767 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-3-XXXXXX");
768 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
770 sun
.sun_family
= AF_UNIX
;
772 while (bind (tempfd
, (struct sockaddr
*) &sun
,
773 offsetof (struct sockaddr_un
, sun_path
)
774 + strlen (sun
.sun_path
) + 1) != 0);
778 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
780 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
782 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
783 FAIL_EXIT1 ("connect: %m");
785 unlink (sun
.sun_path
);
787 xpthread_barrier_wait (&b2
);
790 xpthread_barrier_wait (&b2
);
792 pthread_cleanup_push (cl
, NULL
);
796 recv (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0);
798 pthread_cleanup_pop (0);
800 FAIL_EXIT1 ("recv returned");
805 tf_recvfrom (void *arg
)
807 struct sockaddr_un sun
;
809 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
811 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
816 TEST_VERIFY_EXIT (tries
++ < 10);
818 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-4-XXXXXX");
819 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
821 sun
.sun_family
= AF_UNIX
;
823 while (bind (tempfd
, (struct sockaddr
*) &sun
,
824 offsetof (struct sockaddr_un
, sun_path
)
825 + strlen (sun
.sun_path
) + 1) != 0);
827 tempfname
= strdup (sun
.sun_path
);
829 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
831 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
833 xpthread_barrier_wait (&b2
);
836 xpthread_barrier_wait (&b2
);
838 pthread_cleanup_push (cl
, NULL
);
841 socklen_t len
= sizeof (sun
);
843 recvfrom (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0,
844 (struct sockaddr
*) &sun
, &len
);
846 pthread_cleanup_pop (0);
848 FAIL_EXIT1 ("recvfrom returned");
853 tf_recvmsg (void *arg
)
855 struct sockaddr_un sun
;
857 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
859 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
864 TEST_VERIFY_EXIT (tries
++ < 10);
866 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-5-XXXXXX");
867 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
869 sun
.sun_family
= AF_UNIX
;
871 while (bind (tempfd
, (struct sockaddr
*) &sun
,
872 offsetof (struct sockaddr_un
, sun_path
)
873 + strlen (sun
.sun_path
) + 1) != 0);
875 tempfname
= strdup (sun
.sun_path
);
877 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
879 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
881 xpthread_barrier_wait (&b2
);
884 xpthread_barrier_wait (&b2
);
886 pthread_cleanup_push (cl
, NULL
);
890 iov
[0].iov_base
= mem
;
891 iov
[0].iov_len
= arg
== NULL
? sizeof (mem
) : 0;
895 m
.msg_namelen
= sizeof (sun
);
898 m
.msg_control
= NULL
;
899 m
.msg_controllen
= 0;
901 recvmsg (tempfd2
, &m
, 0);
903 pthread_cleanup_pop (0);
905 FAIL_EXIT1 ("recvmsg returned");
913 fifofd
= mkfifo (fifoname
, S_IWUSR
| S_IRUSR
);
915 FAIL_EXIT1 ("mkfifo: %m");
919 xpthread_barrier_wait (&b2
);
922 xpthread_barrier_wait (&b2
);
924 pthread_cleanup_push (cl_fifo
, NULL
);
926 open (arg
? "Makefile" : fifoname
, O_RDONLY
);
928 pthread_cleanup_pop (0);
930 FAIL_EXIT1 ("open returned");
938 // XXX If somebody can provide a portable test case in which close()
939 // blocks we can enable this test to run in both rounds.
942 char fname
[] = "/tmp/tst-cancel-fd-XXXXXX";
943 tempfd
= mkstemp (fname
);
945 FAIL_EXIT1 ("mkstemp failed: %m");
948 xpthread_barrier_wait (&b2
);
950 xpthread_barrier_wait (&b2
);
952 pthread_cleanup_push (cl
, NULL
);
956 pthread_cleanup_pop (0);
958 FAIL_EXIT1 ("close returned");
966 // XXX If somebody can provide a portable test case in which pread()
967 // blocks we can enable this test to run in both rounds.
970 tempfd
= open ("Makefile", O_RDONLY
);
972 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
974 xpthread_barrier_wait (&b2
);
976 xpthread_barrier_wait (&b2
);
978 pthread_cleanup_push (cl
, NULL
);
981 pread (tempfd
, mem
, sizeof (mem
), 0);
983 pthread_cleanup_pop (0);
985 FAIL_EXIT1 ("pread returned");
990 tf_pwrite (void *arg
)
993 // XXX If somebody can provide a portable test case in which pwrite()
994 // blocks we can enable this test to run in both rounds.
997 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
998 tempfd
= mkstemp (fname
);
1000 FAIL_EXIT1 ("mkstemp failed: %m");
1003 xpthread_barrier_wait (&b2
);
1005 xpthread_barrier_wait (&b2
);
1007 pthread_cleanup_push (cl
, NULL
);
1010 pwrite (tempfd
, mem
, sizeof (mem
), 0);
1012 pthread_cleanup_pop (0);
1014 FAIL_EXIT1 ("pwrite returned");
1018 tf_preadv (void *arg
)
1023 /* XXX If somebody can provide a portable test case in which preadv
1024 blocks we can enable this test to run in both rounds. */
1027 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1028 tempfd
= fd
= mkstemp (fname
);
1030 FAIL_EXIT1 ("mkstemp failed: %m");
1033 xpthread_barrier_wait (&b2
);
1035 xpthread_barrier_wait (&b2
);
1038 pthread_cleanup_push (cl
, NULL
);
1041 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1042 s
= preadv (fd
, iov
, 1, 0);
1044 pthread_cleanup_pop (0);
1046 FAIL_EXIT1 ("preadv returns with %zd", s
);
1050 tf_pwritev (void *arg
)
1055 /* XXX If somebody can provide a portable test case in which pwritev
1056 blocks we can enable this test to run in both rounds. */
1059 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1060 tempfd
= fd
= mkstemp (fname
);
1062 FAIL_EXIT1 ("mkstemp failed: %m");
1065 xpthread_barrier_wait (&b2
);
1067 xpthread_barrier_wait (&b2
);
1070 pthread_cleanup_push (cl
, NULL
);
1072 char buf
[WRITE_BUFFER_SIZE
];
1073 memset (buf
, '\0', sizeof (buf
));
1074 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1075 s
= pwritev (fd
, iov
, 1, 0);
1077 pthread_cleanup_pop (0);
1079 FAIL_EXIT1 ("pwritev returns with %zd", s
);
1083 tf_pwritev2 (void *arg
)
1088 /* XXX If somebody can provide a portable test case in which pwritev2
1089 blocks we can enable this test to run in both rounds. */
1094 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1095 tempfd
= fd
= mkstemp (fname
);
1097 FAIL_EXIT1 ("mkstemp: %m");
1100 xpthread_barrier_wait (&b2
);
1102 xpthread_barrier_wait (&b2
);
1105 pthread_cleanup_push (cl
, NULL
);
1107 char buf
[WRITE_BUFFER_SIZE
];
1108 memset (buf
, '\0', sizeof (buf
));
1109 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1110 s
= pwritev2 (fd
, iov
, 1, 0, 0);
1112 pthread_cleanup_pop (0);
1114 FAIL_EXIT1 ("pwritev2 returns with %zd", s
);
1118 tf_preadv2 (void *arg
)
1123 /* XXX If somebody can provide a portable test case in which preadv2
1124 blocks we can enable this test to run in both rounds. */
1129 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1130 tempfd
= fd
= mkstemp (fname
);
1132 FAIL_EXIT1 ("mkstemp failed: %m");
1135 xpthread_barrier_wait (&b2
);
1137 xpthread_barrier_wait (&b2
);
1140 pthread_cleanup_push (cl
, NULL
);
1143 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1144 s
= preadv2 (fd
, iov
, 1, 0, 0);
1146 pthread_cleanup_pop (0);
1148 FAIL_EXIT1 ("preadv2 returns with %zd", s
);
1152 tf_fsync (void *arg
)
1155 // XXX If somebody can provide a portable test case in which fsync()
1156 // blocks we can enable this test to run in both rounds.
1159 tempfd
= open ("Makefile", O_RDONLY
);
1161 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
1163 xpthread_barrier_wait (&b2
);
1165 xpthread_barrier_wait (&b2
);
1167 pthread_cleanup_push (cl
, NULL
);
1171 pthread_cleanup_pop (0);
1173 FAIL_EXIT1 ("fsync returned");
1178 tf_fdatasync (void *arg
)
1181 // XXX If somebody can provide a portable test case in which fdatasync()
1182 // blocks we can enable this test to run in both rounds.
1185 tempfd
= open ("Makefile", O_RDONLY
);
1187 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
1189 xpthread_barrier_wait (&b2
);
1191 xpthread_barrier_wait (&b2
);
1193 pthread_cleanup_push (cl
, NULL
);
1197 pthread_cleanup_pop (0);
1199 FAIL_EXIT1 ("fdatasync returned");
1204 tf_msync (void *arg
)
1207 // XXX If somebody can provide a portable test case in which msync()
1208 // blocks we can enable this test to run in both rounds.
1211 tempfd
= open ("Makefile", O_RDONLY
);
1213 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
1215 void *p
= xmmap (NULL
, 10, PROT_READ
, MAP_SHARED
, tempfd
);
1217 xpthread_barrier_wait (&b2
);
1219 xpthread_barrier_wait (&b2
);
1221 pthread_cleanup_push (cl
, NULL
);
1225 pthread_cleanup_pop (0);
1227 FAIL_EXIT1 ("msync returned");
1232 tf_sendto (void *arg
)
1234 struct sockaddr_un sun
;
1236 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1238 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
1243 TEST_VERIFY_EXIT (tries
++ < 10);
1245 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-6-XXXXXX");
1246 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
1248 sun
.sun_family
= AF_UNIX
;
1250 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1251 offsetof (struct sockaddr_un
, sun_path
)
1252 + strlen (sun
.sun_path
) + 1) != 0);
1256 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1258 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
1260 set_socket_buffer (tempfd2
);
1262 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1263 FAIL_EXIT1 ("connect: %m");
1265 unlink (sun
.sun_path
);
1267 xpthread_barrier_wait (&b2
);
1270 xpthread_barrier_wait (&b2
);
1272 pthread_cleanup_push (cl
, NULL
);
1274 char mem
[WRITE_BUFFER_SIZE
];
1276 sendto (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0, NULL
, 0);
1278 pthread_cleanup_pop (0);
1280 FAIL_EXIT1 ("sendto returned");
1285 tf_sendmsg (void *arg
)
1288 // XXX If somebody can provide a portable test case in which sendmsg()
1289 // blocks we can enable this test to run in both rounds.
1292 struct sockaddr_un sun
;
1294 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1296 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
1301 TEST_VERIFY_EXIT (tries
++ < 10);
1303 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-7-XXXXXX");
1304 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
1306 sun
.sun_family
= AF_UNIX
;
1308 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1309 offsetof (struct sockaddr_un
, sun_path
)
1310 + strlen (sun
.sun_path
) + 1) != 0);
1311 tempfname
= strdup (sun
.sun_path
);
1313 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1315 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
1317 xpthread_barrier_wait (&b2
);
1319 xpthread_barrier_wait (&b2
);
1321 pthread_cleanup_push (cl
, NULL
);
1324 struct iovec iov
[1];
1325 iov
[0].iov_base
= mem
;
1330 m
.msg_namelen
= (offsetof (struct sockaddr_un
, sun_path
)
1331 + strlen (sun
.sun_path
) + 1);
1334 m
.msg_control
= NULL
;
1335 m
.msg_controllen
= 0;
1337 sendmsg (tempfd2
, &m
, 0);
1339 pthread_cleanup_pop (0);
1341 FAIL_EXIT1 ("sendmsg returned");
1346 tf_creat (void *arg
)
1349 // XXX If somebody can provide a portable test case in which sendmsg()
1350 // blocks we can enable this test to run in both rounds.
1353 xpthread_barrier_wait (&b2
);
1355 xpthread_barrier_wait (&b2
);
1357 pthread_cleanup_push (cl
, NULL
);
1359 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1361 pthread_cleanup_pop (0);
1363 FAIL_EXIT1 ("creat returned");
1368 tf_connect (void *arg
)
1371 // XXX If somebody can provide a portable test case in which connect()
1372 // blocks we can enable this test to run in both rounds.
1375 struct sockaddr_un sun
;
1377 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1379 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
1384 TEST_VERIFY_EXIT (tries
++ < 10);
1386 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1387 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
1389 sun
.sun_family
= AF_UNIX
;
1391 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1392 offsetof (struct sockaddr_un
, sun_path
)
1393 + strlen (sun
.sun_path
) + 1) != 0);
1394 tempfname
= strdup (sun
.sun_path
);
1398 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1400 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
1402 xpthread_barrier_wait (&b2
);
1405 xpthread_barrier_wait (&b2
);
1407 pthread_cleanup_push (cl
, NULL
);
1409 connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
));
1411 pthread_cleanup_pop (0);
1413 FAIL_EXIT1 ("connect returned");
1418 tf_tcdrain (void *arg
)
1421 // XXX If somebody can provide a portable test case in which tcdrain()
1422 // blocks we can enable this test to run in both rounds.
1425 xpthread_barrier_wait (&b2
);
1428 xpthread_barrier_wait (&b2
);
1430 pthread_cleanup_push (cl
, NULL
);
1432 /* Regardless of stderr being a terminal, the tcdrain call should be
1434 tcdrain (STDERR_FILENO
);
1436 pthread_cleanup_pop (0);
1438 FAIL_EXIT1 ("tcdrain returned");
1443 tf_msgrcv (void *arg
)
1445 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1447 FAIL_EXIT1 ("msgget (IPC_PRIVATE, 0666 | IPC_CREAT): %m");
1449 xpthread_barrier_wait (&b2
);
1452 xpthread_barrier_wait (&b2
);
1456 pthread_cleanup_push (cl
, NULL
);
1464 /* We need a positive random number. */
1466 randnr
= random () % 64000;
1467 while (randnr
<= 0);
1471 s
= msgrcv (tempmsg
, (struct msgbuf
*) &m
, 10, randnr
, 0);
1473 while (errno
== EIDRM
|| errno
== EINTR
);
1475 pthread_cleanup_pop (0);
1477 msgctl (tempmsg
, IPC_RMID
, NULL
);
1479 FAIL_EXIT1 ("msgrcv returned %zd", s
);
1484 tf_msgsnd (void *arg
)
1487 // XXX If somebody can provide a portable test case in which msgsnd()
1488 // blocks we can enable this test to run in both rounds.
1491 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1493 FAIL_EXIT1 ("msgget (IPC_PRIVATE, 0666 | IPC_CREAT): %m");
1495 xpthread_barrier_wait (&b2
);
1497 xpthread_barrier_wait (&b2
);
1499 pthread_cleanup_push (cl
, NULL
);
1506 /* We need a positive random number. */
1508 m
.type
= random () % 64000;
1509 while (m
.type
<= 0);
1510 msgsnd (tempmsg
, (struct msgbuf
*) &m
, sizeof (m
.mem
), 0);
1512 pthread_cleanup_pop (0);
1514 msgctl (tempmsg
, IPC_RMID
, NULL
);
1516 FAIL_EXIT1 ("msgsnd returned");
1520 struct cancel_tests tests
[] =
1522 ADD_TEST (read
, 2, 0),
1523 ADD_TEST (readv
, 2, 0),
1524 ADD_TEST (select
, 2, 0),
1525 ADD_TEST (pselect
, 2, 0),
1526 ADD_TEST (poll
, 2, 0),
1527 ADD_TEST (ppoll
, 2, 0),
1528 ADD_TEST (write
, 2, 0),
1529 ADD_TEST (writev
, 2, 0),
1530 ADD_TEST (sleep
, 2, 0),
1531 ADD_TEST (usleep
, 2, 0),
1532 ADD_TEST (nanosleep
, 2, 0),
1533 ADD_TEST (wait
, 2, 0),
1534 ADD_TEST (waitid
, 2, 0),
1535 ADD_TEST (waitpid
, 2, 0),
1536 ADD_TEST (sigpause
, 2, 0),
1537 ADD_TEST (sigsuspend
, 2, 0),
1538 ADD_TEST (sigwait
, 2, 0),
1539 ADD_TEST (sigwaitinfo
, 2, 0),
1540 ADD_TEST (sigtimedwait
, 2, 0),
1541 ADD_TEST (pause
, 2, 0),
1542 ADD_TEST (accept
, 2, 0),
1543 ADD_TEST (send
, 2, 0),
1544 ADD_TEST (recv
, 2, 0),
1545 ADD_TEST (recvfrom
, 2, 0),
1546 ADD_TEST (recvmsg
, 2, 0),
1547 ADD_TEST (preadv
, 2, 1),
1548 ADD_TEST (preadv2
, 2, 1),
1549 ADD_TEST (pwritev
, 2, 1),
1550 ADD_TEST (pwritev2
, 2, 1),
1551 ADD_TEST (open
, 2, 1),
1552 ADD_TEST (close
, 2, 1),
1553 ADD_TEST (pread
, 2, 1),
1554 ADD_TEST (pwrite
, 2, 1),
1555 ADD_TEST (fsync
, 2, 1),
1556 ADD_TEST (fdatasync
, 2, 1),
1557 ADD_TEST (msync
, 2, 1),
1558 ADD_TEST (sendto
, 2, 1),
1559 ADD_TEST (sendmsg
, 2, 1),
1560 ADD_TEST (creat
, 2, 1),
1561 ADD_TEST (connect
, 2, 1),
1562 ADD_TEST (tcdrain
, 2, 1),
1563 ADD_TEST (msgrcv
, 2, 0),
1564 ADD_TEST (msgsnd
, 2, 1),
1566 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
1568 #include "tst-cancel4-common.c"