2 * Copyright (C) - 2018 Francis Deslauriers <francis.deslauriers@efficios.com>
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by the
6 * Free Software Foundation; version 2.1 of the License.
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "callsites.h"
37 fprintf(stderr
, "Test list (-t X):\n");
38 fprintf(stderr
, "\t0: dlopen() all libraries pass in arguments and execute "
40 fprintf(stderr
, "\t1: simulate the upgrade of a probe provider using dlopen() and dlclose(). \n");
41 fprintf(stderr
, "\t2: simulate the upgrade of a library containing the callsites using dlopen() and dlclose(). \n");
44 int dl_open_all(int nb_libraries
, char **libraries
)
49 handles
= malloc(nb_libraries
* sizeof(void *));
55 /* Iterate over the libs to dlopen and save the handles. */
56 for (i
= 0; i
< nb_libraries
; i
++) {
57 handles
[i
] = dlopen(libraries
[i
], RTLD_NOW
);
71 * Takes 2 paths to libraries, dlopen() the first, trace, dlopen() the second,
72 * and dlclose the first to simulate the upgrade of a library.
74 int upgrade_lib(int nb_libraries
, char **libraries
)
79 if (nb_libraries
!= 2) {
84 /* Iterate over the libs to dlopen and save the handles. */
85 for (i
= 0; i
< nb_libraries
; i
++) {
86 handles
[i
] = dlopen(libraries
[i
], RTLD_NOW
);
95 ret
= dlclose(handles
[0]);
107 * Simulate the upgrade of a library containing a callsite.
108 * Receives two libraries containing callsites for the same tracepoint.
110 int upgrade_callsite(int nb_libraries
, char **libraries
)
114 void (*fct_ptr
[2])(void);
116 if (nb_libraries
!= 2) {
121 /* Load the probes in the first library. */
122 handles
[0] = dlopen(libraries
[0], RTLD_NOW
);
129 * Get the pointer to the old function containing the callsite and call it.
131 fct_ptr
[0] = dlsym(handles
[0], "call_tracepoint");
138 /* Load the new callsite library. */
139 handles
[1] = dlopen(libraries
[1], RTLD_NOW
);
146 * Get the pointer to the new function containing the callsite and call it.
148 fct_ptr
[1] = dlsym(handles
[1], "call_tracepoint");
155 /* Unload the old callsite library. */
156 ret
= dlclose(handles
[0]);
161 /* Call the function containing the callsite in the new library. */
164 ret
= dlclose(handles
[1]);
173 int main(int argc
, const char **argv
)
175 int c
, ret
= 0, test
= -1, nb_libraries
= 0;
176 char **libraries
= NULL
;
178 struct poptOption optionsTable
[] = {
179 { "test", 't', POPT_ARG_INT
, &test
, 0, "Test to run", NULL
},
180 { "list", 'l', 0, 0, 'l', "List of tests (-t X)", NULL
},
182 { NULL
, 0, 0, NULL
, 0 }
185 optCon
= poptGetContext(NULL
, argc
, argv
, optionsTable
, 0);
187 poptPrintUsage(optCon
, stderr
, 0);
192 while ((c
= poptGetNextOpt(optCon
)) >= 0) {
201 * Populate the libraries array with the arguments passed to the process.
203 while (poptPeekArg(optCon
) != NULL
) {
204 char **realloced_libraries
= NULL
;
207 realloced_libraries
= realloc(libraries
, nb_libraries
* sizeof(char *));
208 if (!realloced_libraries
) {
212 libraries
= realloced_libraries
;
213 libraries
[nb_libraries
- 1] = (char *) poptGetArg(optCon
);
219 ret
= dl_open_all(nb_libraries
, libraries
);
221 fprintf(stderr
, "Test not implemented for configuration "
222 "(HAS_CALLSITES=%d)\n", HAS_CALLSITES
== 1);
227 ret
= upgrade_lib(nb_libraries
, libraries
);
229 fprintf(stderr
, "Test not implemented for configuration "
230 "(HAS_CALLSITES=%d)\n", HAS_CALLSITES
== 1);
235 ret
= upgrade_callsite(nb_libraries
, libraries
);
237 fprintf(stderr
, "Test not implemented for configuration "
238 "(HAS_CALLSITES=%d)\n", HAS_CALLSITES
== 1);
242 fprintf(stderr
, "Test %d not implemented\n", test
);
248 poptFreeContext(optCon
);
This page took 0.034304 seconds and 4 git commands to generate.