1 | /* |
---|
2 | * Copyright (c) 2014 Chris Johns <chrisj@rtems.org>. All rights reserved. |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.org/license/LICENSE. |
---|
7 | */ |
---|
8 | |
---|
9 | #include "dl-o2.h" |
---|
10 | |
---|
11 | #include <dlfcn.h> |
---|
12 | |
---|
13 | #include <rtems/test.h> |
---|
14 | |
---|
15 | #define printf(...) rtems_printf(&rtems_test_printer, __VA_ARGS__); |
---|
16 | |
---|
17 | typedef int (*func1_t)(int argc, const char* argv[]); |
---|
18 | |
---|
19 | static void* find_sym(const char* name) |
---|
20 | { |
---|
21 | void* sym = dlsym(RTLD_DEFAULT, name); |
---|
22 | if (sym == NULL) |
---|
23 | printf("dlsym failed: not found: %s\n", name); |
---|
24 | return sym; |
---|
25 | } |
---|
26 | |
---|
27 | static int dl_o1_callback(const char* message, int count) |
---|
28 | { |
---|
29 | printf("dl_o1_callback: %s\n", message); |
---|
30 | return count + 1; |
---|
31 | } |
---|
32 | |
---|
33 | /* |
---|
34 | * Yes a decl in the source. This is a modules main and I could not find which |
---|
35 | * header main is defined in. |
---|
36 | */ |
---|
37 | int rtems_main (int argc, const char* argv[]); |
---|
38 | |
---|
39 | #define PDOUBLE(_d) ((int) (_d)), (int) ((_d) * 100.0) % 100 |
---|
40 | |
---|
41 | int rtems_main (int argc, const char* argv[]) |
---|
42 | { |
---|
43 | func1_t f1; |
---|
44 | double f2_ret; |
---|
45 | int arg; |
---|
46 | int ret; |
---|
47 | |
---|
48 | printf("Loaded module: argc:%d [%s]\n", argc, __FILE__); |
---|
49 | for (arg = 0; arg < argc; ++arg) |
---|
50 | printf(" %d: %s\n", arg, argv[arg]); |
---|
51 | |
---|
52 | f1 = find_sym ("dl_o2_func1"); |
---|
53 | if (f1 == NULL) |
---|
54 | return 0; |
---|
55 | |
---|
56 | if (f1 (argc, argv) != argc) |
---|
57 | { |
---|
58 | printf("rtems_main: dl_o2_func1 returned bad value\n"); |
---|
59 | return 0; |
---|
60 | } |
---|
61 | |
---|
62 | f2_ret = dl_o2_func2 (7.1, 33.0); |
---|
63 | printf("rtems_main: dl_o2_func2 returned: %d.%02d\n", |
---|
64 | PDOUBLE(f2_ret)); |
---|
65 | if (f2_ret != (7.1 * 33.0)) |
---|
66 | { |
---|
67 | printf("rtems_main: dl_o2_func2 returned a bad\n"); |
---|
68 | return 0; |
---|
69 | } |
---|
70 | |
---|
71 | ret = dl_o2_func3 (dl_o1_callback, 1); |
---|
72 | printf ("rtems_main: callback count: %d\n", ret); |
---|
73 | |
---|
74 | return argc; |
---|
75 | } |
---|