1 /* Common file for all tst-cancel4_*
3 Copyright (C) 2016-2018 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/>. */
23 if (socketpair (AF_UNIX
, SOCK_STREAM
, PF_UNIX
, fds
) != 0)
25 perror ("socketpair");
29 set_socket_buffer (fds
[1]);
31 if (mktemp (fifoname
) == NULL
)
33 printf ("%s: cannot generate temp file name: %m\n", __func__
);
39 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
41 if (tests
[cnt
].only_early
)
44 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
46 puts ("b2 init failed");
50 /* Reset the counter for the cleanup handler. */
54 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, NULL
) != 0)
56 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
61 int r
= pthread_barrier_wait (&b2
);
62 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
64 printf ("%s: barrier_wait failed\n", __func__
);
69 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
70 while (nanosleep (&ts
, &ts
) != 0)
73 if (pthread_cancel (th
) != 0)
75 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
81 if (pthread_join (th
, &status
) != 0)
83 printf ("join for '%s' failed\n", tests
[cnt
].name
);
87 if (status
!= PTHREAD_CANCELED
)
89 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
94 if (pthread_barrier_destroy (&b2
) != 0)
96 puts ("barrier_destroy failed");
103 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
109 printf ("cleanup handler called more than once for '%s'\n",
115 printf ("in-time cancel test of '%s' successful\n", tests
[cnt
].name
);
127 if (tempfname
!= NULL
)
135 msgctl (tempmsg
, IPC_RMID
, NULL
);
140 for (cnt
= 0; cnt
< ntest_tf
; ++cnt
)
142 if (pthread_barrier_init (&b2
, NULL
, tests
[cnt
].nb
) != 0)
144 puts ("b2 init failed");
148 /* Reset the counter for the cleanup handler. */
152 if (pthread_create (&th
, NULL
, tests
[cnt
].tf
, (void *) 1l) != 0)
154 printf ("create for '%s' test failed\n", tests
[cnt
].name
);
159 int r
= pthread_barrier_wait (&b2
);
160 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
162 printf ("%s: barrier_wait failed\n", __func__
);
167 if (pthread_cancel (th
) != 0)
169 printf ("cancel for '%s' failed\n", tests
[cnt
].name
);
174 r
= pthread_barrier_wait (&b2
);
175 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
177 printf ("%s: barrier_wait failed\n", __func__
);
183 if (pthread_join (th
, &status
) != 0)
185 printf ("join for '%s' failed\n", tests
[cnt
].name
);
189 if (status
!= PTHREAD_CANCELED
)
191 printf ("thread for '%s' not canceled\n", tests
[cnt
].name
);
196 if (pthread_barrier_destroy (&b2
) != 0)
198 puts ("barrier_destroy failed");
205 printf ("cleanup handler not called for '%s'\n", tests
[cnt
].name
);
211 printf ("cleanup handler called more than once for '%s'\n",
217 printf ("early cancel test of '%s' successful\n", tests
[cnt
].name
);
229 if (tempfname
!= NULL
)
237 msgctl (tempmsg
, IPC_RMID
, NULL
);
246 #include <support/test-driver.c>