unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: [PATCH v8 7/8] nptl: Add test cases for ISO C11 threads
Date: Fri,  2 Feb 2018 15:04:43 -0200	[thread overview]
Message-ID: <1517591084-11347-8-git-send-email-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <1517591084-11347-1-git-send-email-adhemerval.zanella@linaro.org>

This patch adds to testsuite new test cases to test all new introduced
C11 threads functions, types and macros are tested.

Checked with a build for all major ABI (aarch64-linux-gnu, alpha-linux-gnu,
arm-linux-gnueabi, i386-linux-gnu, ia64-linux-gnu, m68k-linux-gnu,
microblaze-linux-gnu [1], mips{64}-linux-gnu, nios2-linux-gnu,
powerpc{64le}-linux-gnu, s390{x}-linux-gnu, sparc{64}-linux-gnu,
tile{pro,gx}-linux-gnu, and x86_64-linux-gnu).

Also ran a full check on aarch64-linux-gnu, x86_64-linux-gnu, i686-linux-gnu,
arm-linux-gnueabhf, and powerpc64le-linux-gnu.

	Adhemerval Zanella  <adhemerval.zanella@linaro.org>
	Juan Manuel Torres Palma  <jmtorrespalma@gmail.com>

	* nptl/Makefile (tests): Add new test files.
	* nptl/tst-call-once.c : New file. Tests C11 functions and types.
	* nptl/tst-cnd-basic.c: Likewise.
	* nptl/tst-cnd-broadcast.c: Likewise.
	* nptl/tst-cnd-timedwait.c: Likewise.
	* nptl/tst-mtx-basic.c: Likewise.
	* nptl/tst-mtx-recursive.c: Likewise.
	* nptl/tst-mtx-timedlock.c: Likewise.
	* nptl/tst-mtx-trylock.c: Likewise.
	* nptl/tst-thrd-basic.c: Likewise.
	* nptl/tst-thrd-detach.c: Likewise.
	* nptl/tst-thrd-sleep.c: Likewise.
	* nptl/tst-tss-basic.c: Likewise.
---
 ChangeLog                | 17 +++++++++
 nptl/Makefile            |  5 ++-
 nptl/tst-call-once.c     | 66 ++++++++++++++++++++++++++++++++
 nptl/tst-cnd-basic.c     | 68 +++++++++++++++++++++++++++++++++
 nptl/tst-cnd-broadcast.c | 83 ++++++++++++++++++++++++++++++++++++++++
 nptl/tst-cnd-timedwait.c | 70 ++++++++++++++++++++++++++++++++++
 nptl/tst-mtx-basic.c     | 73 ++++++++++++++++++++++++++++++++++++
 nptl/tst-mtx-recursive.c | 45 ++++++++++++++++++++++
 nptl/tst-mtx-timedlock.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++
 nptl/tst-mtx-trylock.c   | 90 ++++++++++++++++++++++++++++++++++++++++++++
 nptl/tst-thrd-detach.c   | 52 +++++++++++++++++++++++++
 nptl/tst-thrd-sleep.c    | 51 +++++++++++++++++++++++++
 nptl/tst-tss-basic.c     | 75 ++++++++++++++++++++++++++++++++++++
 13 files changed, 792 insertions(+), 1 deletion(-)
 create mode 100644 nptl/tst-call-once.c
 create mode 100644 nptl/tst-cnd-basic.c
 create mode 100644 nptl/tst-cnd-broadcast.c
 create mode 100644 nptl/tst-cnd-timedwait.c
 create mode 100644 nptl/tst-mtx-basic.c
 create mode 100644 nptl/tst-mtx-recursive.c
 create mode 100644 nptl/tst-mtx-timedlock.c
 create mode 100644 nptl/tst-mtx-trylock.c
 create mode 100644 nptl/tst-thrd-detach.c
 create mode 100644 nptl/tst-thrd-sleep.c
 create mode 100644 nptl/tst-tss-basic.c

