aboutsummaryrefslogtreecommitdiff
path: root/htl/tests
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2018-04-02 01:43:22 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2018-04-02 01:44:14 +0200
commit33574c17eefcf326c1cd30eb9f915ad26d3d9ef2 (patch)
tree2c1b143f2b7a0ceba9fba000b70dd2889d56e60f /htl/tests
parent03e2aa50fd512449025bba8c244d16338d8526a4 (diff)
downloadglibc-33574c17eefcf326c1cd30eb9f915ad26d3d9ef2.zip
glibc-33574c17eefcf326c1cd30eb9f915ad26d3d9ef2.tar.gz
glibc-33574c17eefcf326c1cd30eb9f915ad26d3d9ef2.tar.bz2
hurd: Add hurd thread library
Contributed by Agustina Arzille <avarzille@riseup.net> Amos Jeffries <squid3@treenet.co.nz> David Michael <fedora.dm0@gmail.com> Marco Gerards <marco@gnu.org> Marcus Brinkmann <marcus@gnu.org> Neal H. Walfield <neal@gnu.org> Pino Toscano <toscano.pino@tiscali.it> Richard Braun <rbraun@sceen.net> Roland McGrath <roland@gnu.org> Samuel Thibault <samuel.thibault@ens-lyon.org> Thomas DiModica <ricinwich@yahoo.com> Thomas Schwinge <tschwinge@gnu.org> * htl: New directory. * sysdeps/htl: New directory. * sysdeps/hurd/htl: New directory. * sysdeps/i386/htl: New directory. * sysdeps/mach/htl: New directory. * sysdeps/mach/hurd/htl: New directory. * sysdeps/mach/hurd/i386/htl: New directory. * nscd/Depend, resolv/Depend, rt/Depend: Add htl dependency. * sysdeps/mach/hurd/i386/Implies: Add mach/hurd/i386/htl imply. * sysdeps/mach/hurd/i386/libpthread.abilist: New file.
Diffstat (limited to 'htl/tests')
-rw-r--r--htl/tests/Makefile40
-rw-r--r--htl/tests/README6
-rw-r--r--htl/tests/test-1.c68
-rw-r--r--htl/tests/test-10.c62
-rw-r--r--htl/tests/test-11.c159
-rw-r--r--htl/tests/test-12.c45
-rw-r--r--htl/tests/test-13.c82
-rw-r--r--htl/tests/test-14.c60
-rw-r--r--htl/tests/test-15.c102
-rw-r--r--htl/tests/test-16.c87
-rw-r--r--htl/tests/test-17.c73
-rw-r--r--htl/tests/test-2.c56
-rw-r--r--htl/tests/test-3.c71
-rw-r--r--htl/tests/test-4.c102
-rw-r--r--htl/tests/test-5.c91
-rw-r--r--htl/tests/test-6.c114
-rw-r--r--htl/tests/test-7.c89
-rw-r--r--htl/tests/test-8.c78
-rw-r--r--htl/tests/test-9.c104
-rw-r--r--htl/tests/test-__pthread_destroy_specific-skip.c100
20 files changed, 1589 insertions, 0 deletions
diff --git a/htl/tests/Makefile b/htl/tests/Makefile
new file mode 100644
index 0000000..7177ad1
--- /dev/null
+++ b/htl/tests/Makefile
@@ -0,0 +1,40 @@
+ifdef INSTALL_ROOT
+INSTALL_ROOT_CPPFLAGS = -isystem $(INSTALL_ROOT)/include
+INSTALL_ROOT_LDFLAGS = -L$(INSTALL_ROOT)/lib -Wl,-rpath,$(INSTALL_ROOT)/lib
+endif
+
+CFLAGS=-Wall -g
+
+LDLIBS = -lpthread
+
+CHECK_SRC := test-1.c test-2.c test-3.c test-6.c test-7.c test-8.c \
+ test-9.c test-10.c test-11.c test-12.c test-13.c test-14.c \
+ test-15.c test-16.c test-17.c test-__pthread_destroy_specific-skip.c
+
+CHECK_OBJS := $(addsuffix .o,$(basename $(notdir $(CHECK_SRC))))
+CHECK_PROGS := $(basename $(notdir $(CHECK_SRC))) \
+ $(addsuffix -static, $(basename $(CHECK_SRC)))
+
+%.o: %.c
+ $(CC) $(INSTALL_ROOT_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $< -c -o $@
+
+%: %.o
+ $(CC) $(INSTALL_ROOT_LDFLAGS) $(LDFLAGS) $< -o $@ $(LDLIBS)
+
+%-static: %.o
+ $(CC) -static $(INSTALL_ROOT_LDFLAGS) $(LDFLAGS) $< -o $@ $(LDLIBS)
+
+check: $(CHECK_OBJS) $(CHECK_PROGS)
+ for i in $(CHECK_PROGS); do \
+ echo -n Running $$i...\ ; \
+ if ./$$i 2>&1 > $$i.out; \
+ then \
+ echo Success.; \
+ else \
+ echo Failure.; \
+ fi \
+ done
+
+clean:
+ rm -f $(CHECK_OBJS) $(CHECK_PROGS) \
+ $(addsuffix .out,$(basename $(notdir $(CHECK_PROGS)))) \ No newline at end of file
diff --git a/htl/tests/README b/htl/tests/README
new file mode 100644
index 0000000..230f1b2
--- /dev/null
+++ b/htl/tests/README
@@ -0,0 +1,6 @@
+Testing of installed package:
+
+ $ [libpthread]/configure --prefix=[install_root]
+ $ make
+ $ make install
+ $ make -C [libpthread]/tests/ INSTALL_ROOT=[install_root] clean check
diff --git a/htl/tests/test-1.c b/htl/tests/test-1.c
new file mode 100644
index 0000000..25263ee
--- /dev/null
+++ b/htl/tests/test-1.c
@@ -0,0 +1,68 @@
+/* Test mutexes.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+#include <error.h>
+#include <errno.h>
+#include <stdio.h>
+
+#define THREADS 500
+
+void *
+foo (void *arg)
+{
+ pthread_mutex_t *mutex = arg;
+ pthread_mutex_lock (mutex);
+ pthread_mutex_unlock (mutex);
+ return mutex;
+}
+
+int
+main (int argc, char **argv)
+{
+ int i;
+ error_t err;
+ pthread_t tid[THREADS];
+ pthread_mutex_t mutex[THREADS];
+
+ for (i = 0; i < THREADS; i++)
+ {
+ pthread_mutex_init (&mutex[i], 0);
+ pthread_mutex_lock (&mutex[i]);
+ err = pthread_create (&tid[i], 0, foo, &mutex[i]);
+ if (err)
+ error (1, err, "pthread_create");
+ sched_yield ();
+ }
+
+ for (i = THREADS - 1; i >= 0; i--)
+ {
+ void *ret;
+ pthread_mutex_unlock (&mutex[i]);
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+ assert (ret == &mutex[i]);
+ }
+
+ return 0;
+}
diff --git a/htl/tests/test-10.c b/htl/tests/test-10.c
new file mode 100644
index 0000000..31d3449
--- /dev/null
+++ b/htl/tests/test-10.c
@@ -0,0 +1,62 @@
+/* Test error checking mutexes.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ pthread_mutexattr_t mattr;
+ pthread_mutex_t mutex;
+
+ err = pthread_mutexattr_init (&mattr);
+ if (err)
+ error (1, err, "pthread_mutexattr_init");
+
+ err = pthread_mutexattr_settype (&mattr, PTHREAD_MUTEX_ERRORCHECK);
+ if (err)
+ error (1, err, "pthread_mutexattr_settype");
+
+ err = pthread_mutex_init (&mutex, &mattr);
+ if (err)
+ error (1, err, "pthread_mutex_init");
+
+ err = pthread_mutexattr_destroy (&mattr);
+ if (err)
+ error (1, err, "pthread_mutexattr_destroy");
+
+ err = pthread_mutex_lock (&mutex);
+ assert (err == 0);
+
+ err = pthread_mutex_lock (&mutex);
+ assert (err == EDEADLK);
+
+ err = pthread_mutex_unlock (&mutex);
+ assert (err == 0);
+
+ err = pthread_mutex_unlock (&mutex);
+ assert (err == EPERM);
+
+ return 0;
+}
diff --git a/htl/tests/test-11.c b/htl/tests/test-11.c
new file mode 100644
index 0000000..f8c7a42
--- /dev/null
+++ b/htl/tests/test-11.c
@@ -0,0 +1,159 @@
+/* Test rwlocks.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 1
+
+int a;
+int b;
+
+/* Get a read lock and assert that a == b. */
+void *
+test1 (void *arg)
+{
+ error_t err;
+ pthread_rwlock_t *lock = arg;
+ int i;
+
+ for (i = 0; i < 200; i++)
+ {
+ err = pthread_rwlock_rdlock (lock);
+ assert (err == 0);
+
+ assert (a == b);
+
+ sched_yield ();
+
+ assert (a == b);
+
+ err = pthread_rwlock_unlock (lock);
+ assert (err == 0);
+ }
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ pthread_rwlockattr_t attr;
+ pthread_rwlock_t lock;
+ int pshared;
+
+ int i;
+ pthread_t tid[THREADS];
+ void *ret;
+
+ err = pthread_rwlockattr_init (&attr);
+ if (err)
+ error (1, err, "pthread_rwlockattr_init");
+
+ err = pthread_rwlockattr_getpshared (&attr, &pshared);
+ if (err)
+ error (1, err, "pthread_rwlockattr_getpshared");
+
+ /* Assert the default state as mandated by POSIX. */
+ assert (pshared == PTHREAD_PROCESS_PRIVATE);
+
+ err = pthread_rwlockattr_setpshared (&attr, pshared);
+ if (err)
+ error (1, err, "pthread_rwlockattr_setpshared");
+
+ err = pthread_rwlock_init (&lock, &attr);
+ if (err)
+ error (1, err, "pthread_rwlock_init");
+
+ err = pthread_rwlockattr_destroy (&attr);
+ if (err)
+ error (1, err, "pthread_rwlockattr_destroy");
+
+ /* Now test the lock. */
+
+ for (i = 0; i < THREADS; i++)
+ {
+ err = pthread_create (&tid[i], 0, test1, &lock);
+ if (err)
+ error (1, err, "pthread_create");
+ }
+
+ for (i = 0; i < 10; i++)
+ {
+ sched_yield ();
+
+ /* Get a write lock. */
+ pthread_rwlock_wrlock (&lock);
+ /* Increment a and b giving other threads a chance to run in
+ between. */
+ sched_yield ();
+ a++;
+ sched_yield ();
+ b++;
+ sched_yield ();
+ /* Unlock. */
+ pthread_rwlock_unlock (&lock);
+ }
+
+ for (i = 0; i < THREADS; i++)
+ {
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+ }
+
+ /* Read lock it. */
+ err = pthread_rwlock_tryrdlock (&lock);
+ assert (err == 0);
+
+ /* Try to write lock it. It should fail with EBUSY. */
+ err = pthread_rwlock_trywrlock (&lock);
+ assert (err == EBUSY);
+
+ /* Drop the read lock. */
+ err = pthread_rwlock_unlock (&lock);
+ assert (err == 0);
+
+ /* Get a write lock. */
+ err = pthread_rwlock_trywrlock (&lock);
+ assert (err == 0);
+
+ /* Fail trying to acquire another write lock. */
+ err = pthread_rwlock_trywrlock (&lock);
+ assert (err == EBUSY);
+
+ /* Try to get a read lock which should also fail. */
+ err = pthread_rwlock_tryrdlock (&lock);
+ assert (err == EBUSY);
+
+ /* Unlock it. */
+ err = pthread_rwlock_unlock (&lock);
+ assert (err == 0);
+
+
+ err = pthread_rwlock_destroy (&lock);
+ if (err)
+ error (1, err, "pthread_rwlock_destroy");
+
+ return 0;
+}
diff --git a/htl/tests/test-12.c b/htl/tests/test-12.c
new file mode 100644
index 0000000..9676446
--- /dev/null
+++ b/htl/tests/test-12.c
@@ -0,0 +1,45 @@
+/* Test concurrency level.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+int
+main (int argc, char **argv)
+{
+ int i;
+ int err;
+
+ i = pthread_getconcurrency ();
+ assert (i == 0);
+
+ err = pthread_setconcurrency (-1);
+ assert (err == EINVAL);
+
+ err = pthread_setconcurrency (4);
+ assert (err == 0);
+
+ i = pthread_getconcurrency ();
+ assert (i == 4);
+
+ return 0;
+}
diff --git a/htl/tests/test-13.c b/htl/tests/test-13.c
new file mode 100644
index 0000000..d142149
--- /dev/null
+++ b/htl/tests/test-13.c
@@ -0,0 +1,82 @@
+/* Test condition attributes and pthread_cond_timedwait.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <sys/time.h>
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ int i;
+ pthread_condattr_t attr;
+ pthread_cond_t cond;
+ struct timespec ts;
+ pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+ struct timeval before, after;
+ int diff;
+
+ err = pthread_condattr_init (&attr);
+ if (err)
+ error (1, err, "pthread_condattr_init");
+
+ err = pthread_condattr_getpshared (&attr, &i);
+ if (err)
+ error (1, err, "pthread_condattr_getpshared");
+ assert (i == PTHREAD_PROCESS_PRIVATE);
+
+ err = pthread_condattr_setpshared (&attr, PTHREAD_PROCESS_PRIVATE);
+ assert (err == 0);
+
+ err = pthread_cond_init (&cond, &attr);
+ if (err)
+ error (1, err, "pthread_cond_init");
+
+ err = pthread_condattr_destroy (&attr);
+ if (err)
+ error (1, err, "pthread_condattr_destroy");
+
+ gettimeofday (&before, 0);
+ ts.tv_sec = before.tv_sec + 1;
+ ts.tv_nsec = before.tv_usec * 1000;
+
+ printf ("Starting wait @ %d\n", (int) before.tv_sec);
+
+ pthread_mutex_lock (&m);
+ err = pthread_cond_timedwait (&cond, &m, &ts);
+
+ gettimeofday (&after, 0);
+
+ printf ("End wait @ %d (err = %d)\n", (int) after.tv_sec, err);
+
+ assert (err == ETIMEDOUT);
+
+ diff = after.tv_sec * 1000000 + after.tv_usec
+ - before.tv_sec * 1000000 - before.tv_usec;
+
+ if (diff < 900000 || diff > 1100000)
+ error (1, EGRATUITOUS, "pthread_cond_timedwait waited %d us", diff);
+
+ return 0;
+}
diff --git a/htl/tests/test-14.c b/htl/tests/test-14.c
new file mode 100644
index 0000000..6e7cef1
--- /dev/null
+++ b/htl/tests/test-14.c
@@ -0,0 +1,60 @@
+/* Test pthread_mutex_timedlock.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <sys/time.h>
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ struct timespec ts;
+ pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+ struct timeval before, after;
+ int diff;
+
+ gettimeofday (&before, 0);
+ ts.tv_sec = before.tv_sec + 1;
+ ts.tv_nsec = before.tv_usec * 1000;
+
+ printf ("Starting wait @ %d\n", (int) before.tv_sec);
+
+ pthread_mutex_lock (&m);
+ /* A default mutex shall dead lock if locked twice. As such we do
+ not need spawn a second thread. */
+ err = pthread_mutex_timedlock (&m, &ts);
+ assert (err == ETIMEDOUT);
+
+ gettimeofday (&after, 0);
+
+ printf ("End wait @ %d\n", (int) after.tv_sec);
+
+ diff = after.tv_sec * 1000000 + after.tv_usec
+ - before.tv_sec * 1000000 - before.tv_usec;
+
+ if (diff < 900000 || diff > 1100000)
+ error (1, EGRATUITOUS, "pthread_mutex_timedlock waited %d us", diff);
+
+ return 0;
+}
diff --git a/htl/tests/test-15.c b/htl/tests/test-15.c
new file mode 100644
index 0000000..baf866a
--- /dev/null
+++ b/htl/tests/test-15.c
@@ -0,0 +1,102 @@
+/* Test pthread_rwlock_timedrdlock and pthread_rwlock_timedwrlock.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <sys/time.h>
+
+#define THREADS 10
+
+pthread_rwlock_t rwlock;
+
+void *
+test (void *arg)
+{
+ error_t err;
+ int foo = (int) arg;
+ struct timespec ts;
+ struct timeval before, after;
+ int diff;
+
+ gettimeofday (&before, 0);
+ ts.tv_sec = before.tv_sec + 1;
+ ts.tv_nsec = before.tv_usec * 1000;
+
+ printf ("Thread %d starting wait @ %d\n", pthread_self (),
+ (int) before.tv_sec);
+
+ if (foo % 2 == 0)
+ err = pthread_rwlock_timedrdlock (&rwlock, &ts);
+ else
+ err = pthread_rwlock_timedwrlock (&rwlock, &ts);
+
+ assert (err == ETIMEDOUT);
+
+ gettimeofday (&after, 0);
+
+ printf ("Thread %d ending wait @ %d\n", pthread_self (), (int) after.tv_sec);
+
+ diff = after.tv_sec * 1000000 + after.tv_usec
+ - before.tv_sec * 1000000 - before.tv_usec;
+
+ if (diff < 900000 || diff > 1100000)
+ error (1, EGRATUITOUS, "pthread_mutex_timedlock waited %d us", diff);
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ int i;
+ pthread_t tid[THREADS];
+
+ err = pthread_rwlock_init (&rwlock, 0);
+ if (err)
+ error (1, err, "pthread_rwlock_init");
+
+ /* Lock it so all the threads will block. */
+ err = pthread_rwlock_wrlock (&rwlock);
+ assert (err == 0);
+
+ for (i = 0; i < THREADS; i++)
+ {
+ err = pthread_create (&tid[i], 0, test, (void *) i);
+ if (err)
+ error (1, err, "pthread_create");
+ }
+
+ for (i = 0; i < THREADS; i++)
+ {
+ void *ret;
+
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ assert (ret == 0);
+ }
+
+ return 0;
+}
diff --git a/htl/tests/test-16.c b/htl/tests/test-16.c
new file mode 100644
index 0000000..519aa84
--- /dev/null
+++ b/htl/tests/test-16.c
@@ -0,0 +1,87 @@
+/* Test pthread_kill.c.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <hurd/signal.h>
+
+pthread_t testthread;
+
+int i;
+
+void *
+test (void *arg)
+{
+ error_t err;
+
+ printf ("test: %d\n", pthread_self ());
+
+ err = pthread_kill (pthread_self (), SIGINFO);
+ if (err)
+ error (1, err, "pthread_kill");
+
+ /* To avoid using condition variables in a signal handler. */
+ while (i == 0)
+ sched_yield ();
+
+ return 0;
+}
+
+static void
+handler (int sig)
+{
+ assert (pthread_equal (pthread_self (), testthread));
+ printf ("handler: %d\n", pthread_self ());
+ i = 1;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ struct sigaction sa;
+ void *ret;
+
+ printf ("main: %d\n", pthread_self ());
+
+ sa.sa_handler = handler;
+ sa.sa_mask = 0;
+ sa.sa_flags = 0;
+
+ err = sigaction (SIGINFO, &sa, 0);
+ if (err)
+ error (1, err, "sigaction");
+
+ err = pthread_create (&testthread, 0, test, 0);
+ if (err)
+ error (1, err, "pthread_create");
+
+ err = pthread_join (testthread, &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ assert (ret == 0);
+
+ return 0;
+}
diff --git a/htl/tests/test-17.c b/htl/tests/test-17.c
new file mode 100644
index 0000000..ffc90b5
--- /dev/null
+++ b/htl/tests/test-17.c
@@ -0,0 +1,73 @@
+/* Test that the key reuse inside libpthread does not cause thread
+ specific values to persist.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE 1
+
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+#include <errno.h>
+
+void
+work (int iter)
+{
+ error_t err;
+ pthread_key_t key1;
+ pthread_key_t key2;
+ void *value1;
+ void *value2;
+
+ printf ("work/%d: start\n", iter);
+ err = pthread_key_create (&key1, NULL);
+ assert (err == 0);
+ err = pthread_key_create (&key2, NULL);
+ assert (err == 0);
+
+ value1 = pthread_getspecific (key1);
+ value2 = pthread_getspecific (key2);
+ printf ("work/%d: pre-setspecific: %p,%p\n", iter, value1, value2);
+ assert (value1 == NULL);
+ assert (value2 == NULL);
+ err = pthread_setspecific (key1, (void *) (0x100 + iter));
+ assert (err == 0);
+ err = pthread_setspecific (key2, (void *) (0x200 + iter));
+ assert (err == 0);
+
+ value1 = pthread_getspecific (key1);
+ value2 = pthread_getspecific (key2);
+ printf ("work/%d: post-setspecific: %p,%p\n", iter, value1, value2);
+ assert (value1 == (void *) (0x100 + iter));
+ assert (value2 == (void *) (0x200 + iter));
+
+ err = pthread_key_delete (key1);
+ assert (err == 0);
+ err = pthread_key_delete (key2);
+ assert (err == 0);
+}
+
+int
+main (int argc, char *argv[])
+{
+ int i;
+
+ for (i = 0; i < 8; ++i)
+ work (i + 1);
+
+ return 0;
+}
diff --git a/htl/tests/test-2.c b/htl/tests/test-2.c
new file mode 100644
index 0000000..1194a34
--- /dev/null
+++ b/htl/tests/test-2.c
@@ -0,0 +1,56 @@
+/* Test detachability.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+#include <unistd.h>
+
+void *
+thread (void *arg)
+{
+ while (1)
+ sched_yield ();
+}
+
+int
+main (int argc, char **argv)
+{
+ int err;
+ pthread_t tid;
+ void *ret;
+
+ err = pthread_create (&tid, 0, thread, 0);
+ if (err)
+ error (1, err, "pthread_create");
+
+ err = pthread_detach (tid);
+ if (err)
+ error (1, err, "pthread_detach");
+
+ err = pthread_detach (tid);
+ assert (err == EINVAL);
+
+ err = pthread_join (tid, &ret);
+ assert (err == EINVAL);
+
+ return 0;
+}
diff --git a/htl/tests/test-3.c b/htl/tests/test-3.c
new file mode 100644
index 0000000..beed473
--- /dev/null
+++ b/htl/tests/test-3.c
@@ -0,0 +1,71 @@
+/* Test the thread attribute get and set methods.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <sched.h>
+#include <assert.h>
+#include <errno.h>
+
+int
+main (int argc, char *argv[])
+{
+ error_t err;
+ pthread_attr_t attr;
+
+ int i;
+ struct sched_param sp;
+ void *p;
+ size_t sz;
+
+ err = pthread_attr_init (&attr);
+ assert_perror (err);
+
+ err = pthread_attr_destroy (&attr);
+ assert_perror (err);
+
+ err = pthread_attr_init (&attr);
+ assert_perror (err);
+
+#define TEST1(foo, rv, v) \
+ err = pthread_attr_get##foo (&attr, rv); \
+ assert_perror (err); \
+ \
+ err = pthread_attr_set##foo (&attr, v); \
+ assert_perror (err);
+
+#define TEST(foo, rv, v) TEST1(foo, rv, v)
+
+ TEST (inheritsched, &i, i);
+ TEST (schedparam, &sp, &sp);
+ TEST (schedpolicy, &i, i);
+ TEST (scope, &i, i);
+ TEST (stackaddr, &p, p);
+ TEST (detachstate, &i, i);
+ TEST (guardsize, &sz, sz);
+ TEST (stacksize, &sz, sz);
+
+ err = pthread_attr_getstack (&attr, &p, &sz);
+ assert_perror (err);
+
+ err = pthread_attr_setstack (&attr, p, sz);
+ assert_perror (err);
+
+ return 0;
+}
diff --git a/htl/tests/test-4.c b/htl/tests/test-4.c
new file mode 100644
index 0000000..b8c24b7
--- /dev/null
+++ b/htl/tests/test-4.c
@@ -0,0 +1,102 @@
+/* Test the stack guard.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+size_t stacksize;
+
+void *
+thr (void *arg)
+{
+ int i;
+ char *foo;
+
+ foo = alloca (3 * stacksize / 4);
+ for (i = 0; i < sizeof foo; i++)
+ foo[i] = -1;
+
+ return (void *) 1;
+}
+
+int
+main (int argc, char *argv[])
+{
+ error_t err;
+ pid_t child;
+
+ child = fork ();
+ switch (child)
+ {
+ case -1:
+ error (1, errno, "fork");
+ break;
+
+ case 0:
+ {
+ pthread_attr_t attr;
+ pthread_t tid;
+ void *ret;
+
+ err = pthread_attr_init (&attr);
+ assert_perror (err);
+
+ err = pthread_attr_getstacksize (&attr, &stacksize);
+ assert_perror (err);
+
+ err = pthread_attr_setguardsize (&attr, stacksize / 2);
+ if (err == ENOTSUP)
+ {
+ printf ("Stack guard attribute not supported.\n");
+ return 1;
+ }
+ assert_perror (err);
+
+ err = pthread_create (&tid, &attr, thr, 0);
+ assert_perror (err);
+
+ err = pthread_attr_destroy (&attr);
+ assert_perror (err);
+
+ err = pthread_join (tid, &ret);
+ /* Should never be successful. */
+ printf ("Thread did not segfault!?!\n");
+ assert_perror (err);
+ return 0;
+ }
+
+ default:
+ {
+ pid_t pid;
+ int status;
+
+ pid = waitpid (child, &status, 0);
+ printf ("pid = %d; child = %d; status = %d\n", pid, child, status);
+ assert (pid == child);
+ assert (status != 0);
+ }
+ }
+
+ return 0;
+}
diff --git a/htl/tests/test-5.c b/htl/tests/test-5.c
new file mode 100644
index 0000000..ef9691c
--- /dev/null
+++ b/htl/tests/test-5.c
@@ -0,0 +1,91 @@
+/* Test signals.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <error.h>
+#include <assert.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+
+void *
+thr (void *arg)
+{
+ *(int *) 0 = 0;
+ return 0;
+}
+
+int foobar;
+
+int
+main (int argc, char *argv[])
+{
+ error_t err;
+ pid_t child;
+
+ struct rlimit limit;
+
+ limit.rlim_cur = 0;
+ limit.rlim_max = 0;
+
+ err = setrlimit (RLIMIT_CORE, &limit);
+ if (err)
+ error (1, err, "setrlimit");
+
+ child = fork ();
+ switch (child)
+ {
+ case -1:
+ error (1, errno, "fork");
+ break;
+
+ case 0:
+ {
+ pthread_t tid;
+ void *ret;
+
+ err = pthread_create (&tid, 0, thr, 0);
+ if (err)
+ error (1, err, "pthread_create");
+
+ err = pthread_join (tid, &ret);
+ assert_perror (err);
+
+ /* Should have never returned. Our parent expects us to fail
+ thus we succeed and indicate the error. */
+ return 0;
+ }
+
+ default:
+ {
+ pid_t pid;
+ int status;
+
+ pid = waitpid (child, &status, 0);
+ printf ("pid = %d; child = %d; status = %d\n", pid, child, status);
+ assert (pid == child);
+ assert (status != 0);
+ }
+ }
+
+ return 0;
+}
diff --git a/htl/tests/test-6.c b/htl/tests/test-6.c
new file mode 100644
index 0000000..e25d419
--- /dev/null
+++ b/htl/tests/test-6.c
@@ -0,0 +1,114 @@
+/* Test barriers.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <error.h>
+#include <assert.h>
+#include <errno.h>
+
+#define THREADS 500
+#define WAITS 3
+
+void *
+dowait (void *arg)
+{
+ pthread_barrier_t *barrier = arg;
+ int ret;
+
+ ret = pthread_barrier_wait (barrier);
+ printf ("%d ", pthread_self ());
+ return (void *) ret;
+}
+
+int
+main (int argc, char **argv)
+{
+ pthread_barrierattr_t attr;
+ pthread_barrier_t barrier;
+
+ int i, j;
+ error_t err;
+ pthread_t tid[THREADS];
+
+ int havesyncs;
+
+ err = pthread_barrierattr_init (&attr);
+ if (err)
+ error (1, err, "pthread_barrierattr_init");
+
+ err = pthread_barrierattr_getpshared (&attr, &i);
+ if (err)
+ error (1, err, "pthread_barrierattr_getpshared");
+ assert (i == PTHREAD_PROCESS_PRIVATE || i == PTHREAD_PROCESS_SHARED);
+
+ err = pthread_barrierattr_setpshared (&attr, PTHREAD_PROCESS_PRIVATE);
+ if (err)
+ error (1, err, "pthread_barrierattr_setpshared");
+
+ err = pthread_barrier_init (&barrier, &attr, THREADS + 1);
+ if (err)
+ error (1, err, "pthread_barrier_init");
+
+ for (j = 0; j < WAITS; j++)
+ {
+
+ for (i = 0; i < THREADS; i++)
+ {
+ err = pthread_create (&tid[i], 0, dowait, &barrier);
+ if (err)
+ error (1, err, "pthread_create (%d)", i);
+ }
+
+ printf ("Manager will now call pthread_barrier_wait.\n");
+
+ havesyncs
+ = pthread_barrier_wait (&barrier) == PTHREAD_BARRIER_SERIAL_THREAD
+ ? 1 : 0;
+
+ for (i = THREADS - 1; i >= 0; i--)
+ {
+ void *ret;
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ switch ((int) ret)
+ {
+ case 0:
+ break;
+
+ case PTHREAD_BARRIER_SERIAL_THREAD:
+ havesyncs++;
+ break;
+
+ default:
+ assert (!"Unknown value returned from pthread_barrier_wait.");
+ break;
+ }
+ }
+
+ printf ("\n");
+
+ assert (havesyncs == 1);
+ }
+
+ return 0;
+}
diff --git a/htl/tests/test-7.c b/htl/tests/test-7.c
new file mode 100644
index 0000000..4823de2
--- /dev/null
+++ b/htl/tests/test-7.c
@@ -0,0 +1,89 @@
+/* Test Thread-Specific Data.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <stdio.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 10
+#define KEYS 400
+
+pthread_key_t key[KEYS];
+
+void *
+thr (void *arg)
+{
+ error_t err;
+ int i;
+
+ for (i = 0; i < KEYS; i++)
+ {
+ printf ("pthread_getspecific(%d).\n", key[i]);
+ assert (pthread_getspecific (key[i]) == NULL);
+ printf ("pthread_setspecific(%d, %d).\n", key[i], pthread_self ());
+ err = pthread_setspecific (key[i], (void *) pthread_self ());
+ printf ("pthread_setspecific(%d, %d) => %d.\n", key[i], pthread_self (),
+ err);
+ assert_perror (err);
+ }
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ int i;
+ pthread_t tid[THREADS];
+
+ void des (void *val)
+ {
+ assert ((pthread_t) val == pthread_self ());
+ }
+
+ assert (pthread_getspecific ((pthread_key_t) 0) == NULL);
+ assert (pthread_setspecific ((pthread_key_t) 0, (void *) 0x1) == EINVAL);
+
+ for (i = 0; i < KEYS; i++)
+ err = pthread_key_create (&key[i], des);
+
+ for (i = 0; i < THREADS; i++)
+ {
+ err = pthread_create (&tid[i], 0, thr, 0);
+ if (err)
+ error (1, err, "pthread_create (%d)", i);
+ }
+
+ for (i = 0; i < THREADS; i++)
+ {
+ void *ret;
+
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ assert (ret == 0);
+ }
+
+ return 0;
+}
diff --git a/htl/tests/test-8.c b/htl/tests/test-8.c
new file mode 100644
index 0000000..9cf74a7
--- /dev/null
+++ b/htl/tests/test-8.c
@@ -0,0 +1,78 @@
+/* Test pthread_once.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 10
+
+pthread_once_t inc_var_once = PTHREAD_ONCE_INIT;
+int var;
+
+void
+inc_var (void)
+{
+ var++;
+}
+
+void *
+thr (void *arg)
+{
+ int i;
+
+ for (i = 0; i < 500; i++)
+ pthread_once (&inc_var_once, inc_var);
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ int i;
+ pthread_t tid[THREADS];
+
+ for (i = 0; i < THREADS; i++)
+ {
+ err = pthread_create (&tid[i], 0, thr, 0);
+ if (err)
+ error (1, err, "pthread_create (%d)", i);
+ }
+
+ assert (thr (0) == 0);
+
+ for (i = 0; i < THREADS; i++)
+ {
+ void *ret;
+
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ assert (ret == 0);
+ }
+
+ assert (var == 1);
+
+ return 0;
+}
diff --git a/htl/tests/test-9.c b/htl/tests/test-9.c
new file mode 100644
index 0000000..ad6bc36
--- /dev/null
+++ b/htl/tests/test-9.c
@@ -0,0 +1,104 @@
+/* Test recursive mutexes.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <assert.h>
+#include <error.h>
+#include <errno.h>
+
+#define THREADS 10
+
+int foo;
+
+void *
+thr (void *arg)
+{
+ int i;
+
+ pthread_mutex_lock (arg);
+
+ foo = pthread_self ();
+
+ for (i = 0; i < 500; i++)
+ pthread_mutex_lock (arg);
+ for (i = 0; i < 500; i++)
+ pthread_mutex_unlock (arg);
+
+ assert (foo == pthread_self ());
+
+ pthread_mutex_unlock (arg);
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ error_t err;
+ int i;
+ pthread_t tid[THREADS];
+ pthread_mutexattr_t mattr;
+ pthread_mutex_t mutex;
+
+ err = pthread_mutexattr_init (&mattr);
+ if (err)
+ error (1, err, "pthread_mutexattr_init");
+
+ err = pthread_mutexattr_settype (&mattr, PTHREAD_MUTEX_RECURSIVE);
+ if (err)
+ error (1, err, "pthread_mutexattr_settype");
+
+ err = pthread_mutex_init (&mutex, &mattr);
+ if (err)
+ error (1, err, "pthread_mutex_init");
+
+ err = pthread_mutexattr_destroy (&mattr);
+ if (err)
+ error (1, err, "pthread_mutexattr_destroy");
+
+ pthread_mutex_lock (&mutex);
+ pthread_mutex_lock (&mutex);
+ pthread_mutex_unlock (&mutex);
+ pthread_mutex_unlock (&mutex);
+
+ for (i = 0; i < THREADS; i++)
+ {
+ err = pthread_create (&tid[i], 0, thr, &mutex);
+ if (err)
+ error (1, err, "pthread_create (%d)", i);
+ }
+
+ for (i = 0; i < THREADS; i++)
+ {
+ void *ret;
+
+ err = pthread_join (tid[i], &ret);
+ if (err)
+ error (1, err, "pthread_join");
+
+ assert (ret == 0);
+ }
+
+ err = pthread_mutex_destroy (&mutex);
+ if (err)
+ error (1, err, "pthread_mutex_destroy");
+
+ return 0;
+}
diff --git a/htl/tests/test-__pthread_destroy_specific-skip.c b/htl/tests/test-__pthread_destroy_specific-skip.c
new file mode 100644
index 0000000..c54ccad
--- /dev/null
+++ b/htl/tests/test-__pthread_destroy_specific-skip.c
@@ -0,0 +1,100 @@
+/* Check that __pthread_destroy_specific works correctly if it has to skip
+ unused slots.
+ Copyright (C) 2000-2018 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+
+#include <error.h>
+#include <pthread.h>
+#include <stdio.h>
+
+
+#define N_k 42
+
+static volatile int v;
+
+static void
+d (void *x)
+{
+ int *i = (int *) x;
+
+ if (v != *i)
+ error (1, 0, "FAILED %d %d", v, *i);
+ v += 2;
+
+ printf ("%s %d\n", __FUNCTION__, *i);
+ fflush (stdout);
+}
+
+static void *
+test (void *x)
+{
+ pthread_key_t k[N_k];
+ static int k_v[N_k];
+
+ int err, i;
+
+ for (i = 0; i < N_k; i += 1)
+ {
+ err = pthread_key_create (&k[i], &d);
+ if (err != 0)
+ error (1, err, "pthread_key_create %d", i);
+ }
+
+ for (i = 0; i < N_k; i += 1)
+ {
+ k_v[i] = i;
+ err = pthread_setspecific (k[i], &k_v[i]);
+ if (err != 0)
+ error (1, err, "pthread_setspecific %d", i);
+ }
+
+ /* Delete every even key. */
+ for (i = 0; i < N_k; i += 2)
+ {
+ err = pthread_key_delete (k[i]);
+ if (err != 0)
+ error (1, err, "pthread_key_delete %d", i);
+ }
+
+ v = 1;
+ pthread_exit (NULL);
+
+ return NULL;
+}
+
+
+int
+main (void)
+{
+ pthread_t tid;
+ int err;
+
+ err = pthread_create (&tid, 0, test, NULL);
+ if (err != 0)
+ error (1, err, "pthread_create");
+
+ err = pthread_join (tid, NULL);
+ if (err)
+ error (1, err, "pthread_join");
+
+ if (v != N_k + 1)
+ error (1, 0, "FAILED END %d %d", v, N_k + 1);
+
+ return 0;
+}