Add tests for strfrom functions
[glibc.git] / nptl / tst-cancel4.c
blobfd0ab4070eadcb55dc868e66da68731fcefc2dd8
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>
40 /* Since STREAMS are not supported in the standard Linux kernel and
41 there we don't advertise STREAMS as supported is no need to test
42 the STREAMS related functions. This affects
43 getmsg() getpmsg() putmsg()
44 putpmsg()
46 lockf() and fcntl() are tested in tst-cancel16.
48 pthread_join() is tested in tst-join5.
50 pthread_testcancel()'s only purpose is to allow cancellation. This
51 is tested in several places.
53 sem_wait() and sem_timedwait() are checked in tst-cancel1[2345] tests.
55 mq_send(), mq_timedsend(), mq_receive() and mq_timedreceive() are checked
56 in tst-mqueue8{,x} tests.
58 aio_suspend() is tested in tst-cancel17.
60 clock_nanosleep() is tested in tst-cancel18.
62 Linux sendmmsg and recvmmsg are checked in tst-cancel4_1.c and
63 tst-cancel4_2.c respectively.
66 #include "tst-cancel4-common.h"
69 #ifndef IPC_ADDVAL
70 # define IPC_ADDVAL 0
71 #endif
74 static void *
75 tf_read (void *arg)
77 int fd;
78 int r;
80 if (arg == NULL)
81 fd = fds[0];
82 else
84 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
85 tempfd = fd = mkstemp (fname);
86 if (fd == -1)
87 printf ("%s: mkstemp failed\n", __FUNCTION__);
88 unlink (fname);
90 r = pthread_barrier_wait (&b2);
91 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
93 printf ("%s: barrier_wait failed\n", __FUNCTION__);
94 exit (1);
98 r = pthread_barrier_wait (&b2);
99 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
101 printf ("%s: barrier_wait failed\n", __FUNCTION__);
102 exit (1);
105 ssize_t s;
106 pthread_cleanup_push (cl, NULL);
108 char buf[100];
109 s = read (fd, buf, sizeof (buf));
111 pthread_cleanup_pop (0);
113 printf ("%s: read returns with %zd\n", __FUNCTION__, s);
115 exit (1);
119 static void *
120 tf_readv (void *arg)
122 int fd;
123 int r;
125 if (arg == NULL)
126 fd = fds[0];
127 else
129 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
130 tempfd = fd = mkstemp (fname);
131 if (fd == -1)
132 printf ("%s: mkstemp failed\n", __FUNCTION__);
133 unlink (fname);
135 r = pthread_barrier_wait (&b2);
136 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
138 printf ("%s: barrier_wait failed\n", __FUNCTION__);
139 exit (1);
143 r = pthread_barrier_wait (&b2);
144 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
146 printf ("%s: barrier_wait failed\n", __FUNCTION__);
147 exit (1);
150 ssize_t s;
151 pthread_cleanup_push (cl, NULL);
153 char buf[100];
154 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
155 s = readv (fd, iov, 1);
157 pthread_cleanup_pop (0);
159 printf ("%s: readv returns with %zd\n", __FUNCTION__, s);
161 exit (1);
165 static void *
166 tf_write (void *arg)
168 int fd;
169 int r;
171 if (arg == NULL)
172 fd = fds[1];
173 else
175 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
176 tempfd = fd = mkstemp (fname);
177 if (fd == -1)
178 printf ("%s: mkstemp failed\n", __FUNCTION__);
179 unlink (fname);
181 r = pthread_barrier_wait (&b2);
182 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
184 printf ("%s: barrier_wait failed\n", __FUNCTION__);
185 exit (1);
189 r = pthread_barrier_wait (&b2);
190 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
192 printf ("%s: barrier_wait failed\n", __FUNCTION__);
193 exit (1);
196 ssize_t s;
197 pthread_cleanup_push (cl, NULL);
199 char buf[WRITE_BUFFER_SIZE];
200 memset (buf, '\0', sizeof (buf));
201 s = write (fd, buf, sizeof (buf));
203 pthread_cleanup_pop (0);
205 printf ("%s: write returns with %zd\n", __FUNCTION__, s);
207 exit (1);
211 static void *
212 tf_writev (void *arg)
214 int fd;
215 int r;
217 if (arg == NULL)
218 fd = fds[1];
219 else
221 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
222 tempfd = fd = mkstemp (fname);
223 if (fd == -1)
224 printf ("%s: mkstemp failed\n", __FUNCTION__);
225 unlink (fname);
227 r = pthread_barrier_wait (&b2);
228 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
230 printf ("%s: barrier_wait failed\n", __FUNCTION__);
231 exit (1);
235 r = pthread_barrier_wait (&b2);
236 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
238 printf ("%s: barrier_wait failed\n", __FUNCTION__);
239 exit (1);
242 ssize_t s;
243 pthread_cleanup_push (cl, NULL);
245 char buf[WRITE_BUFFER_SIZE];
246 memset (buf, '\0', sizeof (buf));
247 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
248 s = writev (fd, iov, 1);
250 pthread_cleanup_pop (0);
252 printf ("%s: writev returns with %zd\n", __FUNCTION__, s);
254 exit (1);
258 static void *
259 tf_sleep (void *arg)
261 int r = pthread_barrier_wait (&b2);
262 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
264 printf ("%s: barrier_wait failed\n", __FUNCTION__);
265 exit (1);
268 if (arg != NULL)
270 r = pthread_barrier_wait (&b2);
271 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
273 printf ("%s: barrier_wait failed\n", __FUNCTION__);
274 exit (1);
278 pthread_cleanup_push (cl, NULL);
280 sleep (arg == NULL ? 1000000 : 0);
282 pthread_cleanup_pop (0);
284 printf ("%s: sleep returns\n", __FUNCTION__);
286 exit (1);
290 static void *
291 tf_usleep (void *arg)
293 int r = pthread_barrier_wait (&b2);
294 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
296 printf ("%s: barrier_wait failed\n", __FUNCTION__);
297 exit (1);
300 if (arg != NULL)
302 r = pthread_barrier_wait (&b2);
303 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
305 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
306 exit (1);
310 pthread_cleanup_push (cl, NULL);
312 usleep (arg == NULL ? (useconds_t) ULONG_MAX : 0);
314 pthread_cleanup_pop (0);
316 printf ("%s: usleep returns\n", __FUNCTION__);
318 exit (1);
322 static void *
323 tf_nanosleep (void *arg)
325 int r = pthread_barrier_wait (&b2);
326 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
328 printf ("%s: barrier_wait failed\n", __FUNCTION__);
329 exit (1);
332 if (arg != NULL)
334 r = pthread_barrier_wait (&b2);
335 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
337 printf ("%s: barrier_wait failed\n", __FUNCTION__);
338 exit (1);
342 pthread_cleanup_push (cl, NULL);
344 struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 };
345 TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
347 pthread_cleanup_pop (0);
349 printf ("%s: nanosleep returns\n", __FUNCTION__);
351 exit (1);
355 static void *
356 tf_select (void *arg)
358 int fd;
359 int r;
361 if (arg == NULL)
362 fd = fds[0];
363 else
365 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
366 tempfd = fd = mkstemp (fname);
367 if (fd == -1)
368 printf ("%s: mkstemp failed\n", __FUNCTION__);
369 unlink (fname);
371 r = pthread_barrier_wait (&b2);
372 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
374 printf ("%s: barrier_wait failed\n", __FUNCTION__);
375 exit (1);
379 r = pthread_barrier_wait (&b2);
380 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
382 printf ("%s: barrier_wait failed\n", __FUNCTION__);
383 exit (1);
386 fd_set rfs;
387 FD_ZERO (&rfs);
388 FD_SET (fd, &rfs);
390 int s;
391 pthread_cleanup_push (cl, NULL);
393 s = select (fd + 1, &rfs, NULL, NULL, NULL);
395 pthread_cleanup_pop (0);
397 printf ("%s: select returns with %d (%s)\n", __FUNCTION__, s,
398 strerror (errno));
400 exit (1);
404 static void *
405 tf_pselect (void *arg)
407 int fd;
408 int r;
410 if (arg == NULL)
411 fd = fds[0];
412 else
414 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
415 tempfd = fd = mkstemp (fname);
416 if (fd == -1)
417 printf ("%s: mkstemp failed\n", __FUNCTION__);
418 unlink (fname);
420 r = pthread_barrier_wait (&b2);
421 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
423 printf ("%s: barrier_wait failed\n", __FUNCTION__);
424 exit (1);
428 r = pthread_barrier_wait (&b2);
429 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
431 printf ("%s: barrier_wait failed\n", __FUNCTION__);
432 exit (1);
435 fd_set rfs;
436 FD_ZERO (&rfs);
437 FD_SET (fd, &rfs);
439 int s;
440 pthread_cleanup_push (cl, NULL);
442 s = pselect (fd + 1, &rfs, NULL, NULL, NULL, NULL);
444 pthread_cleanup_pop (0);
446 printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__, s,
447 strerror (errno));
449 exit (1);
453 static void *
454 tf_poll (void *arg)
456 int fd;
457 int r;
459 if (arg == NULL)
460 fd = fds[0];
461 else
463 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
464 tempfd = fd = mkstemp (fname);
465 if (fd == -1)
466 printf ("%s: mkstemp failed\n", __FUNCTION__);
467 unlink (fname);
469 r = pthread_barrier_wait (&b2);
470 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
472 printf ("%s: barrier_wait failed\n", __FUNCTION__);
473 exit (1);
477 r = pthread_barrier_wait (&b2);
478 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
480 printf ("%s: barrier_wait failed\n", __FUNCTION__);
481 exit (1);
484 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
486 int s;
487 pthread_cleanup_push (cl, NULL);
489 s = poll (rfs, 1, -1);
491 pthread_cleanup_pop (0);
493 printf ("%s: poll returns with %d (%s)\n", __FUNCTION__, s,
494 strerror (errno));
496 exit (1);
500 static void *
501 tf_ppoll (void *arg)
503 int fd;
504 int r;
506 if (arg == NULL)
507 fd = fds[0];
508 else
510 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
511 tempfd = fd = mkstemp (fname);
512 if (fd == -1)
513 printf ("%s: mkstemp failed\n", __FUNCTION__);
514 unlink (fname);
516 r = pthread_barrier_wait (&b2);
517 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
519 printf ("%s: barrier_wait failed\n", __FUNCTION__);
520 exit (1);
524 r = pthread_barrier_wait (&b2);
525 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
527 printf ("%s: barrier_wait failed\n", __FUNCTION__);
528 exit (1);
531 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
533 int s;
534 pthread_cleanup_push (cl, NULL);
536 s = ppoll (rfs, 1, NULL, NULL);
538 pthread_cleanup_pop (0);
540 printf ("%s: ppoll returns with %d (%s)\n", __FUNCTION__, s,
541 strerror (errno));
543 exit (1);
547 static void *
548 tf_wait (void *arg)
550 pid_t pid = fork ();
551 if (pid == -1)
553 puts ("fork failed");
554 exit (1);
557 if (pid == 0)
559 /* Make the program disappear after a while. */
560 if (arg == NULL)
561 sleep (10);
562 exit (0);
565 int r;
566 if (arg != NULL)
568 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
569 while (nanosleep (&ts, &ts) != 0)
570 continue;
572 r = pthread_barrier_wait (&b2);
573 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
575 printf ("%s: barrier_wait failed\n", __FUNCTION__);
576 exit (1);
580 r = pthread_barrier_wait (&b2);
581 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
583 printf ("%s: barrier_wait failed\n", __FUNCTION__);
584 exit (1);
587 int s;
588 pthread_cleanup_push (cl, NULL);
590 s = wait (NULL);
592 pthread_cleanup_pop (0);
594 printf ("%s: wait returns with %d (%s)\n", __FUNCTION__, s,
595 strerror (errno));
597 exit (1);
601 static void *
602 tf_waitpid (void *arg)
605 pid_t pid = fork ();
606 if (pid == -1)
608 puts ("fork failed");
609 exit (1);
612 if (pid == 0)
614 /* Make the program disappear after a while. */
615 if (arg == NULL)
616 sleep (10);
617 exit (0);
620 int r;
621 if (arg != NULL)
623 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
624 while (nanosleep (&ts, &ts) != 0)
625 continue;
627 r = pthread_barrier_wait (&b2);
628 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
630 printf ("%s: barrier_wait failed\n", __FUNCTION__);
631 exit (1);
635 r = pthread_barrier_wait (&b2);
636 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
638 printf ("%s: barrier_wait failed\n", __FUNCTION__);
639 exit (1);
642 int s;
643 pthread_cleanup_push (cl, NULL);
645 s = waitpid (-1, NULL, 0);
647 pthread_cleanup_pop (0);
649 printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__, s,
650 strerror (errno));
652 exit (1);
656 static void *
657 tf_waitid (void *arg)
659 pid_t pid = fork ();
660 if (pid == -1)
662 puts ("fork failed");
663 exit (1);
666 if (pid == 0)
668 /* Make the program disappear after a while. */
669 if (arg == NULL)
670 sleep (10);
671 exit (0);
674 int r;
675 if (arg != NULL)
677 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
678 while (nanosleep (&ts, &ts) != 0)
679 continue;
681 r = pthread_barrier_wait (&b2);
682 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
684 printf ("%s: barrier_wait failed\n", __FUNCTION__);
685 exit (1);
689 r = pthread_barrier_wait (&b2);
690 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
692 printf ("%s: barrier_wait failed\n", __FUNCTION__);
693 exit (1);
696 int s;
697 pthread_cleanup_push (cl, NULL);
699 #ifndef WEXITED
700 # define WEXITED 0
701 #endif
702 siginfo_t si;
703 s = waitid (P_PID, pid, &si, WEXITED);
705 pthread_cleanup_pop (0);
707 printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__, s,
708 strerror (errno));
710 exit (1);
714 static void *
715 tf_sigpause (void *arg)
717 int r = pthread_barrier_wait (&b2);
718 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
720 printf ("%s: barrier_wait failed\n", __FUNCTION__);
721 exit (1);
724 if (arg != NULL)
726 r = pthread_barrier_wait (&b2);
727 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
729 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
730 exit (1);
734 pthread_cleanup_push (cl, NULL);
736 sigpause (sigmask (SIGINT));
738 pthread_cleanup_pop (0);
740 printf ("%s: sigpause returned\n", __FUNCTION__);
742 exit (1);
746 static void *
747 tf_sigsuspend (void *arg)
749 int r = pthread_barrier_wait (&b2);
750 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
752 printf ("%s: barrier_wait failed\n", __FUNCTION__);
753 exit (1);
756 if (arg != NULL)
758 r = pthread_barrier_wait (&b2);
759 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
761 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
762 exit (1);
766 pthread_cleanup_push (cl, NULL);
768 /* Just for fun block all signals. */
769 sigset_t mask;
770 sigfillset (&mask);
771 sigsuspend (&mask);
773 pthread_cleanup_pop (0);
775 printf ("%s: sigsuspend returned\n", __FUNCTION__);
777 exit (1);
781 static void *
782 tf_sigwait (void *arg)
784 int r = pthread_barrier_wait (&b2);
785 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
787 printf ("%s: barrier_wait failed\n", __FUNCTION__);
788 exit (1);
791 if (arg != NULL)
793 r = pthread_barrier_wait (&b2);
794 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
796 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
797 exit (1);
801 /* Block SIGUSR1. */
802 sigset_t mask;
803 sigemptyset (&mask);
804 sigaddset (&mask, SIGUSR1);
805 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
807 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
808 exit (1);
811 int sig;
812 pthread_cleanup_push (cl, NULL);
814 /* Wait for SIGUSR1. */
815 sigwait (&mask, &sig);
817 pthread_cleanup_pop (0);
819 printf ("%s: sigwait returned with signal %d\n", __FUNCTION__, sig);
821 exit (1);
825 static void *
826 tf_sigwaitinfo (void *arg)
828 int r = pthread_barrier_wait (&b2);
829 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
831 printf ("%s: barrier_wait failed\n", __FUNCTION__);
832 exit (1);
835 if (arg != NULL)
837 r = pthread_barrier_wait (&b2);
838 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
840 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
841 exit (1);
845 /* Block SIGUSR1. */
846 sigset_t mask;
847 sigemptyset (&mask);
848 sigaddset (&mask, SIGUSR1);
849 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
851 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
852 exit (1);
855 siginfo_t info;
856 pthread_cleanup_push (cl, NULL);
858 /* Wait for SIGUSR1. */
859 sigwaitinfo (&mask, &info);
861 pthread_cleanup_pop (0);
863 printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__,
864 info.si_signo);
866 exit (1);
870 static void *
871 tf_sigtimedwait (void *arg)
873 int r = pthread_barrier_wait (&b2);
874 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
876 printf ("%s: barrier_wait failed\n", __FUNCTION__);
877 exit (1);
880 if (arg != NULL)
882 r = pthread_barrier_wait (&b2);
883 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
885 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
886 exit (1);
890 /* Block SIGUSR1. */
891 sigset_t mask;
892 sigemptyset (&mask);
893 sigaddset (&mask, SIGUSR1);
894 if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0)
896 printf ("%s: pthread_sigmask failed\n", __FUNCTION__);
897 exit (1);
900 /* Wait for SIGUSR1. */
901 siginfo_t info;
902 struct timespec ts = { .tv_sec = 60, .tv_nsec = 0 };
903 pthread_cleanup_push (cl, NULL);
905 sigtimedwait (&mask, &info, &ts);
907 pthread_cleanup_pop (0);
909 printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__,
910 info.si_signo);
912 exit (1);
916 static void *
917 tf_pause (void *arg)
919 int r = pthread_barrier_wait (&b2);
920 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
922 printf ("%s: barrier_wait failed\n", __FUNCTION__);
923 exit (1);
926 if (arg != NULL)
928 r = pthread_barrier_wait (&b2);
929 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
931 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
932 exit (1);
936 pthread_cleanup_push (cl, NULL);
938 pause ();
940 pthread_cleanup_pop (0);
942 printf ("%s: pause returned\n", __FUNCTION__);
944 exit (1);
948 static void *
949 tf_accept (void *arg)
951 struct sockaddr_un sun;
952 /* To test a non-blocking accept call we make the call file by using
953 a datagrame socket. */
954 int pf = arg == NULL ? SOCK_STREAM : SOCK_DGRAM;
956 tempfd = socket (AF_UNIX, pf, 0);
957 if (tempfd == -1)
959 printf ("%s: socket call failed\n", __FUNCTION__);
960 exit (1);
963 int tries = 0;
966 if (++tries > 10)
968 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
971 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
972 if (mktemp (sun.sun_path) == NULL)
974 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
975 exit (1);
978 sun.sun_family = AF_UNIX;
980 while (bind (tempfd, (struct sockaddr *) &sun,
981 offsetof (struct sockaddr_un, sun_path)
982 + strlen (sun.sun_path) + 1) != 0);
984 unlink (sun.sun_path);
986 listen (tempfd, 5);
988 socklen_t len = sizeof (sun);
990 int r = pthread_barrier_wait (&b2);
991 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
993 printf ("%s: barrier_wait failed\n", __FUNCTION__);
994 exit (1);
997 if (arg != NULL)
999 r = pthread_barrier_wait (&b2);
1000 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1002 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1003 exit (1);
1007 pthread_cleanup_push (cl, NULL);
1009 accept (tempfd, (struct sockaddr *) &sun, &len);
1011 pthread_cleanup_pop (0);
1013 printf ("%s: accept returned\n", __FUNCTION__);
1015 exit (1);
1019 static void *
1020 tf_send (void *arg)
1022 struct sockaddr_un sun;
1024 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1025 if (tempfd == -1)
1027 printf ("%s: first socket call failed\n", __FUNCTION__);
1028 exit (1);
1031 int tries = 0;
1034 if (++tries > 10)
1036 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1039 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
1040 if (mktemp (sun.sun_path) == NULL)
1042 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1043 exit (1);
1046 sun.sun_family = AF_UNIX;
1048 while (bind (tempfd, (struct sockaddr *) &sun,
1049 offsetof (struct sockaddr_un, sun_path)
1050 + strlen (sun.sun_path) + 1) != 0);
1052 listen (tempfd, 5);
1054 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1055 if (tempfd2 == -1)
1057 printf ("%s: second socket call failed\n", __FUNCTION__);
1058 exit (1);
1061 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1063 printf ("%s: connect failed\n", __FUNCTION__);
1064 exit(1);
1067 unlink (sun.sun_path);
1069 int r = pthread_barrier_wait (&b2);
1070 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1072 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1073 exit (1);
1076 if (arg != NULL)
1078 r = pthread_barrier_wait (&b2);
1079 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1081 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1082 exit (1);
1086 pthread_cleanup_push (cl, NULL);
1088 /* Very large block, so that the send call blocks. */
1089 char mem[700000];
1091 send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
1093 pthread_cleanup_pop (0);
1095 printf ("%s: send returned\n", __FUNCTION__);
1097 exit (1);
1101 static void *
1102 tf_recv (void *arg)
1104 struct sockaddr_un sun;
1106 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1107 if (tempfd == -1)
1109 printf ("%s: first socket call failed\n", __FUNCTION__);
1110 exit (1);
1113 int tries = 0;
1116 if (++tries > 10)
1118 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1121 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX");
1122 if (mktemp (sun.sun_path) == NULL)
1124 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1125 exit (1);
1128 sun.sun_family = AF_UNIX;
1130 while (bind (tempfd, (struct sockaddr *) &sun,
1131 offsetof (struct sockaddr_un, sun_path)
1132 + strlen (sun.sun_path) + 1) != 0);
1134 listen (tempfd, 5);
1136 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1137 if (tempfd2 == -1)
1139 printf ("%s: second socket call failed\n", __FUNCTION__);
1140 exit (1);
1143 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
1145 printf ("%s: connect failed\n", __FUNCTION__);
1146 exit(1);
1149 unlink (sun.sun_path);
1151 int r = pthread_barrier_wait (&b2);
1152 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1154 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1155 exit (1);
1158 if (arg != NULL)
1160 r = pthread_barrier_wait (&b2);
1161 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1163 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1164 exit (1);
1168 pthread_cleanup_push (cl, NULL);
1170 char mem[70];
1172 recv (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0);
1174 pthread_cleanup_pop (0);
1176 printf ("%s: recv returned\n", __FUNCTION__);
1178 exit (1);
1182 static void *
1183 tf_recvfrom (void *arg)
1185 struct sockaddr_un sun;
1187 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1188 if (tempfd == -1)
1190 printf ("%s: first socket call failed\n", __FUNCTION__);
1191 exit (1);
1194 int tries = 0;
1197 if (++tries > 10)
1199 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1202 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX");
1203 if (mktemp (sun.sun_path) == NULL)
1205 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1206 exit (1);
1209 sun.sun_family = AF_UNIX;
1211 while (bind (tempfd, (struct sockaddr *) &sun,
1212 offsetof (struct sockaddr_un, sun_path)
1213 + strlen (sun.sun_path) + 1) != 0);
1215 tempfname = strdup (sun.sun_path);
1217 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1218 if (tempfd2 == -1)
1220 printf ("%s: second socket call failed\n", __FUNCTION__);
1221 exit (1);
1224 int r = pthread_barrier_wait (&b2);
1225 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1227 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1228 exit (1);
1231 if (arg != NULL)
1233 r = pthread_barrier_wait (&b2);
1234 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1236 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1237 exit (1);
1241 pthread_cleanup_push (cl, NULL);
1243 char mem[70];
1244 socklen_t len = sizeof (sun);
1246 recvfrom (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0,
1247 (struct sockaddr *) &sun, &len);
1249 pthread_cleanup_pop (0);
1251 printf ("%s: recvfrom returned\n", __FUNCTION__);
1253 exit (1);
1257 static void *
1258 tf_recvmsg (void *arg)
1260 struct sockaddr_un sun;
1262 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1263 if (tempfd == -1)
1265 printf ("%s: first socket call failed\n", __FUNCTION__);
1266 exit (1);
1269 int tries = 0;
1272 if (++tries > 10)
1274 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
1277 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
1278 if (mktemp (sun.sun_path) == NULL)
1280 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
1281 exit (1);
1284 sun.sun_family = AF_UNIX;
1286 while (bind (tempfd, (struct sockaddr *) &sun,
1287 offsetof (struct sockaddr_un, sun_path)
1288 + strlen (sun.sun_path) + 1) != 0);
1290 tempfname = strdup (sun.sun_path);
1292 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1293 if (tempfd2 == -1)
1295 printf ("%s: second socket call failed\n", __FUNCTION__);
1296 exit (1);
1299 int r = pthread_barrier_wait (&b2);
1300 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1302 printf ("%s: barrier_wait failed\n", __FUNCTION__);
1303 exit (1);
1306 if (arg != NULL)
1308 r = pthread_barrier_wait (&b2);
1309 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1311 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
1312 exit (1);
1316 pthread_cleanup_push (cl, NULL);
1318 char mem[70];
1319 struct iovec iov[1];
1320 iov[0].iov_base = mem;
1321 iov[0].iov_len = arg == NULL ? sizeof (mem) : 0;
1323 struct msghdr m;
1324 m.msg_name = &sun;
1325 m.msg_namelen = sizeof (sun);
1326 m.msg_iov = iov;
1327 m.msg_iovlen = 1;
1328 m.msg_control = NULL;
1329 m.msg_controllen = 0;
1331 recvmsg (tempfd2, &m, 0);
1333 pthread_cleanup_pop (0);
1335 printf ("%s: recvmsg returned\n", __FUNCTION__);
1337 exit (1);
1340 static void *
1341 tf_open (void *arg)
1343 if (arg == NULL)
1345 fifofd = mkfifo (fifoname, S_IWUSR | S_IRUSR);
1346 if (fifofd == -1)
1348 printf ("%s: mkfifo failed: %m\n", __func__);
1349 exit (1);
1352 else
1354 int r = pthread_barrier_wait (&b2);
1355 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1357 printf ("%s: barrier_wait failed: %m\n", __func__);
1358 exit (1);
1362 int r = pthread_barrier_wait (&b2);
1363 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
1365 printf ("%s: 2nd barrier_wait failed: %m\n", __func__);
1366 exit (1);
1369 pthread_cleanup_push (cl_fifo, NULL);
1371 open (arg ? "Makefile" : fifoname, 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"