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