diff --git a/nptl/Makefile b/nptl/Makefile
index 4ee1db0..7416275 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -315,7 +315,10 @@ tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \
 	tst-thread_local1 tst-mutex-errorcheck tst-robust10 \
 	tst-robust-fork tst-create-detached tst-memstream \
 	tst-thread-exit-clobber tst-minstack-cancel tst-minstack-exit \
-	tst-minstack-throw
+	tst-minstack-throw \
+	tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \
+	tst-cnd-timedwait tst-thrd-detach tst-mtx-basic tst-thrd-sleep \
+	tst-mtx-recursive tst-tss-basic tst-call-once tst-mtx-timedlock
 
 tests-internal := tst-rwlock19 tst-rwlock20 \
 		  tst-sem11 tst-sem12 tst-sem13 \
diff --git a/nptl/tst-call-once.c b/nptl/tst-call-once.c
new file mode 100644
index 0000000..b677181
--- /dev/null
+++ b/nptl/tst-call-once.c
@@ -0,0 +1,66 @@
+/* C11 threads call_once test.
+   Copyright (C) 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 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <threads.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+/* Flag that controls the first thread access.  */
+static once_flag flag = ONCE_FLAG_INIT;
+
+static int value = 0;
+
+static void
+do_once (void)
+{
+  value++;
+}
+
+static int
+func (void* data)
+{
+  call_once (&flag, do_once);
+  thrd_exit (thrd_success);
+}
+
+#define N 20
+
+int
+do_test (void)
+{
+  thrd_t ids[N];
+
+  for (int i = 0; i < N; ++i)
+    {
+      if (thrd_create (&ids[i], func, NULL) != thrd_success)
+	FAIL_EXIT1 ("thrd_create failed");
+    }
+
+  /* Join threads.  */
+  for (int i = 0; i < N; ++i)
+    {
+      if (thrd_join (ids[i], NULL) != thrd_success)
+	FAIL_EXIT1 ("thrd_join failed");
+    }
+
+  return (value != 1);
+}
+
+#include <support/test-driver.c>
diff --git a/nptl/tst-cnd-basic.c b/nptl/tst-cnd-basic.c
new file mode 100644
index 0000000..84b7f5f
--- /dev/null
+++ b/nptl/tst-cnd-basic.c
@@ -0,0 +1,68 @@
+/* C11 threads condition variable tests.
+   Copyright (C) 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 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <threads.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+/* Shared condition variable between child and parent.  */
+static cnd_t cond;
+
+/* Mutex needed to signal and wait threads.  */
+static mtx_t mutex;
+
+static int
+signal_parent (void)
+{
+  if (cnd_signal (&cond) != thrd_success)
+    FAIL_EXIT1 ("cnd_signal");
+
+  thrd_exit (thrd_success);
+}
+
+static int
+do_test (void)
+{
+  thrd_t id;
+
+  if (cnd_init (&cond) != thrd_success)
+    FAIL_EXIT1 ("cnd_init failed");
+  if (mtx_init (&mutex, mtx_plain) != thrd_success)
+    FAIL_EXIT1 ("mtx_init failed");
+
+  if (thrd_create (&id, (thrd_start_t) signal_parent, NULL)
+      != thrd_success)
+    FAIL_EXIT1 ("thrd_create failed");
+
+  if (cnd_wait (&cond, &mutex) != thrd_success)
+    FAIL_EXIT1 ("cnd_wait failed");
+
+  /* Joining is not mandatory here, but still done to assure child thread
+     ends correctly.  */
+  if (thrd_join (id, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd_join failed");
+
+  mtx_destroy (&mutex);
+  cnd_destroy (&cond);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/nptl/tst-cnd-broadcast.c b/nptl/tst-cnd-broadcast.c
new file mode 100644
index 0000000..90d6843
--- /dev/null
+++ b/nptl/tst-cnd-broadcast.c
@@ -0,0 +1,83 @@
+/* C11 threads condition broadcast variable tests.
+   Copyright (C) 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 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <threads.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+/* Condition variable where child threads will wait.  */
+static cnd_t cond;
+
+/* Mutex to control wait on cond.  */
+static mtx_t mutex;
+
+/* Code executed by each thread.  */
+static int
+child_wait (void* data)
+{
+  /* Wait until parent thread sends broadcast here.  */
+  mtx_lock (&mutex);
+  cnd_wait (&cond, &mutex);
+  mtx_unlock (&mutex);
+
+  thrd_exit (thrd_success);
+}
+
+#define N 5
+
+static int
+do_test (void)
+{
+  thrd_t ids[N];
+  unsigned char i;
+
+  if (cnd_init (&cond) != thrd_success)
+    FAIL_EXIT1 ("cnd_init failed");
+  if (mtx_init (&mutex, mtx_plain) != thrd_success)
+    FAIL_EXIT1 ("mtx_init failed");
+
+  /* Create N new threads.  */
+  for (i = 0; i < N; ++i)
+    {
+      if (thrd_create (&ids[i], child_wait, NULL) != thrd_success)
+	FAIL_EXIT1 ("thrd_create failed");
+    }
+
+  /* Wait for other threads to reach their wait func.  */
+  thrd_sleep (&((struct timespec){.tv_sec = 2}), NULL);
+
+  mtx_lock (&mutex);
+  if (cnd_broadcast (&cond) != thrd_success)
+    FAIL_EXIT1 ("cnd_broadcast failed");
+  mtx_unlock (&mutex);
+
+  for (i = 0; i < N; ++i)
+    {
+      if (thrd_join (ids[i], NULL) != thrd_success)
+	FAIL_EXIT1 ("thrd_join failed");
+    }
+
+  mtx_destroy (&mutex);
+  cnd_destroy (&cond);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/nptl/tst-cnd-timedwait.c b/nptl/tst-cnd-timedwait.c
new file mode 100644
index 0000000..45a1512
--- /dev/null
+++ b/nptl/tst-cnd-timedwait.c
@@ -0,0 +1,70 @@
+/* C11 threads condition timed wait variable tests.
+   Copyright (C) 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 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <threads.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+/* Shared condition variable between child and parent.  */
+static cnd_t cond;
+
+/* Mutex needed to signal and wait threads.  */
+static mtx_t mutex;
+
+static int
+signal_parent (void *arg)
+{
+  if (cnd_signal (&cond) != thrd_success)
+    FAIL_EXIT1 ("cnd_signal failed");
+
+  thrd_exit (thrd_success);
+}
+
+static int
+do_test (void)
+{
+  thrd_t id;
+  struct timespec w_time;
+
+  if (cnd_init (&cond) != thrd_success)
+    FAIL_EXIT1 ("cnd_init failed");
+  if (mtx_init (&mutex, mtx_plain) != thrd_success)
+    FAIL_EXIT1 ("mtx_init failed");
+
+  if (clock_gettime (CLOCK_REALTIME, &w_time) != 0)
+    FAIL_EXIT1 ("clock_gettime failed");
+  w_time.tv_nsec += 150000;
+
+  if (thrd_create (&id, signal_parent, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd_create failed");
+
+  if (cnd_timedwait (&cond, &mutex, &w_time) != thrd_success)
+    FAIL_EXIT1 ("cnd_timedwait failed");
+
+  if (thrd_join (id, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd_join failed");
+
+  mtx_destroy (&mutex);
+  cnd_destroy (&cond);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/nptl/tst-mtx-basic.c b/nptl/tst-mtx-basic.c
new file mode 100644
index 0000000..8507312
--- /dev/null
+++ b/nptl/tst-mtx-basic.c
@@ -0,0 +1,73 @@
+/* C11 threads basic mutex tests.
+   Copyright (C) 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 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <threads.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+/* Shared mutex between child and parent.  */
+static mtx_t mutex;
+
+/* Shared counter to check possible race conditions.  */
+static int counter;
+
+static int
+child_add (void *arg)
+{
+  if (mtx_lock (&mutex) != thrd_success)
+    FAIL_EXIT1 ("mtx_lock failed");
+
+  counter++;
+
+  if (mtx_unlock (&mutex) != thrd_success)
+    FAIL_EXIT1 ("mtx_unlock failed");
+
+  thrd_exit (thrd_success);
+}
+
+static int
+do_test (void)
+{
+  mtx_init (&mutex, mtx_plain);
+
+  thrd_t id;
+  if (thrd_create (&id, child_add, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd_create failed");
+
+  if (mtx_lock (&mutex) != thrd_success)
+    FAIL_EXIT1 ("mtx_lock failed");
+
+  counter++;
+
+  if (mtx_unlock (&mutex) != thrd_success)
+    FAIL_EXIT1 ("mtx_unlock failed");
+
+  if (thrd_join (id, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd_join failed");
+
+  if (counter != 2)
+    FAIL_EXIT1 ("counter (%d) != 2", counter);
+
+  mtx_destroy (&mutex);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/nptl/tst-mtx-recursive.c b/nptl/tst-mtx-recursive.c
new file mode 100644
index 0000000..7a6bfc2
--- /dev/null
+++ b/nptl/tst-mtx-recursive.c
@@ -0,0 +1,45 @@
+/* C11 threads recursive mutex tests.
+   Copyright (C) 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 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <threads.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+  static mtx_t mutex;
+
+  if (mtx_init (&mutex, mtx_recursive) != thrd_success)
+    FAIL_EXIT1 ("mtx_init failed");
+
+  if (mtx_lock (&mutex) != thrd_success)
+    FAIL_EXIT1 ("mtx_lock failed");
+
+  /* Lock mutex second time, if not recursive should deadlock.  */
+  if (mtx_lock (&mutex) != thrd_success)
+    FAIL_EXIT1 ("mtx_lock failed");
+
+  mtx_destroy (&mutex);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/nptl/tst-mtx-timedlock.c b/nptl/tst-mtx-timedlock.c
new file mode 100644
index 0000000..dcae828
--- /dev/null
+++ b/nptl/tst-mtx-timedlock.c
@@ -0,0 +1,98 @@
+/* C11 threads timed mutex tests.
+   Copyright (C) 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 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <threads.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+/* Shared mutex between child and parent.  */
+static mtx_t mutex;
+
+/* Shared counter to check possible race conditions.  */
+static char shrd_counter;
+
+/* Maximum amount of time waiting for mutex.  */
+static struct timespec wait_time;
+
+/* Function to choose an action to do, depending on mtx_timedlock
+   return value.  */
+static inline void
+choose_action (int action, char* thread_name)
+{
+  switch (action)
+    {
+      case thrd_success:
+        ++shrd_counter;
+
+	if (mtx_unlock (&mutex) != thrd_success)
+	  FAIL_EXIT1 ("mtx_unlock failed");
+      break;
+
+      case thrd_timedout:
+        break;
+
+      case thrd_error:
+	FAIL_EXIT1 ("%s lock error", thread_name);
+        break;
+    }
+}
+
+static int
+child_add (void *arg)
+{
+  char child_name[] = "child";
+
+  /* Try to lock mutex.  */
+  choose_action (mtx_timedlock (&mutex, &wait_time), child_name);
+  thrd_exit (thrd_success);
+}
+
+static int
+do_test (void)
+{
+  thrd_t id;
+  char parent_name[] = "parent";
+
+  if (mtx_init (&mutex, mtx_timed) != thrd_success)
+    FAIL_EXIT1 ("mtx_init failed");
+
+  if (clock_gettime (CLOCK_REALTIME, &wait_time) != 0)
+    FAIL_EXIT1 ("clock_gettime failed");
+  /* Tiny amount of time, to assure that if any thread finds it busy.
+     It will receive thrd_timedout.  */
+  wait_time.tv_nsec += 1;
+
+  if (thrd_create (&id, child_add, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd_create failed");
+
+  choose_action (mtx_timedlock (&mutex, &wait_time), parent_name);
+
+  if (thrd_join (id, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd_join failed");
+
+  if (shrd_counter != 2 && shrd_counter != 1)
+    FAIL_EXIT1 ("shrd_counter != {1,2} (%d)", shrd_counter);
+
+  mtx_destroy (&mutex);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/nptl/tst-mtx-trylock.c b/nptl/tst-mtx-trylock.c
new file mode 100644
index 0000000..9df84a3
--- /dev/null
+++ b/nptl/tst-mtx-trylock.c
@@ -0,0 +1,90 @@
+/* C11 threads trylock mutex tests.
+   Copyright (C) 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 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <threads.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+/* Shared mutex between child and parent.  */
+static mtx_t mutex;
+
+/* Shared counter to check possible race conditions.  */
+static char shrd_counter;
+
+/* Function to choose an action to do, depending on mtx_trylock
+   return value.  */
+static inline void
+choose_action (int action, char* thread_name)
+{
+  switch (action)
+    {
+      case thrd_success:
+        ++shrd_counter;
+
+	if (mtx_unlock (&mutex) != thrd_success)
+	  FAIL_EXIT1 ("mtx_unlock failed");
+      break;
+
+      case thrd_busy:
+        break;
+
+      case thrd_error:
+	FAIL_EXIT1 ("%s lock error", thread_name);
+        break;
+    }
+}
+
+static int
+child_add (void *arg)
+{
+  char child_name[] = "child";
+
+  /* Try to lock mutex.  */
+  choose_action (mtx_trylock (&mutex), child_name);
+
+  thrd_exit (thrd_success);
+}
+
+static int
+do_test (void)
+{
+  thrd_t id;
+  char parent_name[] = "parent";
+
+  if (mtx_init (&mutex, mtx_timed) != thrd_success)
+    FAIL_EXIT1 ("mtx_init failed");
+
+  if (thrd_create (&id, child_add, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd_create failed");
+
+  choose_action (mtx_trylock (&mutex), parent_name);
+
+  if (thrd_join (id, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd_join failed");
+
+  if (shrd_counter != 2 && shrd_counter != 1)
+    FAIL_EXIT1 ("shrd_counter != {1,2} (%d)", shrd_counter);
+
+  mtx_destroy (&mutex);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/nptl/tst-thrd-detach.c b/nptl/tst-thrd-detach.c
new file mode 100644
index 0000000..72ba845
--- /dev/null
+++ b/nptl/tst-thrd-detach.c
@@ -0,0 +1,52 @@
+/* C11 threads thread detach tests.
+   Copyright (C) 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 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <threads.h>
+#include <time.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+static int
+detach_thrd (void *arg)
+{
+  if (thrd_detach (thrd_current ()) != thrd_success)
+    FAIL_EXIT1 ("thrd_detach failed");
+  thrd_exit (thrd_success);
+}
+
+static int
+do_test (void)
+{
+  thrd_t id;
+
+  /* Create new thread.  */
+  if (thrd_create (&id, detach_thrd, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd_create failed");
+
+  /* Give some time so the thread can finish.  */
+  thrd_sleep (&(struct timespec) {.tv_sec = 2}, NULL);
+
+  if (thrd_join (id, NULL) == thrd_success)
+    FAIL_EXIT1 ("thrd_join succeed where it should fail");
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/nptl/tst-thrd-sleep.c b/nptl/tst-thrd-sleep.c
new file mode 100644
index 0000000..3805671
--- /dev/null
+++ b/nptl/tst-thrd-sleep.c
@@ -0,0 +1,51 @@
+/* C11 threads thread sleep tests.
+   Copyright (C) 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 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <threads.h>
+#include <time.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+static int
+sleep_thrd (void *arg)
+{
+  struct timespec const *tl = (struct timespec const *) arg;
+  if (thrd_sleep (tl, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd_sleep failed");
+
+  thrd_exit (thrd_success);
+}
+
+static int
+do_test (void)
+{
+  thrd_t id;
+  struct timespec wait_time = {.tv_sec = 3};
+
+  if (thrd_create (&id, sleep_thrd, (void *) (&wait_time)) != thrd_success)
+    FAIL_EXIT1 ("thrd_create failed");
+
+  if (thrd_join (id, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd failed");
+
+  return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/nptl/tst-tss-basic.c b/nptl/tst-tss-basic.c
new file mode 100644
index 0000000..e82edad
--- /dev/null
+++ b/nptl/tst-tss-basic.c
@@ -0,0 +1,75 @@
+/* C11 threads specific storage tests.
+   Copyright (C) 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 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <threads.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <support/check.h>
+
+/* Thread specific storage.  */
+static tss_t key;
+
+#define TSS_VALUE (void*) 0xFF
+
+static int
+tss_thrd (void *arg)
+{
+  if (tss_create (&key, NULL) != thrd_success)
+    FAIL_EXIT1 ("tss_create failed");
+
+  if (tss_set (key, TSS_VALUE))
+    FAIL_EXIT1 ("tss_set failed");
+
+  void *value = tss_get (key);
+  if (value == 0)
+    FAIL_EXIT1 ("tss_get failed");
+  if (value != TSS_VALUE)
+    FAIL_EXIT1 ("tss_get returned %p, expected %p", value, TSS_VALUE);
+
+  thrd_exit (thrd_success);
+}
+
+static int
+do_test (void)
+{
+  /* Setting an invalid key should return an error.  */
+  if (tss_set (key, TSS_VALUE) == thrd_success)
+    FAIL_EXIT1 ("tss_set succeed where it should have failed");
+
+  if (tss_create (&key, NULL) != thrd_success)
+    FAIL_EXIT1 ("tss_create failed");
+
+  thrd_t id;
+  if (thrd_create (&id, tss_thrd, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd_create failed");
+
+  if (thrd_join (id, NULL) != thrd_success)
+    FAIL_EXIT1 ("thrd failed");
+
+  /* The value set in tss_thrd should not be visible here.  */
+  void *value = tss_get (key);
+  if (value != 0)
+    FAIL_EXIT1 ("tss_get succeed where it should have failed");
+
+  tss_delete (key);
+
+  return 0;
+}
+
+#include <support/test-driver.c>
-- 
2.7.4



  parent reply	other threads:[~2018-02-02 17:04 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-02 17:04 [PATCH v8 0/8] Add support for ISO C threads.h Adhemerval Zanella
2018-02-02 17:04 ` [PATCH v8 1/8] nptl: Add C11 threads thrd_* functions Adhemerval Zanella
2018-02-08 13:49   ` Gabriel F. T. Gomes
2018-02-09 10:56     ` Adhemerval Zanella
2018-02-26 12:28       ` Gabriel F. T. Gomes
2018-07-06 12:46   ` Florian Weimer
2018-07-10 19:26     ` Adhemerval Zanella
2018-07-11 15:49       ` Szabolcs Nagy
2018-07-11 16:24         ` Adhemerval Zanella
2018-07-12 12:18           ` Florian Weimer
2018-07-12 17:38             ` Adhemerval Zanella
2018-07-13  7:03               ` Florian Weimer
2018-07-12 16:46   ` Florian Weimer
2018-07-12 17:52     ` Adhemerval Zanella
2018-07-12 18:24       ` Florian Weimer
2018-07-12 19:19         ` Adhemerval Zanella
2018-07-12 19:26           ` Florian Weimer
2018-07-12 19:41             ` Adhemerval Zanella
2018-07-12 19:32       ` Adhemerval Zanella
2018-07-12 19:35         ` Florian Weimer
2018-07-12 19:43           ` Adhemerval Zanella
2018-07-13  9:45   ` Florian Weimer
2018-07-13 12:59     ` Adhemerval Zanella
2018-07-13 13:04       ` Florian Weimer
2018-07-13 13:18         ` Adhemerval Zanella
2018-07-13 13:21           ` Florian Weimer
2018-07-13  9:48   ` Florian Weimer
2018-07-25  7:20   ` Andreas Schwab
2018-07-25  7:38     ` Florian Weimer
2018-07-25 10:29     ` Joseph Myers
2018-02-02 17:04 ` [PATCH v8 2/8] nptl: Add C11 threads mtx_* functions Adhemerval Zanella
2018-07-06 12:51   ` Florian Weimer
2018-07-10 12:35     ` Adhemerval Zanella
2018-07-12 18:39       ` Florian Weimer
2018-07-12 20:30         ` Adhemerval Zanella
2018-07-12 20:38           ` Florian Weimer
2018-07-13 13:08             ` Adhemerval Zanella
2018-07-13 13:10               ` Florian Weimer
2018-07-24 12:04   ` Adhemerval Zanella
2018-07-24 16:04     ` Carlos O'Donell
2018-02-02 17:04 ` [PATCH v8 3/8] nptl: Add C11 threads call_once functions Adhemerval Zanella
2018-07-13  9:32   ` Florian Weimer
2018-02-02 17:04 ` [PATCH v8 4/8] nptl: Add C11 threads cnd_* functions Adhemerval Zanella
2018-02-02 17:04 ` [PATCH v8 5/8] nptl: Add C11 threads tss_* functions Adhemerval Zanella
2018-07-12 16:48   ` Florian Weimer
2018-07-12 20:32     ` Adhemerval Zanella
2018-07-12 20:37       ` Florian Weimer
2018-02-02 17:04 ` [PATCH v8 6/8] nptl: Add abilist symbols for C11 threads Adhemerval Zanella
2018-07-13  9:50   ` Florian Weimer
2018-07-13 15:49     ` Adhemerval Zanella
2018-07-13 17:49       ` Florian Weimer
2018-07-13 18:47         ` Adhemerval Zanella
2018-07-13 19:56           ` Florian Weimer
2018-07-13 21:09             ` Adhemerval Zanella
2018-07-14 13:50               ` Florian Weimer
2018-07-18 17:40         ` Joseph Myers
2018-07-18 20:02           ` Adhemerval Zanella
2018-07-18 21:19           ` Florian Weimer
2018-02-02 17:04 ` Adhemerval Zanella [this message]
2018-07-13  9:31   ` [PATCH v8 7/8] nptl: Add test cases for ISO " Florian Weimer
2018-07-13 13:10     ` Adhemerval Zanella
2018-07-13 13:11       ` Florian Weimer
2018-07-13 13:29         ` Adhemerval Zanella
2018-07-17 13:53           ` Adhemerval Zanella
2018-02-02 17:04 ` [PATCH v8 8/8] Add manual documentation for threads.h Adhemerval Zanella
2018-06-27 13:39 ` [PATCH v8 0/8] Add support for ISO C threads.h Adhemerval Zanella
2018-07-19 17:46   ` Adhemerval Zanella
2018-07-19 18:43     ` Carlos O'Donell
2018-07-19 19:12       ` Rical Jasan
2018-07-19 19:58         ` Adhemerval Zanella
2018-07-21  0:26           ` Rical Jasan
2018-07-21  2:11             ` Carlos O'Donell
2018-07-21  6:22               ` Rical Jasan
2018-07-21 13:40                 ` Adhemerval Zanella
2018-07-19 21:26       ` Joseph Myers
2018-07-20 12:32         ` Adhemerval Zanella
2018-07-20 13:22           ` Rical Jasan
2018-07-20 13:54             ` Rical Jasan
2018-07-20 14:04               ` Carlos O'Donell
2018-07-20 15:02             ` [PATCH v8 0/8] Add support for ISO C threads.h [thrd_exit] Rical Jasan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1517591084-11347-8-git-send-email-adhemerval.zanella@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).