1 | /*
|
---|
2 | * Copyright (c) 2016 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup dltest
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * @file
|
---|
35 | * @brief Test dynamic linking
|
---|
36 | */
|
---|
37 |
|
---|
38 | #include <dlfcn.h>
|
---|
39 | #include <libdltest.h>
|
---|
40 | #include <stdbool.h>
|
---|
41 | #include <stdio.h>
|
---|
42 | #include <stdlib.h>
|
---|
43 |
|
---|
44 | /** libdltest library handle */
|
---|
45 | static void *handle;
|
---|
46 |
|
---|
47 | /** If true, do not run dlfcn tests */
|
---|
48 | static bool no_dlfcn = false;
|
---|
49 |
|
---|
50 | /** Test dlsym() function */
|
---|
51 | static bool test_dlsym(void)
|
---|
52 | {
|
---|
53 | int (*p_dl_get_constant)(void);
|
---|
54 |
|
---|
55 | printf("dlsym()... ");
|
---|
56 | p_dl_get_constant = dlsym(handle, "dl_get_constant");
|
---|
57 | if (p_dl_get_constant == NULL) {
|
---|
58 | printf("FAILED\n");
|
---|
59 | return false;
|
---|
60 | }
|
---|
61 |
|
---|
62 | printf("Passed\n");
|
---|
63 | return true;
|
---|
64 | }
|
---|
65 |
|
---|
66 | /** Test calling function that returns a constant */
|
---|
67 | static bool test_dlfcn_dl_get_constant(void)
|
---|
68 | {
|
---|
69 | int (*p_dl_get_constant)(void);
|
---|
70 | int val;
|
---|
71 |
|
---|
72 | printf("Call dlsym/dl_get_constant...\n");
|
---|
73 |
|
---|
74 | p_dl_get_constant = dlsym(handle, "dl_get_constant");
|
---|
75 | if (p_dl_get_constant == NULL) {
|
---|
76 | printf("FAILED\n");
|
---|
77 | return false;
|
---|
78 | }
|
---|
79 |
|
---|
80 | val = p_dl_get_constant();
|
---|
81 |
|
---|
82 | printf("Got %d, expected %d... ", val, dl_constant);
|
---|
83 | if (val != dl_constant) {
|
---|
84 | printf("FAILED\n");
|
---|
85 | return false;
|
---|
86 | }
|
---|
87 |
|
---|
88 | printf("Passed\n");
|
---|
89 | return true;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /** Test calling a function that returns contents of a private initialized
|
---|
93 | * variable.
|
---|
94 | */
|
---|
95 | static bool test_dlfcn_dl_get_private_var(void)
|
---|
96 | {
|
---|
97 | int (*p_dl_get_private_var)(void);
|
---|
98 | int *(*p_dl_get_private_var_addr)(void);
|
---|
99 | int val;
|
---|
100 |
|
---|
101 | printf("Call dlsym/dl_get_private_var...\n");
|
---|
102 |
|
---|
103 | p_dl_get_private_var = dlsym(handle, "dl_get_private_var");
|
---|
104 | if (p_dl_get_private_var == NULL) {
|
---|
105 | printf("FAILED\n");
|
---|
106 | return false;
|
---|
107 | }
|
---|
108 |
|
---|
109 | p_dl_get_private_var_addr = dlsym(handle, "dl_get_private_var_addr");
|
---|
110 | if (p_dl_get_private_var_addr == NULL) {
|
---|
111 | printf("FAILED\n");
|
---|
112 | return false;
|
---|
113 | }
|
---|
114 |
|
---|
115 | val = p_dl_get_private_var();
|
---|
116 |
|
---|
117 | printf("Got %d, expected %d... ", val, dl_private_var_val);
|
---|
118 | if (val != dl_private_var_val) {
|
---|
119 | printf("dl_get_private_var_addr -> %p\n",
|
---|
120 | p_dl_get_private_var_addr());
|
---|
121 | printf("FAILED\n");
|
---|
122 | return false;
|
---|
123 | }
|
---|
124 |
|
---|
125 | printf("Passed\n");
|
---|
126 | return true;
|
---|
127 | }
|
---|
128 |
|
---|
129 | /** Test calling a function that returns contents of a private uninitialized
|
---|
130 | * variable.
|
---|
131 | */
|
---|
132 | static bool test_dlfcn_dl_get_private_uvar(void)
|
---|
133 | {
|
---|
134 | int (*p_dl_get_private_uvar)(void);
|
---|
135 | int *(*p_dl_get_private_uvar_addr)(void);
|
---|
136 | int val;
|
---|
137 |
|
---|
138 | printf("Call dlsym/dl_get_private_uvar...\n");
|
---|
139 |
|
---|
140 | p_dl_get_private_uvar = dlsym(handle, "dl_get_private_uvar");
|
---|
141 | if (p_dl_get_private_uvar == NULL) {
|
---|
142 | printf("FAILED\n");
|
---|
143 | return false;
|
---|
144 | }
|
---|
145 |
|
---|
146 | p_dl_get_private_uvar_addr = dlsym(handle, "dl_get_private_uvar_addr");
|
---|
147 | if (p_dl_get_private_uvar_addr == NULL) {
|
---|
148 | printf("FAILED\n");
|
---|
149 | return false;
|
---|
150 | }
|
---|
151 |
|
---|
152 | val = p_dl_get_private_uvar();
|
---|
153 |
|
---|
154 | printf("Got %d, expected %d... ", val, 0);
|
---|
155 | if (val != 0) {
|
---|
156 | printf("dl_get_private_uvar_addr -> %p\n",
|
---|
157 | p_dl_get_private_uvar_addr());
|
---|
158 | printf("FAILED\n");
|
---|
159 | return false;
|
---|
160 | }
|
---|
161 |
|
---|
162 | printf("Passed\n");
|
---|
163 | return true;
|
---|
164 | }
|
---|
165 |
|
---|
166 | /** Test calling a function that returns the contents of a public initialized
|
---|
167 | * variable.
|
---|
168 | */
|
---|
169 | static bool test_dlfcn_dl_get_public_var(void)
|
---|
170 | {
|
---|
171 | int (*p_dl_get_public_var)(void);
|
---|
172 | int *(*p_dl_get_public_var_addr)(void);
|
---|
173 | int val;
|
---|
174 |
|
---|
175 | printf("Call dlsym/dl_get_public_var...\n");
|
---|
176 |
|
---|
177 | p_dl_get_public_var = dlsym(handle, "dl_get_public_var");
|
---|
178 | if (p_dl_get_public_var == NULL) {
|
---|
179 | printf("FAILED\n");
|
---|
180 | return false;
|
---|
181 | }
|
---|
182 |
|
---|
183 | p_dl_get_public_var_addr = dlsym(handle, "dl_get_public_var_addr");
|
---|
184 | if (p_dl_get_public_var_addr == NULL) {
|
---|
185 | printf("FAILED\n");
|
---|
186 | return false;
|
---|
187 | }
|
---|
188 |
|
---|
189 | val = p_dl_get_public_var();
|
---|
190 |
|
---|
191 | printf("Got %d, expected %d... ", val, dl_public_var_val);
|
---|
192 | if (val != dl_public_var_val) {
|
---|
193 | printf("dl_get_public_var_addr -> %p\n",
|
---|
194 | p_dl_get_public_var_addr());
|
---|
195 | printf("FAILED\n");
|
---|
196 | return false;
|
---|
197 | }
|
---|
198 |
|
---|
199 | printf("Passed\n");
|
---|
200 | return true;
|
---|
201 | }
|
---|
202 |
|
---|
203 | /** Test calling a function that returns the contents of a public uninitialized
|
---|
204 | * variable.
|
---|
205 | */
|
---|
206 | static bool test_dlfcn_dl_get_public_uvar(void)
|
---|
207 | {
|
---|
208 | int (*p_dl_get_public_uvar)(void);
|
---|
209 | int *(*p_dl_get_public_uvar_addr)(void);
|
---|
210 | int val;
|
---|
211 |
|
---|
212 | printf("Call dlsym/dl_get_public_uvar...\n");
|
---|
213 |
|
---|
214 | p_dl_get_public_uvar = dlsym(handle, "dl_get_public_uvar");
|
---|
215 | if (p_dl_get_public_uvar == NULL) {
|
---|
216 | printf("FAILED\n");
|
---|
217 | return false;
|
---|
218 | }
|
---|
219 |
|
---|
220 | p_dl_get_public_uvar_addr = dlsym(handle, "dl_get_public_uvar_addr");
|
---|
221 | if (p_dl_get_public_uvar_addr == NULL) {
|
---|
222 | printf("FAILED\n");
|
---|
223 | return false;
|
---|
224 | }
|
---|
225 |
|
---|
226 | val = p_dl_get_public_uvar();
|
---|
227 |
|
---|
228 | printf("Got %d, expected %d... ", val, 0);
|
---|
229 | if (val != 0) {
|
---|
230 | printf("dl_get_public_uvar_addr -> %p\n",
|
---|
231 | p_dl_get_public_uvar_addr());
|
---|
232 | printf("FAILED\n");
|
---|
233 | return false;
|
---|
234 | }
|
---|
235 |
|
---|
236 | printf("Passed\n");
|
---|
237 | return true;
|
---|
238 | }
|
---|
239 |
|
---|
240 | /** Test directly reading a public initialized variable whose address was
|
---|
241 | * obtained using dlsym.
|
---|
242 | */
|
---|
243 | static bool test_dlfcn_read_public_var(void)
|
---|
244 | {
|
---|
245 | int *p_dl_public_var;
|
---|
246 | int *(*p_dl_get_public_var_addr)(void);
|
---|
247 | int val;
|
---|
248 |
|
---|
249 | printf("Read dlsym/dl_public_var...\n");
|
---|
250 |
|
---|
251 | p_dl_public_var = dlsym(handle, "dl_public_var");
|
---|
252 | if (p_dl_public_var == NULL) {
|
---|
253 | printf("FAILED\n");
|
---|
254 | return false;
|
---|
255 | }
|
---|
256 |
|
---|
257 | p_dl_get_public_var_addr = dlsym(handle, "dl_get_public_var_addr");
|
---|
258 | if (p_dl_get_public_var_addr == NULL) {
|
---|
259 | printf("FAILED\n");
|
---|
260 | return false;
|
---|
261 | }
|
---|
262 |
|
---|
263 | val = *p_dl_public_var;
|
---|
264 |
|
---|
265 | printf("Got %d, expected %d... ", val, dl_public_var_val);
|
---|
266 | if (val != dl_public_var_val) {
|
---|
267 | printf("&dl_public_var = %p, "
|
---|
268 | "dl_get_public_var_addr -> %p\n",
|
---|
269 | p_dl_public_var, p_dl_get_public_var_addr());
|
---|
270 | printf("FAILED\n");
|
---|
271 | return false;
|
---|
272 | }
|
---|
273 |
|
---|
274 | printf("Passed\n");
|
---|
275 | return true;
|
---|
276 | }
|
---|
277 |
|
---|
278 | /** Test directly reading a public uninitialized variable whose address was
|
---|
279 | * obtained using dlsym.
|
---|
280 | */
|
---|
281 | static bool test_dlfcn_read_public_uvar(void)
|
---|
282 | {
|
---|
283 | int *p_dl_public_uvar;
|
---|
284 | int *(*p_dl_get_public_uvar_addr)(void);
|
---|
285 | int val;
|
---|
286 |
|
---|
287 | printf("Read dlsym/dl_public_uvar...\n");
|
---|
288 |
|
---|
289 | p_dl_public_uvar = dlsym(handle, "dl_public_uvar");
|
---|
290 | if (p_dl_public_uvar == NULL) {
|
---|
291 | printf("FAILED\n");
|
---|
292 | return false;
|
---|
293 | }
|
---|
294 |
|
---|
295 | p_dl_get_public_uvar_addr = dlsym(handle, "dl_get_public_uvar_addr");
|
---|
296 | if (p_dl_get_public_uvar_addr == NULL) {
|
---|
297 | printf("FAILED\n");
|
---|
298 | return false;
|
---|
299 | }
|
---|
300 |
|
---|
301 | val = *p_dl_public_uvar;
|
---|
302 |
|
---|
303 | printf("Got %d, expected %d... ", val, 0);
|
---|
304 | if (val != 0) {
|
---|
305 | printf("&dl_public_uvar = %p, "
|
---|
306 | "dl_get_public_uvar_addr -> %p\n",
|
---|
307 | p_dl_public_uvar, p_dl_get_public_uvar_addr());
|
---|
308 | printf("FAILED\n");
|
---|
309 | return false;
|
---|
310 | }
|
---|
311 |
|
---|
312 | printf("Passed\n");
|
---|
313 | return true;
|
---|
314 | }
|
---|
315 |
|
---|
316 | #ifndef STATIC_EXE
|
---|
317 |
|
---|
318 | /** Test calling a function that returns contents of a private initialized
|
---|
319 | * fibril-local variable.
|
---|
320 | */
|
---|
321 | static bool test_dlfcn_dl_get_private_fib_var(void)
|
---|
322 | {
|
---|
323 | int (*p_dl_get_private_fib_var)(void);
|
---|
324 | int *(*p_dl_get_private_fib_var_addr)(void);
|
---|
325 | int val;
|
---|
326 |
|
---|
327 | printf("Call dlsym/dl_get_private_fib_var...\n");
|
---|
328 |
|
---|
329 | p_dl_get_private_fib_var = dlsym(handle, "dl_get_private_fib_var");
|
---|
330 | if (p_dl_get_private_fib_var == NULL) {
|
---|
331 | printf("FAILED\n");
|
---|
332 | return false;
|
---|
333 | }
|
---|
334 |
|
---|
335 | p_dl_get_private_fib_var_addr = dlsym(handle, "dl_get_private_fib_var_addr");
|
---|
336 | if (p_dl_get_private_fib_var_addr == NULL) {
|
---|
337 | printf("FAILED\n");
|
---|
338 | return false;
|
---|
339 | }
|
---|
340 |
|
---|
341 | val = p_dl_get_private_fib_var();
|
---|
342 |
|
---|
343 | printf("Got %d, expected %d... ", val, dl_private_fib_var_val);
|
---|
344 | if (val != dl_private_fib_var_val) {
|
---|
345 | printf("dl_get_private_fib_var_addr -> %p\n",
|
---|
346 | p_dl_get_private_fib_var_addr());
|
---|
347 | printf("FAILED\n");
|
---|
348 | return false;
|
---|
349 | }
|
---|
350 |
|
---|
351 | printf("Passed\n");
|
---|
352 | return true;
|
---|
353 | }
|
---|
354 |
|
---|
355 | /** Test calling a function that returns contents of a private uninitialized
|
---|
356 | * fibril-local variable.
|
---|
357 | */
|
---|
358 | static bool test_dlfcn_dl_get_private_fib_uvar(void)
|
---|
359 | {
|
---|
360 | int (*p_dl_get_private_fib_uvar)(void);
|
---|
361 | int *(*p_dl_get_private_fib_uvar_addr)(void);
|
---|
362 | int val;
|
---|
363 |
|
---|
364 | printf("Call dlsym/dl_get_private_fib_uvar...\n");
|
---|
365 |
|
---|
366 | p_dl_get_private_fib_uvar = dlsym(handle, "dl_get_private_fib_uvar");
|
---|
367 | if (p_dl_get_private_fib_uvar == NULL) {
|
---|
368 | printf("FAILED\n");
|
---|
369 | return false;
|
---|
370 | }
|
---|
371 |
|
---|
372 | p_dl_get_private_fib_uvar_addr = dlsym(handle, "dl_get_private_fib_uvar_addr");
|
---|
373 | if (p_dl_get_private_fib_uvar_addr == NULL) {
|
---|
374 | printf("FAILED\n");
|
---|
375 | return false;
|
---|
376 | }
|
---|
377 |
|
---|
378 | val = p_dl_get_private_fib_uvar();
|
---|
379 |
|
---|
380 | printf("Got %d, expected %d... ", val, 0);
|
---|
381 | if (val != 0) {
|
---|
382 | printf("dl_get_private_fib_uvar_addr -> %p\n",
|
---|
383 | p_dl_get_private_fib_uvar_addr());
|
---|
384 | printf("FAILED\n");
|
---|
385 | return false;
|
---|
386 | }
|
---|
387 |
|
---|
388 | printf("Passed\n");
|
---|
389 | return true;
|
---|
390 | }
|
---|
391 |
|
---|
392 | /** Test calling a function that returns the contents of a public initialized
|
---|
393 | * fibril-local variable.
|
---|
394 | */
|
---|
395 | static bool test_dlfcn_dl_get_public_fib_var(void)
|
---|
396 | {
|
---|
397 | int (*p_dl_get_public_fib_var)(void);
|
---|
398 | int *(*p_dl_get_public_fib_var_addr)(void);
|
---|
399 | int val;
|
---|
400 |
|
---|
401 | printf("Call dlsym/dl_get_public_fib_var...\n");
|
---|
402 |
|
---|
403 | p_dl_get_public_fib_var = dlsym(handle, "dl_get_public_fib_var");
|
---|
404 | if (p_dl_get_public_fib_var == NULL) {
|
---|
405 | printf("FAILED\n");
|
---|
406 | return false;
|
---|
407 | }
|
---|
408 |
|
---|
409 | p_dl_get_public_fib_var_addr = dlsym(handle, "dl_get_public_fib_var_addr");
|
---|
410 | if (p_dl_get_public_fib_var_addr == NULL) {
|
---|
411 | printf("FAILED\n");
|
---|
412 | return false;
|
---|
413 | }
|
---|
414 |
|
---|
415 | val = p_dl_get_public_fib_var();
|
---|
416 |
|
---|
417 | printf("Got %d, expected %d... ", val, dl_public_fib_var_val);
|
---|
418 | if (val != dl_public_fib_var_val) {
|
---|
419 | printf("dl_get_public_fib_var_addr -> %p\n",
|
---|
420 | p_dl_get_public_fib_var_addr());
|
---|
421 | printf("FAILED\n");
|
---|
422 | return false;
|
---|
423 | }
|
---|
424 |
|
---|
425 | printf("Passed\n");
|
---|
426 | return true;
|
---|
427 | }
|
---|
428 |
|
---|
429 | /** Test calling a function that returns the contents of a public uninitialized
|
---|
430 | * fibril-local variable.
|
---|
431 | */
|
---|
432 | static bool test_dlfcn_dl_get_public_fib_uvar(void)
|
---|
433 | {
|
---|
434 | int (*p_dl_get_public_fib_uvar)(void);
|
---|
435 | int *(*p_dl_get_public_fib_uvar_addr)(void);
|
---|
436 | int val;
|
---|
437 |
|
---|
438 | printf("Call dlsym/dl_get_public_fib_uvar...\n");
|
---|
439 |
|
---|
440 | p_dl_get_public_fib_uvar = dlsym(handle, "dl_get_public_fib_uvar");
|
---|
441 | if (p_dl_get_public_fib_uvar == NULL) {
|
---|
442 | printf("FAILED\n");
|
---|
443 | return false;
|
---|
444 | }
|
---|
445 |
|
---|
446 | p_dl_get_public_fib_uvar_addr = dlsym(handle, "dl_get_public_fib_uvar_addr");
|
---|
447 | if (p_dl_get_public_fib_uvar_addr == NULL) {
|
---|
448 | printf("FAILED\n");
|
---|
449 | return false;
|
---|
450 | }
|
---|
451 |
|
---|
452 | val = p_dl_get_public_fib_uvar();
|
---|
453 |
|
---|
454 | printf("Got %d, expected %d... ", val, 0);
|
---|
455 | if (val != 0) {
|
---|
456 | printf("dl_get_public_fib_uvar_addr -> %p\n",
|
---|
457 | p_dl_get_public_fib_uvar_addr());
|
---|
458 | printf("FAILED\n");
|
---|
459 | return false;
|
---|
460 | }
|
---|
461 |
|
---|
462 | printf("Passed\n");
|
---|
463 | return true;
|
---|
464 | }
|
---|
465 |
|
---|
466 | /** Test directly reading a public initialized fibril-local variable
|
---|
467 | * whose address was obtained using dlsym.
|
---|
468 | */
|
---|
469 | static bool test_dlfcn_read_public_fib_var(void)
|
---|
470 | {
|
---|
471 | int *p_dl_public_fib_var;
|
---|
472 | int *(*p_dl_get_public_fib_var_addr)(void);
|
---|
473 | int val;
|
---|
474 |
|
---|
475 | printf("Read dlsym/dl_public_fib_var...\n");
|
---|
476 |
|
---|
477 | p_dl_public_fib_var = dlsym(handle, "dl_public_fib_var");
|
---|
478 | if (p_dl_public_fib_var == NULL) {
|
---|
479 | printf("FAILED\n");
|
---|
480 | return false;
|
---|
481 | }
|
---|
482 |
|
---|
483 | p_dl_get_public_fib_var_addr = dlsym(handle, "dl_get_public_fib_var_addr");
|
---|
484 | if (p_dl_get_public_fib_var_addr == NULL) {
|
---|
485 | printf("FAILED\n");
|
---|
486 | return false;
|
---|
487 | }
|
---|
488 |
|
---|
489 | val = *p_dl_public_fib_var;
|
---|
490 |
|
---|
491 | printf("Got %d, expected %d... ", val, dl_public_fib_var_val);
|
---|
492 | if (val != dl_public_fib_var_val) {
|
---|
493 | printf("&dl_public_fib_var = %p, "
|
---|
494 | "dl_get_public_fib_var_addr -> %p\n",
|
---|
495 | p_dl_public_fib_var, p_dl_get_public_fib_var_addr());
|
---|
496 | printf("FAILED\n");
|
---|
497 | return false;
|
---|
498 | }
|
---|
499 |
|
---|
500 | printf("Passed\n");
|
---|
501 | return true;
|
---|
502 | }
|
---|
503 |
|
---|
504 | /** Test directly reading a public uninitialized fibril-local variable
|
---|
505 | * whose address was obtained using dlsym.
|
---|
506 | */
|
---|
507 | static bool test_dlfcn_read_public_fib_uvar(void)
|
---|
508 | {
|
---|
509 | int *p_dl_public_fib_uvar;
|
---|
510 | int *(*p_dl_get_public_fib_uvar_addr)(void);
|
---|
511 | int val;
|
---|
512 |
|
---|
513 | printf("Read dlsym/dl_public_fib_uvar...\n");
|
---|
514 |
|
---|
515 | p_dl_public_fib_uvar = dlsym(handle, "dl_public_fib_uvar");
|
---|
516 | if (p_dl_public_fib_uvar == NULL) {
|
---|
517 | printf("FAILED\n");
|
---|
518 | return false;
|
---|
519 | }
|
---|
520 |
|
---|
521 | p_dl_get_public_fib_uvar_addr = dlsym(handle, "dl_get_public_fib_uvar_addr");
|
---|
522 | if (p_dl_get_public_fib_uvar_addr == NULL) {
|
---|
523 | printf("FAILED\n");
|
---|
524 | return false;
|
---|
525 | }
|
---|
526 |
|
---|
527 | val = *p_dl_public_fib_uvar;
|
---|
528 |
|
---|
529 | printf("Got %d, expected %d... ", val, 0);
|
---|
530 | if (val != 0) {
|
---|
531 | printf("&dl_public_fib_uvar = %p, "
|
---|
532 | "dl_get_public_fib_uvar_addr -> %p\n",
|
---|
533 | p_dl_public_fib_uvar, p_dl_get_public_fib_uvar_addr());
|
---|
534 | printf("FAILED\n");
|
---|
535 | return false;
|
---|
536 | }
|
---|
537 |
|
---|
538 | printf("Passed\n");
|
---|
539 | return true;
|
---|
540 | }
|
---|
541 |
|
---|
542 | #endif /* STATIC_EXE */
|
---|
543 |
|
---|
544 | #ifdef DLTEST_LINKED
|
---|
545 |
|
---|
546 | /** Test directly calling function that returns a constant */
|
---|
547 | static bool test_lnk_dl_get_constant(void)
|
---|
548 | {
|
---|
549 | int val;
|
---|
550 |
|
---|
551 | printf("Call linked dl_get_constant...\n");
|
---|
552 |
|
---|
553 | val = dl_get_constant();
|
---|
554 |
|
---|
555 | printf("Got %d, expected %d... ", val, dl_constant);
|
---|
556 | if (val != dl_constant) {
|
---|
557 | printf("FAILED\n");
|
---|
558 | return false;
|
---|
559 | }
|
---|
560 |
|
---|
561 | printf("Passed\n");
|
---|
562 | return true;
|
---|
563 | }
|
---|
564 |
|
---|
565 | /** Test dircetly calling a function that returns contents of a private
|
---|
566 | * initialized variable.
|
---|
567 | */
|
---|
568 | static bool test_lnk_dl_get_private_var(void)
|
---|
569 | {
|
---|
570 | int val;
|
---|
571 |
|
---|
572 | printf("Call linked dl_get_private_var...\n");
|
---|
573 |
|
---|
574 | val = dl_get_private_var();
|
---|
575 |
|
---|
576 | printf("Got %d, expected %d... ", val, dl_private_var_val);
|
---|
577 | if (val != dl_private_var_val) {
|
---|
578 | printf("dl_get_private_var_addr -> %p\n",
|
---|
579 | dl_get_private_var_addr());
|
---|
580 | printf("FAILED\n");
|
---|
581 | return false;
|
---|
582 | }
|
---|
583 |
|
---|
584 | printf("Passed\n");
|
---|
585 | return true;
|
---|
586 | }
|
---|
587 |
|
---|
588 | /** Test dircetly calling a function that returns contents of a private
|
---|
589 | * uninitialized variable.
|
---|
590 | */
|
---|
591 | static bool test_lnk_dl_get_private_uvar(void)
|
---|
592 | {
|
---|
593 | int val;
|
---|
594 |
|
---|
595 | printf("Call linked dl_get_private_uvar...\n");
|
---|
596 |
|
---|
597 | val = dl_get_private_uvar();
|
---|
598 |
|
---|
599 | printf("Got %d, expected %d... ", val, 0);
|
---|
600 | if (val != 0) {
|
---|
601 | printf("dl_get_private_uvar_addr -> %p\n",
|
---|
602 | dl_get_private_uvar_addr());
|
---|
603 | printf("FAILED\n");
|
---|
604 | return false;
|
---|
605 | }
|
---|
606 |
|
---|
607 | printf("Passed\n");
|
---|
608 | return true;
|
---|
609 | }
|
---|
610 |
|
---|
611 | /** Test directly calling a function that returns the contents of a public
|
---|
612 | * initialized variable.
|
---|
613 | */
|
---|
614 | static bool test_lnk_dl_get_public_var(void)
|
---|
615 | {
|
---|
616 | int val;
|
---|
617 |
|
---|
618 | printf("Call linked dl_get_public_var...\n");
|
---|
619 |
|
---|
620 | val = dl_get_public_var();
|
---|
621 |
|
---|
622 | printf("Got %d, expected %d... ", val, dl_public_var_val);
|
---|
623 | if (val != dl_public_var_val) {
|
---|
624 | printf("dl_get_public_var_addr -> %p\n",
|
---|
625 | dl_get_public_var_addr());
|
---|
626 | printf("FAILED\n");
|
---|
627 | return false;
|
---|
628 | }
|
---|
629 |
|
---|
630 | printf("Passed\n");
|
---|
631 | return true;
|
---|
632 | }
|
---|
633 |
|
---|
634 | /** Test directly calling a function that returns the contents of a public
|
---|
635 | * uninitialized variable.
|
---|
636 | */
|
---|
637 | static bool test_lnk_dl_get_public_uvar(void)
|
---|
638 | {
|
---|
639 | int val;
|
---|
640 |
|
---|
641 | printf("Call linked dl_get_public_uvar...\n");
|
---|
642 |
|
---|
643 | val = dl_get_public_uvar();
|
---|
644 |
|
---|
645 | printf("Got %d, expected %d... ", val, 0);
|
---|
646 | if (val != 0) {
|
---|
647 | printf("dl_get_public_uvar_addr -> %p\n",
|
---|
648 | dl_get_public_uvar_addr());
|
---|
649 | printf("FAILED\n");
|
---|
650 | return false;
|
---|
651 | }
|
---|
652 |
|
---|
653 | printf("Passed\n");
|
---|
654 | return true;
|
---|
655 | }
|
---|
656 |
|
---|
657 | /** Test directly reading a public initialized variable. */
|
---|
658 | static bool test_lnk_read_public_var(void)
|
---|
659 | {
|
---|
660 | int val;
|
---|
661 |
|
---|
662 | printf("Read linked dl_public_var...\n");
|
---|
663 |
|
---|
664 | val = dl_public_var;
|
---|
665 |
|
---|
666 | printf("Got %d, expected %d... ", val, dl_public_var_val);
|
---|
667 | if (val != dl_public_var_val) {
|
---|
668 | printf("&dl_public_var = %p, dl_get_public_var_addr -> %p\n",
|
---|
669 | &dl_public_var, dl_get_public_var_addr());
|
---|
670 | printf("FAILED\n");
|
---|
671 | return false;
|
---|
672 | }
|
---|
673 |
|
---|
674 | printf("Passed\n");
|
---|
675 | return true;
|
---|
676 | }
|
---|
677 |
|
---|
678 | /** Test directly reading a public uninitialized variable. */
|
---|
679 | static bool test_lnk_read_public_uvar(void)
|
---|
680 | {
|
---|
681 | int val;
|
---|
682 |
|
---|
683 | printf("Read linked dl_public_uvar...\n");
|
---|
684 |
|
---|
685 | val = dl_public_uvar;
|
---|
686 |
|
---|
687 | printf("Got %d, expected %d... ", val, 0);
|
---|
688 | if (val != 0) {
|
---|
689 | printf("&dl_public_uvar = %p, dl_get_public_uvar_addr -> %p\n",
|
---|
690 | &dl_public_uvar, dl_get_public_uvar_addr());
|
---|
691 | printf("FAILED\n");
|
---|
692 | return false;
|
---|
693 | }
|
---|
694 |
|
---|
695 | printf("Passed\n");
|
---|
696 | return true;
|
---|
697 | }
|
---|
698 |
|
---|
699 | /** Test dircetly calling a function that returns contents of a private
|
---|
700 | * initialized fibril-local variable.
|
---|
701 | */
|
---|
702 | static bool test_lnk_dl_get_private_fib_var(void)
|
---|
703 | {
|
---|
704 | int val;
|
---|
705 |
|
---|
706 | printf("Call linked dl_get_private_fib_var...\n");
|
---|
707 |
|
---|
708 | val = dl_get_private_fib_var();
|
---|
709 |
|
---|
710 | printf("Got %d, expected %d... ", val, dl_private_fib_var_val);
|
---|
711 | if (val != dl_private_fib_var_val) {
|
---|
712 | printf("dl_get_private_fib_var_addr -> %p\n",
|
---|
713 | dl_get_private_fib_var_addr());
|
---|
714 | printf("FAILED\n");
|
---|
715 | return false;
|
---|
716 | }
|
---|
717 |
|
---|
718 | printf("Passed\n");
|
---|
719 | return true;
|
---|
720 | }
|
---|
721 |
|
---|
722 | /** Test dircetly calling a function that returns contents of a private
|
---|
723 | * uninitialized fibril-local variable.
|
---|
724 | */
|
---|
725 | static bool test_lnk_dl_get_private_fib_uvar(void)
|
---|
726 | {
|
---|
727 | int val;
|
---|
728 |
|
---|
729 | printf("Call linked dl_get_private_fib_uvar...\n");
|
---|
730 |
|
---|
731 | val = dl_get_private_fib_uvar();
|
---|
732 |
|
---|
733 | printf("Got %d, expected %d... ", val, 0);
|
---|
734 | if (val != 0) {
|
---|
735 | printf("dl_get_private_fib_uvar_addr -> %p\n",
|
---|
736 | dl_get_private_fib_var_addr());
|
---|
737 | printf("FAILED\n");
|
---|
738 | return false;
|
---|
739 | }
|
---|
740 |
|
---|
741 | printf("Passed\n");
|
---|
742 | return true;
|
---|
743 | }
|
---|
744 |
|
---|
745 | /** Test directly calling a function that returns the contents of a public
|
---|
746 | * initialized fibril-local variable.
|
---|
747 | */
|
---|
748 | static bool test_lnk_dl_get_public_fib_var(void)
|
---|
749 | {
|
---|
750 | int val;
|
---|
751 |
|
---|
752 | printf("Call linked dl_get_public_fib_var...\n");
|
---|
753 |
|
---|
754 | val = dl_get_public_fib_var();
|
---|
755 |
|
---|
756 | printf("Got %d, expected %d... ", val, dl_public_fib_var_val);
|
---|
757 | if (val != dl_public_fib_var_val) {
|
---|
758 | printf("dl_get_public_fib_var_addr -> %p\n",
|
---|
759 | dl_get_public_fib_var_addr());
|
---|
760 | printf("FAILED\n");
|
---|
761 | return false;
|
---|
762 | }
|
---|
763 |
|
---|
764 | printf("Passed\n");
|
---|
765 | return true;
|
---|
766 | }
|
---|
767 |
|
---|
768 | /** Test directly calling a function that returns the contents of a public
|
---|
769 | * uninitialized fibril-local variable.
|
---|
770 | */
|
---|
771 | static bool test_lnk_dl_get_public_fib_uvar(void)
|
---|
772 | {
|
---|
773 | int val;
|
---|
774 |
|
---|
775 | printf("Call linked dl_get_public_fib_uvar...\n");
|
---|
776 |
|
---|
777 | val = dl_get_public_fib_uvar();
|
---|
778 |
|
---|
779 | printf("Got %d, expected %d... ", val, 0);
|
---|
780 | if (val != 0) {
|
---|
781 | printf("dl_get_public_fib_uvar_addr -> %p\n",
|
---|
782 | dl_get_public_fib_uvar_addr());
|
---|
783 | printf("FAILED\n");
|
---|
784 | return false;
|
---|
785 | }
|
---|
786 |
|
---|
787 | printf("Passed\n");
|
---|
788 | return true;
|
---|
789 | }
|
---|
790 |
|
---|
791 | /** Test directly reading a public initialized fibril-local variable. */
|
---|
792 | static bool test_lnk_read_public_fib_var(void)
|
---|
793 | {
|
---|
794 | int val;
|
---|
795 |
|
---|
796 | printf("Read linked dl_public_fib_var...\n");
|
---|
797 |
|
---|
798 | val = dl_public_fib_var;
|
---|
799 |
|
---|
800 | printf("Got %d, expected %d... ", val, dl_public_fib_var_val);
|
---|
801 | if (val != dl_public_fib_var_val) {
|
---|
802 | printf("&dl_public_fib_var = %p, "
|
---|
803 | "dl_get_public_fib_var_addr -> %p\n",
|
---|
804 | &dl_public_fib_var, dl_get_public_fib_var_addr());
|
---|
805 | printf("FAILED\n");
|
---|
806 | return false;
|
---|
807 | }
|
---|
808 |
|
---|
809 | printf("Passed\n");
|
---|
810 | return true;
|
---|
811 | }
|
---|
812 |
|
---|
813 | /** Test directly reading a public uninitialized fibril-local variable. */
|
---|
814 | static bool test_lnk_read_public_fib_uvar(void)
|
---|
815 | {
|
---|
816 | int val;
|
---|
817 |
|
---|
818 | printf("Read linked dl_public_fib_uvar...\n");
|
---|
819 |
|
---|
820 | val = dl_public_fib_uvar;
|
---|
821 |
|
---|
822 | printf("Got %d, expected %d... ", val, 0);
|
---|
823 | if (val != 0) {
|
---|
824 | printf("&dl_public_fib_uvar = %p, "
|
---|
825 | "dl_get_public_fib_uvar_addr -> %p\n",
|
---|
826 | &dl_public_fib_uvar, dl_get_public_fib_uvar_addr());
|
---|
827 | printf("FAILED\n");
|
---|
828 | return false;
|
---|
829 | }
|
---|
830 |
|
---|
831 | printf("Passed\n");
|
---|
832 | return true;
|
---|
833 | }
|
---|
834 |
|
---|
835 | #endif /* DLTEST_LINKED */
|
---|
836 |
|
---|
837 | static int test_dlfcn(void)
|
---|
838 | {
|
---|
839 | printf("dlopen()... ");
|
---|
840 | handle = dlopen("libdltest.so.0", 0);
|
---|
841 | if (handle == NULL) {
|
---|
842 | printf("FAILED\n");
|
---|
843 | return 1;
|
---|
844 | }
|
---|
845 |
|
---|
846 | printf("Passed\n");
|
---|
847 |
|
---|
848 | if (!test_dlsym())
|
---|
849 | return 1;
|
---|
850 |
|
---|
851 | if (!test_dlfcn_dl_get_constant())
|
---|
852 | return 1;
|
---|
853 |
|
---|
854 | if (!test_dlfcn_dl_get_private_var())
|
---|
855 | return 1;
|
---|
856 |
|
---|
857 | if (!test_dlfcn_dl_get_private_uvar())
|
---|
858 | return 1;
|
---|
859 |
|
---|
860 | if (!test_dlfcn_dl_get_public_var())
|
---|
861 | return 1;
|
---|
862 |
|
---|
863 | if (!test_dlfcn_dl_get_public_uvar())
|
---|
864 | return 1;
|
---|
865 |
|
---|
866 | if (!test_dlfcn_read_public_var())
|
---|
867 | return 1;
|
---|
868 |
|
---|
869 | if (!test_dlfcn_read_public_uvar())
|
---|
870 | return 1;
|
---|
871 |
|
---|
872 | #ifndef STATIC_EXE
|
---|
873 | if (!test_dlfcn_dl_get_private_fib_var())
|
---|
874 | return 1;
|
---|
875 |
|
---|
876 | if (!test_dlfcn_dl_get_private_fib_uvar())
|
---|
877 | return 1;
|
---|
878 |
|
---|
879 | if (!test_dlfcn_dl_get_public_fib_var())
|
---|
880 | return 1;
|
---|
881 |
|
---|
882 | if (!test_dlfcn_dl_get_public_fib_uvar())
|
---|
883 | return 1;
|
---|
884 |
|
---|
885 | if (!test_dlfcn_read_public_fib_var())
|
---|
886 | return 1;
|
---|
887 |
|
---|
888 | if (!test_dlfcn_read_public_fib_uvar())
|
---|
889 | return 1;
|
---|
890 | #endif /* STATIC_EXE */
|
---|
891 |
|
---|
892 | // printf("dlclose()... ");
|
---|
893 | // dlclose(handle);
|
---|
894 | // printf("Passed\n");
|
---|
895 |
|
---|
896 | return 0;
|
---|
897 | }
|
---|
898 |
|
---|
899 | #ifdef DLTEST_LINKED
|
---|
900 |
|
---|
901 | static int test_lnk(void)
|
---|
902 | {
|
---|
903 | if (!test_lnk_dl_get_constant())
|
---|
904 | return 1;
|
---|
905 |
|
---|
906 | if (!test_lnk_dl_get_private_var())
|
---|
907 | return 1;
|
---|
908 |
|
---|
909 | if (!test_lnk_dl_get_private_uvar())
|
---|
910 | return 1;
|
---|
911 |
|
---|
912 | if (!test_lnk_dl_get_public_var())
|
---|
913 | return 1;
|
---|
914 |
|
---|
915 | if (!test_lnk_dl_get_public_uvar())
|
---|
916 | return 1;
|
---|
917 |
|
---|
918 | if (!test_lnk_read_public_var())
|
---|
919 | return 1;
|
---|
920 |
|
---|
921 | if (!test_lnk_read_public_uvar())
|
---|
922 | return 1;
|
---|
923 |
|
---|
924 | if (!test_lnk_dl_get_private_fib_var())
|
---|
925 | return 1;
|
---|
926 |
|
---|
927 | if (!test_lnk_dl_get_private_fib_uvar())
|
---|
928 | return 1;
|
---|
929 |
|
---|
930 | if (!test_lnk_dl_get_public_fib_var())
|
---|
931 | return 1;
|
---|
932 |
|
---|
933 | if (!test_lnk_dl_get_public_fib_uvar())
|
---|
934 | return 1;
|
---|
935 |
|
---|
936 | if (!test_lnk_read_public_fib_var())
|
---|
937 | return 1;
|
---|
938 |
|
---|
939 | if (!test_lnk_read_public_fib_uvar())
|
---|
940 | return 1;
|
---|
941 |
|
---|
942 | return 0;
|
---|
943 | }
|
---|
944 |
|
---|
945 | #endif /* DLTEST_LINKED */
|
---|
946 |
|
---|
947 | static void print_syntax(void)
|
---|
948 | {
|
---|
949 | fprintf(stderr, "syntax: dltest [-n]\n");
|
---|
950 | fprintf(stderr, "\t-n Do not run dlfcn tests\n");
|
---|
951 | }
|
---|
952 |
|
---|
953 | int main(int argc, char *argv[])
|
---|
954 | {
|
---|
955 | printf("Dynamic linking test\n");
|
---|
956 |
|
---|
957 | if (argc > 1) {
|
---|
958 | if (argc > 2) {
|
---|
959 | print_syntax();
|
---|
960 | return 1;
|
---|
961 | }
|
---|
962 |
|
---|
963 | if (str_cmp(argv[1], "-n") == 0) {
|
---|
964 | no_dlfcn = true;
|
---|
965 | } else {
|
---|
966 | print_syntax();
|
---|
967 | return 1;
|
---|
968 | }
|
---|
969 | }
|
---|
970 |
|
---|
971 | if (!no_dlfcn) {
|
---|
972 | if (test_dlfcn() != 0)
|
---|
973 | return 1;
|
---|
974 | }
|
---|
975 |
|
---|
976 | #ifdef DLTEST_LINKED
|
---|
977 | if (test_lnk() != 0)
|
---|
978 | return 1;
|
---|
979 | #endif
|
---|
980 |
|
---|
981 | printf("All passed.\n");
|
---|
982 | return 0;
|
---|
983 | }
|
---|
984 |
|
---|
985 | /**
|
---|
986 | * @}
|
---|
987 | */
|
---|