| 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 | static |
| 18 | int dlopen_ust(const char *lib_soname) |
| 19 | { |
| 20 | int ret = EXIT_SUCCESS; |
| 21 | void *handle; |
| 22 | |
| 23 | handle = dlopen(lib_soname, RTLD_NOW | RTLD_GLOBAL); |
| 24 | if (!handle) { |
| 25 | printf("Error: dlopen of liblttng-ust shared library (%s).\n", lib_soname); |
| 26 | ret = EXIT_FAILURE; |
| 27 | } else { |
| 28 | printf("Success: dlopen of liblttng-ust shared library (%s).\n", lib_soname); |
| 29 | } |
| 30 | |
| 31 | return ret; |
| 32 | } |
| 33 | |
| 34 | static |
| 35 | int dlopen_abi0(void) |
| 36 | { |
| 37 | return dlopen_ust(LTTNG_UST_LIB_ABI0_SO_NAME); |
| 38 | } |
| 39 | |
| 40 | static |
| 41 | int dlopen_abi1(void) |
| 42 | { |
| 43 | return dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); |
| 44 | } |
| 45 | |
| 46 | static |
| 47 | int dlopen_abi0_abi1(void) |
| 48 | { |
| 49 | int ret = EXIT_SUCCESS; |
| 50 | |
| 51 | ret = dlopen_ust(LTTNG_UST_LIB_ABI0_SO_NAME); |
| 52 | if (ret != EXIT_SUCCESS) |
| 53 | return ret; |
| 54 | |
| 55 | ret = dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); |
| 56 | |
| 57 | return ret; |
| 58 | } |
| 59 | |
| 60 | static |
| 61 | int dlopen_abi1_abi0(void) |
| 62 | { |
| 63 | int ret = EXIT_SUCCESS; |
| 64 | |
| 65 | ret = dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); |
| 66 | if (ret != EXIT_SUCCESS) |
| 67 | return ret; |
| 68 | |
| 69 | ret = dlopen_ust(LTTNG_UST_LIB_ABI0_SO_NAME); |
| 70 | |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | static |
| 75 | int dlopen_abi1_abi1(void) |
| 76 | { |
| 77 | int ret = EXIT_SUCCESS; |
| 78 | |
| 79 | ret = dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); |
| 80 | if (ret != EXIT_SUCCESS) |
| 81 | return ret; |
| 82 | |
| 83 | ret = dlopen_ust(LTTNG_UST_LIB_ABI1_SO_NAME); |
| 84 | |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | static |
| 89 | void usage(char **argv) |
| 90 | { |
| 91 | printf("Usage: %s <test_type>\n", argv[0]); |
| 92 | printf(" test_type: abi0, abi1, abi0_abi1, abi1_abi0, abi1_abi1\n"); |
| 93 | } |
| 94 | |
| 95 | int main(int argc, char **argv) |
| 96 | { |
| 97 | int ret = EXIT_SUCCESS; |
| 98 | const char *test_type; |
| 99 | |
| 100 | if (argc != 2) { |
| 101 | usage(argv); |
| 102 | return EXIT_FAILURE; |
| 103 | } else { |
| 104 | test_type = argv[1]; |
| 105 | } |
| 106 | |
| 107 | printf("This application is NOT linked on liblttng-ust.\n"); |
| 108 | |
| 109 | if (strcmp(test_type, "abi0") == 0) |
| 110 | ret = dlopen_abi0(); |
| 111 | else if (strcmp(test_type, "abi1") == 0) |
| 112 | ret = dlopen_abi1(); |
| 113 | else if (strcmp(test_type, "abi0_abi1") == 0) |
| 114 | ret = dlopen_abi0_abi1(); |
| 115 | else if (strcmp(test_type, "abi1_abi0") == 0) |
| 116 | ret = dlopen_abi1_abi0(); |
| 117 | else if (strcmp(test_type, "abi1_abi1") == 0) |
| 118 | ret = dlopen_abi1_abi1(); |
| 119 | else { |
| 120 | usage(argv); |
| 121 | ret = EXIT_FAILURE; |
| 122 | } |
| 123 | |
| 124 | return ret; |
| 125 | } |