Test library load/unload events
[lttng-tools.git] / tests / regression / ust / ust-dl / prog.c
1 /* _GNU_SOURCE is defined by config.h */
2 #include <dlfcn.h>
3 #include <stdio.h>
4 #include <errno.h>
5 #include <unistd.h>
6 #include <stdlib.h>
7
8 /*
9 * libfoo has a direct dependency on libbar.
10 * libbar has a direct dependency on libzzz.
11 * This test is therefore a mix of dlopen/dlclose and dlmopen/dlclose of
12 * libfoo, and of its direct dependencies.
13 */
14 int main(int argc, char **argv)
15 {
16 void *h0, *h1, *h2, *h3, *h4;
17 char *error;
18 int (*foo)(void);
19
20 h0 = dlopen("libbar.so", RTLD_LAZY);
21 if (!h0) {
22 goto get_error;
23 }
24 h1 = dlmopen(LM_ID_BASE, "libfoo.so", RTLD_LAZY);
25 if (!h1) {
26 goto get_error;
27 }
28 h2 = dlopen("libzzz.so", RTLD_LAZY);
29 if (!h2) {
30 goto get_error;
31 }
32 h3 = dlopen("libfoo.so", RTLD_LAZY);
33 if (!h3) {
34 goto get_error;
35 }
36 h4 = dlopen("libfoo.so", RTLD_LAZY);
37 if (!h4) {
38 goto get_error;
39 }
40
41 foo = dlsym(h1, "foo");
42 error = dlerror();
43 if (error != NULL) {
44 goto error;
45 }
46
47 foo();
48
49 if (dlclose(h0)) {
50 goto get_error;
51 }
52 if (dlclose(h1)) {
53 goto get_error;
54 }
55 if (dlclose(h2)) {
56 goto get_error;
57 }
58 if (dlclose(h3)) {
59 goto get_error;
60 }
61 if (dlclose(h4)) {
62 goto get_error;
63 }
64
65 exit(EXIT_SUCCESS);
66
67 get_error:
68 error = dlerror();
69 error:
70 fprintf(stderr, "%s\n", error);
71 exit(EXIT_FAILURE);
72 }
This page took 0.032859 seconds and 4 git commands to generate.