diff options
author | Salvatore Cro <salvatore.cro@st.com> | 2010-09-10 10:55:43 +0200 |
---|---|---|
committer | Carmelo Amoroso <carmelo.amoroso@st.com> | 2010-09-15 12:59:45 +0200 |
commit | 447c70a5dc04e85f96c2ae477ce851fdfdd8c719 (patch) | |
tree | 709d458b5142324d34fface4a89f281f00d0097c /test/nptl/tst-basic7.c | |
parent | a27dd6924e7964d92b49f4d5ebe2e68cfb2742dd (diff) |
tests: Added new nptl tests
tests: Added several nptl tests from glibc 2.10.1
Signed-off-by: Salvatore Cro <salvatore.cro@st.com>
Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'test/nptl/tst-basic7.c')
-rw-r--r-- | test/nptl/tst-basic7.c | 75 |
1 files changed, 75 insertions, 0 deletions
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 <errno.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <limits.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. */ + 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" |