6a91089df27dc0c1281060d0e11a897354237efd
2 * Copyright (C) 2018 Francis Deslauriers <francis.deslauriers@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
15 #include "callsites.h"
27 fprintf(stderr
, "Test list (-t X):\n");
28 fprintf(stderr
, "\t0: dlopen() all libraries pass in arguments and execute "
30 fprintf(stderr
, "\t1: simulate the upgrade of a probe provider using dlopen() and dlclose(). \n");
31 fprintf(stderr
, "\t2: simulate the upgrade of a library containing the callsites using dlopen() and dlclose(). \n");
34 int dl_open_all(int nb_libraries
, char **libraries
)
39 handles
= malloc(nb_libraries
* sizeof(void *));
45 /* Iterate over the libs to dlopen and save the handles. */
46 for (i
= 0; i
< nb_libraries
; i
++) {
47 handles
[i
] = dlopen(libraries
[i
], RTLD_NOW
);
61 * Takes 2 paths to libraries, dlopen() the first, trace, dlopen() the second,
62 * and dlclose the first to simulate the upgrade of a library.
64 int upgrade_lib(int nb_libraries
, char **libraries
)
69 if (nb_libraries
!= 2) {
74 /* Iterate over the libs to dlopen and save the handles. */
75 for (i
= 0; i
< nb_libraries
; i
++) {
76 handles
[i
] = dlopen(libraries
[i
], RTLD_NOW
);
85 ret
= dlclose(handles
[0]);
97 * Simulate the upgrade of a library containing a callsite.
98 * Receives two libraries containing callsites for the same tracepoint.
100 int upgrade_callsite(int nb_libraries
, char **libraries
)
104 void (*fct_ptr
[2])(void);
106 if (nb_libraries
!= 2) {
111 /* Load the probes in the first library. */
112 handles
[0] = dlopen(libraries
[0], RTLD_NOW
);
119 * Get the pointer to the old function containing the callsite and call it.
121 fct_ptr
[0] = dlsym(handles
[0], "call_tracepoint");
128 /* Load the new callsite library. */
129 handles
[1] = dlopen(libraries
[1], RTLD_NOW
);
136 * Get the pointer to the new function containing the callsite and call it.
138 fct_ptr
[1] = dlsym(handles
[1], "call_tracepoint");
145 /* Unload the old callsite library. */
146 ret
= dlclose(handles
[0]);
151 /* Call the function containing the callsite in the new library. */
154 ret
= dlclose(handles
[1]);
163 int main(int argc
, const char **argv
)
165 int c
, ret
= 0, test
= -1, nb_libraries
= 0;
166 char **libraries
= NULL
;
168 struct poptOption optionsTable
[] = {
169 { "test", 't', POPT_ARG_INT
, &test
, 0, "Test to run", NULL
},
170 { "list", 'l', 0, 0, 'l', "List of tests (-t X)", NULL
},
172 { NULL
, 0, 0, NULL
, 0 }
175 optCon
= poptGetContext(NULL
, argc
, argv
, optionsTable
, 0);
177 poptPrintUsage(optCon
, stderr
, 0);
182 while ((c
= poptGetNextOpt(optCon
)) >= 0) {
191 * Populate the libraries array with the arguments passed to the process.
193 while (poptPeekArg(optCon
) != NULL
) {
194 char **realloced_libraries
= NULL
;
197 realloced_libraries
= realloc(libraries
, nb_libraries
* sizeof(char *));
198 if (!realloced_libraries
) {
202 libraries
= realloced_libraries
;
203 libraries
[nb_libraries
- 1] = (char *) poptGetArg(optCon
);
209 ret
= dl_open_all(nb_libraries
, libraries
);
211 fprintf(stderr
, "Test not implemented for configuration "
212 "(HAS_CALLSITES=%d)\n", HAS_CALLSITES
== 1);
217 ret
= upgrade_lib(nb_libraries
, libraries
);
219 fprintf(stderr
, "Test not implemented for configuration "
220 "(HAS_CALLSITES=%d)\n", HAS_CALLSITES
== 1);
225 ret
= upgrade_callsite(nb_libraries
, libraries
);
227 fprintf(stderr
, "Test not implemented for configuration "
228 "(HAS_CALLSITES=%d)\n", HAS_CALLSITES
== 1);
232 fprintf(stderr
, "Test %d not implemented\n", test
);
238 poptFreeContext(optCon
);
This page took 0.033789 seconds and 3 git commands to generate.