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