1 /* Copyright (C) 2002-2019 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 <https://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
));
169 /* The write can return a value higher than 0 (meaning partial write)
170 due to the SIGCANCEL, but the thread may still be pending
172 pthread_testcancel ();
174 pthread_cleanup_pop (0);
176 FAIL_EXIT1 ("write returns with %zd", s
);
181 tf_writev (void *arg
)
189 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
190 tempfd
= fd
= mkstemp (fname
);
192 FAIL_EXIT1 ("mkstemp failed: %m");
195 xpthread_barrier_wait (&b2
);
198 xpthread_barrier_wait (&b2
);
201 pthread_cleanup_push (cl
, NULL
);
203 char buf
[WRITE_BUFFER_SIZE
];
204 memset (buf
, '\0', sizeof (buf
));
205 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
206 s
= writev (fd
, iov
, 1);
208 pthread_cleanup_pop (0);
210 FAIL_EXIT1 ("writev returns with %zd", s
);
217 xpthread_barrier_wait (&b2
);
220 xpthread_barrier_wait (&b2
);
222 pthread_cleanup_push (cl
, NULL
);
224 sleep (arg
== NULL
? 1000000 : 0);
226 pthread_cleanup_pop (0);
228 FAIL_EXIT1 ("sleep returns");
233 tf_usleep (void *arg
)
235 xpthread_barrier_wait (&b2
);
238 xpthread_barrier_wait (&b2
);
240 pthread_cleanup_push (cl
, NULL
);
242 usleep (arg
== NULL
? (useconds_t
) ULONG_MAX
: 0);
244 pthread_cleanup_pop (0);
246 FAIL_EXIT1 ("usleep returns");
251 tf_nanosleep (void *arg
)
253 xpthread_barrier_wait (&b2
);
256 xpthread_barrier_wait (&b2
);
258 pthread_cleanup_push (cl
, NULL
);
260 struct timespec ts
= { .tv_sec
= arg
== NULL
? 10000000 : 0, .tv_nsec
= 0 };
261 TEMP_FAILURE_RETRY (nanosleep (&ts
, &ts
));
263 pthread_cleanup_pop (0);
265 FAIL_EXIT1 ("nanosleep returns");
270 tf_select (void *arg
)
278 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
279 tempfd
= fd
= mkstemp (fname
);
281 FAIL_EXIT1 ("mkstemp failed: %m");
284 xpthread_barrier_wait (&b2
);
287 xpthread_barrier_wait (&b2
);
294 pthread_cleanup_push (cl
, NULL
);
296 s
= select (fd
+ 1, &rfs
, NULL
, NULL
, NULL
);
298 pthread_cleanup_pop (0);
300 FAIL_EXIT1 ("select returns with %d: %m", s
);
305 tf_pselect (void *arg
)
313 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
314 tempfd
= fd
= mkstemp (fname
);
316 FAIL_EXIT1 ("mkstemp failed: %m");
319 xpthread_barrier_wait (&b2
);
322 xpthread_barrier_wait (&b2
);
329 pthread_cleanup_push (cl
, NULL
);
331 s
= pselect (fd
+ 1, &rfs
, NULL
, NULL
, NULL
, NULL
);
333 pthread_cleanup_pop (0);
335 FAIL_EXIT1 ("pselect returns with %d: %m", s
);
348 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
349 tempfd
= fd
= mkstemp (fname
);
351 FAIL_EXIT1 ("mkstemp failed: %m");
354 xpthread_barrier_wait (&b2
);
357 xpthread_barrier_wait (&b2
);
359 struct pollfd rfs
[1] = { [0] = { .fd
= fd
, .events
= POLLIN
} };
362 pthread_cleanup_push (cl
, NULL
);
364 s
= poll (rfs
, 1, -1);
366 pthread_cleanup_pop (0);
368 FAIL_EXIT1 ("poll returns with %d: %m", s
);
381 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
382 tempfd
= fd
= mkstemp (fname
);
384 FAIL_EXIT1 ("mkstemp failed: %m");
387 xpthread_barrier_wait (&b2
);
390 xpthread_barrier_wait (&b2
);
392 struct pollfd rfs
[1] = { [0] = { .fd
= fd
, .events
= POLLIN
} };
395 pthread_cleanup_push (cl
, NULL
);
397 s
= ppoll (rfs
, 1, NULL
, NULL
);
399 pthread_cleanup_pop (0);
401 FAIL_EXIT1 ("ppoll returns with %d: %m", s
);
410 FAIL_EXIT1 ("fork: %m");
414 /* Make the program disappear after a while. */
422 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
423 while (nanosleep (&ts
, &ts
) != 0)
426 xpthread_barrier_wait (&b2
);
429 xpthread_barrier_wait (&b2
);
432 pthread_cleanup_push (cl
, NULL
);
436 pthread_cleanup_pop (0);
438 FAIL_EXIT1 ("wait returns with %d: %m", s
);
443 tf_waitpid (void *arg
)
447 FAIL_EXIT1 ("fork: %m");
451 /* Make the program disappear after a while. */
459 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
460 while (nanosleep (&ts
, &ts
) != 0)
463 xpthread_barrier_wait (&b2
);
466 xpthread_barrier_wait (&b2
);
469 pthread_cleanup_push (cl
, NULL
);
471 s
= waitpid (-1, NULL
, 0);
473 pthread_cleanup_pop (0);
475 FAIL_EXIT1 ("waitpid returns with %d: %m", s
);
480 tf_waitid (void *arg
)
484 FAIL_EXIT1 ("fork: %m");
488 /* Make the program disappear after a while. */
496 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
497 while (nanosleep (&ts
, &ts
) != 0)
500 xpthread_barrier_wait (&b2
);
503 xpthread_barrier_wait (&b2
);
506 pthread_cleanup_push (cl
, NULL
);
512 s
= waitid (P_PID
, pid
, &si
, WEXITED
);
514 pthread_cleanup_pop (0);
516 FAIL_EXIT1 ("waitid returns with %d: %m", s
);
521 tf_sigpause (void *arg
)
523 xpthread_barrier_wait (&b2
);
526 xpthread_barrier_wait (&b2
);
528 pthread_cleanup_push (cl
, NULL
);
530 sigpause (sigmask (SIGINT
));
532 pthread_cleanup_pop (0);
534 FAIL_EXIT1 ("sigpause returned");
539 tf_sigsuspend (void *arg
)
541 xpthread_barrier_wait (&b2
);
544 xpthread_barrier_wait (&b2
);
546 pthread_cleanup_push (cl
, NULL
);
548 /* Just for fun block all signals. */
553 pthread_cleanup_pop (0);
555 FAIL_EXIT1 ("sigsuspend returned");
560 tf_sigwait (void *arg
)
562 xpthread_barrier_wait (&b2
);
565 xpthread_barrier_wait (&b2
);
570 sigaddset (&mask
, SIGUSR1
);
571 TEST_VERIFY_EXIT (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) == 0);
574 pthread_cleanup_push (cl
, NULL
);
576 /* Wait for SIGUSR1. */
577 sigwait (&mask
, &sig
);
579 pthread_cleanup_pop (0);
581 FAIL_EXIT1 ("sigwait returned with signal %d", sig
);
586 tf_sigwaitinfo (void *arg
)
588 xpthread_barrier_wait (&b2
);
591 xpthread_barrier_wait (&b2
);
596 sigaddset (&mask
, SIGUSR1
);
597 TEST_VERIFY_EXIT (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) == 0);
600 pthread_cleanup_push (cl
, NULL
);
602 /* Wait for SIGUSR1. */
603 sigwaitinfo (&mask
, &info
);
605 pthread_cleanup_pop (0);
607 FAIL_EXIT1 ("sigwaitinfo returned with signal %d", info
.si_signo
);
612 tf_sigtimedwait (void *arg
)
614 xpthread_barrier_wait (&b2
);
617 xpthread_barrier_wait (&b2
);
622 sigaddset (&mask
, SIGUSR1
);
623 TEST_VERIFY_EXIT (pthread_sigmask (SIG_BLOCK
, &mask
, NULL
) == 0);
625 /* Wait for SIGUSR1. */
627 struct timespec ts
= { .tv_sec
= 60, .tv_nsec
= 0 };
628 pthread_cleanup_push (cl
, NULL
);
630 sigtimedwait (&mask
, &info
, &ts
);
632 pthread_cleanup_pop (0);
634 FAIL_EXIT1 ("sigtimedwait returned with signal %d", info
.si_signo
);
641 xpthread_barrier_wait (&b2
);
644 xpthread_barrier_wait (&b2
);
646 pthread_cleanup_push (cl
, NULL
);
650 pthread_cleanup_pop (0);
652 FAIL_EXIT1 ("pause returned");
657 tf_accept (void *arg
)
659 struct sockaddr_un sun
;
660 /* To test a non-blocking accept call we make the call file by using
661 a datagrame socket. */
662 int pf
= arg
== NULL
? SOCK_STREAM
: SOCK_DGRAM
;
664 tempfd
= socket (AF_UNIX
, pf
, 0);
666 FAIL_EXIT1 ("socket (AF_UNIX, %s, 0): %m", arg
== NULL
? "SOCK_STREAM"
672 TEST_VERIFY_EXIT (tries
++ < 10);
674 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-1-XXXXXX");
675 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
677 sun
.sun_family
= AF_UNIX
;
679 while (bind (tempfd
, (struct sockaddr
*) &sun
,
680 offsetof (struct sockaddr_un
, sun_path
)
681 + strlen (sun
.sun_path
) + 1) != 0);
683 unlink (sun
.sun_path
);
687 socklen_t len
= sizeof (sun
);
689 xpthread_barrier_wait (&b2
);
692 xpthread_barrier_wait (&b2
);
694 pthread_cleanup_push (cl
, NULL
);
696 accept (tempfd
, (struct sockaddr
*) &sun
, &len
);
698 pthread_cleanup_pop (0);
700 FAIL_EXIT1 ("accept returned");
707 struct sockaddr_un sun
;
709 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
711 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
716 TEST_VERIFY_EXIT (tries
++ < 10);
718 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
719 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
721 sun
.sun_family
= AF_UNIX
;
723 while (bind (tempfd
, (struct sockaddr
*) &sun
,
724 offsetof (struct sockaddr_un
, sun_path
)
725 + strlen (sun
.sun_path
) + 1) != 0);
729 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
731 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
733 set_socket_buffer (tempfd2
);
735 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
736 FAIL_EXIT1 ("connect: %m");
738 unlink (sun
.sun_path
);
740 xpthread_barrier_wait (&b2
);
743 xpthread_barrier_wait (&b2
);
745 pthread_cleanup_push (cl
, NULL
);
747 char mem
[WRITE_BUFFER_SIZE
];
749 send (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0);
750 /* The send can return a value higher than 0 (meaning partial send)
751 due to the SIGCANCEL, but the thread may still be pending
753 pthread_testcancel ();
755 pthread_cleanup_pop (0);
757 FAIL_EXIT1 ("send returned");
764 struct sockaddr_un sun
;
766 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
768 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
773 TEST_VERIFY_EXIT (tries
++ < 10);
775 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-3-XXXXXX");
776 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
778 sun
.sun_family
= AF_UNIX
;
780 while (bind (tempfd
, (struct sockaddr
*) &sun
,
781 offsetof (struct sockaddr_un
, sun_path
)
782 + strlen (sun
.sun_path
) + 1) != 0);
786 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
788 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
790 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
791 FAIL_EXIT1 ("connect: %m");
793 unlink (sun
.sun_path
);
795 xpthread_barrier_wait (&b2
);
798 xpthread_barrier_wait (&b2
);
800 pthread_cleanup_push (cl
, NULL
);
804 recv (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0);
806 pthread_cleanup_pop (0);
808 FAIL_EXIT1 ("recv returned");
813 tf_recvfrom (void *arg
)
815 struct sockaddr_un sun
;
817 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
819 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
824 TEST_VERIFY_EXIT (tries
++ < 10);
826 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-4-XXXXXX");
827 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
829 sun
.sun_family
= AF_UNIX
;
831 while (bind (tempfd
, (struct sockaddr
*) &sun
,
832 offsetof (struct sockaddr_un
, sun_path
)
833 + strlen (sun
.sun_path
) + 1) != 0);
835 tempfname
= strdup (sun
.sun_path
);
837 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
839 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
841 xpthread_barrier_wait (&b2
);
844 xpthread_barrier_wait (&b2
);
846 pthread_cleanup_push (cl
, NULL
);
849 socklen_t len
= sizeof (sun
);
851 recvfrom (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 0, 0,
852 (struct sockaddr
*) &sun
, &len
);
854 pthread_cleanup_pop (0);
856 FAIL_EXIT1 ("recvfrom returned");
861 tf_recvmsg (void *arg
)
863 struct sockaddr_un sun
;
865 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
867 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
872 TEST_VERIFY_EXIT (tries
++ < 10);
874 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-5-XXXXXX");
875 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
877 sun
.sun_family
= AF_UNIX
;
879 while (bind (tempfd
, (struct sockaddr
*) &sun
,
880 offsetof (struct sockaddr_un
, sun_path
)
881 + strlen (sun
.sun_path
) + 1) != 0);
883 tempfname
= strdup (sun
.sun_path
);
885 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
887 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
889 xpthread_barrier_wait (&b2
);
892 xpthread_barrier_wait (&b2
);
894 pthread_cleanup_push (cl
, NULL
);
898 iov
[0].iov_base
= mem
;
899 iov
[0].iov_len
= arg
== NULL
? sizeof (mem
) : 0;
903 m
.msg_namelen
= sizeof (sun
);
906 m
.msg_control
= NULL
;
907 m
.msg_controllen
= 0;
909 recvmsg (tempfd2
, &m
, 0);
911 pthread_cleanup_pop (0);
913 FAIL_EXIT1 ("recvmsg returned");
921 fifofd
= mkfifo (fifoname
, S_IWUSR
| S_IRUSR
);
923 FAIL_EXIT1 ("mkfifo: %m");
927 xpthread_barrier_wait (&b2
);
930 xpthread_barrier_wait (&b2
);
932 pthread_cleanup_push (cl_fifo
, NULL
);
934 open (arg
? "Makefile" : fifoname
, O_RDONLY
);
936 pthread_cleanup_pop (0);
938 FAIL_EXIT1 ("open returned");
946 // XXX If somebody can provide a portable test case in which close()
947 // blocks we can enable this test to run in both rounds.
950 char fname
[] = "/tmp/tst-cancel-fd-XXXXXX";
951 tempfd
= mkstemp (fname
);
953 FAIL_EXIT1 ("mkstemp failed: %m");
956 xpthread_barrier_wait (&b2
);
958 xpthread_barrier_wait (&b2
);
960 pthread_cleanup_push (cl
, NULL
);
964 pthread_cleanup_pop (0);
966 FAIL_EXIT1 ("close returned");
974 // XXX If somebody can provide a portable test case in which pread()
975 // blocks we can enable this test to run in both rounds.
978 tempfd
= open ("Makefile", O_RDONLY
);
980 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
982 xpthread_barrier_wait (&b2
);
984 xpthread_barrier_wait (&b2
);
986 pthread_cleanup_push (cl
, NULL
);
989 pread (tempfd
, mem
, sizeof (mem
), 0);
991 pthread_cleanup_pop (0);
993 FAIL_EXIT1 ("pread returned");
998 tf_pwrite (void *arg
)
1001 // XXX If somebody can provide a portable test case in which pwrite()
1002 // blocks we can enable this test to run in both rounds.
1005 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1006 tempfd
= mkstemp (fname
);
1008 FAIL_EXIT1 ("mkstemp failed: %m");
1011 xpthread_barrier_wait (&b2
);
1013 xpthread_barrier_wait (&b2
);
1015 pthread_cleanup_push (cl
, NULL
);
1018 pwrite (tempfd
, mem
, sizeof (mem
), 0);
1020 pthread_cleanup_pop (0);
1022 FAIL_EXIT1 ("pwrite returned");
1026 tf_preadv (void *arg
)
1031 /* XXX If somebody can provide a portable test case in which preadv
1032 blocks we can enable this test to run in both rounds. */
1035 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1036 tempfd
= fd
= mkstemp (fname
);
1038 FAIL_EXIT1 ("mkstemp failed: %m");
1041 xpthread_barrier_wait (&b2
);
1043 xpthread_barrier_wait (&b2
);
1046 pthread_cleanup_push (cl
, NULL
);
1049 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1050 s
= preadv (fd
, iov
, 1, 0);
1052 pthread_cleanup_pop (0);
1054 FAIL_EXIT1 ("preadv returns with %zd", s
);
1058 tf_pwritev (void *arg
)
1063 /* XXX If somebody can provide a portable test case in which pwritev
1064 blocks we can enable this test to run in both rounds. */
1067 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1068 tempfd
= fd
= mkstemp (fname
);
1070 FAIL_EXIT1 ("mkstemp failed: %m");
1073 xpthread_barrier_wait (&b2
);
1075 xpthread_barrier_wait (&b2
);
1078 pthread_cleanup_push (cl
, NULL
);
1080 char buf
[WRITE_BUFFER_SIZE
];
1081 memset (buf
, '\0', sizeof (buf
));
1082 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1083 s
= pwritev (fd
, iov
, 1, 0);
1085 pthread_cleanup_pop (0);
1087 FAIL_EXIT1 ("pwritev returns with %zd", s
);
1091 tf_pwritev2 (void *arg
)
1096 /* XXX If somebody can provide a portable test case in which pwritev2
1097 blocks we can enable this test to run in both rounds. */
1102 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1103 tempfd
= fd
= mkstemp (fname
);
1105 FAIL_EXIT1 ("mkstemp: %m");
1108 xpthread_barrier_wait (&b2
);
1110 xpthread_barrier_wait (&b2
);
1113 pthread_cleanup_push (cl
, NULL
);
1115 char buf
[WRITE_BUFFER_SIZE
];
1116 memset (buf
, '\0', sizeof (buf
));
1117 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1118 s
= pwritev2 (fd
, iov
, 1, 0, 0);
1120 pthread_cleanup_pop (0);
1122 FAIL_EXIT1 ("pwritev2 returns with %zd", s
);
1126 tf_preadv2 (void *arg
)
1131 /* XXX If somebody can provide a portable test case in which preadv2
1132 blocks we can enable this test to run in both rounds. */
1137 char fname
[] = "/tmp/tst-cancel4-fd-XXXXXX";
1138 tempfd
= fd
= mkstemp (fname
);
1140 FAIL_EXIT1 ("mkstemp failed: %m");
1143 xpthread_barrier_wait (&b2
);
1145 xpthread_barrier_wait (&b2
);
1148 pthread_cleanup_push (cl
, NULL
);
1151 struct iovec iov
[1] = { [0] = { .iov_base
= buf
, .iov_len
= sizeof (buf
) } };
1152 s
= preadv2 (fd
, iov
, 1, 0, 0);
1154 pthread_cleanup_pop (0);
1156 FAIL_EXIT1 ("preadv2 returns with %zd", s
);
1160 tf_fsync (void *arg
)
1163 // XXX If somebody can provide a portable test case in which fsync()
1164 // blocks we can enable this test to run in both rounds.
1167 tempfd
= open ("Makefile", O_RDONLY
);
1169 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
1171 xpthread_barrier_wait (&b2
);
1173 xpthread_barrier_wait (&b2
);
1175 pthread_cleanup_push (cl
, NULL
);
1179 pthread_cleanup_pop (0);
1181 FAIL_EXIT1 ("fsync returned");
1186 tf_fdatasync (void *arg
)
1189 // XXX If somebody can provide a portable test case in which fdatasync()
1190 // blocks we can enable this test to run in both rounds.
1193 tempfd
= open ("Makefile", O_RDONLY
);
1195 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
1197 xpthread_barrier_wait (&b2
);
1199 xpthread_barrier_wait (&b2
);
1201 pthread_cleanup_push (cl
, NULL
);
1205 pthread_cleanup_pop (0);
1207 FAIL_EXIT1 ("fdatasync returned");
1212 tf_msync (void *arg
)
1215 // XXX If somebody can provide a portable test case in which msync()
1216 // blocks we can enable this test to run in both rounds.
1219 tempfd
= open ("Makefile", O_RDONLY
);
1221 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
1223 void *p
= xmmap (NULL
, 10, PROT_READ
, MAP_SHARED
, tempfd
);
1225 xpthread_barrier_wait (&b2
);
1227 xpthread_barrier_wait (&b2
);
1229 pthread_cleanup_push (cl
, NULL
);
1233 pthread_cleanup_pop (0);
1235 FAIL_EXIT1 ("msync returned");
1240 tf_sendto (void *arg
)
1242 struct sockaddr_un sun
;
1244 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1246 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
1251 TEST_VERIFY_EXIT (tries
++ < 10);
1253 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-6-XXXXXX");
1254 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
1256 sun
.sun_family
= AF_UNIX
;
1258 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1259 offsetof (struct sockaddr_un
, sun_path
)
1260 + strlen (sun
.sun_path
) + 1) != 0);
1264 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1266 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
1268 set_socket_buffer (tempfd2
);
1270 if (connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
)) != 0)
1271 FAIL_EXIT1 ("connect: %m");
1273 unlink (sun
.sun_path
);
1275 xpthread_barrier_wait (&b2
);
1278 xpthread_barrier_wait (&b2
);
1280 pthread_cleanup_push (cl
, NULL
);
1282 char mem
[WRITE_BUFFER_SIZE
];
1284 sendto (tempfd2
, mem
, arg
== NULL
? sizeof (mem
) : 1, 0, NULL
, 0);
1286 pthread_cleanup_pop (0);
1288 FAIL_EXIT1 ("sendto returned");
1293 tf_sendmsg (void *arg
)
1296 // XXX If somebody can provide a portable test case in which sendmsg()
1297 // blocks we can enable this test to run in both rounds.
1300 struct sockaddr_un sun
;
1302 tempfd
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1304 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
1309 TEST_VERIFY_EXIT (tries
++ < 10);
1311 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-7-XXXXXX");
1312 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
1314 sun
.sun_family
= AF_UNIX
;
1316 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1317 offsetof (struct sockaddr_un
, sun_path
)
1318 + strlen (sun
.sun_path
) + 1) != 0);
1319 tempfname
= strdup (sun
.sun_path
);
1321 tempfd2
= socket (AF_UNIX
, SOCK_DGRAM
, 0);
1323 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
1325 xpthread_barrier_wait (&b2
);
1327 xpthread_barrier_wait (&b2
);
1329 pthread_cleanup_push (cl
, NULL
);
1332 struct iovec iov
[1];
1333 iov
[0].iov_base
= mem
;
1338 m
.msg_namelen
= (offsetof (struct sockaddr_un
, sun_path
)
1339 + strlen (sun
.sun_path
) + 1);
1342 m
.msg_control
= NULL
;
1343 m
.msg_controllen
= 0;
1345 sendmsg (tempfd2
, &m
, 0);
1347 pthread_cleanup_pop (0);
1349 FAIL_EXIT1 ("sendmsg returned");
1354 tf_creat (void *arg
)
1357 // XXX If somebody can provide a portable test case in which sendmsg()
1358 // blocks we can enable this test to run in both rounds.
1361 xpthread_barrier_wait (&b2
);
1363 xpthread_barrier_wait (&b2
);
1365 pthread_cleanup_push (cl
, NULL
);
1367 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1369 pthread_cleanup_pop (0);
1371 FAIL_EXIT1 ("creat returned");
1376 tf_connect (void *arg
)
1379 // XXX If somebody can provide a portable test case in which connect()
1380 // blocks we can enable this test to run in both rounds.
1383 struct sockaddr_un sun
;
1385 tempfd
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1387 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
1392 TEST_VERIFY_EXIT (tries
++ < 10);
1394 strcpy (sun
.sun_path
, "/tmp/tst-cancel4-socket-2-XXXXXX");
1395 TEST_VERIFY_EXIT (mktemp (sun
.sun_path
) != NULL
);
1397 sun
.sun_family
= AF_UNIX
;
1399 while (bind (tempfd
, (struct sockaddr
*) &sun
,
1400 offsetof (struct sockaddr_un
, sun_path
)
1401 + strlen (sun
.sun_path
) + 1) != 0);
1402 tempfname
= strdup (sun
.sun_path
);
1406 tempfd2
= socket (AF_UNIX
, SOCK_STREAM
, 0);
1408 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
1410 xpthread_barrier_wait (&b2
);
1413 xpthread_barrier_wait (&b2
);
1415 pthread_cleanup_push (cl
, NULL
);
1417 connect (tempfd2
, (struct sockaddr
*) &sun
, sizeof (sun
));
1419 pthread_cleanup_pop (0);
1421 FAIL_EXIT1 ("connect returned");
1426 tf_tcdrain (void *arg
)
1429 // XXX If somebody can provide a portable test case in which tcdrain()
1430 // blocks we can enable this test to run in both rounds.
1433 xpthread_barrier_wait (&b2
);
1436 xpthread_barrier_wait (&b2
);
1438 pthread_cleanup_push (cl
, NULL
);
1440 /* Regardless of stderr being a terminal, the tcdrain call should be
1442 tcdrain (STDERR_FILENO
);
1444 pthread_cleanup_pop (0);
1446 FAIL_EXIT1 ("tcdrain returned");
1451 tf_msgrcv (void *arg
)
1453 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1455 FAIL_EXIT1 ("msgget (IPC_PRIVATE, 0666 | IPC_CREAT): %m");
1457 xpthread_barrier_wait (&b2
);
1460 xpthread_barrier_wait (&b2
);
1464 pthread_cleanup_push (cl
, NULL
);
1472 /* We need a positive random number. */
1474 randnr
= random () % 64000;
1475 while (randnr
<= 0);
1479 s
= msgrcv (tempmsg
, (struct msgbuf
*) &m
, 10, randnr
, 0);
1481 while (errno
== EIDRM
|| errno
== EINTR
);
1483 pthread_cleanup_pop (0);
1485 msgctl (tempmsg
, IPC_RMID
, NULL
);
1487 FAIL_EXIT1 ("msgrcv returned %zd", s
);
1492 tf_msgsnd (void *arg
)
1495 // XXX If somebody can provide a portable test case in which msgsnd()
1496 // blocks we can enable this test to run in both rounds.
1499 tempmsg
= msgget (IPC_PRIVATE
, 0666 | IPC_CREAT
);
1501 FAIL_EXIT1 ("msgget (IPC_PRIVATE, 0666 | IPC_CREAT): %m");
1503 xpthread_barrier_wait (&b2
);
1505 xpthread_barrier_wait (&b2
);
1507 pthread_cleanup_push (cl
, NULL
);
1514 /* We need a positive random number. */
1516 m
.type
= random () % 64000;
1517 while (m
.type
<= 0);
1518 msgsnd (tempmsg
, (struct msgbuf
*) &m
, sizeof (m
.mem
), 0);
1520 pthread_cleanup_pop (0);
1522 msgctl (tempmsg
, IPC_RMID
, NULL
);
1524 FAIL_EXIT1 ("msgsnd returned");
1528 struct cancel_tests tests
[] =
1530 ADD_TEST (read
, 2, 0),
1531 ADD_TEST (readv
, 2, 0),
1532 ADD_TEST (select
, 2, 0),
1533 ADD_TEST (pselect
, 2, 0),
1534 ADD_TEST (poll
, 2, 0),
1535 ADD_TEST (ppoll
, 2, 0),
1536 ADD_TEST (write
, 2, 0),
1537 ADD_TEST (writev
, 2, 0),
1538 ADD_TEST (sleep
, 2, 0),
1539 ADD_TEST (usleep
, 2, 0),
1540 ADD_TEST (nanosleep
, 2, 0),
1541 ADD_TEST (wait
, 2, 0),
1542 ADD_TEST (waitid
, 2, 0),
1543 ADD_TEST (waitpid
, 2, 0),
1544 ADD_TEST (sigpause
, 2, 0),
1545 ADD_TEST (sigsuspend
, 2, 0),
1546 ADD_TEST (sigwait
, 2, 0),
1547 ADD_TEST (sigwaitinfo
, 2, 0),
1548 ADD_TEST (sigtimedwait
, 2, 0),
1549 ADD_TEST (pause
, 2, 0),
1550 ADD_TEST (accept
, 2, 0),
1551 ADD_TEST (send
, 2, 0),
1552 ADD_TEST (recv
, 2, 0),
1553 ADD_TEST (recvfrom
, 2, 0),
1554 ADD_TEST (recvmsg
, 2, 0),
1555 ADD_TEST (preadv
, 2, 1),
1556 ADD_TEST (preadv2
, 2, 1),
1557 ADD_TEST (pwritev
, 2, 1),
1558 ADD_TEST (pwritev2
, 2, 1),
1559 ADD_TEST (open
, 2, 1),
1560 ADD_TEST (close
, 2, 1),
1561 ADD_TEST (pread
, 2, 1),
1562 ADD_TEST (pwrite
, 2, 1),
1563 ADD_TEST (fsync
, 2, 1),
1564 ADD_TEST (fdatasync
, 2, 1),
1565 ADD_TEST (msync
, 2, 1),
1566 ADD_TEST (sendto
, 2, 1),
1567 ADD_TEST (sendmsg
, 2, 1),
1568 ADD_TEST (creat
, 2, 1),
1569 ADD_TEST (connect
, 2, 1),
1570 ADD_TEST (tcdrain
, 2, 1),
1571 ADD_TEST (msgrcv
, 2, 0),
1572 ADD_TEST (msgsnd
, 2, 1),
1574 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
1576 #include "tst-cancel4-common.c"