typos
[glibc/history.git] / nptl / tst-stack1.c
blob93405981d34fecda6d2756ec747ac01bb5be93ea
1 /* Copyright (C) 2002, 2003 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <limits.h>
21 #include <pthread.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <sys/param.h>
25 #include <unistd.h>
28 static void *stack;
29 static size_t size;
32 static void *
33 tf (void *a)
35 int result = 0;
37 puts ("child start");
39 pthread_attr_t attr;
40 if (pthread_getattr_np (pthread_self (), &attr) != 0)
42 puts ("getattr_np failed");
43 exit (1);
46 size_t test_size;
47 void *test_stack;
48 if (pthread_attr_getstack (&attr, &test_stack, &test_size) != 0)
50 puts ("attr_getstack failed");
51 exit (1);
54 if (test_size != size)
56 printf ("child: reported size differs: is %zu, expected %zu\n",
57 test_size, size);
58 result = 1;
61 if (test_stack != stack)
63 printf ("child: reported stack address differs: is %p, expected %p\n",
64 test_stack, stack);
65 result = 1;
68 puts ("child OK");
70 return result ? (void *) 1l : NULL;
74 int
75 do_test (void)
77 int result = 0;
79 size = MAX (4 * getpagesize (), PTHREAD_STACK_MIN);
80 if (posix_memalign (&stack, getpagesize (), size) != 0)
82 puts ("out of memory while allocating the stack memory");
83 exit (1);
86 pthread_attr_t attr;
87 if (pthread_attr_init (&attr) != 0)
89 puts ("attr_init failed");
90 exit (1);
93 puts ("attr_setstack");
94 if (pthread_attr_setstack (&attr, stack, size) != 0)
96 puts ("attr_setstack failed");
97 exit (1);
100 size_t test_size;
101 void *test_stack;
102 puts ("attr_getstack");
103 if (pthread_attr_getstack (&attr, &test_stack, &test_size) != 0)
105 puts ("attr_getstack failed");
106 exit (1);
109 if (test_size != size)
111 printf ("reported size differs: is %zu, expected %zu\n",
112 test_size, size);
113 result = 1;
116 if (test_stack != stack)
118 printf ("reported stack address differs: is %p, expected %p\n",
119 test_stack, stack);
120 result = 1;
123 puts ("create");
125 pthread_t th;
126 if (pthread_create (&th, &attr, tf, NULL) != 0)
128 puts ("failed to create thread");
129 exit (1);
132 void *status;
133 if (pthread_join (th, &status) != 0)
135 puts ("join failed");
136 exit (1);
139 result |= status != NULL;
141 return result;
145 #define TEST_FUNCTION do_test ()
146 #include "../test-skeleton.c"