Add and use new glibc-internal futex API.
[glibc.git] / nptl / tst-stack1.c
blob6a11dafa11c69e5bf79d6df54f740624b2680bb2
1 /* Copyright (C) 2002-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <limits.h>
20 #include <pthread.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <sys/param.h>
24 #include <unistd.h>
27 static void *stack;
28 static size_t size;
31 static void *
32 tf (void *a)
34 int result = 0;
36 puts ("child start");
38 pthread_attr_t attr;
39 if (pthread_getattr_np (pthread_self (), &attr) != 0)
41 puts ("getattr_np failed");
42 exit (1);
45 size_t test_size;
46 void *test_stack;
47 if (pthread_attr_getstack (&attr, &test_stack, &test_size) != 0)
49 puts ("attr_getstack failed");
50 exit (1);
53 if (test_size != size)
55 printf ("child: reported size differs: is %zu, expected %zu\n",
56 test_size, size);
57 result = 1;
60 if (test_stack != stack)
62 printf ("child: reported stack address differs: is %p, expected %p\n",
63 test_stack, stack);
64 result = 1;
67 puts ("child OK");
69 return result ? (void *) 1l : NULL;
73 int
74 do_test (void)
76 int result = 0;
78 size = MAX (4 * getpagesize (), PTHREAD_STACK_MIN);
79 if (posix_memalign (&stack, getpagesize (), size) != 0)
81 puts ("out of memory while allocating the stack memory");
82 exit (1);
85 pthread_attr_t attr;
86 if (pthread_attr_init (&attr) != 0)
88 puts ("attr_init failed");
89 exit (1);
92 puts ("attr_setstack");
93 if (pthread_attr_setstack (&attr, stack, size) != 0)
95 puts ("attr_setstack failed");
96 exit (1);
99 size_t test_size;
100 void *test_stack;
101 puts ("attr_getstack");
102 if (pthread_attr_getstack (&attr, &test_stack, &test_size) != 0)
104 puts ("attr_getstack failed");
105 exit (1);
108 if (test_size != size)
110 printf ("reported size differs: is %zu, expected %zu\n",
111 test_size, size);
112 result = 1;
115 if (test_stack != stack)
117 printf ("reported stack address differs: is %p, expected %p\n",
118 test_stack, stack);
119 result = 1;
122 puts ("create");
124 pthread_t th;
125 if (pthread_create (&th, &attr, tf, NULL) != 0)
127 puts ("failed to create thread");
128 exit (1);
131 void *status;
132 if (pthread_join (th, &status) != 0)
134 puts ("join failed");
135 exit (1);
138 result |= status != NULL;
140 return result;
144 #define TEST_FUNCTION do_test ()
145 #include "../test-skeleton.c"