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 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
730 FAIL_EXIT1 ("connect: %m");
732 unlink (sun
.sun_path
);
734 xpthread_barrier_wait (&b2
);
737 xpthread_barrier_wait (&b2
);
739 pthread_cleanup_push (cl
, NULL
);
741 /* Very large block, so that the send call blocks. */
744 send (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0);
746 pthread_cleanup_pop (0);
748 FAIL_EXIT1 ("send returned");
755 struct sockaddr_un sun
;
757 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
759 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
764 TEST_VERIFY_EXIT (tries
++ < 10);
766 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-3-XXXXXX");
767 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
769 sun
.sun_family
= AF_UNIX
;
771 while (bind (tempfd
, (struct sockaddr
*) &sun
,
772 offsetof (struct sockaddr_un
, sun_path
)
773 + strlen (sun
.sun_path
) + 1) != 0);
777 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
779 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
781 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
782 FAIL_EXIT1 ("connect: %m");
784 unlink (sun
.sun_path
);
786 xpthread_barrier_wait (&b2
);
789 xpthread_barrier_wait (&b2
);
791 pthread_cleanup_push (cl
, NULL
);
795 recv (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0);
797 pthread_cleanup_pop (0);
799 FAIL_EXIT1 ("recv returned");
804 tf_recvfrom (void *arg
)
806 struct sockaddr_un sun
;
808 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
810 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
815 TEST_VERIFY_EXIT (tries
++ < 10);
817 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-4-XXXXXX");
818 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
820 sun
.sun_family
= AF_UNIX
;
822 while (bind (tempfd
, (struct sockaddr
*) &sun
,
823 offsetof (struct sockaddr_un
, sun_path
)
824 + strlen (sun
.sun_path
) + 1) != 0);
826 tempfname
= strdup (sun
.sun_path
);
828 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
830 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
832 xpthread_barrier_wait (&b2
);
835 xpthread_barrier_wait (&b2
);
837 pthread_cleanup_push (cl
, NULL
);
840 socklen_t len
= sizeof (sun
);
842 recvfrom (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0,
843 (struct sockaddr
*) &sun
, &len
);
845 pthread_cleanup_pop (0);
847 FAIL_EXIT1 ("recvfrom returned");
852 tf_recvmsg (void *arg
)
854 struct sockaddr_un sun
;
856 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
858 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
863 TEST_VERIFY_EXIT (tries
++ < 10);
865 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-5-XXXXXX");
866 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
868 sun
.sun_family
= AF_UNIX
;
870 while (bind (tempfd
, (struct sockaddr
*) &sun
,
871 offsetof (struct sockaddr_un
, sun_path
)
872 + strlen (sun
.sun_path
) + 1) != 0);
874 tempfname
= strdup (sun
.sun_path
);
876 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
878 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
880 xpthread_barrier_wait (&b2
);
883 xpthread_barrier_wait (&b2
);
885 pthread_cleanup_push (cl
, NULL
);
889 iov
[0].iov_base
= mem
;
890 iov
[0].iov_len
= arg
== NULL
? sizeof (mem
) : 0;
894 m
.msg_namelen
= sizeof (sun
);
897 m
.msg_control
= NULL
;
898 m
.msg_controllen
= 0;
900 recvmsg (tempfd2
, &m
, 0);
902 pthread_cleanup_pop (0);
904 FAIL_EXIT1 ("recvmsg returned");
912 fifofd
= mkfifo (fifoname
, S_IWUSR
| S_IRUSR
);
914 FAIL_EXIT1 ("mkfifo: %m");
918 xpthread_barrier_wait (&b2
);
921 xpthread_barrier_wait (&b2
);
923 pthread_cleanup_push (cl_fifo
, NULL
);
925 open (arg
? "Makefile" : fifoname
, O_RDONLY
);
927 pthread_cleanup_pop (0);
929 FAIL_EXIT1 ("open returned");
937 // XXX If somebody can provide a portable test case in which close()
938 // blocks we can enable this test to run in both rounds.
941 char fname
[] = "/tmp/tst-cancel-fd-XXXXXX";
942 tempfd
= mkstemp (fname
);
944 FAIL_EXIT1 ("mkstemp failed: %m");
947 xpthread_barrier_wait (&b2
);
949 xpthread_barrier_wait (&b2
);
951 pthread_cleanup_push (cl
, NULL
);
955 pthread_cleanup_pop (0);
957 FAIL_EXIT1 ("close returned");
965 // XXX If somebody can provide a portable test case in which pread()
966 // blocks we can enable this test to run in both rounds.
969 tempfd
= open ("Makefile", O_RDONLY
);
971 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
973 xpthread_barrier_wait (&b2
);
975 xpthread_barrier_wait (&b2
);
977 pthread_cleanup_push (cl
, NULL
);
980 pread (tempfd
, mem
, sizeof (mem
), 0);
982 pthread_cleanup_pop (0);
984 FAIL_EXIT1 ("pread returned");
989 tf_pwrite (void *arg
)
992 // XXX If somebody can provide a portable test case in which pwrite()
993 // blocks we can enable this test to run in both rounds.
996 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
997 tempfd
= mkstemp (fname
);
999 FAIL_EXIT1 ("mkstemp failed: %m");
1002 xpthread_barrier_wait (&b2
);
1004 xpthread_barrier_wait (&b2
);
1006 pthread_cleanup_push (cl
, NULL
);
1009 pwrite (tempfd
, mem
, sizeof (mem
), 0);
1011 pthread_cleanup_pop (0);
1013 FAIL_EXIT1 ("pwrite returned");
1017 tf_preadv (void *arg
)
1022 /* XXX If somebody can provide a portable test case in which preadv
1023 blocks we can enable this test to run in both rounds. */
1026 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1027 tempfd
= fd
= mkstemp (fname
);
1029 FAIL_EXIT1 ("mkstemp failed: %m");
1032 xpthread_barrier_wait (&b2
);
1034 xpthread_barrier_wait (&b2
);
1037 pthread_cleanup_push (cl
, NULL
);
1040 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1041 s
= preadv (fd
, iov
, 1, 0);
1043 pthread_cleanup_pop (0);
1045 FAIL_EXIT1 ("preadv returns with %zd", s
);
1049 tf_pwritev (void *arg
)
1054 /* XXX If somebody can provide a portable test case in which pwritev
1055 blocks we can enable this test to run in both rounds. */
1058 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1059 tempfd
= fd
= mkstemp (fname
);
1061 FAIL_EXIT1 ("mkstemp failed: %m");
1064 xpthread_barrier_wait (&b2
);
1066 xpthread_barrier_wait (&b2
);
1069 pthread_cleanup_push (cl
, NULL
);
1071 char buf
[WRITE_BUFFER_SIZE
];
1072 memset (buf
, '\0', sizeof (buf
));
1073 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1074 s
= pwritev (fd
, iov
, 1, 0);
1076 pthread_cleanup_pop (0);
1078 FAIL_EXIT1 ("pwritev returns with %zd", s
);
1082 tf_pwritev2 (void *arg
)
1087 /* XXX If somebody can provide a portable test case in which pwritev2
1088 blocks we can enable this test to run in both rounds. */
1093 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1094 tempfd
= fd
= mkstemp (fname
);
1096 FAIL_EXIT1 ("mkstemp: %m");
1099 xpthread_barrier_wait (&b2
);
1101 xpthread_barrier_wait (&b2
);
1104 pthread_cleanup_push (cl
, NULL
);
1106 char buf
[WRITE_BUFFER_SIZE
];
1107 memset (buf
, '\0', sizeof (buf
));
1108 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1109 s
= pwritev2 (fd
, iov
, 1, 0, 0);
1111 pthread_cleanup_pop (0);
1113 FAIL_EXIT1 ("pwritev2 returns with %zd", s
);
1117 tf_preadv2 (void *arg
)
1122 /* XXX If somebody can provide a portable test case in which preadv2
1123 blocks we can enable this test to run in both rounds. */
1128 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1129 tempfd
= fd
= mkstemp (fname
);
1131 FAIL_EXIT1 ("mkstemp failed: %m");
1134 xpthread_barrier_wait (&b2
);
1136 xpthread_barrier_wait (&b2
);
1139 pthread_cleanup_push (cl
, NULL
);
1142 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1143 s
= preadv2 (fd
, iov
, 1, 0, 0);
1145 pthread_cleanup_pop (0);
1147 FAIL_EXIT1 ("preadv2 returns with %zd", s
);
1151 tf_fsync (void *arg
)
1154 // XXX If somebody can provide a portable test case in which fsync()
1155 // blocks we can enable this test to run in both rounds.
1158 tempfd
= open ("Makefile", O_RDONLY
);
1160 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
1162 xpthread_barrier_wait (&b2
);
1164 xpthread_barrier_wait (&b2
);
1166 pthread_cleanup_push (cl
, NULL
);
1170 pthread_cleanup_pop (0);
1172 FAIL_EXIT1 ("fsync returned");
1177 tf_fdatasync (void *arg
)
1180 // XXX If somebody can provide a portable test case in which fdatasync()
1181 // blocks we can enable this test to run in both rounds.
1184 tempfd
= open ("Makefile", O_RDONLY
);
1186 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
1188 xpthread_barrier_wait (&b2
);
1190 xpthread_barrier_wait (&b2
);
1192 pthread_cleanup_push (cl
, NULL
);
1196 pthread_cleanup_pop (0);
1198 FAIL_EXIT1 ("fdatasync returned");
1203 tf_msync (void *arg
)
1206 // XXX If somebody can provide a portable test case in which msync()
1207 // blocks we can enable this test to run in both rounds.
1210 tempfd
= open ("Makefile", O_RDONLY
);
1212 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
1214 void *p
= xmmap (NULL
, 10, PROT_READ
, MAP_SHARED
, tempfd
);
1216 xpthread_barrier_wait (&b2
);
1218 xpthread_barrier_wait (&b2
);
1220 pthread_cleanup_push (cl
, NULL
);
1224 pthread_cleanup_pop (0);
1226 FAIL_EXIT1 ("msync returned");
1231 tf_sendto (void *arg
)
1234 // XXX If somebody can provide a portable test case in which sendto()
1235 // blocks we can enable this test to run in both rounds.
1238 struct sockaddr_un sun
;
1240 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1242 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
1247 TEST_VERIFY_EXIT (tries
++ < 10);
1249 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-6-XXXXXX");
1250 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
1252 sun
.sun_family
= AF_UNIX
;
1254 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1255 offsetof (struct sockaddr_un
, sun_path
)
1256 + strlen (sun
.sun_path
) + 1) != 0);
1257 tempfname
= strdup (sun
.sun_path
);
1259 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1261 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
1263 xpthread_barrier_wait (&b2
);
1265 xpthread_barrier_wait (&b2
);
1267 pthread_cleanup_push (cl
, NULL
);
1271 sendto (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0,
1272 (struct sockaddr
*) &sun
,
1273 offsetof (struct sockaddr_un
, sun_path
) + strlen (sun
.sun_path
) + 1);
1275 pthread_cleanup_pop (0);
1277 FAIL_EXIT1 ("sendto returned");
1282 tf_sendmsg (void *arg
)
1285 // XXX If somebody can provide a portable test case in which sendmsg()
1286 // blocks we can enable this test to run in both rounds.
1289 struct sockaddr_un sun
;
1291 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1293 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
1298 TEST_VERIFY_EXIT (tries
++ < 10);
1300 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-7-XXXXXX");
1301 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
1303 sun
.sun_family
= AF_UNIX
;
1305 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1306 offsetof (struct sockaddr_un
, sun_path
)
1307 + strlen (sun
.sun_path
) + 1) != 0);
1308 tempfname
= strdup (sun
.sun_path
);
1310 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1312 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
1314 xpthread_barrier_wait (&b2
);
1316 xpthread_barrier_wait (&b2
);
1318 pthread_cleanup_push (cl
, NULL
);
1321 struct iovec iov
[1];
1322 iov
[0].iov_base
= mem
;
1327 m
.msg_namelen
= (offsetof (struct sockaddr_un
, sun_path
)
1328 + strlen (sun
.sun_path
) + 1);
1331 m
.msg_control
= NULL
;
1332 m
.msg_controllen
= 0;
1334 sendmsg (tempfd2
, &m
, 0);
1336 pthread_cleanup_pop (0);
1338 FAIL_EXIT1 ("sendmsg returned");
1343 tf_creat (void *arg
)
1346 // XXX If somebody can provide a portable test case in which sendmsg()
1347 // blocks we can enable this test to run in both rounds.
1350 xpthread_barrier_wait (&b2
);
1352 xpthread_barrier_wait (&b2
);
1354 pthread_cleanup_push (cl
, NULL
);
1356 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1358 pthread_cleanup_pop (0);
1360 FAIL_EXIT1 ("creat returned");
1365 tf_connect (void *arg
)
1368 // XXX If somebody can provide a portable test case in which connect()
1369 // blocks we can enable this test to run in both rounds.
1372 struct sockaddr_un sun
;
1374 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1376 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
1381 TEST_VERIFY_EXIT (tries
++ < 10);
1383 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1384 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
1386 sun
.sun_family
= AF_UNIX
;
1388 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1389 offsetof (struct sockaddr_un
, sun_path
)
1390 + strlen (sun
.sun_path
) + 1) != 0);
1391 tempfname
= strdup (sun
.sun_path
);
1395 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1397 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
1399 xpthread_barrier_wait (&b2
);
1402 xpthread_barrier_wait (&b2
);
1404 pthread_cleanup_push (cl
, NULL
);
1406 connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
));
1408 pthread_cleanup_pop (0);
1410 FAIL_EXIT1 ("connect returned");
1415 tf_tcdrain (void *arg
)
1418 // XXX If somebody can provide a portable test case in which tcdrain()
1419 // blocks we can enable this test to run in both rounds.
1422 xpthread_barrier_wait (&b2
);
1425 xpthread_barrier_wait (&b2
);
1427 pthread_cleanup_push (cl
, NULL
);
1429 /* Regardless of stderr being a terminal, the tcdrain call should be
1431 tcdrain (STDERR_FILENO
);
1433 pthread_cleanup_pop (0);
1435 FAIL_EXIT1 ("tcdrain returned");
1440 tf_msgrcv (void *arg
)
1442 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1444 FAIL_EXIT1 ("msgget (IPC_PRIVATE, 0666 | IPC_CREAT): %m");
1446 xpthread_barrier_wait (&b2
);
1449 xpthread_barrier_wait (&b2
);
1453 pthread_cleanup_push (cl
, NULL
);
1461 /* We need a positive random number. */
1463 randnr
= random () % 64000;
1464 while (randnr
<= 0);
1468 s
= msgrcv (tempmsg
, (struct msgbuf
*) &m
, 10, randnr
, 0);
1470 while (errno
== EIDRM
|| errno
== EINTR
);
1472 pthread_cleanup_pop (0);
1474 msgctl (tempmsg
, IPC_RMID
, NULL
);
1476 FAIL_EXIT1 ("msgrcv returned %zd", s
);
1481 tf_msgsnd (void *arg
)
1484 // XXX If somebody can provide a portable test case in which msgsnd()
1485 // blocks we can enable this test to run in both rounds.
1488 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1490 FAIL_EXIT1 ("msgget (IPC_PRIVATE, 0666 | IPC_CREAT): %m");
1492 xpthread_barrier_wait (&b2
);
1494 xpthread_barrier_wait (&b2
);
1496 pthread_cleanup_push (cl
, NULL
);
1503 /* We need a positive random number. */
1505 m
.type
= random () % 64000;
1506 while (m
.type
<= 0);
1507 msgsnd (tempmsg
, (struct msgbuf
*) &m
, sizeof (m
.mem
), 0);
1509 pthread_cleanup_pop (0);
1511 msgctl (tempmsg
, IPC_RMID
, NULL
);
1513 FAIL_EXIT1 ("msgsnd returned");
1517 struct cancel_tests tests
[] =
1519 ADD_TEST (read
, 2, 0),
1520 ADD_TEST (readv
, 2, 0),
1521 ADD_TEST (select
, 2, 0),
1522 ADD_TEST (pselect
, 2, 0),
1523 ADD_TEST (poll
, 2, 0),
1524 ADD_TEST (ppoll
, 2, 0),
1525 ADD_TEST (write
, 2, 0),
1526 ADD_TEST (writev
, 2, 0),
1527 ADD_TEST (sleep
, 2, 0),
1528 ADD_TEST (usleep
, 2, 0),
1529 ADD_TEST (nanosleep
, 2, 0),
1530 ADD_TEST (wait
, 2, 0),
1531 ADD_TEST (waitid
, 2, 0),
1532 ADD_TEST (waitpid
, 2, 0),
1533 ADD_TEST (sigpause
, 2, 0),
1534 ADD_TEST (sigsuspend
, 2, 0),
1535 ADD_TEST (sigwait
, 2, 0),
1536 ADD_TEST (sigwaitinfo
, 2, 0),
1537 ADD_TEST (sigtimedwait
, 2, 0),
1538 ADD_TEST (pause
, 2, 0),
1539 ADD_TEST (accept
, 2, 0),
1540 ADD_TEST (send
, 2, 0),
1541 ADD_TEST (recv
, 2, 0),
1542 ADD_TEST (recvfrom
, 2, 0),
1543 ADD_TEST (recvmsg
, 2, 0),
1544 ADD_TEST (preadv
, 2, 1),
1545 ADD_TEST (preadv2
, 2, 1),
1546 ADD_TEST (pwritev
, 2, 1),
1547 ADD_TEST (pwritev2
, 2, 1),
1548 ADD_TEST (open
, 2, 1),
1549 ADD_TEST (close
, 2, 1),
1550 ADD_TEST (pread
, 2, 1),
1551 ADD_TEST (pwrite
, 2, 1),
1552 ADD_TEST (fsync
, 2, 1),
1553 ADD_TEST (fdatasync
, 2, 1),
1554 ADD_TEST (msync
, 2, 1),
1555 ADD_TEST (sendto
, 2, 1),
1556 ADD_TEST (sendmsg
, 2, 1),
1557 ADD_TEST (creat
, 2, 1),
1558 ADD_TEST (connect
, 2, 1),
1559 ADD_TEST (tcdrain
, 2, 1),
1560 ADD_TEST (msgrcv
, 2, 0),
1561 ADD_TEST (msgsnd
, 2, 1),
1563 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
1565 #include "tst-cancel4-common.c"