From 447c70a5dc04e85f96c2ae477ce851fdfdd8c719 Mon Sep 17 00:00:00 2001 From: Salvatore Cro Date: Fri, 10 Sep 2010 10:55:43 +0200 Subject: tests: Added new nptl tests tests: Added several nptl tests from glibc 2.10.1 Signed-off-by: Salvatore Cro Signed-off-by: Carmelo Amoroso --- test/nptl/Makefile.in | 70 +- test/nptl/tst-align3.c | 57 + test/nptl/tst-basic7.c | 75 ++ test/nptl/tst-cancel18.c | 174 +++ test/nptl/tst-cancel23.c | 1 + test/nptl/tst-cancel25.c | 171 +++ test/nptl/tst-cancel4.c | 2374 +++++++++++++++++++++++++++++++++++ test/nptl/tst-cancel5.c | 1 + test/nptl/tst-cancelx10.c | 1 + test/nptl/tst-cancelx11.c | 1 + test/nptl/tst-cancelx12.c | 1 + test/nptl/tst-cancelx13.c | 1 + test/nptl/tst-cancelx14.c | 1 + test/nptl/tst-cancelx15.c | 1 + test/nptl/tst-cancelx16.c | 1 + test/nptl/tst-cancelx18.c | 1 + test/nptl/tst-cancelx2.c | 1 + test/nptl/tst-cancelx20.c | 1 + test/nptl/tst-cancelx21.c | 1 + test/nptl/tst-cancelx3.c | 1 + test/nptl/tst-cancelx4.c | 1 + test/nptl/tst-cancelx6.c | 1 + test/nptl/tst-cancelx7.c | 1 + test/nptl/tst-cancelx8.c | 1 + test/nptl/tst-cancelx9.c | 1 + test/nptl/tst-cleanupx0.c | 1 + test/nptl/tst-cleanupx1.c | 1 + test/nptl/tst-cleanupx2.c | 1 + test/nptl/tst-cleanupx3.c | 1 + test/nptl/tst-cleanupx4.c | 1 + test/nptl/tst-cond22.c | 160 +++ test/nptl/tst-cond23.c | 184 +++ test/nptl/tst-dlsym1.c | 66 + test/nptl/tst-fini1.c | 35 + test/nptl/tst-fini1mod.c | 72 ++ test/nptl/tst-getpid1.c | 122 ++ test/nptl/tst-getpid2.c | 2 + test/nptl/tst-getpid3.c | 114 ++ test/nptl/tst-initializers1-c89.c | 1 + test/nptl/tst-initializers1-c99.c | 1 + test/nptl/tst-initializers1-gnu89.c | 1 + test/nptl/tst-initializers1-gnu99.c | 1 + test/nptl/tst-join6.c | 2 + test/nptl/tst-oddstacklimit.c | 1 + test/nptl/tst-oncex3.c | 1 + test/nptl/tst-oncex4.c | 1 + test/nptl/tst-rwlock2a.c | 2 + test/nptl/tst-sem10.c | 88 ++ test/nptl/tst-sem11.c | 76 ++ test/nptl/tst-sem12.c | 14 + test/nptl/tst-signal7.c | 59 + test/nptl/tst-tsd6.c | 89 ++ test/nptl/tst-typesizes.c | 96 ++ test/nptl/tst-unload.c | 47 + test/nptl/tst-vfork1.c | 150 +++ test/nptl/tst-vfork1x.c | 150 +++ test/nptl/tst-vfork2.c | 199 +++ test/nptl/tst-vfork2x.c | 199 +++ 58 files changed, 4877 insertions(+), 1 deletion(-) create mode 100644 test/nptl/tst-align3.c create mode 100644 test/nptl/tst-basic7.c create mode 100644 test/nptl/tst-cancel18.c create mode 100644 test/nptl/tst-cancel23.c create mode 100644 test/nptl/tst-cancel25.c create mode 100644 test/nptl/tst-cancel4.c create mode 100644 test/nptl/tst-cancel5.c create mode 100644 test/nptl/tst-cancelx10.c create mode 100644 test/nptl/tst-cancelx11.c create mode 100644 test/nptl/tst-cancelx12.c create mode 100644 test/nptl/tst-cancelx13.c create mode 100644 test/nptl/tst-cancelx14.c create mode 100644 test/nptl/tst-cancelx15.c create mode 100644 test/nptl/tst-cancelx16.c create mode 100644 test/nptl/tst-cancelx18.c create mode 100644 test/nptl/tst-cancelx2.c create mode 100644 test/nptl/tst-cancelx20.c create mode 100644 test/nptl/tst-cancelx21.c create mode 100644 test/nptl/tst-cancelx3.c create mode 100644 test/nptl/tst-cancelx4.c create mode 100644 test/nptl/tst-cancelx6.c create mode 100644 test/nptl/tst-cancelx7.c create mode 100644 test/nptl/tst-cancelx8.c create mode 100644 test/nptl/tst-cancelx9.c create mode 100644 test/nptl/tst-cleanupx0.c create mode 100644 test/nptl/tst-cleanupx1.c create mode 100644 test/nptl/tst-cleanupx2.c create mode 100644 test/nptl/tst-cleanupx3.c create mode 100644 test/nptl/tst-cleanupx4.c create mode 100644 test/nptl/tst-cond22.c create mode 100644 test/nptl/tst-cond23.c create mode 100644 test/nptl/tst-dlsym1.c create mode 100644 test/nptl/tst-fini1.c create mode 100644 test/nptl/tst-fini1mod.c create mode 100644 test/nptl/tst-getpid1.c create mode 100644 test/nptl/tst-getpid2.c create mode 100644 test/nptl/tst-getpid3.c create mode 100644 test/nptl/tst-initializers1-c89.c create mode 100644 test/nptl/tst-initializers1-c99.c create mode 100644 test/nptl/tst-initializers1-gnu89.c create mode 100644 test/nptl/tst-initializers1-gnu99.c create mode 100644 test/nptl/tst-join6.c create mode 100644 test/nptl/tst-oddstacklimit.c create mode 100644 test/nptl/tst-oncex3.c create mode 100644 test/nptl/tst-oncex4.c create mode 100644 test/nptl/tst-rwlock2a.c create mode 100644 test/nptl/tst-sem10.c create mode 100644 test/nptl/tst-sem11.c create mode 100644 test/nptl/tst-sem12.c create mode 100644 test/nptl/tst-signal7.c create mode 100644 test/nptl/tst-tsd6.c create mode 100644 test/nptl/tst-typesizes.c create mode 100644 test/nptl/tst-unload.c create mode 100644 test/nptl/tst-vfork1.c create mode 100644 test/nptl/tst-vfork1x.c create mode 100644 test/nptl/tst-vfork2.c create mode 100644 test/nptl/tst-vfork2x.c diff --git a/test/nptl/Makefile.in b/test/nptl/Makefile.in index 8ad952a91..b6a279ebf 100644 --- a/test/nptl/Makefile.in +++ b/test/nptl/Makefile.in @@ -31,7 +31,19 @@ TESTS := tst-align tst-align2 tst-atfork1 tst-attr1 tst-attr2 tst-attr3 \ tst-signal5 tst-signal6 tst-spin1 tst-spin2 tst-spin3 \ tst-stack1 tst-stack2 tst-stdio1 tst-stdio2 tst-sysconf \ tst-tls1 tst-tls2 tst-tls3 tst-tls4 tst-tls5 tst-tsd1 tst-tsd2 \ - tst-tsd3 tst-tsd4 tst-tsd5 tst-umask1 + tst-tsd3 tst-tsd4 tst-tsd5 tst-umask1 \ + tst-align3 tst-cancel4 tst-cancel5 tst-cancel18 tst-cancel23 \ + tst-cancel25 tst-cancelx2 tst-cancelx3 tst-cancelx4 tst-cancelx6 \ + tst-cancelx7 tst-cancelx8 tst-cancelx9 tst-cancelx10 tst-cancelx11 \ + tst-cancelx12 tst-cancelx13 tst-cancelx14 tst-cancelx15 tst-cancelx16 \ + tst-cancelx18 tst-cancelx20 tst-cancelx21 tst-cleanupx0 tst-cleanupx1 \ + tst-cleanupx2 tst-cleanupx3 tst-cleanupx4 tst-cond22 tst-cond23 \ + tst-dlsym1 tst-getpid1 tst-getpid2 tst-getpid3 tst-join6 tst-tsd6 \ + tst-oddstacklimit tst-oncex3 tst-oncex4 tst-rwlock2a \ + tst-basic7 tst-fini1 tst-signal7 \ + tst-unload tst-vfork1x tst-vfork2x tst-sem10 tst-sem11 tst-sem12 \ + tst-typesizes tst-initializers1-c89 tst-initializers1-c99 \ + tst-initializers1-gnu89 tst-initializers1-gnu99 # # These are for the RT library and POSIX timers. @@ -97,9 +109,60 @@ CFLAGS_tst-tls5modd.so := -fPIC -DPIC -DSHARED -shared -DNOT_IN_libc CFLAGS_tst-tls5mode.so := -fPIC -DPIC -DSHARED -shared -DNOT_IN_libc CFLAGS_tst-tls5modf.so := -fPIC -DPIC -DSHARED -shared -DNOT_IN_libc +CFLAGS_tst-fini1mod.so := -fPIC -DPIC -DSHARED -shared -DNOT_IN_libc +LDFLAGS_tst-cond11 = -lrt +LDFLAGS_tst-cond19 = -lrt +LDFLAGS_tst-cancel18 = -lrt +LDFLAGS_tst-cancelx18 = -lrt +LDFLAGS_tst-clock2 = -lrt +LDFLAGS_tst-rwlock14 = -lrt +LDFLAGS_tst-fini1 = -Wl,-rpath=./ tst-fini1mod.so +LDFLAGS_tst-fini1mod.so = -Wl,-soname=tst-fini1mod.so +LDFLAGS_tst-unload = -ldl +LDFLAGS_tst-cancel5 := -lpthread -lpthread_nonshared +LDFLAGS_tst-cancel23 := -lc -lpthread +LDFLAGS_tst-vfork1x := -lc -lpthread +LDFLAGS_tst-vfork2x := -lc -lpthread + +CFLAGS_tst-cancelx2 += -fexceptions +CFLAGS_tst-cancelx3 += -fexceptions +CFLAGS_tst-cancelx4 += -fexceptions +CFLAGS_tst-cancelx6 += -fexceptions +CFLAGS_tst-cancelx7 += -fexceptions +CFLAGS_tst-cancelx8 += -fexceptions +CFLAGS_tst-cancelx9 += -fexceptions +CFLAGS_tst-cancelx10 += -fexceptions +CFLAGS_tst-cancelx11 += -fexceptions +CFLAGS_tst-cancelx12 += -fexceptions +CFLAGS_tst-cancelx13 += -fexceptions +CFLAGS_tst-cancelx14 += -fexceptions +CFLAGS_tst-cancelx15 += -fexceptions +CFLAGS_tst-cancelx16 += -fexceptions +CFLAGS_tst-cancelx18 += -fexceptions +CFLAGS_tst-cancelx20 += -fexceptions -fasynchronous-unwind-tables +CFLAGS_tst-cancelx21 += -fexceptions -fasynchronous-unwind-tables +CFLAGS_tst-cleanupx0 += -fexceptions -fasynchronous-unwind-tables +CFLAGS_tst-cleanupx1 += -fexceptions -fasynchronous-unwind-tables +CFLAGS_tst-cleanupx2 += -fexceptions +CFLAGS_tst-cleanupx3 += -fexceptions + +CFLAGS_tst-oncex3 += -fexceptions +CFLAGS_tst-oncex4 += -fexceptions +CFLAGS_tst-align += $(stack-align-test-flags) +CFLAGS_tst-align3 += $(stack-align-test-flags) +CFLAGS_tst-initializers1 = -W -Wall -Werror +CFLAGS_tst-sem11 += -fexceptions -fasynchronous-unwind-tables +CFLAGS_tst-sem12 += -fexceptions -fasynchronous-unwind-tables +CFLAGS_tst-initializers1 = -W -Wall -Werror +CFLAGS_tst-initializers1-c89 = $(CFLAGS-tst-initializers1) -std=c89 +CFLAGS_tst-initializers1-c99 = $(CFLAGS-tst-initializers1) -std=c99 +CFLAGS_tst-initializers1-gnu89 = $(CFLAGS-tst-initializers1) -std=gnu89 +CFLAGS_tst-initializers1-gnu99 = $(CFLAGS-tst-initializers1) -std=gnu99 + EXTRA_LDFLAGS = $(if $(findstring -lpthread,$(LDFLAGS_$@)),,-lpthread) LDFLAGS_tst-cleanup4 := tst-cleanup4aux.o +LDFLAGS_tst-cleanupx4 := tst-cleanup4aux.o LDFLAGS_tst-clock2 := -lrt LDFLAGS_tst-cond11 := -lrt LDFLAGS_tst-cond19 := -lrt @@ -127,6 +190,7 @@ LDFLAGS_tst-timer2 := -lrt -lpthread LDFLAGS_tst-timer3 := -lrt -lpthread LDFLAGS_tst-timer4 := -lrt -lpthread LDFLAGS_tst-timer5 := -lrt -lpthread +LDFLAGS_tst-dlsym1 := -ldl -rdynamic LDFLAGS_tst-tls3mod.so := -shared -static-libgcc -lpthread LDFLAGS_tst-tls4moda.so := -shared -static-libgcc LDFLAGS_tst-tls4modb.so := -shared -static-libgcc @@ -137,6 +201,7 @@ LDFLAGS_tst-tls5modc.so := -shared -static-libgcc LDFLAGS_tst-tls5modd.so := -shared -static-libgcc LDFLAGS_tst-tls5mode.so := -shared -static-libgcc LDFLAGS_tst-tls5modf.so := -shared -static-libgcc +LDFLAGS_tst-cleanupx4 := tst-cleanup4aux.o # # Special case @@ -149,6 +214,9 @@ tst-tls3: tst-tls3mod.so tst-tls4: tst-tls4moda.so tst-tls4modb.so tst-tls5: tst-tls5mod.so +tst-cleanupx4 : tst-cleanup4aux.o +tst-fini1: tst-fini1mod.so + OPTS_tst-cancel7 = --command ./tst-cancel7 OPTS_tst-mqueue7 = -- ./tst-mqueue7 OPTS_tst-exec4 = ./tst-exec4 diff --git a/test/nptl/tst-align3.c b/test/nptl/tst-align3.c new file mode 100644 index 000000000..f4507f2eb --- /dev/null +++ b/test/nptl/tst-align3.c @@ -0,0 +1,57 @@ +/* Copyright (C) 2005 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Jakub Jelinek , 2005. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include "tst-stack-align.h" + +static bool ok = true; +static pthread_once_t once = PTHREAD_ONCE_INIT; + +static void +once_test (void) +{ + puts ("in once_test"); + + if (TEST_STACK_ALIGN ()) + ok = false; +} + +static int +do_test (void) +{ + puts ("in main"); + + if (TEST_STACK_ALIGN ()) + ok = false; + + if (pthread_once (&once, once_test)) + { + puts ("pthread once failed"); + return 1; + } + + return ok ? 0 : 1; +} + + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/test/nptl/tst-basic7.c b/test/nptl/tst-basic7.c new file mode 100644 index 000000000..15b618786 --- /dev/null +++ b/test/nptl/tst-basic7.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void use_stack (size_t needed); + +void (*use_stack_ptr) (size_t) = use_stack; + +static void +use_stack (size_t needed) +{ + size_t sz = sysconf (_SC_PAGESIZE); + char *buf = alloca (sz); + memset (buf, '\0', sz); + + if (needed > sz) + use_stack_ptr (needed - sz); +} + +static void +use_up_memory (void) +{ + struct rlimit rl; + getrlimit (RLIMIT_AS, &rl); + rl.rlim_cur = 10 * 1024 * 1024; + setrlimit (RLIMIT_AS, &rl); + + char *c; + int PAGESIZE = getpagesize (); + while (1) + { + c = mmap (NULL, PAGESIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); + if (c == MAP_FAILED) + break; + } +} + +static void * +child (void *arg) +{ + sleep (1); + return arg; +} + +static int +do_test (void) +{ + int err; + pthread_t tid; + + /* Allocate the memory needed for the stack. */ + use_stack_ptr (PTHREAD_STACK_MIN); + + use_up_memory (); + + err = pthread_create (&tid, NULL, child, NULL); + if (err != 0) + { + printf ("pthread_create returns %d: %s\n", err, + err == EAGAIN ? "OK" : "FAIL"); + return err != EAGAIN; + } + + /* We did not fail to allocate memory despite the preparation. Oh well. */ + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/test/nptl/tst-cancel18.c b/test/nptl/tst-cancel18.c new file mode 100644 index 000000000..15e9ddfbb --- /dev/null +++ b/test/nptl/tst-cancel18.c @@ -0,0 +1,174 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 2003. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include +#include +#include +#include + + +static pthread_barrier_t b; + + +/* Cleanup handling test. */ +static int cl_called; + +static void +cl (void *arg) +{ + ++cl_called; +} + + +static void * +tf (void *arg) +{ + int r = pthread_barrier_wait (&b); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 }; + TEMP_FAILURE_RETRY (clock_nanosleep (CLOCK_REALTIME, 0, &ts, &ts)); + + pthread_cleanup_pop (0); + + puts ("clock_nanosleep returned"); + + exit (1); +} + + +static int +do_test (void) +{ + if (pthread_barrier_init (&b, NULL, 2) != 0) + { + puts ("barrier_init failed"); + return 1; + } + + pthread_t th; + if (pthread_create (&th, NULL, tf, NULL) != 0) + { + puts ("1st create failed"); + return 1; + } + + int r = pthread_barrier_wait (&b); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + exit (1); + } + + struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 }; + while (nanosleep (&ts, &ts) != 0) + continue; + + puts ("going to cancel in-time"); + if (pthread_cancel (th) != 0) + { + puts ("1st cancel failed"); + return 1; + } + + void *status; + if (pthread_join (th, &status) != 0) + { + puts ("1st join failed"); + return 1; + } + if (status != PTHREAD_CANCELED) + { + puts ("1st thread not canceled"); + return 1; + } + + if (cl_called == 0) + { + puts ("cleanup handler not called"); + return 1; + } + if (cl_called > 1) + { + puts ("cleanup handler called more than once"); + return 1; + } + + puts ("in-time cancellation succeeded"); + + + cl_called = 0; + + if (pthread_create (&th, NULL, tf, NULL) != 0) + { + puts ("2nd create failed"); + return 1; + } + + puts ("going to cancel early"); + if (pthread_cancel (th) != 0) + { + puts ("2nd cancel failed"); + return 1; + } + + r = pthread_barrier_wait (&b); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + exit (1); + } + + if (pthread_join (th, &status) != 0) + { + puts ("2nd join failed"); + return 1; + } + if (status != PTHREAD_CANCELED) + { + puts ("2nd thread not canceled"); + return 1; + } + + if (cl_called == 0) + { + printf ("cleanup handler not called\n"); + return 1; + } + if (cl_called > 1) + { + printf ("cleanup handler called more than once\n"); + return 1; + } + + puts ("early cancellation succeeded"); + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/test/nptl/tst-cancel23.c b/test/nptl/tst-cancel23.c new file mode 100644 index 000000000..211168748 --- /dev/null +++ b/test/nptl/tst-cancel23.c @@ -0,0 +1 @@ +#include "tst-cancel22.c" diff --git a/test/nptl/tst-cancel25.c b/test/nptl/tst-cancel25.c new file mode 100644 index 000000000..00b99ad55 --- /dev/null +++ b/test/nptl/tst-cancel25.c @@ -0,0 +1,171 @@ +#include +#include +#include +#include + + +static pthread_barrier_t b; +static pthread_t th2; + + +static void * +tf2 (void *arg) +{ + sigset_t mask; + if (pthread_sigmask (SIG_SETMASK, NULL, &mask) != 0) + { + puts ("pthread_sigmask failed"); + exit (1); + } + if (sigismember (&mask, SIGCANCEL)) + { + puts ("SIGCANCEL blocked in new thread"); + exit (1); + } + + /* Sync with the main thread so that we do not test anything else. */ + int e = pthread_barrier_wait (&b); + if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + exit (1); + } + + while (1) + { + /* Just a cancelable call. */ + struct timespec ts = { 10000, 0 }; + nanosleep (&ts, 0); + } + + return NULL; +} + + +static void +unwhand (void *arg) +{ + if (pthread_create (&th2, NULL, tf2, NULL) != 0) + { + puts ("unwhand: create failed"); + exit (1); + } +} + + +static void * +tf (void *arg) +{ + pthread_cleanup_push (unwhand, NULL); + + /* Sync with the main thread so that we do not test anything else. */ + int e = pthread_barrier_wait (&b); + if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + exit (1); + } + + while (1) + { + /* Just a cancelable call. */ + struct timespec ts = { 10000, 0 }; + nanosleep (&ts, 0); + } + + pthread_cleanup_pop (0); + + return NULL; +} + + +static int +do_test (void) +{ + if (pthread_barrier_init (&b, NULL, 2) != 0) + { + puts ("barrier_init failed"); + return 1; + } + + pthread_t th1; + if (pthread_create (&th1, NULL, tf, NULL) != 0) + { + puts ("create failed"); + return 1; + } + + int e = pthread_barrier_wait (&b); + if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + return 1; + } + + /* Make sure tf1 enters nanosleep. */ + struct timespec ts = { 0, 500000000 }; + while (nanosleep (&ts, &ts) != 0) + ; + + if (pthread_cancel (th1) != 0) + { + puts ("1st cancel failed"); + return 1; + } + + void *res; + if (pthread_join (th1, &res) != 0) + { + puts ("1st join failed"); + return 1; + } + if (res != PTHREAD_CANCELED) + { + puts ("1st thread not canceled"); + return 1; + } + + e = pthread_barrier_wait (&b); + if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + return 1; + } + + /* Make sure tf2 enters nanosleep. */ + ts.tv_sec = 0; + ts.tv_nsec = 500000000; + while (nanosleep (&ts, &ts) != 0) + ; + + puts ("calling pthread_cancel the second time"); + if (pthread_cancel (th2) != 0) + { + puts ("2nd cancel failed"); + return 1; + } + + puts ("calling pthread_join the second time"); + if (pthread_join (th2, &res) != 0) + { + puts ("2nd join failed"); + return 1; + } + if (res != PTHREAD_CANCELED) + { + puts ("2nd thread not canceled"); + return 1; + } + + if (pthread_barrier_destroy (&b) != 0) + { + puts ("barrier_destroy failed"); + return 0; + } + + return 0; +} + +#define TEST_FUNCTION do_test () +#define TIMEOUT 4 +#include "../test-skeleton.c" diff --git a/test/nptl/tst-cancel4.c b/test/nptl/tst-cancel4.c new file mode 100644 index 000000000..12d40d5bd --- /dev/null +++ b/test/nptl/tst-cancel4.c @@ -0,0 +1,2374 @@ +/* Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 2002. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* NOTE: this tests functionality beyond POSIX. POSIX does not allow + exit to be called more than once. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pthreadP.h" + + +/* Since STREAMS are not supported in the standard Linux kernel and + there we don't advertise STREAMS as supported is no need to test + the STREAMS related functions. This affects + getmsg() getpmsg() putmsg() + putpmsg() + + lockf() and fcntl() are tested in tst-cancel16. + + pthread_join() is tested in tst-join5. + + pthread_testcancel()'s only purpose is to allow cancellation. This + is tested in several places. + + sem_wait() and sem_timedwait() are checked in tst-cancel1[2345] tests. + + mq_send(), mq_timedsend(), mq_receive() and mq_timedreceive() are checked + in tst-mqueue8{,x} tests. + + aio_suspend() is tested in tst-cancel17. + + clock_nanosleep() is tested in tst-cancel18. +*/ + +/* Pipe descriptors. */ +static int fds[2]; + +/* Temporary file descriptor, to be closed after each round. */ +static int tempfd = -1; +static int tempfd2 = -1; +/* Name of temporary file to be removed after each round. */ +static char *tempfname; +/* Temporary message queue. */ +static int tempmsg = -1; + +/* Often used barrier for two threads. */ +static pthread_barrier_t b2; + + +#ifndef IPC_ADDVAL +# define IPC_ADDVAL 0 +#endif + +#define WRITE_BUFFER_SIZE 4096 + +/* Cleanup handling test. */ +static int cl_called; + +static void +cl (void *arg) +{ + ++cl_called; +} + + + +static void * +tf_read (void *arg) +{ + int fd; + int r; + + if (arg == NULL) + fd = fds[0]; + else + { + char fname[] = "/tmp/tst-cancel4-fd-XXXXXX"; + tempfd = fd = mkstemp (fname); + if (fd == -1) + printf ("%s: mkstemp failed\n", __FUNCTION__); + unlink (fname); + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + ssize_t s; + pthread_cleanup_push (cl, NULL); + + char buf[100]; + s = read (fd, buf, sizeof (buf)); + + pthread_cleanup_pop (0); + + printf ("%s: read returns with %zd\n", __FUNCTION__, s); + + exit (1); +} + + +static void * +tf_readv (void *arg) +{ + int fd; + int r; + + if (arg == NULL) + fd = fds[0]; + else + { + char fname[] = "/tmp/tst-cancel4-fd-XXXXXX"; + tempfd = fd = mkstemp (fname); + if (fd == -1) + printf ("%s: mkstemp failed\n", __FUNCTION__); + unlink (fname); + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + ssize_t s; + pthread_cleanup_push (cl, NULL); + + char buf[100]; + struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } }; + s = readv (fd, iov, 1); + + pthread_cleanup_pop (0); + + printf ("%s: readv returns with %zd\n", __FUNCTION__, s); + + exit (1); +} + + +static void * +tf_write (void *arg) +{ + int fd; + int r; + + if (arg == NULL) + fd = fds[1]; + else + { + char fname[] = "/tmp/tst-cancel4-fd-XXXXXX"; + tempfd = fd = mkstemp (fname); + if (fd == -1) + printf ("%s: mkstemp failed\n", __FUNCTION__); + unlink (fname); + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + ssize_t s; + pthread_cleanup_push (cl, NULL); + + char buf[WRITE_BUFFER_SIZE]; + memset (buf, '\0', sizeof (buf)); + s = write (fd, buf, sizeof (buf)); + + pthread_cleanup_pop (0); + + printf ("%s: write returns with %zd\n", __FUNCTION__, s); + + exit (1); +} + + +static void * +tf_writev (void *arg) +{ + int fd; + int r; + + if (arg == NULL) + fd = fds[1]; + else + { + char fname[] = "/tmp/tst-cancel4-fd-XXXXXX"; + tempfd = fd = mkstemp (fname); + if (fd == -1) + printf ("%s: mkstemp failed\n", __FUNCTION__); + unlink (fname); + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + ssize_t s; + pthread_cleanup_push (cl, NULL); + + char buf[WRITE_BUFFER_SIZE]; + memset (buf, '\0', sizeof (buf)); + struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } }; + s = writev (fd, iov, 1); + + pthread_cleanup_pop (0); + + printf ("%s: writev returns with %zd\n", __FUNCTION__, s); + + exit (1); +} + + +static void * +tf_sleep (void *arg) +{ + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + sleep (arg == NULL ? 1000000 : 0); + + pthread_cleanup_pop (0); + + printf ("%s: sleep returns\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_usleep (void *arg) +{ + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + usleep (arg == NULL ? (useconds_t) ULONG_MAX : 0); + + pthread_cleanup_pop (0); + + printf ("%s: usleep returns\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_nanosleep (void *arg) +{ + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 }; + TEMP_FAILURE_RETRY (nanosleep (&ts, &ts)); + + pthread_cleanup_pop (0); + + printf ("%s: nanosleep returns\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_select (void *arg) +{ + int fd; + int r; + + if (arg == NULL) + fd = fds[0]; + else + { + char fname[] = "/tmp/tst-cancel4-fd-XXXXXX"; + tempfd = fd = mkstemp (fname); + if (fd == -1) + printf ("%s: mkstemp failed\n", __FUNCTION__); + unlink (fname); + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + fd_set rfs; + FD_ZERO (&rfs); + FD_SET (fd, &rfs); + + int s; + pthread_cleanup_push (cl, NULL); + + s = select (fd + 1, &rfs, NULL, NULL, NULL); + + pthread_cleanup_pop (0); + + printf ("%s: select returns with %d (%s)\n", __FUNCTION__, s, + strerror (errno)); + + exit (1); +} + + +static void * +tf_pselect (void *arg) +{ + int fd; + int r; + + if (arg == NULL) + fd = fds[0]; + else + { + char fname[] = "/tmp/tst-cancel4-fd-XXXXXX"; + tempfd = fd = mkstemp (fname); + if (fd == -1) + printf ("%s: mkstemp failed\n", __FUNCTION__); + unlink (fname); + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + fd_set rfs; + FD_ZERO (&rfs); + FD_SET (fd, &rfs); + + int s; + pthread_cleanup_push (cl, NULL); + + s = pselect (fd + 1, &rfs, NULL, NULL, NULL, NULL); + + pthread_cleanup_pop (0); + + printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__, s, + strerror (errno)); + + exit (1); +} + + +static void * +tf_poll (void *arg) +{ + int fd; + int r; + + if (arg == NULL) + fd = fds[0]; + else + { + char fname[] = "/tmp/tst-cancel4-fd-XXXXXX"; + tempfd = fd = mkstemp (fname); + if (fd == -1) + printf ("%s: mkstemp failed\n", __FUNCTION__); + unlink (fname); + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } }; + + int s; + pthread_cleanup_push (cl, NULL); + + s = poll (rfs, 1, -1); + + pthread_cleanup_pop (0); + + printf ("%s: poll returns with %d (%s)\n", __FUNCTION__, s, + strerror (errno)); + + exit (1); +} + + +static void * +tf_ppoll (void *arg) +{ + int fd; + int r; + + if (arg == NULL) + fd = fds[0]; + else + { + char fname[] = "/tmp/tst-cancel4-fd-XXXXXX"; + tempfd = fd = mkstemp (fname); + if (fd == -1) + printf ("%s: mkstemp failed\n", __FUNCTION__); + unlink (fname); + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } }; + + int s; + pthread_cleanup_push (cl, NULL); + + s = ppoll (rfs, 1, NULL, NULL); + + pthread_cleanup_pop (0); + + printf ("%s: ppoll returns with %d (%s)\n", __FUNCTION__, s, + strerror (errno)); + + exit (1); +} + + +static void * +tf_wait (void *arg) +{ + pid_t pid = fork (); + if (pid == -1) + { + puts ("fork failed"); + exit (1); + } + + if (pid == 0) + { + /* Make the program disappear after a while. */ + if (arg == NULL) + sleep (10); + exit (0); + } + + int r; + if (arg != NULL) + { + struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 }; + while (nanosleep (&ts, &ts) != 0) + continue; + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + int s; + pthread_cleanup_push (cl, NULL); + + s = wait (NULL); + + pthread_cleanup_pop (0); + + printf ("%s: wait returns with %d (%s)\n", __FUNCTION__, s, + strerror (errno)); + + exit (1); +} + + +static void * +tf_waitpid (void *arg) +{ + + pid_t pid = fork (); + if (pid == -1) + { + puts ("fork failed"); + exit (1); + } + + if (pid == 0) + { + /* Make the program disappear after a while. */ + if (arg == NULL) + sleep (10); + exit (0); + } + + int r; + if (arg != NULL) + { + struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 }; + while (nanosleep (&ts, &ts) != 0) + continue; + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + int s; + pthread_cleanup_push (cl, NULL); + + s = waitpid (-1, NULL, 0); + + pthread_cleanup_pop (0); + + printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__, s, + strerror (errno)); + + exit (1); +} + + +static void * +tf_waitid (void *arg) +{ + pid_t pid = fork (); + if (pid == -1) + { + puts ("fork failed"); + exit (1); + } + + if (pid == 0) + { + /* Make the program disappear after a while. */ + if (arg == NULL) + sleep (10); + exit (0); + } + + int r; + if (arg != NULL) + { + struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 }; + while (nanosleep (&ts, &ts) != 0) + continue; + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + int s; + pthread_cleanup_push (cl, NULL); + +#ifndef WEXITED +# define WEXITED 0 +#endif + siginfo_t si; + s = waitid (P_PID, pid, &si, WEXITED); + + pthread_cleanup_pop (0); + + printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__, s, + strerror (errno)); + + exit (1); +} + + +static void * +tf_sigpause (void *arg) +{ + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + /* Just for fun block the cancellation signal. We need to use + __xpg_sigpause since otherwise we will get the BSD version. */ + //__xpg_sigpause (SIGCANCEL); + + __sigpause (SIGCANCEL, 1); + + pthread_cleanup_pop (0); + + printf ("%s: sigpause returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_sigsuspend (void *arg) +{ + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + /* Just for fun block all signals. */ + sigset_t mask; + sigfillset (&mask); + sigsuspend (&mask); + + pthread_cleanup_pop (0); + + printf ("%s: sigsuspend returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_sigwait (void *arg) +{ + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + /* Block SIGUSR1. */ + sigset_t mask; + sigemptyset (&mask); + sigaddset (&mask, SIGUSR1); + if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0) + { + printf ("%s: pthread_sigmask failed\n", __FUNCTION__); + exit (1); + } + + int sig; + pthread_cleanup_push (cl, NULL); + + /* Wait for SIGUSR1. */ + sigwait (&mask, &sig); + + pthread_cleanup_pop (0); + + printf ("%s: sigwait returned with signal %d\n", __FUNCTION__, sig); + + exit (1); +} + + +static void * +tf_sigwaitinfo (void *arg) +{ + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + /* Block SIGUSR1. */ + sigset_t mask; + sigemptyset (&mask); + sigaddset (&mask, SIGUSR1); + if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0) + { + printf ("%s: pthread_sigmask failed\n", __FUNCTION__); + exit (1); + } + + siginfo_t info; + pthread_cleanup_push (cl, NULL); + + /* Wait for SIGUSR1. */ + sigwaitinfo (&mask, &info); + + pthread_cleanup_pop (0); + + printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__, + info.si_signo); + + exit (1); +} + + +static void * +tf_sigtimedwait (void *arg) +{ + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + /* Block SIGUSR1. */ + sigset_t mask; + sigemptyset (&mask); + sigaddset (&mask, SIGUSR1); + if (pthread_sigmask (SIG_BLOCK, &mask, NULL) != 0) + { + printf ("%s: pthread_sigmask failed\n", __FUNCTION__); + exit (1); + } + + /* Wait for SIGUSR1. */ + siginfo_t info; + struct timespec ts = { .tv_sec = 60, .tv_nsec = 0 }; + pthread_cleanup_push (cl, NULL); + + sigtimedwait (&mask, &info, &ts); + + pthread_cleanup_pop (0); + + printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__, + info.si_signo); + + exit (1); +} + + +static void * +tf_pause (void *arg) +{ + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + pause (); + + pthread_cleanup_pop (0); + + printf ("%s: pause returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_accept (void *arg) +{ + struct sockaddr_un sun; + /* To test a non-blocking accept call we make the call file by using + a datagrame socket. */ + int pf = arg == NULL ? SOCK_STREAM : SOCK_DGRAM; + + tempfd = socket (AF_UNIX, pf, 0); + if (tempfd == -1) + { + printf ("%s: socket call failed\n", __FUNCTION__); + exit (1); + } + + int tries = 0; + do + { + if (++tries > 10) + { + printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); + } + + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX"); + if (mktemp (sun.sun_path) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + + sun.sun_family = AF_UNIX; + } + while (bind (tempfd, (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1) != 0); + + unlink (sun.sun_path); + + listen (tempfd, 5); + + socklen_t len = sizeof (sun); + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + accept (tempfd, (struct sockaddr *) &sun, &len); + + pthread_cleanup_pop (0); + + printf ("%s: accept returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_send (void *arg) +{ + struct sockaddr_un sun; + + tempfd = socket (AF_UNIX, SOCK_STREAM, 0); + if (tempfd == -1) + { + printf ("%s: first socket call failed\n", __FUNCTION__); + exit (1); + } + + int tries = 0; + do + { + if (++tries > 10) + { + printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); + } + + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX"); + if (mktemp (sun.sun_path) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + + sun.sun_family = AF_UNIX; + } + while (bind (tempfd, (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1) != 0); + + listen (tempfd, 5); + + tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0); + if (tempfd2 == -1) + { + printf ("%s: second socket call failed\n", __FUNCTION__); + exit (1); + } + + if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0) + { + printf ("%s: connect failed\n", __FUNCTION__); + exit(1); + } + + unlink (sun.sun_path); + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + /* Very large block, so that the send call blocks. */ + char mem[700000]; + + send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0); + + pthread_cleanup_pop (0); + + printf ("%s: send returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_recv (void *arg) +{ + struct sockaddr_un sun; + + tempfd = socket (AF_UNIX, SOCK_STREAM, 0); + if (tempfd == -1) + { + printf ("%s: first socket call failed\n", __FUNCTION__); + exit (1); + } + + int tries = 0; + do + { + if (++tries > 10) + { + printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); + } + + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX"); + if (mktemp (sun.sun_path) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + + sun.sun_family = AF_UNIX; + } + while (bind (tempfd, (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1) != 0); + + listen (tempfd, 5); + + tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0); + if (tempfd2 == -1) + { + printf ("%s: second socket call failed\n", __FUNCTION__); + exit (1); + } + + if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0) + { + printf ("%s: connect failed\n", __FUNCTION__); + exit(1); + } + + unlink (sun.sun_path); + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + char mem[70]; + + recv (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0); + + pthread_cleanup_pop (0); + + printf ("%s: recv returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_recvfrom (void *arg) +{ + struct sockaddr_un sun; + + tempfd = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd == -1) + { + printf ("%s: first socket call failed\n", __FUNCTION__); + exit (1); + } + + int tries = 0; + do + { + if (++tries > 10) + { + printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); + } + + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX"); + if (mktemp (sun.sun_path) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + + sun.sun_family = AF_UNIX; + } + while (bind (tempfd, (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1) != 0); + + tempfname = strdup (sun.sun_path); + + tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd2 == -1) + { + printf ("%s: second socket call failed\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + char mem[70]; + socklen_t len = sizeof (sun); + + recvfrom (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0, + (struct sockaddr *) &sun, &len); + + pthread_cleanup_pop (0); + + printf ("%s: recvfrom returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_recvmsg (void *arg) +{ + struct sockaddr_un sun; + + tempfd = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd == -1) + { + printf ("%s: first socket call failed\n", __FUNCTION__); + exit (1); + } + + int tries = 0; + do + { + if (++tries > 10) + { + printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); + } + + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX"); + if (mktemp (sun.sun_path) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + + sun.sun_family = AF_UNIX; + } + while (bind (tempfd, (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1) != 0); + + tempfname = strdup (sun.sun_path); + + tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd2 == -1) + { + printf ("%s: second socket call failed\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + char mem[70]; + struct iovec iov[1]; + iov[0].iov_base = mem; + iov[0].iov_len = arg == NULL ? sizeof (mem) : 0; + + struct msghdr m; + m.msg_name = &sun; + m.msg_namelen = sizeof (sun); + m.msg_iov = iov; + m.msg_iovlen = 1; + m.msg_control = NULL; + m.msg_controllen = 0; + + recvmsg (tempfd2, &m, 0); + + pthread_cleanup_pop (0); + + printf ("%s: recvmsg returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_open (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which open() + // blocks we can enable this test to run in both rounds. + abort (); + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + open ("Makefile", O_RDONLY); + + pthread_cleanup_pop (0); + + printf ("%s: open returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_close (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which close() + // blocks we can enable this test to run in both rounds. + abort (); + + char fname[] = "/tmp/tst-cancel-fd-XXXXXX"; + tempfd = mkstemp (fname); + if (tempfd == -1) + { + printf ("%s: mkstemp failed\n", __FUNCTION__); + exit (1); + } + unlink (fname); + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + close (tempfd); + + pthread_cleanup_pop (0); + + printf ("%s: close returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_pread (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which pread() + // blocks we can enable this test to run in both rounds. + abort (); + + tempfd = open ("Makefile", O_RDONLY); + if (tempfd == -1) + { + printf ("%s: cannot open Makefile\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + char mem[10]; + pread (tempfd, mem, sizeof (mem), 0); + + pthread_cleanup_pop (0); + + printf ("%s: pread returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_pwrite (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which pwrite() + // blocks we can enable this test to run in both rounds. + abort (); + + char fname[] = "/tmp/tst-cancel4-fd-XXXXXX"; + tempfd = mkstemp (fname); + if (tempfd == -1) + { + printf ("%s: mkstemp failed\n", __FUNCTION__); + exit (1); + } + unlink (fname); + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + char mem[10]; + pwrite (tempfd, mem, sizeof (mem), 0); + + pthread_cleanup_pop (0); + + printf ("%s: pwrite returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_fsync (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which fsync() + // blocks we can enable this test to run in both rounds. + abort (); + + tempfd = open ("Makefile", O_RDONLY); + if (tempfd == -1) + { + printf ("%s: cannot open Makefile\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + fsync (tempfd); + + pthread_cleanup_pop (0); + + printf ("%s: fsync returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_fdatasync (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which fdatasync() + // blocks we can enable this test to run in both rounds. + abort (); + + tempfd = open ("Makefile", O_RDONLY); + if (tempfd == -1) + { + printf ("%s: cannot open Makefile\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + fdatasync (tempfd); + + pthread_cleanup_pop (0); + + printf ("%s: fdatasync returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_msync (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which msync() + // blocks we can enable this test to run in both rounds. + abort (); + + tempfd = open ("Makefile", O_RDONLY); + if (tempfd == -1) + { + printf ("%s: cannot open Makefile\n", __FUNCTION__); + exit (1); + } + void *p = mmap (NULL, 10, PROT_READ, MAP_SHARED, tempfd, 0); + if (p == MAP_FAILED) + { + printf ("%s: mmap failed\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + msync (p, 10, 0); + + pthread_cleanup_pop (0); + + printf ("%s: msync returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_sendto (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which sendto() + // blocks we can enable this test to run in both rounds. + abort (); + + struct sockaddr_un sun; + + tempfd = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd == -1) + { + printf ("%s: first socket call failed\n", __FUNCTION__); + exit (1); + } + + int tries = 0; + do + { + if (++tries > 10) + { + printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); + } + + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX"); + if (mktemp (sun.sun_path) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + + sun.sun_family = AF_UNIX; + } + while (bind (tempfd, (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1) != 0); + tempfname = strdup (sun.sun_path); + + tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd2 == -1) + { + printf ("%s: second socket call failed\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + char mem[1]; + + sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0, + (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1); + + pthread_cleanup_pop (0); + + printf ("%s: sendto returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_sendmsg (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which sendmsg() + // blocks we can enable this test to run in both rounds. + abort (); + + struct sockaddr_un sun; + + tempfd = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd == -1) + { + printf ("%s: first socket call failed\n", __FUNCTION__); + exit (1); + } + + int tries = 0; + do + { + if (++tries > 10) + { + printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); + } + + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX"); + if (mktemp (sun.sun_path) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + + sun.sun_family = AF_UNIX; + } + while (bind (tempfd, (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1) != 0); + tempfname = strdup (sun.sun_path); + + tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd2 == -1) + { + printf ("%s: second socket call failed\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + char mem[1]; + struct iovec iov[1]; + iov[0].iov_base = mem; + iov[0].iov_len = 1; + + struct msghdr m; + m.msg_name = &sun; + m.msg_namelen = (offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1); + m.msg_iov = iov; + m.msg_iovlen = 1; + m.msg_control = NULL; + m.msg_controllen = 0; + + sendmsg (tempfd2, &m, 0); + + pthread_cleanup_pop (0); + + printf ("%s: sendmsg returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_creat (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which sendmsg() + // blocks we can enable this test to run in both rounds. + abort (); + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + creat ("tmp/tst-cancel-4-should-not-exist", 0666); + + pthread_cleanup_pop (0); + + printf ("%s: creat returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_connect (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which connect() + // blocks we can enable this test to run in both rounds. + abort (); + + struct sockaddr_un sun; + + tempfd = socket (AF_UNIX, SOCK_STREAM, 0); + if (tempfd == -1) + { + printf ("%s: first socket call failed\n", __FUNCTION__); + exit (1); + } + + int tries = 0; + do + { + if (++tries > 10) + { + printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); + } + + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX"); + if (mktemp (sun.sun_path) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + + sun.sun_family = AF_UNIX; + } + while (bind (tempfd, (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1) != 0); + tempfname = strdup (sun.sun_path); + + listen (tempfd, 5); + + tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0); + if (tempfd2 == -1) + { + printf ("%s: second socket call failed\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)); + + pthread_cleanup_pop (0); + + printf ("%s: connect returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_tcdrain (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which tcdrain() + // blocks we can enable this test to run in both rounds. + abort (); + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + /* Regardless of stderr being a terminal, the tcdrain call should be + canceled. */ + tcdrain (STDERR_FILENO); + + pthread_cleanup_pop (0); + + printf ("%s: tcdrain returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_msgrcv (void *arg) +{ + tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT); + if (tempmsg == -1) + { + printf ("%s: msgget failed: %s\n", __FUNCTION__, strerror (errno)); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r