about summary refs log tree commit diff
path: root/sysdeps/pthread/tst-basic7.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2020-02-09 16:12:35 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-02-09 16:12:53 +0000
commitcca76b6db216805267212ab03c8691e8e6960338 (patch)
tree3a668a36d36fc7d3fa309656f0131e9ed53ea4cc /sysdeps/pthread/tst-basic7.c
parent19a64d9f6eda12cd4b802aac470c645d208a1216 (diff)
downloadglibc-cca76b6db216805267212ab03c8691e8e6960338.tar.gz
glibc-cca76b6db216805267212ab03c8691e8e6960338.tar.xz
glibc-cca76b6db216805267212ab03c8691e8e6960338.zip
pthread: Move basic tests from nptl to sysdeps/pthread
So they can be checked with htl too.
Diffstat (limited to 'sysdeps/pthread/tst-basic7.c')
-rw-r--r--sysdeps/pthread/tst-basic7.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/sysdeps/pthread/tst-basic7.c b/sysdeps/pthread/tst-basic7.c
new file mode 100644
index 0000000000..26a599c178
--- /dev/null
+++ b/sysdeps/pthread/tst-basic7.c
@@ -0,0 +1,79 @@
+#include <errno.h>
+#include <limits.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/resource.h>
+
+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.  */
+#ifdef PTHREAD_STACK_MIN
+  use_stack_ptr (PTHREAD_STACK_MIN);
+#else
+  use_stack_ptr (4 * getpagesize ());
+#endif
+
+  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"