(yn_test): Expect invalid exception for negative arguments. (y0_test): Likewise....
[glibc.git] / nptl / tst-stack3.c
blobfa9aeddd9cd47cc93055836d062f35e3ae35ddf4
1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
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 /* Test whether pthread_create/pthread_join with user defined stacks
21 doesn't leak memory. */
23 #include <limits.h>
24 #include <mcheck.h>
25 #include <pthread.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <unistd.h>
31 static int seen;
33 static void *
34 tf (void *p)
36 ++seen;
37 return NULL;
40 static int
41 do_test (void)
43 mtrace ();
45 void *stack;
46 int res = posix_memalign (&stack, getpagesize (), 4 * PTHREAD_STACK_MIN);
47 if (res)
49 printf ("malloc failed %s\n", strerror (res));
50 return 1;
53 pthread_attr_t attr;
54 pthread_attr_init (&attr);
56 int result = 0;
57 res = pthread_attr_setstack (&attr, stack, 4 * PTHREAD_STACK_MIN);
58 if (res)
60 printf ("pthread_attr_setstack failed %d\n", res);
61 result = 1;
64 for (int i = 0; i < 16; ++i)
66 /* Create the thread. */
67 pthread_t th;
68 res = pthread_create (&th, &attr, tf, NULL);
69 if (res)
71 printf ("pthread_create failed %d\n", res);
72 result = 1;
74 else
76 res = pthread_join (th, NULL);
77 if (res)
79 printf ("pthread_join failed %d\n", res);
80 result = 1;
85 pthread_attr_destroy (&attr);
87 if (seen != 16)
89 printf ("seen %d != 16\n", seen);
90 result = 1;
93 free (stack);
94 return result;
97 #define TEST_FUNCTION do_test ()
98 #include "../test-skeleton.c"