| 1 | #!/bin/bash |
| 2 | |
| 3 | # SPDX-FileCopyrightText: 2023 EfficiOS, Inc |
| 4 | # |
| 5 | # SPDX-License-Identifier: LGPL-2.1-only |
| 6 | |
| 7 | if [ "x${UST_TESTS_SRCDIR:-}" != "x" ]; then |
| 8 | UTILSSH="$UST_TESTS_SRCDIR/utils/utils.sh" |
| 9 | else |
| 10 | UTILSSH="$(dirname "$0")/../../utils/utils.sh" |
| 11 | fi |
| 12 | |
| 13 | # shellcheck source=../../utils/utils.sh |
| 14 | source "$UTILSSH" |
| 15 | |
| 16 | # shellcheck source=../../utils/tap.sh |
| 17 | source "$UST_TESTS_SRCDIR/utils/tap.sh" |
| 18 | |
| 19 | CURDIR="${UST_TESTS_BUILDDIR}/regression/abi0-conflict" |
| 20 | |
| 21 | LIBFAKEUST0_PATH="${CURDIR}/.libs" |
| 22 | LIBFAKEUST0="${LIBFAKEUST0_PATH}/libfakeust0.so" |
| 23 | |
| 24 | LIBUST1_PATH="${UST_TESTS_BUILDDIR}/../src/lib/lttng-ust/.libs/" |
| 25 | LIBUST1="${LIBUST1_PATH}/liblttng-ust.so.1" |
| 26 | |
| 27 | STD_OUTPUT="/dev/null" |
| 28 | STD_ERROR="/dev/null" |
| 29 | |
| 30 | NUM_TESTS=22 |
| 31 | |
| 32 | # Set this variable to disable tests that rely on a library using a symbol from |
| 33 | # the global offset table even if it provides its own copy, which is the |
| 34 | # default behavior on Linux. This happens when using the '-Bsymbolic-functions' |
| 35 | # linker flag. |
| 36 | UST_TESTS_LD_SYMBOLIC_FUNC=${UST_TESTS_LD_SYMBOLIC_FUNC:-} |
| 37 | |
| 38 | # On FreeBSD, symbol resolution when dlopening a shared object will always |
| 39 | # favor symbols local to this shared object and thus our canary function will |
| 40 | # never be called which breaks our abi conflict detection when abi1 is loaded |
| 41 | # first. |
| 42 | if [ "$UST_OS_TYPE" = "freebsd" ]; then |
| 43 | UST_TESTS_LD_SYMBOLIC_FUNC=1 |
| 44 | fi |
| 45 | |
| 46 | if [ "$UST_TESTS_LD_SYMBOLIC_FUNC" != "" ]; then |
| 47 | NUM_TESTS=$((NUM_TESTS - 4)) |
| 48 | fi |
| 49 | |
| 50 | # Force abort on CRIT() to detect ABI conflicts |
| 51 | export LTTNG_UST_ABORT_ON_CRITICAL=1 |
| 52 | |
| 53 | plan_tests $NUM_TESTS |
| 54 | |
| 55 | ### |
| 56 | ## LD_PRELOAD tests |
| 57 | ### |
| 58 | |
| 59 | diag "LD_PRELOAD" |
| 60 | |
| 61 | ## App NOT linked on liblttng-ust |
| 62 | |
| 63 | "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 64 | ok $? "LD_PRELOAD: no-ust app works" |
| 65 | |
| 66 | LD_PRELOAD="${LIBFAKEUST0}" "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 67 | ok $? "LD_PRELOAD: no-ust app with abi0 preload succeeds" |
| 68 | |
| 69 | LD_PRELOAD="${LIBFAKEUST0}:${LIBUST1}" "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 70 | isnt $? 0 "LD_PRELOAD: no-ust app with abi0 and abi1 preload fails" |
| 71 | |
| 72 | LD_PRELOAD="${LIBUST1}:${LIBFAKEUST0}" "${CURDIR}/app_noust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 73 | isnt $? 0 "LD_PRELOAD: no-ust app with abi1 and abi0 preload fails" |
| 74 | |
| 75 | |
| 76 | ## App linked on liblttng-ust.so.1 |
| 77 | |
| 78 | "${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 79 | ok $? "LD_PRELOAD: ust app works" |
| 80 | |
| 81 | LD_PRELOAD="${LIBFAKEUST0}" "${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 82 | isnt $? 0 "LD_PRELOAD: ust app with abi0 preload fails" |
| 83 | |
| 84 | LD_PRELOAD="${LIBFAKEUST0}:${LIBUST1}" "${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 85 | isnt $? 0 "LD_PRELOAD: ust app with abi0 and abi1 preload fails" |
| 86 | |
| 87 | LD_PRELOAD="${LIBUST1}:${LIBFAKEUST0}" "${CURDIR}/app_ust" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 88 | isnt $? 0 "LD_PRELOAD: ust app with abi1 and abi0 preload fails" |
| 89 | |
| 90 | |
| 91 | ### |
| 92 | ## dlopen tests |
| 93 | ### |
| 94 | |
| 95 | diag "dlopen" |
| 96 | |
| 97 | ## App NOT linked on liblttng-ust |
| 98 | |
| 99 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 100 | ok $? "dlopen: no-ust app works" |
| 101 | |
| 102 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi1_abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 103 | ok $? "dlopen: no-ust app with abi1 and abi1 succeeds" |
| 104 | |
| 105 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi0_abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 106 | isnt $? 0 "dlopen: no-ust app with abi0 and abi1 fails" |
| 107 | |
| 108 | if [ "$UST_TESTS_LD_SYMBOLIC_FUNC" = "" ]; then |
| 109 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_noust_dlopen" abi1_abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 110 | isnt $? 0 "dlopen: no-ust app with abi1 and abi0 fails" |
| 111 | fi |
| 112 | |
| 113 | ## App linked on liblttng-ust.so.1 |
| 114 | |
| 115 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 116 | ok $? "dlopen: ust app works" |
| 117 | |
| 118 | if [ "$UST_TESTS_LD_SYMBOLIC_FUNC" = "" ]; then |
| 119 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 120 | isnt $? 0 "dlopen: ust app with abi0 fails" |
| 121 | |
| 122 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi0_abi1 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 123 | isnt $? 0 "dlopen: ust app with abi0 and abi1 fails" |
| 124 | |
| 125 | LD_LIBRARY_PATH="$LIBFAKEUST0_PATH:$LIBUST1_PATH" "${CURDIR}/app_ust_dlopen" abi1_abi0 >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 126 | isnt $? 0 "dlopen: ust app with abi1 and abi0 fails" |
| 127 | fi |
| 128 | |
| 129 | |
| 130 | ### |
| 131 | ## Indirect linking |
| 132 | ### |
| 133 | |
| 134 | diag "Indirect linking" |
| 135 | |
| 136 | ## App NOT linked on liblttng-ust |
| 137 | |
| 138 | "${CURDIR}/app_noust_indirect_abi0" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 139 | ok $? "indirect: no-ust app with abi0 succeeds" |
| 140 | |
| 141 | "${CURDIR}/app_noust_indirect_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 142 | ok $? "indirect: no-ust app with abi1 succeeds" |
| 143 | |
| 144 | "${CURDIR}/app_noust_indirect_abi0_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 145 | isnt $? 0 "indirect: no-ust app with abi0 and abi1 fails" |
| 146 | |
| 147 | ## App linked on liblttng-ust |
| 148 | |
| 149 | "${CURDIR}/app_ust_indirect_abi0" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 150 | isnt $? 0 "indirect: ust app with abi0 fails" |
| 151 | |
| 152 | "${CURDIR}/app_ust_indirect_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 153 | ok $? "indirect: ust app with abi1 succeeds" |
| 154 | |
| 155 | "${CURDIR}/app_ust_indirect_abi0_abi1" >"$STD_OUTPUT" 2>"$STD_ERROR" |
| 156 | isnt $? 0 "indirect: ust app with abi0 and abi1 fails" |