sparc: disable cancellable system, as it fails in strange ways right now
[uclibc-ng.git] / test / tls / tst-tls8.c
blob2541609f18429f03b9b5c28aed86e750e1d0c843
1 #include <dlfcn.h>
2 #include <stdio.h>
3 #include <stdlib.h>
5 #include <tls.h>
6 #include <link.h>
7 #ifdef __UCLIBC__
8 #include "dl-elf.h"
9 #include "dl-hash.h"
10 #endif
13 #define TEST_FUNCTION do_test ()
14 static int
15 do_test (void)
17 #ifdef USE_TLS
18 static const char modname1[] = "tst-tlsmod3.so";
19 static const char modname2[] = "tst-tlsmod4.so";
20 int result = 0;
21 int (*fp1) (void);
22 int (*fp2) (int, int *);
23 void *h1;
24 void *h2;
25 int i;
26 size_t modid1 = (size_t) -1;
27 size_t modid2 = (size_t) -1;
28 int *bazp;
30 for (i = 0; i < 10; ++i)
32 h1 = dlopen (modname1, RTLD_LAZY);
33 if (h1 == NULL)
35 printf ("cannot open '%s': %s\n", modname1, dlerror ());
36 exit (1);
39 /* Dirty test code here: we peek into a private data structure.
40 We make sure that the module gets assigned the same ID every
41 time. The value of the first round is used. */
42 #ifdef __UCLIBC__
43 if (modid1 == (size_t) -1)
44 modid1 = ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid;
45 else if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid
46 != (size_t) modid1)
48 printf ("round %d: modid now %zd, initially %zd\n",
50 ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid,
51 modid1);
52 result = 1;
54 #else
55 if (modid1 == (size_t) -1)
56 modid1 = ((struct link_map *) h1)->l_tls_modid;
57 else if (((struct link_map *) h1)->l_tls_modid != modid1)
59 printf ("round %d: modid now %zd, initially %zd\n",
60 i, ((struct link_map *) h1)->l_tls_modid, modid1);
61 result = 1;
63 #endif
65 fp1 = dlsym (h1, "in_dso2");
66 if (fp1 == NULL)
68 printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
69 exit (1);
72 result |= fp1 ();
76 h2 = dlopen (modname2, RTLD_LAZY);
77 if (h2 == NULL)
79 printf ("cannot open '%s': %s\n", modname2, dlerror ());
80 exit (1);
83 /* Dirty test code here: we peek into a private data structure.
84 We make sure that the module gets assigned the same ID every
85 time. The value of the first round is used. */
86 #ifdef __UCLIBC__
87 if (modid2 == (size_t) -1)
88 modid2 = ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid;
89 else if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid
90 != (size_t) modid2)
92 printf ("round %d: modid now %zd, initially %zd\n",
94 ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid,
95 modid2);
96 result = 1;
98 #else
99 if (modid2 == (size_t) -1)
100 modid2 = ((struct link_map *) h1)->l_tls_modid;
101 else if (((struct link_map *) h1)->l_tls_modid != modid2)
103 printf ("round %d: modid now %zd, initially %zd\n",
104 i, ((struct link_map *) h1)->l_tls_modid, modid2);
105 result = 1;
107 #endif
109 bazp = dlsym (h2, "baz");
110 if (bazp == NULL)
112 printf ("cannot get symbol 'baz' in %s\n", modname2);
113 exit (1);
116 *bazp = 42 + i;
118 fp2 = dlsym (h2, "in_dso");
119 if (fp2 == NULL)
121 printf ("cannot get symbol 'in_dso' in %s\n", modname2);
122 exit (1);
125 result |= fp2 (42 + i, bazp);
127 dlclose (h1);
128 dlclose (h2);
131 h1 = dlopen (modname1, RTLD_LAZY);
132 if (h1 == NULL)
134 printf ("cannot open '%s': %s\n", modname1, dlerror ());
135 exit (1);
138 /* Dirty test code here: we peek into a private data structure.
139 We make sure that the module gets assigned the same ID every
140 time. The value of the first round is used. */
141 #ifdef __UCLIBC__
142 if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid
143 != modid1)
145 printf ("round %d: modid now %zd, initially %zd\n",
147 ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid,
148 modid1);
149 result = 1;
151 #else
152 if (((struct link_map *) h1)->l_tls_modid != modid1)
154 printf ("round %d: modid now %zd, initially %zd\n",
155 i, ((struct link_map *) h1)->l_tls_modid, modid1);
156 result = 1;
158 #endif
160 fp1 = dlsym (h1, "in_dso2");
161 if (fp1 == NULL)
163 printf ("cannot get symbol 'in_dso2' in %s\n", modname1);
164 exit (1);
167 result |= fp1 ();
171 h2 = dlopen (modname2, RTLD_LAZY);
172 if (h2 == NULL)
174 printf ("cannot open '%s': %s\n", modname2, dlerror ());
175 exit (1);
178 /* Dirty test code here: we peek into a private data structure.
179 We make sure that the module gets assigned the same ID every
180 time. The value of the first round is used. */
181 #ifdef __UCLIBC__
182 if (((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid
183 != modid2)
185 printf ("round %d: modid now %zd, initially %zd\n",
187 ((struct link_map *)((struct dyn_elf *)h1)->dyn)->l_tls_modid,
188 modid2);
189 result = 1;
191 #else
192 if (((struct link_map *) h1)->l_tls_modid != modid2)
194 printf ("round %d: modid now %zd, initially %zd\n",
195 i, ((struct link_map *) h1)->l_tls_modid, modid2);
196 result = 1;
198 #endif
200 bazp = dlsym (h2, "baz");
201 if (bazp == NULL)
203 printf ("cannot get symbol 'baz' in %s\n", modname2);
204 exit (1);
207 *bazp = 62 + i;
209 fp2 = dlsym (h2, "in_dso");
210 if (fp2 == NULL)
212 printf ("cannot get symbol 'in_dso' in %s\n", modname2);
213 exit (1);
216 result |= fp2 (62 + i, bazp);
218 /* This time the dlclose calls are in reverse order. */
219 dlclose (h2);
220 dlclose (h1);
223 return result;
224 #else
225 return 0;
226 #endif
230 #include "../test-skeleton.c"