Fix: handle leak in abi tests
[lttng-ust.git] / tests / regression / abi0-conflict / app_noust_dlopen.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
5 */
6
7 #include <dlfcn.h>
8 #include <stdbool.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <unistd.h>
12 #include <string.h>
13
14 #define LTTNG_UST_LIB_ABI0_SO_NAME "libfakeust0.so"
15 #define LTTNG_UST_LIB_ABI1_SO_NAME "liblttng-ust.so.1"
16
17 struct lib_desc {
18 const char *soname;
19 void *handle;
20 };
21
22 static struct lib_desc lib_desc[] = {
23 [0] = {
24 .soname = LTTNG_UST_LIB_ABI0_SO_NAME,
25 },
26 [1] = {
27 .soname = LTTNG_UST_LIB_ABI1_SO_NAME,
28 },
29 [2] = {
30 .soname = LTTNG_UST_LIB_ABI1_SO_NAME,
31 },
32 };
33
34 static
35 int dlopen_ust(struct lib_desc *desc)
36 {
37 int ret = EXIT_SUCCESS;
38
39 desc->handle = dlopen(desc->soname, RTLD_NOW | RTLD_GLOBAL);
40 if (!desc->handle) {
41 printf("Error: dlopen of liblttng-ust shared library (%s).\n", desc->soname);
42 ret = EXIT_FAILURE;
43 } else {
44 printf("Success: dlopen of liblttng-ust shared library (%s).\n", desc->soname);
45 }
46
47 return ret;
48 }
49
50 static
51 int dlopen_abi0(void)
52 {
53 return dlopen_ust(&lib_desc[0]);
54 }
55
56 static
57 int dlopen_abi1(void)
58 {
59 return dlopen_ust(&lib_desc[1]);
60 }
61
62 static
63 int dlopen_abi0_abi1(void)
64 {
65 int ret = EXIT_SUCCESS;
66
67 ret = dlopen_ust(&lib_desc[0]);
68 if (ret != EXIT_SUCCESS)
69 return ret;
70
71 ret = dlopen_ust(&lib_desc[1]);
72
73 return ret;
74 }
75
76 static
77 int dlopen_abi1_abi0(void)
78 {
79 int ret = EXIT_SUCCESS;
80
81 ret = dlopen_ust(&lib_desc[1]);
82 if (ret != EXIT_SUCCESS)
83 return ret;
84
85 ret = dlopen_ust(&lib_desc[0]);
86
87 return ret;
88 }
89
90 static
91 int dlopen_abi1_abi1(void)
92 {
93 int ret = EXIT_SUCCESS;
94
95 ret = dlopen_ust(&lib_desc[1]);
96 if (ret != EXIT_SUCCESS)
97 return ret;
98
99 ret = dlopen_ust(&lib_desc[2]);
100
101 return ret;
102 }
103
104 static
105 void usage(char **argv)
106 {
107 printf("Usage: %s <test_type>\n", argv[0]);
108 printf(" test_type: abi0, abi1, abi0_abi1, abi1_abi0, abi1_abi1\n");
109 }
110
111 int main(int argc, char **argv)
112 {
113 int ret = EXIT_SUCCESS;
114 const char *test_type;
115
116 if (argc != 2) {
117 usage(argv);
118 return EXIT_FAILURE;
119 } else {
120 test_type = argv[1];
121 }
122
123 printf("This application is NOT linked on liblttng-ust.\n");
124
125 if (strcmp(test_type, "abi0") == 0)
126 ret = dlopen_abi0();
127 else if (strcmp(test_type, "abi1") == 0)
128 ret = dlopen_abi1();
129 else if (strcmp(test_type, "abi0_abi1") == 0)
130 ret = dlopen_abi0_abi1();
131 else if (strcmp(test_type, "abi1_abi0") == 0)
132 ret = dlopen_abi1_abi0();
133 else if (strcmp(test_type, "abi1_abi1") == 0)
134 ret = dlopen_abi1_abi1();
135 else {
136 usage(argv);
137 ret = EXIT_FAILURE;
138 }
139
140 return ret;
141 }
This page took 0.031467 seconds and 4 git commands to generate.