Fix: handle leak in abi tests
[lttng-ust.git] / tests / regression / abi0-conflict / app_ust_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 #include <arpa/inet.h>
14
15 #define LTTNG_UST_TRACEPOINT_DEFINE
16 #include "ust_tests_hello.h"
17
18 #define LTTNG_UST_LIB_ABI0_SO_NAME "libfakeust0.so"
19 #define LTTNG_UST_LIB_ABI1_SO_NAME "liblttng-ust.so.1"
20
21 struct lib_desc {
22 const char *soname;
23 void *handle;
24 };
25
26 static struct lib_desc lib_desc[] = {
27 [0] = {
28 .soname = LTTNG_UST_LIB_ABI0_SO_NAME,
29 },
30 [1] = {
31 .soname = LTTNG_UST_LIB_ABI1_SO_NAME,
32 },
33 [2] = {
34 .soname = LTTNG_UST_LIB_ABI1_SO_NAME,
35 },
36 };
37
38 static
39 int dlopen_ust(struct lib_desc *desc)
40 {
41 int ret = EXIT_SUCCESS;
42
43 desc->handle = dlopen(desc->soname, RTLD_NOW | RTLD_GLOBAL);
44 if (!desc->handle) {
45 printf("Error: dlopen of liblttng-ust shared library (%s).\n", desc->soname);
46 ret = EXIT_FAILURE;
47 } else {
48 printf("Success: dlopen of liblttng-ust shared library (%s).\n", desc->soname);
49 }
50
51 return ret;
52 }
53
54 static
55 int dlopen_abi0(void)
56 {
57 return dlopen_ust(&lib_desc[0]);
58 }
59
60 static
61 int dlopen_abi1(void)
62 {
63 return dlopen_ust(&lib_desc[1]);
64 }
65
66 static
67 int dlopen_abi0_abi1(void)
68 {
69 int ret = EXIT_SUCCESS;
70
71 ret = dlopen_ust(&lib_desc[0]);
72 if (ret != EXIT_SUCCESS)
73 return ret;
74
75 ret = dlopen_ust(&lib_desc[1]);
76
77 return ret;
78 }
79
80 static
81 int dlopen_abi1_abi0(void)
82 {
83 int ret = EXIT_SUCCESS;
84
85 ret = dlopen_ust(&lib_desc[1]);
86 if (ret != EXIT_SUCCESS)
87 return ret;
88
89 ret = dlopen_ust(&lib_desc[0]);
90
91 return ret;
92 }
93
94 static
95 int dlopen_abi1_abi1(void)
96 {
97 int ret = EXIT_SUCCESS;
98
99 ret = dlopen_ust(&lib_desc[1]);
100 if (ret != EXIT_SUCCESS)
101 return ret;
102
103 ret = dlopen_ust(&lib_desc[2]);
104
105 return ret;
106 }
107
108 static
109 void usage(char **argv)
110 {
111 printf("Usage: %s <test_type>\n", argv[0]);
112 printf(" test_type: abi0, abi1, abi0_abi1, abi1_abi0, abi1_abi1\n");
113 }
114
115 int main(int argc, char **argv)
116 {
117 int ret = EXIT_SUCCESS;
118 const char *test_type;
119 int i, netint;
120 long values[] = { 1, 2, 3 };
121 char text[10] = "test";
122 double dbl = 2.0;
123 float flt = 2222.0;
124 bool mybool = 123; /* should print "1" */
125
126 if (argc != 2) {
127 usage(argv);
128 return EXIT_FAILURE;
129 } else {
130 test_type = argv[1];
131 }
132
133 printf("This application is linked on liblttng-ust.\n");
134
135 if (strcmp(test_type, "abi0") == 0)
136 ret = dlopen_abi0();
137 else if (strcmp(test_type, "abi1") == 0)
138 ret = dlopen_abi1();
139 else if (strcmp(test_type, "abi0_abi1") == 0)
140 ret = dlopen_abi0_abi1();
141 else if (strcmp(test_type, "abi1_abi0") == 0)
142 ret = dlopen_abi1_abi0();
143 else if (strcmp(test_type, "abi1_abi1") == 0)
144 ret = dlopen_abi1_abi1();
145 else {
146 usage(argv);
147 ret = EXIT_FAILURE;
148 }
149
150 for (i = 0; i < 10; i++) {
151 netint = htonl(i);
152 lttng_ust_tracepoint(ust_tests_hello, tptest, i, netint, values,
153 text, strlen(text), dbl, flt, mybool);
154 }
155
156 return ret;
157 }
This page took 0.031652 seconds and 4 git commands to generate.