155ef81ae27ebc6ba7c699916129ab48425fc915
2 * Copyright (C) 2018 Francis Deslauriers <francis.deslauriers@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
15 #include "callsites.h"
18 void exec_callsite(void);
19 void exec_callsite(void)
26 static void print_list(void)
28 fprintf(stderr
, "Test list (-t X):\n");
30 "\t0: dlopen() all libraries pass in arguments and execute "
33 "\t1: simulate the upgrade of a probe provider using dlopen() and dlclose(). \n");
35 "\t2: simulate the upgrade of a library containing the callsites using dlopen() and dlclose(). \n");
39 static int dl_open_all(int nb_libraries
, char **libraries
)
44 handles
= malloc(nb_libraries
* sizeof(void *));
50 /* Iterate over the libs to dlopen and save the handles. */
51 for (i
= 0; i
< nb_libraries
; i
++) {
52 handles
[i
] = dlopen(libraries
[i
], RTLD_NOW
);
66 * Takes 2 paths to libraries, dlopen() the first, trace, dlopen() the second,
67 * and dlclose the first to simulate the upgrade of a library.
69 static int upgrade_lib(int nb_libraries
, char **libraries
)
74 if (nb_libraries
!= 2) {
79 /* Iterate over the libs to dlopen and save the handles. */
80 for (i
= 0; i
< nb_libraries
; i
++) {
81 handles
[i
] = dlopen(libraries
[i
], RTLD_NOW
);
90 ret
= dlclose(handles
[0]);
100 #endif /* HAS_CALLSITES */
104 * Simulate the upgrade of a library containing a callsite.
105 * Receives two libraries containing callsites for the same tracepoint.
107 static int upgrade_callsite(int nb_libraries
, char **libraries
)
111 void (*fct_ptr
[2])(void);
113 if (nb_libraries
!= 2) {
118 /* Load the probes in the first library. */
119 handles
[0] = dlopen(libraries
[0], RTLD_NOW
);
126 * Get the pointer to the old function containing the callsite and call it.
128 fct_ptr
[0] = dlsym(handles
[0], "call_tracepoint");
135 /* Load the new callsite library. */
136 handles
[1] = dlopen(libraries
[1], RTLD_NOW
);
143 * Get the pointer to the new function containing the callsite and call it.
145 fct_ptr
[1] = dlsym(handles
[1], "call_tracepoint");
152 /* Unload the old callsite library. */
153 ret
= dlclose(handles
[0]);
158 /* Call the function containing the callsite in the new library. */
161 ret
= dlclose(handles
[1]);
169 #endif /* !HAS_CALLSITES */
171 int main(int argc
, const char **argv
)
173 int c
, ret
= 0, test
= -1, nb_libraries
= 0;
174 char **libraries
= NULL
;
176 struct poptOption optionsTable
[] = {
177 { "test", 't', POPT_ARG_INT
, &test
, 0, "Test to run", NULL
},
178 { "list", 'l', 0, 0, 'l', "List of tests (-t X)", NULL
},
179 POPT_AUTOHELP
{ NULL
, 0, 0, NULL
, 0, NULL
, NULL
}
182 optCon
= poptGetContext(NULL
, argc
, argv
, optionsTable
, 0);
184 poptPrintUsage(optCon
, stderr
, 0);
189 while ((c
= poptGetNextOpt(optCon
)) >= 0) {
198 * Populate the libraries array with the arguments passed to the process.
200 while (poptPeekArg(optCon
) != NULL
) {
201 char **realloced_libraries
= NULL
;
204 realloced_libraries
= realloc(libraries
, nb_libraries
* sizeof(char *));
205 if (!realloced_libraries
) {
209 libraries
= realloced_libraries
;
210 libraries
[nb_libraries
- 1] = (char *) poptGetArg(optCon
);
216 ret
= dl_open_all(nb_libraries
, libraries
);
219 "Test not implemented for configuration "
220 "(HAS_CALLSITES=%d)\n",
226 ret
= upgrade_lib(nb_libraries
, libraries
);
229 "Test not implemented for configuration "
230 "(HAS_CALLSITES=%d)\n",
236 ret
= upgrade_callsite(nb_libraries
, libraries
);
239 "Test not implemented for configuration "
240 "(HAS_CALLSITES=%d)\n",
245 fprintf(stderr
, "Test %d not implemented\n", test
);
251 poptFreeContext(optCon
);
This page took 0.035513 seconds and 5 git commands to generate.