Test library load/unload events
[lttng-tools.git] / tests / regression / ust / ust-dl / prog.c
CommitLineData
d8ed06af 1/* _GNU_SOURCE is defined by config.h */
c70c42cc 2#include <dlfcn.h>
d8ed06af
MD
3#include <stdio.h>
4#include <errno.h>
5#include <unistd.h>
6#include <stdlib.h>
c70c42cc 7
d8ed06af
MD
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 */
14int main(int argc, char **argv)
c70c42cc 15{
d8ed06af
MD
16 void *h0, *h1, *h2, *h3, *h4;
17 char *error;
18 int (*foo)(void);
c70c42cc 19
d8ed06af
MD
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 }
c70c42cc 40
d8ed06af
MD
41 foo = dlsym(h1, "foo");
42 error = dlerror();
43 if (error != NULL) {
44 goto error;
45 }
c70c42cc 46
d8ed06af 47 foo();
c70c42cc 48
d8ed06af
MD
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
67get_error:
68 error = dlerror();
69error:
70 fprintf(stderr, "%s\n", error);
71 exit(EXIT_FAILURE);
c70c42cc 72}
This page took 0.02578 seconds and 4 git commands to generate.