1 /* Common file for all tst-cancel4_*
3 Copyright (C) 2016 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
26 if (socketpair (AF_UNIX
, SOCK_STREAM
, PF_UNIX
, fds
) != 0)
28 perror ("socketpair");
34 setsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, sizeof(val
));
35 if (getsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, &len
) < 0)
37 perror ("getsockopt");
40 if (val
>= WRITE_BUFFER_SIZE
)
42 puts ("minimum write buffer size too large");
45 setsockopt (fds
[1], SOL_SOCKET
, SO_SNDBUF
, &val
, sizeof(val
));
49 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
51 if (tests
[cnt
].only_early
)
54 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
56 puts ("b2 init failed");
60 /* Reset the counter for the cleanup handler. */
64 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, NULL
) != 0)
66 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
71 int r
= pthread_barrier_wait (&b2
);
72 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
74 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
79 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
80 while (nanosleep (&ts
, &ts
) != 0)
83 if (pthread_cancel (th
) != 0)
85 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
91 if (pthread_join (th
, &status
) != 0)
93 printf ("join for '%s' failed\n", tests
[cnt
].name
);
97 if (status
!= PTHREAD_CANCELED
)
99 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
104 if (pthread_barrier_destroy (&b2
) != 0)
106 puts ("barrier_destroy failed");
113 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
119 printf ("cleanup handler called more than once for '%s'\n",
125 printf ("in-time cancel test of '%s' successful\n", tests
[cnt
].name
);
137 if (tempfname
!= NULL
)
145 msgctl (tempmsg
, IPC_RMID
, NULL
);
150 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
152 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
154 puts ("b2 init failed");
158 /* Reset the counter for the cleanup handler. */
162 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, (void *) 1l) != 0)
164 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
169 int r
= pthread_barrier_wait (&b2
);
170 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
172 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
177 if (pthread_cancel (th
) != 0)
179 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
184 r
= pthread_barrier_wait (&b2
);
185 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
187 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
193 if (pthread_join (th
, &status
) != 0)
195 printf ("join for '%s' failed\n", tests
[cnt
].name
);
199 if (status
!= PTHREAD_CANCELED
)
201 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
206 if (pthread_barrier_destroy (&b2
) != 0)
208 puts ("barrier_destroy failed");
215 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
221 printf ("cleanup handler called more than once for '%s'\n",
227 printf ("early cancel test of '%s' successful\n", tests
[cnt
].name
);
239 if (tempfname
!= NULL
)
247 msgctl (tempmsg
, IPC_RMID
, NULL
);
256 #define TEST_FUNCTION do_test ()
257 #include "../test-skeleton.c"