1 /* Copyright (C) 2003, 2011 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
31 void (*test1
) (void), (*test2
) (void);
33 pthread_barrier_t b2
, b3
;
40 for (i
= 0; i
<= (uintptr_t) arg
; ++i
)
42 int r
= pthread_barrier_wait (&b3
);
43 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
45 puts ("tf: barrier_wait failed");
52 for (i
= 0; i
< 3; ++i
)
54 int r
= pthread_barrier_wait (&b3
);
55 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
57 puts ("tf: barrier_wait failed");
64 for (i
= 0; i
< 3 - (uintptr_t) arg
; ++i
)
66 int r
= pthread_barrier_wait (&b3
);
67 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
69 puts ("tf: barrier_wait failed");
80 int r
= pthread_barrier_wait (&b2
);
81 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
83 puts ("tf2: barrier_wait failed");
88 for (i
= 0; i
< N
; ++i
)
97 const char *modules
[N
]
98 = { "tst-tls4moda.so", "tst-tls4moda.so", "tst-tls4modb.so" };
100 if (pthread_barrier_init (&b2
, NULL
, 2) != 0)
102 puts ("barrier_init failed");
106 if (pthread_barrier_init (&b3
, NULL
, 3) != 0)
108 puts ("barrier_init failed");
112 if (pthread_create (&th
[0], NULL
, tf2
, (void *) (uintptr_t) 1))
114 puts ("pthread_create failed");
118 int r
= pthread_barrier_wait (&b2
);
119 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
121 puts ("barrier_wait failed");
126 for (i
= 0; i
< N
; ++i
)
128 void *h
= dlopen (modules
[i
], RTLD_LAZY
);
131 printf ("dlopen failed %s\n", dlerror ());
135 test1
= dlsym (h
, "test1");
138 printf ("dlsym for test1 failed %s\n", dlerror ());
142 test2
= dlsym (h
, "test2");
145 printf ("dlsym for test2 failed %s\n", dlerror ());
149 if (pthread_create (&th
[1], NULL
, tf
, (void *) (uintptr_t) 2))
151 puts ("pthread_create failed");
155 tf ((void *) (uintptr_t) 0);
157 if (pthread_join (th
[1], NULL
) != 0)
159 puts ("join failed");
165 puts ("dlclose failed");
169 printf ("test %d with %s succeeded\n", i
, modules
[i
]);
172 if (pthread_join (th
[0], NULL
) != 0)
174 puts ("join failed");
182 #define TEST_FUNCTION do_test ()
183 #include "../test-skeleton.c"