tests: Move to kernel style SPDX license identifiers
[lttng-tools.git] / tests / regression / ust / ust-dl / prog.c
CommitLineData
9d16b343
MJ
1/*
2 * Copyright (C) 2016 Antoine Busque <abusque@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
d8ed06af 8/* _GNU_SOURCE is defined by config.h */
c70c42cc 9#include <dlfcn.h>
d8ed06af
MD
10#include <stdio.h>
11#include <errno.h>
12#include <unistd.h>
13#include <stdlib.h>
c70c42cc 14
d8ed06af
MD
15/*
16 * libfoo has a direct dependency on libbar.
17 * libbar has a direct dependency on libzzz.
18 * This test is therefore a mix of dlopen/dlclose and dlmopen/dlclose of
19 * libfoo, and of its direct dependencies.
20 */
21int main(int argc, char **argv)
c70c42cc 22{
bc1d8ca0
PP
23 void *h0, *h2, *h3, *h4;
24
25#ifdef HAVE_DLMOPEN
26 void *h1;
27#endif
28
d8ed06af
MD
29 char *error;
30 int (*foo)(void);
c70c42cc 31
d8ed06af
MD
32 h0 = dlopen("libbar.so", RTLD_LAZY);
33 if (!h0) {
34 goto get_error;
35 }
bc1d8ca0
PP
36
37#ifdef HAVE_DLMOPEN
d8ed06af
MD
38 h1 = dlmopen(LM_ID_BASE, "libfoo.so", RTLD_LAZY);
39 if (!h1) {
40 goto get_error;
41 }
bc1d8ca0
PP
42#endif
43
d8ed06af
MD
44 h2 = dlopen("libzzz.so", RTLD_LAZY);
45 if (!h2) {
46 goto get_error;
47 }
48 h3 = dlopen("libfoo.so", RTLD_LAZY);
49 if (!h3) {
50 goto get_error;
51 }
52 h4 = dlopen("libfoo.so", RTLD_LAZY);
53 if (!h4) {
54 goto get_error;
55 }
c70c42cc 56
bc1d8ca0 57 foo = dlsym(h3, "foo");
d8ed06af
MD
58 error = dlerror();
59 if (error != NULL) {
60 goto error;
61 }
c70c42cc 62
d8ed06af 63 foo();
c70c42cc 64
d8ed06af
MD
65 if (dlclose(h0)) {
66 goto get_error;
67 }
bc1d8ca0
PP
68
69#ifdef HAVE_DLMOPEN
d8ed06af
MD
70 if (dlclose(h1)) {
71 goto get_error;
72 }
bc1d8ca0
PP
73#endif
74
d8ed06af
MD
75 if (dlclose(h2)) {
76 goto get_error;
77 }
78 if (dlclose(h3)) {
79 goto get_error;
80 }
81 if (dlclose(h4)) {
82 goto get_error;
83 }
84
85 exit(EXIT_SUCCESS);
86
87get_error:
88 error = dlerror();
89error:
90 fprintf(stderr, "%s\n", error);
91 exit(EXIT_FAILURE);
c70c42cc 92}
This page took 0.044325 seconds and 5 git commands to generate.