eb14162489ff07d924d25d0b8ae604206ce08ea0
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)
29 fprintf(stderr
, "Test list (-t X):\n");
30 fprintf(stderr
, "\t0: dlopen() all libraries pass in arguments and execute "
32 fprintf(stderr
, "\t1: simulate the upgrade of a probe provider using dlopen() and dlclose(). \n");
33 fprintf(stderr
, "\t2: simulate the upgrade of a library containing the callsites using dlopen() and dlclose(). \n");
38 int dl_open_all(int nb_libraries
, char **libraries
)
43 handles
= malloc(nb_libraries
* sizeof(void *));
49 /* Iterate over the libs to dlopen and save the handles. */
50 for (i
= 0; i
< nb_libraries
; i
++) {
51 handles
[i
] = dlopen(libraries
[i
], RTLD_NOW
);
65 * Takes 2 paths to libraries, dlopen() the first, trace, dlopen() the second,
66 * and dlclose the first to simulate the upgrade of a library.
69 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.
108 int upgrade_callsite(int nb_libraries
, char **libraries
)
112 void (*fct_ptr
[2])(void);
114 if (nb_libraries
!= 2) {
119 /* Load the probes in the first library. */
120 handles
[0] = dlopen(libraries
[0], RTLD_NOW
);
127 * Get the pointer to the old function containing the callsite and call it.
129 fct_ptr
[0] = dlsym(handles
[0], "call_tracepoint");
136 /* Load the new callsite library. */
137 handles
[1] = dlopen(libraries
[1], RTLD_NOW
);
144 * Get the pointer to the new function containing the callsite and call it.
146 fct_ptr
[1] = dlsym(handles
[1], "call_tracepoint");
153 /* Unload the old callsite library. */
154 ret
= dlclose(handles
[0]);
159 /* Call the function containing the callsite in the new library. */
162 ret
= dlclose(handles
[1]);
170 #endif /* !HAS_CALLSITES */
172 int main(int argc
, const char **argv
)
174 int c
, ret
= 0, test
= -1, nb_libraries
= 0;
175 char **libraries
= NULL
;
177 struct poptOption optionsTable
[] = {
178 { "test", 't', POPT_ARG_INT
, &test
, 0, "Test to run", NULL
},
179 { "list", 'l', 0, 0, 'l', "List of tests (-t X)", NULL
},
181 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
}
184 optCon
= poptGetContext(NULL
, argc
, argv
, optionsTable
, 0);
186 poptPrintUsage(optCon
, stderr
, 0);
191 while ((c
= poptGetNextOpt(optCon
)) >= 0) {
200 * Populate the libraries array with the arguments passed to the process.
202 while (poptPeekArg(optCon
) != NULL
) {
203 char **realloced_libraries
= NULL
;
206 realloced_libraries
= realloc(libraries
, nb_libraries
* sizeof(char *));
207 if (!realloced_libraries
) {
211 libraries
= realloced_libraries
;
212 libraries
[nb_libraries
- 1] = (char *) poptGetArg(optCon
);
218 ret
= dl_open_all(nb_libraries
, libraries
);
220 fprintf(stderr
, "Test not implemented for configuration "
221 "(HAS_CALLSITES=%d)\n", HAS_CALLSITES
== 1);
226 ret
= upgrade_lib(nb_libraries
, libraries
);
228 fprintf(stderr
, "Test not implemented for configuration "
229 "(HAS_CALLSITES=%d)\n", HAS_CALLSITES
== 1);
234 ret
= upgrade_callsite(nb_libraries
, libraries
);
236 fprintf(stderr
, "Test not implemented for configuration "
237 "(HAS_CALLSITES=%d)\n", HAS_CALLSITES
== 1);
241 fprintf(stderr
, "Test %d not implemented\n", test
);
247 poptFreeContext(optCon
);
This page took 0.033824 seconds and 4 git commands to generate.