Commit | Line | Data |
---|---|---|
d2a010d1 MJ |
1 | /* |
2 | * SPDX-License-Identifier: LGPL-2.1-only | |
3 | * | |
4 | * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com> | |
5 | */ | |
6 | ||
7 | #include <dlfcn.h> | |
8 | #include <stdbool.h> | |
9 | #include <stdlib.h> | |
10 | #include <stdio.h> | |
11 | #include <unistd.h> | |
12 | #include <string.h> | |
13 | #include <arpa/inet.h> | |
14 | ||
15 | #define LTTNG_UST_TRACEPOINT_DEFINE | |
16 | #include "ust_tests_hello.h" | |
17 | ||
18 | #define LTTNG_UST_LIB_ABI0_SO_NAME "libfakeust0.so" | |
19 | #define LTTNG_UST_LIB_ABI1_SO_NAME "liblttng-ust.so.1" | |
20 | ||
dbbb7396 MD |
21 | struct lib_desc { |
22 | const char *soname; | |
23 | void *handle; | |
24 | }; | |
25 | ||
26 | static struct lib_desc lib_desc[] = { | |
27 | [0] = { | |
28 | .soname = LTTNG_UST_LIB_ABI0_SO_NAME, | |
29 | }, | |
30 | [1] = { | |
31 | .soname = LTTNG_UST_LIB_ABI1_SO_NAME, | |
32 | }, | |
33 | [2] = { | |
34 | .soname = LTTNG_UST_LIB_ABI1_SO_NAME, | |
35 | }, | |
36 | }; | |
37 | ||
d2a010d1 | 38 | static |
dbbb7396 | 39 | int dlopen_ust(struct lib_desc *desc) |
d2a010d1 MJ |
40 | { |
41 | int ret = EXIT_SUCCESS; | |
d2a010d1 | 42 | |
dbbb7396 MD |
43 | desc->handle = dlopen(desc->soname, RTLD_NOW | RTLD_GLOBAL); |
44 | if (!desc->handle) { | |
45 | printf("Error: dlopen of liblttng-ust shared library (%s).\n", desc->soname); | |
d2a010d1 MJ |
46 | ret = EXIT_FAILURE; |
47 | } else { | |
dbbb7396 | 48 | printf("Success: dlopen of liblttng-ust shared library (%s).\n", desc->soname); |
d2a010d1 MJ |
49 | } |
50 | ||
51 | return ret; | |
52 | } | |
53 | ||
54 | static | |
55 | int dlopen_abi0(void) | |
56 | { | |
dbbb7396 | 57 | return dlopen_ust(&lib_desc[0]); |
d2a010d1 MJ |
58 | } |
59 | ||
60 | static | |
61 | int dlopen_abi1(void) | |
62 | { | |
dbbb7396 | 63 | return dlopen_ust(&lib_desc[1]); |
d2a010d1 MJ |
64 | } |
65 | ||
66 | static | |
67 | int dlopen_abi0_abi1(void) | |
68 | { | |
69 | int ret = EXIT_SUCCESS; | |
70 | ||
dbbb7396 | 71 | ret = dlopen_ust(&lib_desc[0]); |
d2a010d1 MJ |
72 | if (ret != EXIT_SUCCESS) |
73 | return ret; | |
74 | ||
dbbb7396 | 75 | ret = dlopen_ust(&lib_desc[1]); |
d2a010d1 MJ |
76 | |
77 | return ret; | |
78 | } | |
79 | ||
80 | static | |
81 | int dlopen_abi1_abi0(void) | |
82 | { | |
83 | int ret = EXIT_SUCCESS; | |
84 | ||
dbbb7396 | 85 | ret = dlopen_ust(&lib_desc[1]); |
d2a010d1 MJ |
86 | if (ret != EXIT_SUCCESS) |
87 | return ret; | |
88 | ||
dbbb7396 | 89 | ret = dlopen_ust(&lib_desc[0]); |
d2a010d1 MJ |
90 | |
91 | return ret; | |
92 | } | |
93 | ||
94 | static | |
95 | int dlopen_abi1_abi1(void) | |
96 | { | |
97 | int ret = EXIT_SUCCESS; | |
98 | ||
dbbb7396 | 99 | ret = dlopen_ust(&lib_desc[1]); |
d2a010d1 MJ |
100 | if (ret != EXIT_SUCCESS) |
101 | return ret; | |
102 | ||
dbbb7396 | 103 | ret = dlopen_ust(&lib_desc[2]); |
d2a010d1 MJ |
104 | |
105 | return ret; | |
106 | } | |
107 | ||
108 | static | |
109 | void usage(char **argv) | |
110 | { | |
111 | printf("Usage: %s <test_type>\n", argv[0]); | |
112 | printf(" test_type: abi0, abi1, abi0_abi1, abi1_abi0, abi1_abi1\n"); | |
113 | } | |
114 | ||
115 | int main(int argc, char **argv) | |
116 | { | |
117 | int ret = EXIT_SUCCESS; | |
118 | const char *test_type; | |
d2a010d1 MJ |
119 | int i, netint; |
120 | long values[] = { 1, 2, 3 }; | |
121 | char text[10] = "test"; | |
122 | double dbl = 2.0; | |
123 | float flt = 2222.0; | |
124 | bool mybool = 123; /* should print "1" */ | |
125 | ||
d2a010d1 MJ |
126 | if (argc != 2) { |
127 | usage(argv); | |
128 | return EXIT_FAILURE; | |
129 | } else { | |
130 | test_type = argv[1]; | |
131 | } | |
132 | ||
133 | printf("This application is linked on liblttng-ust.\n"); | |
134 | ||
135 | if (strcmp(test_type, "abi0") == 0) | |
136 | ret = dlopen_abi0(); | |
137 | else if (strcmp(test_type, "abi1") == 0) | |
138 | ret = dlopen_abi1(); | |
139 | else if (strcmp(test_type, "abi0_abi1") == 0) | |
140 | ret = dlopen_abi0_abi1(); | |
141 | else if (strcmp(test_type, "abi1_abi0") == 0) | |
142 | ret = dlopen_abi1_abi0(); | |
143 | else if (strcmp(test_type, "abi1_abi1") == 0) | |
144 | ret = dlopen_abi1_abi1(); | |
145 | else { | |
146 | usage(argv); | |
147 | ret = EXIT_FAILURE; | |
148 | } | |
149 | ||
150 | for (i = 0; i < 10; i++) { | |
151 | netint = htonl(i); | |
152 | lttng_ust_tracepoint(ust_tests_hello, tptest, i, netint, values, | |
153 | text, strlen(text), dbl, flt, mybool); | |
154 | } | |
155 | ||
156 | return ret; | |
157 | } |